fix: 잔여 백로그 전건 처리 — 회계 예수금/1200%clip/환수가드/net경보 (PL 자율진행)

- fix(a, MED): 회계 분개에 원천세 예수금 leg 분리. (차)8350 지급수수료 gross /
  (대)2530 미지급금 net + (대)2540 예수금 원천세. 기존엔 미지급금에 gross 계상 +
  원천세 분개 누락. account_code '2540' 예수금 추가(V110), 분개쿼리 2-leg 전환.
- fix(b, HIGH): 1200%룰 1차년 한도초과 시 clip+이연. 한도잔여까지만 당월 지급,
  초과분만 분급(7년)으로 이연. 전액 이연 시 당월 원장 미생성 + 세액 재계산.
  (기존: 전액지급 + 전액 분급계획 → 설계 불일치)
- fix(e/f, HIGH/MED): 정착지원금/생보운영지원 환수액 ≤ 지원금 검증으로 net 음수 차단.
  AggregateStep net 음수(공제>지급) 경보 로깅 추가.
- (g) 검토결과 무변경: TaxCalculator/BatchTaxCalculator는 의도된 동일로직 쌍둥이,
  V80 매직팩터는 샘플시드일 뿐 계산경로 아님. 두 쌍둥이 모두 음수가드 적용됨.
- (d) 무변경: 승계 "최신 to_agent=현재귀속자"는 다단계체인에 정합, from==agent_id
  가드는 체인 회귀 유발하므로 정책확정 전 보류(문서화).
- test: CalcRecruitStepTest(clip+이연), SettlingSupportServiceTest(환수>지원 거부).
- 전체 build+test GREEN: 155건 0실패.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
GA Pro
2026-06-03 11:27:53 +09:00
parent 60c4cbae78
commit e2fdc88754
8 changed files with 207 additions and 30 deletions
@@ -97,32 +97,48 @@
recruit_ledger + maintain_ledger UNION → contract_id 포함.
AccountingEntryGenerateStep에서 호출.
-->
<!--
분개 구조 (원천세 반영, 차변합=대변합 균형):
(차) 8350 지급수수료 gross / (대) 2530 미지급금 net + (대) 2540 예수금 원천세
ledger 1건당 net leg(8350/2530) + tax leg(8350/2540, 원천세>0 일 때만) 로 분리 생성.
net = agent_amount COALESCE(tax_amount, 0)
-->
<select id="selectBySettleMonth" resultType="com.ga.core.vo.accounting.ContractAccountingEntryVO">
SELECT l.contract_id,
NULL::BIGINT AS payment_id,
CURRENT_DATE AS entry_date,
'8350' AS debit_account,
'2530' AS credit_account,
l.agent_amount AS amount,
CONCAT('모집수수료 ', l.settle_month) AS description,
l.settle_month AS settle_month,
NULL AS journal_no
<!-- 모집수수료: 미지급금(net) -->
SELECT l.contract_id, NULL::BIGINT AS payment_id, CURRENT_DATE AS entry_date,
'8350' AS debit_account, '2530' AS credit_account,
(l.agent_amount - COALESCE(l.tax_amount, 0)) AS amount,
CONCAT('모집수수료 미지급금 ', l.settle_month) AS description,
l.settle_month AS settle_month, NULL AS journal_no
FROM recruit_ledger l
WHERE l.settle_month = #{settleMonth}
AND l.agent_amount > 0
WHERE l.settle_month = #{settleMonth} AND l.agent_amount > 0
UNION ALL
SELECT l.contract_id,
NULL::BIGINT AS payment_id,
CURRENT_DATE AS entry_date,
'8350' AS debit_account,
'2530' AS credit_account,
l.agent_amount AS amount,
CONCAT('유지수수료 ', l.settle_month) AS description,
l.settle_month AS settle_month,
NULL AS journal_no
<!-- 모집수수료: 원천세 예수금 -->
SELECT l.contract_id, NULL::BIGINT, CURRENT_DATE,
'8350', '2540', l.tax_amount,
CONCAT('모집수수료 원천세 ', l.settle_month),
l.settle_month, NULL
FROM recruit_ledger l
WHERE l.settle_month = #{settleMonth} AND l.agent_amount > 0
AND COALESCE(l.tax_amount, 0) > 0
UNION ALL
<!-- 유지수수료: 미지급금(net) -->
SELECT l.contract_id, NULL::BIGINT, CURRENT_DATE,
'8350', '2530',
(l.agent_amount - COALESCE(l.tax_amount, 0)),
CONCAT('유지수수료 미지급금 ', l.settle_month),
l.settle_month, NULL
FROM maintain_ledger l
WHERE l.settle_month = #{settleMonth}
AND l.agent_amount > 0
WHERE l.settle_month = #{settleMonth} AND l.agent_amount > 0
UNION ALL
<!-- 유지수수료: 원천세 예수금 -->
SELECT l.contract_id, NULL::BIGINT, CURRENT_DATE,
'8350', '2540', l.tax_amount,
CONCAT('유지수수료 원천세 ', l.settle_month),
l.settle_month, NULL
FROM maintain_ledger l
WHERE l.settle_month = #{settleMonth} AND l.agent_amount > 0
AND COALESCE(l.tax_amount, 0) > 0
</select>
</mapper>