3
؀h4=                 @   s   d dl Z d dlZd dlmZmZ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 d d	lmZ d d
lmZ d dlT d dlT d dlmZmZmZmZmZ d dlT dd Z ej!ddgddd Z"dS )    N)datedatetime	timedelta)jsonjsonifyrequest)BookingActivity)Booking)
CreditNote)CreditNoteFacility)CreditNoteGuest)CreditNoteInventory)CreditNoteVehicle)*)	FromCacheappbookings_loggerdbdb_cachec             C   s   | j j  d S )N)sessionclose)self r   //booking_service/app/routes/credit_note_urls.pyr      s    r   z/credit-note/newPOST)methodsc           "   C   s  ddddddddiddig} t tj| }|r@td	|id
fS tjjtjtj	d kjtj
tjd kj }|sg }|jd td|idfS tjtjtjd }|j d d d }|j d d d }ttj }t| ttj d d }t| t|tjd |tjd dtjd ||tj tjd d
}	t|	 ytjj|	 tjj  W nT tk
r }
 z6t|
 tjj  g }|jd t|t|
dd
fS d }
~
X nX xtjd D ]}tttj ||d d t|d t|d |d |d tjd tj d	}ytjj| W n\ tk
rv }
 z>t|
 tjj  tt g }|jd t|t|
dd
fS d }
~
X nX qW xtjd D ]}t ttj ||d  d! t|d" t|d# |d |d tjd tj d$	}ytjj| W n\ tk
rF }
 z>t|
 tjj  tt g }|jd% t|t|
dd
fS d }
~
X nX qW xtjd& D ]}t!ttj ||d' d( t|d) t|d* t|d+ t|d, |d |d |d- tjd tj d.}ytjj| W n\ tk
r0 }
 z>t|
 tjj  tt g }|jd/ t|t|
dd
fS d }
~
X nX qZW xtjd0 D ]}t!ttj ||d( tdtdtdtd|d |d |d1 |d2 |d3 d4t|d5 |d- tjd tj d6}ytjj| W n\ tk
r$ }
 z>t|
 tjj  tt g }|jd7 t|t|
dd
fS d }
~
X nX qDW xtjd8 D ]}t"ttj ||d9 d: t|d) t|d* t|d+ t|d, |d; |d- tjd tj d<}ytjj| W n\ tk
r }
 z>t|
 tjj  tt g }|jd= t|t|
dd
fS d }
~
X nX q8W t#ttj tjd d>tjd tj d?}tjj| y0tjj  tt g }|jd@ td|idAfS  tk
r }
 zFtdB t|
 tjj  tt g }|jdC t|t|
dd
fS d }
~
X nX d S )DN
booking_idz
Booking ID)fieldalias
session_idz
Session IDr   reasoncurrencymessagesi  zDThe selected booking does not appear to exist or has been cancelled.messagei  datar   currency_buy_amountcurrency_sell_amount   )
credit_note_public_idr   credit_note_refcredit_note_currencycredit_note_amountcredit_note_reasoncurrency_buying_rate_at_timecurrency_selling_rate_at_time
created_atr   z0Unable to save  credit note details. Try again .)r#   excguestsguestgatepass_guest_public_idZnumber_of_guestsguest_discountcheck_in_datecheck_out_date)	credit_note_guests_public_idcredit_note_idgatepass_guest_idcredit_number_of_guestscredit_guest_discountcredit_guest_check_in_datecredit_guest_check_out_dater   r/   z5Unable to save  credit note guest details. Try again.vehiclesvehiclegatepass_vehicle_public_idZnumber_of_vehiclesvehicle_discount)	credit_note_vehicles_public_idr8   gatepass_vehicle_idcredit_number_of_vehiclescredit_vehicle_discountcredit_vehicle_check_in_datecredit_vehicle_check_out_dater   r/   z7Unable to save  credit note vehicle details. Try again.accommodationsaccommodationfacility_booking_public_idZnumber_of_adultsZnumber_of_childrenZnumber_of_extra_adultsZnumber_of_extra_childrendiscount) credit_note_facilities_public_idr8   facility_booking_idcredit_facility_booking_adults credit_facility_booking_children$credit_facility_booking_extra_adults&credit_facility_booking_extra_childrencredit_facility_check_in_datecredit_facility_check_out_datecredit_facility_discountr   r/   z8Unable to save  credit note facility details. Try again.Zexternal_accommodationsparameter_idparameter_nameparameter_default_value   supplement_price)rL   r8   rM   rN   rO   rP   rQ   rR   rS   facility_parameter_idfacility_parameter_namerW   external_facilityfacility_supplement_pricerT   r   r/   zAUnable to save  credit note external facility details. Try again.
activitiesZactivityinventory_booking_public_idactivity_date)credit_note_inventory_public_idr8   inventory_booking_idcredit_inventory_booking_adults!credit_inventory_booking_children%credit_inventory_booking_extra_adults'credit_inventory_booking_extra_childrencredit_inventory_datecredit_inventory_discountr   r/   z9Unable to save  credit note inventory details. Try again.zCredit note issued.)booking_activity_public_idr   booking_activity_descriptionr   r/   z Successfully issued credit note.   zthis is the errorz-Unable to issue credit note. Try again later.)$fieldValidationr   r   r   r   r   queryr	   filterdeletion_markerbooking_public_idfirstappendrequestsgetget_buy_sell_rateformatstruuiduuid4printr
   r   nowaddcommit	Exceptionrollbackr   intfloatr   r   r   r   r   )validation_listr"   get_bookingr#   get_exchange_ratebuying_rateselling_rater8   r)   credit_noteesingle_guestZcredit_note_guestsingle_vehicleZcredit_note_vehiclesingle_facilityZcredit_note_facilityZcredit_note_external_facilitysingle_inventorycredit_note_inventorybooking_activityr   r   r   add_credit_note   s   


"



(


(

(


(

(




r   )#rs   rx   r   r   r   flaskr   r   r   database.booking_activity_logr   database.bookingsr	   database.credit_noter
   database.credit_note_facilitiesr   database.credit_note_guestsr   database.credit_note_inventoryr   database.credit_note_vehiclesr   functions.date_operatorsfunctions.validationroutesr   r   r   r   r   	variablesr   router   r   r   r   r   <module>   s    