o
    h                     @   sh   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S )    )datetimetime	timedeltaN)settings)Daytimes	RateListsTaxesc                 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   <   )dater   r   combinemaxmintotal_seconds)
start_timeend_time	datetime1	datetime2date1date2start_time_objend_time_obj
day_start1day_end1
day_start2day_end2total_minutesoverlap_startoverlap_endoverlap_duration r   3/var/www/html/DRIVERZZ_DRIVER_APIS/trips/helpers.pytotal_daytime_minutes	   s(   



r!   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ir   r   r    	<genexpr>1   s    zcreate_order.<locals>.<genexpr>   #d   INRFz+91)nameemailcontactsmsTcheckoutmethod)
netbankingcardupiwalletpaylaterget)	amount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_amountstrusermobileRAZORPAY_CALLBACK_URL)triprazorpay_clientr=   r   r   r    create_order/   s8   rR   c              
   C   sj  zd}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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 }|W S  ty4 } zt| W Y d }~d S d }~ww )Nr   z%I:%M %p z%Y-%m-%d %H:%M:%S   r	   x   )minutes)duration__gtestation_typeday	trip_typeduration   )duration__ltrX   rY   rZ   z	-duration)day_type)r   strptimetrip_start_timer   rL   trip_start_datestatusr   end_datetrip_end_timetrip_end_dateintr   r   r   objectsfilterrX   rZ   order_bylenrater   r9   r   hourminuter!   r
   	Exceptionprint)rP   r:   r   start_timestampr   end_timestamp
time_deltar   extra_minutesrate_day
rate_nightday_chargesnight_chargesrY   	day_startday_endday_minutesnight_minuteser   r   r    calculate_fareR   sV   
 

r}   c                 C   s6   t j }|D ]}t| t| t|j d  } q| S )Nr,   )r   rg   allfloattax_percentage)r:   taxestaxr   r   r    calculate_taxes   s   
 r   )r   r   r   r%   DRIVERZZ_DRIVER_APISr   rates.modelsr   r   r   rC   r!   rR   r}   r   r   r   r   r    <module>   s    &#B