ó
    ˆ<Œj&  ã                   ó   • S r S rSS jrg)aÀ  
Pure comparison logic for the LE Capital -> DealerKit funding sync, added
2026-08-24 (Mark: "LE captial is the source of truth as this is the funding
platform, i need DK funding to match the LE portal", then "add a daily
automation to check funding status and add or settle the funding status on
DK, this can be done using this page ... 'current stock' and 'Stock
History' exports"). Kept separate from bidbrain/dealerkit_write.py (the
live browser automation that actually adds and settles records) and
bidbrain/readers/lecapital.py (the live page reading), so the actual
decision making, what needs adding, what needs settling, can be tested
without a browser at all.

LE Capital is treated as the source of truth throughout: a car it still
shows as actively funded (Current Stock) but DealerKit does not have, or
has marked settled, is a real gap to fix. A car LE Capital shows as settled
(Stock History) but DealerKit still shows live is settled here too. A
funded_value disagreement on a car both sides already agree is live is
never auto corrected, only flagged, same conservative stance already used
elsewhere in this project for a value disagreement (see CLAUDE.md,
HG17NRF's Assurance/Indemnity Fee note).
c                 ó�   • S U R                  S5       5       u  p#nUS-  US-
  -   U-   n[        US5      u  pgUS SUS-   S SUS 3$ )a×  date_iso is a "YYYY-MM-DD" string. Every real DealerKit funding
record on this account runs a fixed term (plan_starts_at plus N
calendar months exactly, proven live against EY69KYV: plan start
2026-05-01, expiry 2026-09-01, four months later to the day), so a new
record's own expiry is always computed this way rather than trusted to
DealerKit's own default (found live to fill in about 8 months out,
wrong, see add_funding_record's own docstring in dealerkit_write.py).c              3   ó8   #   • U  H  n[        U5      v •  M     g 7f)N)Úint)Ú.0Úxs     Ú6/Users/stevendouglas/BidBrain/bidbrain/funding_sync.pyÚ	<genexpr>Ú_add_months.<locals>.<genexpr>    s   é € Ð3Ò2˜!Œs�1�vˆvÒ2ùs   ‚Ú-é   é   Ú04dÚ02d)ÚsplitÚdivmod)Údate_isoÚmonthsÚyÚmÚdÚtotalÚy2Úm2s           r   Ú_add_monthsr      sa   € ñ 4˜xŸ~™~¨cÔ2Ó3�G€Aˆ!Ø�‰V�q˜1‘uÑ Ñ'€EÜ�E˜2Ó�F€BØ�ˆX�Q�r˜A‘v˜c�l ! A c 7Ð+Ð+ó    c           
      ó”  • U Vs0 s H  oDS   U_M
     nn/ nU  HG  nUS   nUR                  U5      n	U	b  M  UR                  UUS   US   [        US   U5      S.5        MI     / n
U Hc  nUS   nUR                  U5      n	U	c  M  U	R                  S5      S:X  d  M5  U	R                  S5      (       a  MM  U
R                  X‡S   S	.5        Me     / nU  Hh  nUR                  US   5      n	U	c  M  U	R                  S5      c  M0  [        U	S   US   -
  5      S
:”  d  MJ  UR                  US   US   U	S   S.5        Mj     XjUS.$ s  snf )aõ  le_current: bidbrain.readers.lecapital.read_current_stock's own
return shape (reg, funded_value, plan_starts_at, ...). le_history:
read_stock_history's own shape (reg, funded_value, plan_starts_at,
settled_on, ...). dk_funding: dealerkit_write.read_dk_funding_list's
own shape (reg, funding_status, funded_value, plan_starts_at,
funding_settled_at).

Returns {"to_add": [...], "to_settle": [...], "mismatched": [...]}.
to_add: dicts with reg, funded_value, plan_starts_at,
funding_expires_at, ready to pass straight to add_funding_record.
to_settle: dicts with reg, settled_on, ready to pass straight to
settle_funding_record.
mismatched: regs live on both sides with a real funded_value
difference, never auto corrected, just surfaced for Mark's own look.
ÚregÚfunded_valueÚplan_starts_at)r   r   r   Úfunding_expires_atÚfunding_statusÚliveÚfunding_settled_atÚ
settled_on)r   r#   g{®Gáz„?)r   Úle_capital_valueÚdealerkit_value)Úto_addÚ	to_settleÚ
mismatched)ÚgetÚappendr   Úabs)Ú
le_currentÚ
le_historyÚ
dk_fundingÚfunded_term_monthsÚrÚ	dk_by_regr&   Úcarr   Úexistingr'   r(   s               r   Ú	plan_syncr4   &   su  € ñ  '1Ó1¢j �5‘˜1’¡j€IÐ1à€FÛˆØ�%‰jˆØ—=‘= Ó%ˆØÓØ�M‰MØØ # NÑ 3Ø"%Ð&6Ñ"7Ü&1°#Ð6FÑ2GÐI[Ó&\ñ	ö ñ	 ð €IÛˆØ�%‰jˆØ—=‘= Ó%ˆØÓ H§L¡LÐ1AÓ$BÀfÕ$LØ Ÿ™Ð%9×:Ó:Ø×Ñ S¸LÑ8IÑJÖKñ ð €JÛˆØ—=‘=  U¡Ó,ˆØÓ H§L¡L°Ó$@Ó$LÜ˜ Ñ0°3°~Ñ3FÑFÓGÈ$ÕNØ×ÑØ˜5‘zØ$'¨Ñ$7Ø#+¨NÑ#;ñö ñ	 ð ÀJÑOÐOùòK 2s   …EN)é   )Ú__doc__r   r4   © r   r   Ú<module>r8      s   ðñò.,õ5Pr   