
    ͐wh                     `    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 Zd Zd Zd Zy)	    )datetimetime	timedeltaN)settings)Daytimes	RateListsTaxesc                 6   |j                         }|j                         }t        |  }t        | }t        j                  ||      }t        j                  ||      }	t        j                  ||      }
t        j                  ||      }d}||	k  rB||k\  r=t	        ||      }t        ||	      }||z
  j                         dz  }|t	        d|      z  }||k  rB||
k\  r=t	        ||
      }t        ||      }||z
  j                         dz  }|t	        d|      z  }|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_durations                   M/mnt/ACDE16A4DE16673C/PROJECTS/DRIVERZZ/DRIVERZZ_DRIVER_APIS/trips/helpers.pytotal_daytime_minutesr"   	   s,    NNENNE :&N?L !!%8J|4H!!%8J|4H MHj!8Iz2)X.'-7FFH2MQ 011Hj!8Iz2)X.'-7FFH2MQ 011    c                    t        j                  t        j                  t        j                  f      }dj                  d t        d      D              }d|z   }|j                  j                  | j                  dz  dd|ddd	t        | j                  j                        z   d
ddiddddddddiit        j                  dd	       |S )N)auth c              3   F   K   | ]  }t        j                  d         yw)>abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZN)randomchoice).0is     r!   	<genexpr>zcreate_order.<locals>.<genexpr>1   s     qrV]]+kls   !   #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_clientrA   s      r!   create_orderrV   /   s    ooH,D,DhFbFb+cdOGGv{|}v~  AL%L  ''//C'%s499#3#344
 4
 "& #!&

 !66 3) 8 r#   c                 D   	 d}t        j                  | j                  d      j                         }t        j                  t	        | j
                        dz   t	        |      z   d      }| j                  dk(  rgt        j                  | j                  d      j                         }t        j                  t	        | j                        dz   t	        |      z   d      }nft        j                  | j                  d      j                         }t        j                  t	        | j                        dz   t	        |      z   d      }||z
  }t        |j                         dz        }|dk\  rn5d|z
  }|t        |      z   }||z
  }t        |j                         dz        }t        j                  j!                  || j"                  d| j$                  	      j'                  d
      }	t        j                  j!                  || j"                  d| j$                  	      j'                  d
      }
t)        |	      dk(  rt        j                  j!                  || j"                  d| j$                        j'                  d      }	t        j                  j!                  || j"                  d| j$                        j'                  d      }
|	d   j*                  }|
d   j*                  }t,        j                  j/                  d      }t        j                  |j0                  d      j                         }t,        j                  j/                  d      }t        j                  |j0                  d      j                         }d}d}|j2                  |j4                  f}|j2                  |j4                  f}t7        ||||      }|j9                         |j9                         k(  r|dz  }||z
  }|||z  z  }|||z  z  }|S # t:        $ r}t=        |       Y d }~y d }~ww xY 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__ltr]   r^   r_   z	-duration)day_type)r   strptimetrip_start_timer   rP   trip_start_datestatusr   end_datetrip_end_timetrip_end_dateintr   r   r   objectsfilterr]   r_   order_bylenrater   r=   r   hourminuter"   r   	Exceptionprint)rT   r>   r   start_timestampr   end_timestamp
time_deltar   extra_minutesrate_day
rate_nightday_chargesnight_chargesr^   	day_startday_endday_minutesnight_minuteses                      r!   calculate_farer   R   s   <&&t';';ZHMMO
"++C0D0D,Ec,I#j/,Y[no;;!((
CHHJH$--c$--.@.DS].RTghM((););ZHMMOH$--c$2D2D.Ec.I#h-.WYlmM #_4
Z557;<C-M)Im,LLM&8J!9!9!;R ?@M$$++-X\XiXiqr  AE  AO  AO+  P  Y  Y  Zd  e&&--MZ^ZkZkst  CG  CQ  CQ-  R  [  [  \f  g
x=A ((//][_[l[ltu  DH  DR  DR/  S  \  \  ]h  iH"**11}]a]n]nvw  FJ  FT  FT1  U  ^  ^  _j  kJqk&&"1**""a"0%%cnnjAFFH	 ""a"0##CNNJ?DDF^^Y%5%56	<<0+IwQ^_ !]%7%7%99%/K &3+++--// as   O>P 	P
PPc           
          t         j                  j                         }|D ]2  }t        | t        | t        |j                        z  dz        z         } 4 | S )Nr0   )r	   rl   allfloattax_percentage)r>   taxestaxs      r!   calculate_taxesr      sU    MME QvfuS5G5G/H&H3&N OOPQ Mr#   )r   r   r   r)   DRIVERZZ_DRIVER_APISr   rates.modelsr   r   r	   rG   r"   rV   r   r    r#   r!   <module>r      s1    . .  ) 3 3 "L F=Dr#   