
    /j~	                         d dl mZ d dlmZmZmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZmZmZmZmZ eeeedZd	 Z ej,                  d
      d        Z ej,                  ddg      d        Zy)    )Decimal)jsonifyrequestabort)api_bp)db)Account)Settings)calculate_avalanchecalculate_snowballcalculate_highest_balancecalculate_proportionalcalculate_custom)	avalanchesnowballhighest_balanceproportionalc            
         t         j                  j                  dd      j                         } | D cg c]  }|j                  xs t        d      t        d      kD  ra|j                  |j                  |j                  xs t        d      |j                  xs t        d      |j                  xs t        d      d c}S c c}w )NcreditT)type	is_active0)idnamebalanceaprmin_payment)
r	   query	filter_byallcurrent_balancer   r   r   r   r   )cardscs     6/var/www/html/financials/app/blueprints/api/paydown.py_credit_card_dictsr%      s    MM##T#BFFHE 
 -= $$FF((8GCL55(GCL==8GCL	

 
 
s   BCz!/paydown/schedule/<strategy_name>c                     | t         vr| dk7  rt        d       t               }t        j                  j                         }|r|j                  n
t        d      }| dk(  rt        |i       }nt        |    ||      }t        |j                        S )Ncustomi  r   )_STRATEGY_CALCr   r%   r
   r   firstextra_monthly_paymentr   r   r   per_card_schedule)strategy_name
card_dictssettingsextraresults        r$   paydown_scheduler1   %   s{    N*}/Hc
#%J~~##%H.6H**GCLE !*b1.z5A6++,,    z/paydown/calculate-customPOST)methodsc                     t        j                  d      xs i } t               }i }|D ]=  }t        |d         }t        | j	                  |d            }	 t        |      ||d   <   ? t        ||      }t        |j                  |j                  t        |j                        |j                  j                         |j                  d      S # t        $ r t        d      ||d   <   Y w xY w)zERecalculate the custom strategy with user-specified per-card amounts.T)silentr   r   )strategymonths_to_payofftotal_interest_paidpayoff_dater+   )r   get_jsonr%   strgetr   	Exceptionr   r   r7   r8   r9   r:   	isoformatr+   )datar-   allocationscardkeyrawr0   s          r$   calculate_custom_strategyrE   6   s     4(.BD#%JK 3$t*o$((3$%	3&-clKT
#	3 j+6FOO"33"6#=#=>))335#55    	3&-clKT
#	3s   CC,+C,N)decimalr   flaskr   r   r   app.blueprints.apir   app.extensionsr   app.models.accountr	   app.models.settingsr
   app.services.amortizationr   r   r   r   r   r(   r%   router1   rE    r2   r$   <module>rO      s     ) ) %  & (  +)0-	 12- 3-  )F8< =r2   