o
    Shz                      @   sp   d dl m Z mZmZ d dlZd dlmZ d dlmZmZm	Z	 d dl
Z
dd Zdd Zd	d
 Zdd Zdd ZdS )    )datetimetime	timedeltaN)settings)Daytimes	RateListsTaxesc              
   C   s  zKd}t | jd }t t| jd t| d}| jdkr:t | jd }t t| jd t| d}nt | j	d }t t| j
d t| d}|| }t| d }|dkrcnd| }|t|d }|| }t| d }tjj|| jd| jd	d
}	tjj|| jd| jd	d
}
t|	dkrtjj|| jd| jdd}	tjj|| jd| jdd}
|	d j}|
d j}tdt|  tdt|  tjjdd}t |jd }tjjdd}t |jd }d}d}|j|jf}|j|jf}t||||}| | kr|d }|| }tdt|  tdt|  tdt|  ||| 7 }||| 7 }tdt|  |W S  tyd } zt| W Y d }~d S d }~ww )Nr   %I:%M %p %Y-%m-%d %H:%M:%S   <   x   minutes)duration__gtestation_typeday	trip_typeduration   )duration__ltr   r   r   	-durationzday charge : znight charge : day_typeztotal_minutes : zday_minutes : znight_minutes : ztotal_amount : )r   strptimetrip_start_timer   strtrip_start_datestatusend_timeend_datetrip_end_timetrip_end_dateinttotal_secondsr   r   objectsfilterr   r   order_bylenrateprintr   get
start_timehourminutetotal_daytime_minutesdate	Exception)tripamountr-   start_timestampr    end_timestamp
time_deltatotal_minutesextra_minutesrate_day
rate_nightday_chargesnight_chargesr   	day_startday_endday_minutesnight_minutese rC   2/var/www/html/DRIVERZZ_ADMIN_APIS/trips/helpers.pycalculate_fare	   sb   
 

rE   c                 C   s  d}t | jd }t t| jd t| d}t | jd }t t| jd t| d}|| }t|	 d }|dkrCnd| }|t
|d }|| }t|	 d }tjj|| j| jd| jdd	}	tjj|| j| jd
| jdd	}
t|	dkrtjj|| j| jd| jdd}	tjj|| j| jd
| jdd}
|	d j}|
d j}tjjdd}t |jd }tjjd
d}t |jd }d}d}|j|jf}|j|jf}t||||}| | kr|d }|| }||| 7 }||| 7 }t| |S )Nr   r	   r
   r   r   r   r   )r   r   uniform_typer   r   r   r   )r   r   rF   r   r   r   r   r   )r   r   r-   r   r   
start_dater    r!   r$   r%   r   r   r&   r'   r   rF   r   r(   r)   r*   r   r,   r.   r/   r0   r1   r+   )r3   r4   r-   r5   r    r6   r7   r8   r9   r:   r;   r<   r=   r   r>   r?   r@   rA   rC   rC   rD   calculate_estimated_fareT   sH   """"

rH   c                 C   s:   | }t j }|D ]}t|t| t|j d  }q	|S )Nd   )r   r&   allfloattax_percentage)r4   trip_amounttaxestaxrC   rC   rD   calculate_taxes   s
   
 rP   c                 C   s   |  }|  }t|  }t| }t||}t||}	t||}
t||}d}||	krK||krKt||}t||	}||  d }|td|7 }||krl||
krlt||
}t||}||  d }|td|7 }|S )Nr   r   )r1   r   r   combinemaxminr%   )r-   r    	datetime1	datetime2date1date2start_time_objend_time_obj
day_start1day_end1
day_start2day_end2r8   overlap_startoverlap_endoverlap_durationrC   rC   rD   r0      s(   



r0   c                 C   s   t jtjtjfd}ddd tdD }d| }|j| j	d dd	|ddd
t
| jj dddidddddd	d	diitjdd	 |S )N)auth c                 s   s    | ]}t d V  qdS )>abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZN)randomchoice).0irC   rC   rD   	<genexpr>   s    zcreate_order.<locals>.<genexpr>   #rI   INRFz+91)nameemailcontactsmsTcheckoutmethod)
netbankingcardupiwalletpaylaterr,   )	r4   currencyaccept_partialreference_idcustomernotifyoptionscallback_urlcallback_method)razorpayClientr   RAZORPAY_KEY_IDRAZORPAY_KEY_SECRETjoinrangepayment_linkcreate
net_amountr   usermobileRAZORPAY_CALLBACK_URL)r3   razorpay_clientry   rC   rC   rD   create_order   s8   r   )r   r   r   rd   DRIVERZZ_ADMIN_APISr   rates.modelsr   r   r   r   rE   rH   rP   r0   r   rC   rC   rC   rD   <module>   s    K<	'