# payment — FRIDAY 消费(patient_settlement 头单级,status∈{1,3})
# 消费 transforms 输出表 payment_rows(lookup settlement_modes 已附主导通道 method)
# status=3(含退费行的单)头单仍是原始消费 → 入 payment;其退费行走 refund_item.yaml,
# LTV = Σpayment − Σrefund 自然对账。
canonical: payment

emits:
  action: payment_received
  subjectType: payment
  occurredAtField: paidAt

primary:
  table: payment_rows
  key: uuid
  dedup_by: uuid

field_mapping:
  externalId:          uuid
  updatedAt:           updated_gmt_at
  createdAt:           created_gmt_at
  patientExternalId:   patient_id
  clinicId:            organization_id
  paidAt:              created_gmt_at     # 结算入库时间(jvs-dw 同款决策:billing_date 有预付失真)
  # 2026-07 业务定调(与 jvs-dw payment.yaml 同步):amount=实付(net_receipts_this),
  # 与 refund_full/refund_item(net_receipts_this)同口径,LTV=实付收入−实付退款自洽;
  # 应收降级 receivableAmount(折扣率分母/权益客识别)。
  amount:              net_receipts_this
  receivableAmount:    receivable_this
  method:              method             # lookup 主导支付通道(现金/微信/刷卡/医保…原样入 fact)
  doctorId:            doctor_id
  encounterExternalId: registration_id    # 关联接诊
  settlementSerialNum: settlement_serial_num   # 结算流水号(passthrough,对账用)
