
    g                     f    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d	 Zy)
    )datetimetime	timedeltaN)settings)Daytimes	RateListsTaxesc                 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   %I:%M %p %Y-%m-%d %H:%M:%S   <   x   minutes)duration__gtestation_typeday	trip_typeduration   )duration__ltr   r   r   	-durationday_type)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rater   get
start_timehourminutetotal_daytime_minutesdate	Exceptionprint)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es                      L/mnt/ACDE16A4DE16673C/PROJECTS/DRIVERZZ/DRIVERZZ_ADMIN_APIS/trips/helpers.pycalculate_farerF   	   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                    d}t        j                  | j                  d      j                         }t        j                  t	        | j
                        dz   t	        |      z   d      }t        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                  | j                  d| j                         j#                  d	      }	t        j                  j                  || j                  | j                  d
| j                         j#                  d	      }
t%        |	      dk(  rt        j                  j                  || j                  | j                  d| j                         j#                  d      }	t        j                  j                  || j                  | j                  d
| j                         j#                  d      }
|	d   j&                  }|
d   j&                  }t(        j                  j+                  d      }t        j                  |j                  d      j                         }t(        j                  j+                  d
      }t        j                  |j                  d      j                         }d}d}|j,                  |j.                  f}|j,                  |j.                  f}t1        ||||      }|j3                         |j3                         k(  r|dz  }||z
  }|||z  z  }|||z  z  }t5        |       |S )Nr   r   r   r   r   r   r   )r   r   uniform_typer   r   r   r   )r   r   rH   r   r   r   r   r   )r   r   r.   r   r   
start_dater"   r#   r&   r'   r   r   r(   r)   r   rH   r   r*   r+   r,   r   r-   r/   r0   r1   r2   r4   )r5   r6   r.   r7   r"   r8   r9   r:   r;   r<   r=   r>   r?   r   r@   rA   rB   rC   s                     rE   calculate_estimated_farerJ   K   s   F""4??J?DDFJ''DOO(<S(@Z(PRefO  
;@@BH%%c$--&8&<S]&JL_`M0J113R78MM)%	-(HH"_4
Z557;<  ''mTXTeTevz  wH  wH  PQ  _c  _m  _m'  n  w  w  xB  CH""))VZVgVgx|  yJ  yJ  RS  ae  ao  ao)  p  y  y  zD  EJ
8}$$++W[WhWhz~  {L  {L  TU  cg  cq  cq+  r  {  {  |G  H&&--=Y]YjYj  }A  }N  }N  VW  ei  es  es-  t  }  }  ~I  J
1+""KqM&&M




!

,C!!#..*=BBDI 



!

,C
;@@BGKM!1!12I||W^^,G'	7O][K !3!3!55!Ao "K/M
kK''F
mm++F	&MM    c           
          t         j                  j                         }|D ]2  }t        | t        | t        |j                        z  dz        z         } 4 | S )Nd   )r	   r(   allfloattax_percentage)r6   taxestaxs      rE   calculate_taxesrS      sU    MME QvfuS5G5G/H&H3&N OOPQ MrK   c                 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   r   )r2   r   r   combinemaxminr'   )r.   r"   	datetime1	datetime2date1date2start_time_objend_time_obj
day_start1day_end1
day_start2day_end2r:   overlap_startoverlap_endoverlap_durations                   rE   r1   r1      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rK   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     rE   	<genexpr>zcreate_order.<locals>.<genexpr>   s     qrV]]+kls   !   #rM   INRFz+91)nameemailcontactsmsTcheckoutmethod)
netbankingcardupiwalletpaylaterr-   )	r6   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)r5   razorpay_clientr   s      rE   create_orderr      s    ooH,D,DhFbFb+cdOGGv{|}v~  AL%L  ''//C'%s499#3#344
 4
 "& #!&

 !66 3) 8 rK   )r   r   r   rj   DRIVERZZ_ADMIN_APISr   rates.modelsr   r   r	   r   rF   rJ   rS   r1   r    rK   rE   <module>r      s6    . .  ( 3 3 =D7x"N rK   