finance
Tables (20)
audit_llm_call
- id — uuid — Primary key — NOT NULL
- clinic_id — bigint — NOT NULL
- endpoint — text — NOT NULL
- model — text — NOT NULL
- status — text — NOT NULL
- error_code — text
- error_message — text
- request_payload — jsonb
- response_payload — jsonb
- finish_reason — text
- latency_ms — integer
- prompt_token_count — integer — NOT NULL
- completion_token_count — integer — NOT NULL
- thought_token_count — integer — NOT NULL
- total_token_count — integer — NOT NULL
- estimated_cost_usd — numeric(12,6)
- occurred_at — timestamptz — NOT NULL
- retention_expires_at — timestamptz — NOT NULL
barobill_bank_transaction
- id — uuid — Primary key — NOT NULL
- clinic_id — bigint — NOT NULL
- connection_id — uuid — Foreign key → barobill_connection.id — NOT NULL
- external_transaction_key — text — NOT NULL
- transaction_at — timestamptz — NOT NULL
- direction — text — NOT NULL
- amount — bigint — NOT NULL
- balance_after — bigint
- summary — text
- raw_payload — jsonb — NOT NULL
- first_ingested_at — timestamptz — NOT NULL
- last_ingested_at — timestamptz — NOT NULL
barobill_card_transaction
- id — uuid — Primary key — NOT NULL
- clinic_id — bigint — NOT NULL
- connection_id — uuid — Foreign key → barobill_connection.id — NOT NULL
- external_transaction_key — text — NOT NULL
- transaction_at — timestamptz — NOT NULL
- transaction_kind — text — NOT NULL
- original_transaction_key — text
- amount — bigint — NOT NULL
- merchant_name — text
- merchant_business_type — text
- merchant_tax_type — integer
- raw_payload — jsonb — NOT NULL
- first_ingested_at — timestamptz — NOT NULL
- last_ingested_at — timestamptz — NOT NULL
barobill_cash_receipt
- id — uuid — Primary key — NOT NULL
- clinic_id — bigint — NOT NULL
- connection_id — uuid — Foreign key → barobill_connection.id — NOT NULL
- trade_direction — text — NOT NULL
- transaction_kind — text — NOT NULL
- nts_confirmation_number — text — NOT NULL
- original_confirmation_number — text
- transaction_at — timestamptz — NOT NULL
- merchant_business_number — text
- merchant_name — text
- total_amount — bigint — NOT NULL
- raw_payload — jsonb — NOT NULL
- first_ingested_at — timestamptz — NOT NULL
- last_ingested_at — timestamptz — NOT NULL
barobill_connection
- id — uuid — Primary key — NOT NULL
- clinic_id — bigint — NOT NULL
- source_kind — text — NOT NULL
- identifier_encrypted — text — NOT NULL
- identifier_hash — text — NOT NULL
- identifier_last4 — text
- identifier_key_version — smallint — NOT NULL
- label — text — NOT NULL
- status — text — NOT NULL
- collect_cycle — text
- connected_at — timestamptz — NOT NULL
- stopped_at — timestamptz
- last_synced_at — timestamptz
- last_sync_attempted_at — timestamptz
- last_sync_status — text
- last_sync_error — text
- last_sync_row_count — integer
- raw_payload — jsonb
- created_at — timestamptz — NOT NULL
- updated_at — timestamptz — NOT NULL
barobill_tax_invoice
- id — uuid — Primary key — NOT NULL
- clinic_id — bigint — NOT NULL
- connection_id — uuid — Foreign key → barobill_connection.id — NOT NULL
- trade_direction — text — NOT NULL
- nts_send_key — text — NOT NULL
- partner_business_number — text
- partner_name — text
- invoice_date — date
- supply_amount — bigint — NOT NULL
- tax_amount — bigint — NOT NULL
- total_amount — bigint
- original_nts_send_key — text
- correction_reason_code — text
- item_name — text
- raw_payload — jsonb — NOT NULL
- first_ingested_at — timestamptz — NOT NULL
- last_ingested_at — timestamptz — NOT NULL
fin_account
- id — uuid — Primary key — NOT NULL
- clinic_id — bigint — NOT NULL
- code — text — NOT NULL
- name — text — NOT NULL
- category — text — NOT NULL
- sort_order — smallint — NOT NULL
- is_active — boolean — NOT NULL
- created_at — timestamptz — NOT NULL
- updated_at — timestamptz — NOT NULL
fin_approval
- id — uuid — Primary key — NOT NULL
- clinic_id — bigint — NOT NULL
- document_type — text — NOT NULL
- status — text — NOT NULL
- title — text — NOT NULL
- vendor_name — text — NOT NULL
- amount — bigint — NOT NULL
- document_date — date — NOT NULL
- requested_payment_date — date — NOT NULL
- payment_method — text — NOT NULL
- body — text — NOT NULL
- attachment_path — text
- created_by_user_id — bigint — NOT NULL
- executor_user_id — bigint
- completed_at — timestamptz
- deleted_at — timestamptz
- deleted_by_user_id — bigint
- created_at — timestamptz — NOT NULL
- updated_at — timestamptz — NOT NULL
fin_approval_event
- id — uuid — Primary key — NOT NULL
- clinic_id — bigint — NOT NULL
- approval_id — uuid — Foreign key → fin_approval.id — NOT NULL
- approval_step_id — uuid — Foreign key → fin_approval_step.id
- actor_user_id — bigint — NOT NULL
- event_type — text — NOT NULL
- before_status — text
- after_status — text
- reason — text
- metadata — jsonb — NOT NULL
- transaction_id — bigint — NOT NULL
- occurred_at — timestamptz — NOT NULL
fin_approval_step
- id — uuid — Primary key — NOT NULL
- clinic_id — bigint — NOT NULL
- approval_id — uuid — Foreign key → fin_approval.id — NOT NULL
- step_order — smallint — NOT NULL
- reviewer_user_id — bigint — NOT NULL
- status — text — NOT NULL
- decision_reason — text
- decided_at — timestamptz
- decided_by_user_id — bigint
- created_at — timestamptz — NOT NULL
- updated_at — timestamptz — NOT NULL
fin_expense
- id — uuid — Primary key — NOT NULL
- clinic_id — bigint — NOT NULL
- source_type — text — NOT NULL
- tax_invoice_id — uuid — Foreign key → barobill_tax_invoice.id
- cash_receipt_id — uuid — Foreign key → barobill_cash_receipt.id
- card_transaction_id — uuid — Foreign key → barobill_card_transaction.id
- occurred_at — timestamptz — NOT NULL
- accounting_date — date — NOT NULL
- vendor_name — text
- amount — bigint — NOT NULL
- evidence_type — text — NOT NULL
- memo — text
- created_by_user_id — bigint
- deleted_at — timestamptz
- deleted_by_user_id — bigint
- created_at — timestamptz — NOT NULL
- updated_at — timestamptz — NOT NULL
fin_expense_approval
- expense_id — uuid — Foreign key → fin_expense.id — NOT NULL
- clinic_id — bigint — NOT NULL
- approval_id — uuid — Foreign key → fin_approval.id — NOT NULL
- linked_by_user_id — bigint — NOT NULL
- linked_at — timestamptz — NOT NULL
fin_expense_classification
- expense_id — uuid — Foreign key → fin_expense.id — NOT NULL
- clinic_id — bigint — NOT NULL
- account_id — uuid — Foreign key → fin_account.id — NOT NULL
- classified_by_user_id — bigint — NOT NULL
- classified_at — timestamptz — NOT NULL
- updated_at — timestamptz — NOT NULL
fin_herb_product
- id — uuid — Primary key — NOT NULL
- clinic_id — bigint — NOT NULL
- name — text — NOT NULL
- selling_price_amount — bigint — NOT NULL
- material_cost_amount — bigint — NOT NULL
- sort_order — smallint — NOT NULL
- is_active — boolean — NOT NULL
- created_at — timestamptz — NOT NULL
- updated_at — timestamptz — NOT NULL
fin_monthly_budget
- clinic_id — bigint — Primary key — NOT NULL
- month — date — Primary key — NOT NULL
- account_id — uuid — Foreign key → fin_account.id — NOT NULL
- approved_amount — bigint — NOT NULL
- is_enabled — boolean — NOT NULL
- approved_by_user_id — bigint — NOT NULL
- approved_at — timestamptz — NOT NULL
- updated_by_user_id — bigint — NOT NULL
- created_at — timestamptz — NOT NULL
- updated_at — timestamptz — NOT NULL
fin_pnl_adjustment
- id — uuid — Primary key — NOT NULL
- clinic_id — bigint — NOT NULL
- month — date — NOT NULL
- account_id — uuid — Foreign key → fin_account.id — NOT NULL
- amount — bigint — NOT NULL
- reason — text — NOT NULL
- created_by_user_id — bigint — NOT NULL
- created_at — timestamptz — NOT NULL
fin_pnl_member_monthly
- clinic_id — bigint — Primary key — NOT NULL
- member_user_id — bigint — Primary key — NOT NULL
- month — date — Primary key — NOT NULL
- member_kind — text — NOT NULL
- salary_amount — bigint — NOT NULL
- incentive_amount — bigint — NOT NULL
- weekly_hours — numeric(5,2) — NOT NULL
- created_by_user_id — bigint — NOT NULL
- updated_by_user_id — bigint — NOT NULL
- created_at — timestamptz — NOT NULL
- updated_at — timestamptz — NOT NULL
notification_delivery
- id — uuid — Primary key — NOT NULL
- clinic_id — bigint — NOT NULL
- recipient_user_id — bigint — NOT NULL
- notification_type — text — NOT NULL
- target_date — date — NOT NULL
- provider — text — NOT NULL
- template_kind — text
- recipient_phone_last4 — text
- expense_count — integer
- total_amount — bigint
- payload_prepared_at — timestamptz
- status — text — NOT NULL
- provider_group_id — text
- provider_message_id — text
- provider_status_code — text
- provider_status_message — text
- error_message — text
- claim_token — uuid — NOT NULL
- claimed_at — timestamptz — NOT NULL
- claim_expires_at — timestamptz — NOT NULL
- next_retry_at — timestamptz
- accepted_at — timestamptz
- created_at — timestamptz — NOT NULL
- updated_at — timestamptz — NOT NULL
notification_delivery_attempt
- id — uuid — Primary key — NOT NULL
- delivery_id — uuid — Foreign key → notification_delivery.id — NOT NULL
- attempt_number — smallint — NOT NULL
- status — text — NOT NULL
- provider_group_id — text
- provider_message_id — text
- provider_status_code — text
- provider_status_message — text
- error_message — text
- attempted_at — timestamptz — NOT NULL
notification_preference
- clinic_id — bigint — Primary key — NOT NULL
- user_id — bigint — Primary key — NOT NULL
- notification_type — text — Primary key — NOT NULL
- is_enabled — boolean — NOT NULL
- send_hour — smallint — NOT NULL
- timezone_name — text — NOT NULL
- updated_by_user_id — bigint — NOT NULL
- created_at — timestamptz — NOT NULL
- updated_at — timestamptz — NOT NULL