ó
    Í«ªj»  ã                   ó¦   • S r SSKrSSKrSSKr\R                  " S5      rSrSrSrSr	Sr
S	r\R                  " S
5      rS rS rS r\" 5       rS rg)a¢  Outstanding finance on a bought car, read from the platform's own
purchase page (2026-09-16, Steven: "some cars that are on finance have
negative equity as the price we agree to pay for the car is less than what
the seller currently owes. Carwow and motorway both track this").

Both platforms settle the seller's finance out of the dealer's payment on
collection (Motorway through Motorway Pay, Carwow through the dealer), and
when the settlement figure is more than the price agreed the seller pays
the shortfall, the negative equity, to the platform before the car moves.
What the dealer needs on file is the settlement figure (DealerKit's own
Stocklisting step has a finance settlement field for it) and the negative
equity, so the car is marked NEGATIVE EQUITY here and the office knows the
logbook waits on the seller's shortfall.

The exact words each platform prints are read from the purchase summary
page's own text, label by label, the same way the payment breakdown is.
Every line mentioning finance, settlement or equity is written to the
platform's detail log once per car, so the labels below can be tightened
against the real wording after the first read. Pure, tested.
é    Nu   Â£\s*([\d,]+)(?:\.(\d{2}))?)zsettlement amountzfinance settlementzsettlement figurezoutstanding finance settlementzoutstanding financezfinance to settleÚ
settlementúamount to finance company)r   )zamount to sellerzamount to youzpaid to sellerzseller receives)znegative equityÚ	shortfallzseller to payzseller payszamount due from sellerzseller contributionzseller shortfall)zfinal vehicle priceúvehicle price)ÚfinanceÚsettleÚequityr   Úlenderzhp Úpcpz^\.(\d{2})$c                 ój  • XS-   4 GH(  nU[        U 5      :  d  M  [        R                  X   5      nU(       d  M5  X!:X  d(  X   R                  5       R	                  S5      (       d  Mb  [        UR                  S5      R                  SS5      5      nUR                  S5      (       a$  U[        UR                  S5      5      S-  -  nUs  $ US-   [        U 5      :  aO  [        R                  XS-      R                  5       5      nU(       a   U[        UR                  S5      5      S-  -  nUs  $    g)u»   The money on line i, else on line i+1 (Motorway's two line split),
with the pence Motorway prints on the line after the pounds ("Â£10,370"
then ".04", seen live 2026-09-16) added back on.é   ô   Â£Ú,Ú é   éd   N)ÚlenÚMONEYÚsearchÚlstripÚ
startswithÚfloatÚgroupÚreplaceÚ
PENCE_LINEÚmatchÚstrip)ÚlinesÚiÚjÚmÚvalueÚpms         Ú?/Users/stevendouglas/BidBrain/bidbrain/readers/finance_lines.pyÚ	_money_atr%   .   sú   € ð �Q‘ŒZˆØŒs�5‹z�>Ü—‘˜U™XÓ&ˆAßˆq�a“f ¡§¡Ó 1× <Ñ <¸T× BÓ BÜ˜aŸg™g a›j×0Ñ0°°bÓ9Ó:�Ø—7‘7˜1—:‘:ØœU 1§7¡7¨1£:Ó.°Ñ4Ñ4�Eð
 ’ð	 ˜‘UœS ›ZÓ'Ü#×)Ñ)¨%°A±©,×*<Ñ*<Ó*>Ó?�BÞØ¤ r§x¡x°£{Ó!3°cÑ!9Ñ9˜Ø’ñ ð ó    c                 ó  • U Hƒ  n[        U 5       Hq  u  p4UR                  5       R                  S5      nXR:X  d4  UR                  US-   5      (       d  UR                  US-   5      (       d  M]  [	        X5      nUc  Mm  Us  s  $    M…     g)zÂThe first label in `labels` order that has a figure, wherever it
sits on the page: label order is priority, not page order (Carwow
prints the amount to the finance company above the settlement).z :Ú Ú:N)Ú	enumerateÚlowerr   r   r%   )r   ÚlabelsÚlabr   ÚlÚlowÚvs          r$   Ú	_labelledr1   A   su   € ó ˆÜ˜eÖ$‰DˆAØ—'‘'“)—/‘/ $Ó'ˆCØ‹z˜SŸ^™^¨C°#©I×6Ñ6¸#¿.¹.ÈÈsÉ×:SÓ:SÜ˜eÓ'�Ø“=Ø”Hó %ñ ð r&   c           
      ó�  ^	• U =(       d    SR                  5        Vs/ s H)  oR                  5       (       d  M  UR                  5       PM+     nn[        U[        5      n[        U[        5      n[        U[
        5      nUc)  Ub&  [        U[        5      nUb  X6:”  a  [        X6-
  S5      n/ n[        U5       H‚  u  p�UR                  5       m	[        U5      S::  aM  [        U	4S j[        S-    5       5      (       a,  UR                  SR                  S X(US-     5       5      5        [        U5      S	:¼  d  M‚    O   X5XGS
.$ s  snf )a�  {finance_settlement, negative_equity, to_finance_company, finance_lines}
from a purchase page's text. A figure is only ever read from a
labelled line; the negative equity is worked out from settlement less
vehicle price when the page names no shortfall itself. None for
anything not on the page. finance_lines carries each matching line
with the two lines after it, short, for the log.r   r   éP   c              3   ó,   >#   • U  H	  oT;   v •  M     g 7f)N© )Ú.0Úwr/   s     €r$   Ú	<genexpr>Ú-finance_from_purchase_text.<locals>.<genexpr>a   s   øé € ÐZÒ2Y¨Q S¦Ò2Yùs   ƒ)z	amount tor   z / c              3   ó*   #   • U  H	  oS S v •  M     g 7f)Né<   r5   )r6   Úxs     r$   r8   r9   b   s   é € Ð"B²>¨a S b¥6²>ùs   ‚é   é   )Úfinance_settlementÚnegative_equityÚto_finance_companyÚfinance_lines)Ú
splitlinesr   r1   ÚSETTLEMENT_LABELSÚFINANCE_COMPANY_LABELSÚNEGATIVE_LABELSÚVEHICLE_PRICE_LABELSÚroundr*   r+   r   ÚanyÚ_WORDSÚappendÚjoin)
Útextr.   r   r   Ú
to_companyÚnegativeÚpriceÚhitsr   r/   s
            @r$   Úfinance_from_purchase_textrR   O   s  ø€ ð "&§¨× 7Ñ 7Ô 9ÓGÒ 9˜1¿W¹W¿Y‹YˆQ�W‰WŽYÑ 9€EÐGÜ˜5Ô"3Ó4€JÜ˜5Ô"8Ó9€JÜ˜¤Ó0€HØÑ˜JÑ2Ü˜%Ô!5Ó6ˆØÑ Ó!3Ü˜ZÑ/°Ó3ˆHØ€DÜ˜%Ö ‰ˆØ�g‰g‹iˆÜˆq‹6�R‹<œCÔZ´&Ð;YÒ2YÓZ×ZÑZØ�K‰K˜Ÿ
™
Ñ"B°5¸1¸q¹5±>Ó"BÓBÔCÜˆt‹9˜�?Ùñ !ð #-Ðakñ  Dð  Dùò Hs
   �E¹Ec                 óè  • X4nU[         ;   d  UR                  S5      (       d  g[         R                  U5         [        R                  R                  [        R                  R                  [        R                  R                  [        R                  R                  [        5      5      5      5      n[        R                  R                  USS5      n[        R                  " USS9  [        [        R                  R                  XP S35      S5       nUR                  U  S	[        R                  R                  5       R                  S
S9 SU S35        US    H  nUR                  SUSS  S35        M     UR                  SUR                  S5      < SUR                  S5      < SUR                  S5      < S35        SSS5        g! , (       d  f       g= f! [         a     gf = f)zÀOnce per car per process: the finance lines and what was read from
them, into data/logs/<platform>_detail.log (already sent to Dealer OS
with the diagnostics), so the real wording can be seen.rB   NÚdataÚlogsT)Úexist_okz_detail.logÚaz purchase finance lines Úseconds)Útimespecz for z:
z  fin | éÈ   Ú
z  read as: settlement r?   z, to finance company rA   z, negative equity r@   )Ú_notedÚgetÚaddÚosÚpathÚdirnameÚabspathÚ__file__rL   ÚmakedirsÚopenÚwriteÚdatetimeÚnowÚ	isoformatÚ	Exception)ÚplatformÚregÚfoundÚkeyÚrootrU   ÚfÚhits           r$   Úfinance_lines_noterr   k   s½  € ð ˆ/€CØ
Œfƒ}˜EŸI™I o×6Ñ6ØÜ
‡J�Jˆs„OðÜ�w‰w�‰œrŸw™wŸ™¬r¯w©w¯©¼r¿w¹w¿¹ÌxÓ?XÓ/YÓZÓ[ˆÜ�w‰w�|‰|˜D &¨&Ó1ˆÜ
�Š�D 4Ò(Ü”"—'‘'—,‘,˜t z°Ð%=Ó>ÀÔDÈð �G‰G�x�jÐ 8¼×9JÑ9J×9NÑ9NÓ9P×9ZÑ9ZÐdmÐ9ZÐ9nÐ8oÐotÐuxÐtyÐy|Ð}Ô~Ø˜_Ô-�Ø—‘˜( 3 t¨ 9 +¨RÐ0Ö1ñ .à�G‰GÐ,¨U¯Y©YÐ7KÓ-LÑ,OÐOdÐej×enÑenð  pDó  fEñ  eHð  HZð  [`÷  [dñ  [dð  evó  [wñ  Zzð  z|ð  }ô  ~÷ E×DÖDûô ó Ùðús1   »CG$ ÄB3GÇ
G$ Ç
G!ÇG$ Ç!G$ Ç$
G1Ç0G1)Ú__doc__rg   r_   ÚreÚcompiler   rD   rE   ÚSELLER_LABELSrF   rG   rJ   r   r%   r1   rR   Úsetr\   rr   r5   r&   r$   Ú<module>rx      sx   ðñó( Û 	Û 	à
�
Š
Ð1Ó2€ðlÐ à7Ð ØZ€ð>€à?Ð Ø	M€ð �ZŠZ˜Ó'€
òò&òDñ2 
‹€ór&   