
    Ai                    h   d dl mZmZ d dlmZmZmZ d dlm	Z	m
Z
 d dlmZ d dlmZ d dl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Zd dlZd dlZd dlZd dlZd dlm Z  d dl!m!Z!m"Z"m#Z# ddl$m%Z% d dl&Z&d dl'Z'd dl(m)Z) d dl m*Z* d dl+m,Z, d dl-m.Z.m/Z/ d dl0m1Z1 d dl2m#Z# d dl3m4Z4m5Z5m6Z6 d dl7m8Z8 d dl9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@ ddlAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZbmcZc d dldmeZemfZfmgZg d dlhmiZimjZjmkZkmlZlmmZmmnZnmoZompZpmqZqmrZrmsZsmtZtmuZumvZv d dlw d dlxmyZymzZzm{Z{m|Z|m}Z}m~Z~mZmZmZmZmZmZmZmZmZmZmZmZ d dlmZ d dlmZ d dlZd dlZd d l!mZ d d!lmZ d d"l!m!Z! d d#lmZ d d$lmZ d d%lmZmZmZmZ d d&lmZ d d'lmZ d dl&Z&d d(lmZ d dlZd dl+m,Z, d dlmZ d d#lmZ d d)lmZ d d*lmZ d d+lmZ d dlZd d,lmZ d d-lmZ d dlZd dlm)Z) d d.lwmZ d d/lmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ d d0lmZ d1 Zd2 Zd3 Zdd4Zd5 Zd6 Zd7 Zd8 Zd9 Zd: Zd; Zd< Zd= Zd> Ze
 e	 eg d?            d@               Ze
 e	 edAdBg            dC               ZdD ZddEZe
 e	 edAdBg            dF               Zee
 e	 edAdBg            dG                      ZdH Zee
 e	 edAdBg            dI                      ZdJ ZdK Ze
 e	 edAdBg            ddL              Ze
 e	 edAdBg            dM               Ze
 e	 edAdBg            dN               Ze
 e	 edAdBg            dO               Zee
 e	 edAdBg            dP                      Ze
 e	 edAdBg            dQ               Ze
dR        Ze
 e	 edAdBg            dS               Ze
 e	 edAdBg            dT               Ze
 e	 edAdBg            dU               Ze
 e	 edAdBg            ddV              Ze
 e	 edAdBg            dW               Ze
 e	 edAdBg            dX               Ze
 e	 edAdBg            dY               Ze
 e	 edAdBg            dZ               Ze
 e	 edAdBg            d[               Ze
 e	 edAdBg            d\               Ze
 e	 edAdBg            d]               Zd^ Ze
 e	 edAdBg            d_               Zd` Ze
 e	 edAdBg            da               Ze
db        Ze
dc        Zdd Ze
 e	 edAdBg            de               Zd dfl-m.Z. dg Zdh Zdi Ze
 e	 edAdBg            dj               Ze
 e	 edAdBg            ddk              Ze
 e	 eg dl            ddm              Ze
 e	 eg dl            dn               Ze
 e	 edAdBg            do               Zdp Ze
 e	 edqg            dr               Z e	 edAdBg            ds        Zdt Ze
 e	 edAdBg            du               Z e	 edAdBg            dv        Zee
 e	 edAdBg            dw                      Ze
 e	 edAdBg            dx               Z e
 e	 edAdBg            dy               Z e	 edAdBg            dz        Zee
 e	 edAdBg            d{                      Ze
 e	 edAdBg            d|               Ze
 e	 edAdBg            d}               Z e	 edAdBg            d~        Zee
 e	 edAdBg            d                      Ze
 e	 edAdBg            d               Ze
 e	 edAdBg            d               Z	 G d de      Z
 G d de      Z e	 edqdg            d        Zee
 e	 edqg            d                      Ze
 e	 edqg            d               Ze
 e	 edqg            d               Ze
 e	 edqdg            dd              Ze
 e	 edg            d               Z G d dej$                        Zd Zd Zd Zd Ze d        Ze d        Zd Ze
 e	 edAdBg            d               Ze
 e	 edAdBg            d               Ze
 e	 edAdBg            d               Ze
 e	 edAdBg            d               Z e	 eg d            d        Zee
 e	 edAdBg            d                      Z e
 e	 edAdBg            d               Z!e
 e	 edAdBg            d               Z"e
 e	 edAdBg            d               Z#e
 e	 edAdBg            d               Z$e
 e	 edAdBg            d               Z%e
 e	 edAdBg            d               Z&e
 e	 edAdBg            d               Z'e
 e	 edAdBg            d               Z(e
 e	 edAdBg            d               Z)e
 e	 edAdBg            d               Z*e
 e	 edAdBg            d               Z+e
 e	 edAdBg            d               Z,e
 e	 edAdBg            d               Z-e
 e	 edAdBg            d               Z.e
 e	 edAdBg            d               Z/e
d        Z0e
d        Z1e
d        Z2e
 e	 edAdBg            d               Z3ee
 e	 edAdBg            d                      Z4e
 e	 edAdBg            dd              Z5e
 e	 edAdBg            d               Z6e
 e	 edAdBg            d               Z7e
 e	 edAdBg            d               Z8e
 e	 edAdBg            d               Z9e
 e	 edAdBg            d               Z:e
 e	 edAdBg            d               Z;e
 e	 edAdBg            d               Z<e
 e	 edAdBg            d               Z=e
 e	 edqdg            dd              Z>d Z?e
 e	 edqg            d               Z@e
 e	 edAdBg            d               ZAe d        ZBd ZCd ZDd ZEd dlFZFd ZGdÄ ZHdĄ ZI edg      dƄ        ZJ edg      dǄ        ZK e	 edAdBg            dȄ        ZLee
 e	 edAdBg            dɄ                      ZMe
 e	 edAdBg            dʄ               ZNe
 e	 edAdBg            d˄               ZOd̄ ZPd̈́ ZQd dl0m1Z1 d΄ ZRdτ ZSdЄ ZTy)    )renderredirect)authenticateloginlogout)user_passes_testlogin_required)api_view)require_POST)inlineformset_factory)SumAvgDateTimeField)validate_email)ValidationError)FN)csrf_exempt)datetimedatetimezone   )shop_add_status_change)chain)get_object_or_404)settings)JsonResponseHttpResponse)messages)r   )	Paginator	EmptyPagePageNotAnInteger)apps)FAQAboutUsAppUrl	ContactUsPrivacyPolicyReturnPolicyTermsAndConditions)"AboutUsForm
AppUrlFormContactUsFormFAQFormPrivacyPolicyFormRefundPolicyFormShopFormStoreUserFormTermsAndConditionsFormUserEditFormUserFormUserModalFormBankDetailsFormCategoryFormProductSubCategoryFormProductFormTagFormDynamicFilterFormSpecialListFormDeliveryBoyFormSKUFormCourierDetailsForm
CouponFormDeliverySlotFormDiscountFormAdFormCustomProductFormProductionUnitFormCustomOrderFormMessageFormYouMayAlsoLikeFormDeliverySettingsFormDeliveryDiscountFormCustomCouponSettingsForm)ShopBankDetailsProductionUnit)ProductCategoryProductSubCategoryProductsSalesUnitProductSelectionProductImageProductVideoTagsDynamicFilteringSpecialListSKUCustomProductCustomProductImageCustomProductVideoYouMayAlsoLike)*)CustomOrderTrackingDeliveryBoysOrderProductCustomizationOrderProductsOrdersOrderDeliveryCouponsDeliverySlotDiscountAdsPaymentCommunicationMessageDeliveryDiscountDeliverySettingsCustomCouponSettingsCustomCouponPaymentModes)	send_mail)EMAIL_HOST_USER)	timedelta)initialize_fcm_app)r   )reverse)Group)CountQr   Prefetch)render_to_string)autocomplete)IsAuthenticated)APIView)Responsestatus)
parse_date)EmailMessage)LoggingOperation)"send_whatsapp_message_delivery_boyemail_sendingsend_notificationsend_whatsapp_messagesmsshop_admin_status_update&shop_admin_status_update_only_one_shop'category_based_shop_admin_status_celery+sub_category_based_shop_admin_status_celerycategory_product_list.product_availability_shop_status_change_celery;master_product_edit_celery_task_to_update_shop_availability,update_sku_long_distance_status_check_celery!long_distance_status_check_celerysku_delete_long_distance_celery!long_distance_master_product_edit)groupc                    	 t        j                  d| d|  d       t        d| d|  d       t        j                  | |t
        j                  |dgd      }|S # t        $ r&}t        j                  d|  d| d	       Y d }~y d }~ww xY w)
NzSending Email to (z) with subject ()F   args	countdownzEmail Send Failed for ():  )logginginfoprintr   apply_asyncr   rq   	Exception)subjectmessage
email_listfail_silently
email_dataes         3E:\Akash\Saasvaap\Navya-Bakers\adminportal\views.py	EmailSendr   R   s    A)*5EgYaPQ":,.>wiqIJ"..WgxG_G_akmr4s9:<
 A.wis1#Q?@@As   AA 	B%BBc                     	 t        j                  | |j                  |||j                  |j                  gd       t        ddd      S # t        $ r%}t        j                  d| d|        Y d }~y d }~ww xY w)Nr   r   r   znotification send successfullyr   msgzNotification send Failed on (r   )	r   r   order_IDpkuuidr   r   r   error)	fcm_tokenordertitledescription	user_uuidr   s         r   NotificationInitr   h   s|    %%Iu~~uk[d[g[ginisis+t  AB  	Cq2RSTT 5k]#aSIJs   AA 	A9A44A9c                     	 t        j                  d       t        j                  | |||gd       y # t        $ r"}t        j
                  d|        Y d }~y d }~ww xY w)Nz#Sending Whatsapp Message to Shipperr   r   )Send Whatsapp message to Shipper Failed: )r   r   r   r   r   r   )numberorderIDnametemplate_namer   s        r   WhatsappMessager   v   sU    :;))}/U`ab A!EFs   03 	AAAc                     t         j                  t         j                  z   dj                  fdt	        |       D              S )N c              3   H   K   | ]  }t        j                          y wN)secretschoice).0_
characterss     r   	<genexpr>z+generate_random_password.<locals>.<genexpr>   s     E}!7>>*-}s   ")stringascii_lettersdigitsjoinrange)lengthr   s    @r   generate_random_passwordr      s0    %%5J77EuV}EEE    c                    i }| j                   dk(  rc| j                  j                  dd      }| j                  j                  dd      }t        | ||      }|t	        | |       t        d      S ddi}t        | d	|      S )
NPOSTusernamer   password)r   r   homepager   zinvalid username or passwordz
login.html)methodr   getr   
auth_loginr   r   )requestr   emailr   users        r   r   r      s    E~~  R0<<##J3 GehGw%J'' >?E'<//r   c                       fd}|S )Nc                      | j                   v S r   	user_type)r   allowed_roless    r   inner_functionz'check_user_role.<locals>.inner_function   s    ~~..r    )r   r   s   ` r   check_user_roler      s    / r   c                 6    | rt        || z  dz  d      }|S d}|S )Nd      r   round)orders_todayfailed_order_todayavg_failed_orderss      r   get_average_failed_ordersr      s3    !#5#D"KQO  r   c                 4   i }| d   rX|d   rSt        | d   |d   z  dz  d      }|dkD  r|dz
  }t        |d      |d<   d|d<   |S d|z
  }t        |d      |d<   d|d<   |S | d   r|d   sd}t        |d      |d<   d|d<   |S d	}t        |d      |d<   d|d<   |S )
Nweek_revenuelast_week_revenuer   r   revenue_differenceincreaseflagdecreaser   r   )r   week_before_last_week_revenuerevenue_difference_outputweek_revenue_percent_with_weeks       r   get_week_difference_outputr      s"    "N#(EFY(Z)..),IJ],^^beegh*j&)C/-Kc-Q*>CDbde>f%&:;0:%f- %$ .13Q-Q*>CDbde>f%&:;0:%f- %$ '0MNa0b-0*>CDbde>f%&:;0:%f-
 %$ ./*>CDbde>f%&:;0:%f-$$r   c                 4   i }| d   rX|d   rSt        | d   |d   z  dz  d      }|dkD  r|dz
  }t        |d      |d<   d|d<   |S d|z
  }t        |d      |d<   d|d<   |S | d   r|d   sd}t        |d      |d<   d|d<   |S d	}t        |d      |d<   d|d<   |S )
Ntoday_revenuelast_week_avg_revenuer   r   today_revenue_percent_with_weekr   r   r   r   r   )r   last_week_revenue_avgrevenue_percent_datar   s       r   get_revenue_percent_datar      s(   _%*?@W*X*/1ORg#S% 2%(+1,-.+0'*S0.MPS.S+FKLkmnFo !BC+5 (   /24S.S+FKLkmnFo !BC+5 (   )2GH_2`.1+FKLkmnFo !BC+5 (
   /0+FKLkmnFo !BC+5 (r   c                    i }| rO|rMt        | |z  d      dz  }|dkD  r|dz
  }t        |d      |d<   d|d<   |S d|z
  }t        |d      |d<   d|d<   |S | r|sd}t        |d      |d<   d|d<   |S d}t        |d      |d<   d|d<   |S )Nr   r   today_count_percent_with_weekr   r   r   r   r   )r   last_week_revenue_countrevenue_count_datar   s       r   get_revenue_count_datar     s    /(-|>U/UXY(Z]`(`%(3.,IC,O)BGHeghBi>?)3v&  -02O,O)BGHeghBi>?)3v&   7,/)BGHeghBi>?)3v&
  -.)BGHeghBi>?)3v&r   c                    t         j                  j                  | j                  | j                  |j
                        j                  ddg      j                  t        d            }t        |d   r|d   ndd	      |d<   |S )
N)created_date__yearcreated_date__month
store_uuid	New OrderFailedorder_status__ingrand_totalmonth_revenuer  r   r   )
rb   objectsfilteryearmonthr   exclude	aggregater   r   )todayshop_idr  s      r   get_month_revenuer    s    NN))UZZ>CkkV]VbVb * ddkdk%x0 el e22;)-( 3< 3*  &+*7*Ho&aQR&TM/"r   c                 
   d }t         j                  j                  d      j                  | j                  j
                        }|r|d   }d| j                  d<   t        j                  j                  ddg      j                  ||j
                  	      j                         }t        t        j                  j                  |d
|j
                        j                  d            }t        |      }t        j                  j                  |d|j
                        j                         }t        ||      }t        j                  j                  |d|j
                        j                         }	t        j                  j                  |g d|j
                        j                         }
t        j                  j                  |j
                        j                  dg      j                         }t        j                  j                  ||j
                  	      j                  ddg      j                  t        d            }d}|d   rt!        |d   r|d   ndd      }|t#        d      z
  }|t#        d      z
  }t        j                  j                  |||j
                        j                  ddg      j                  t        d            }t        j                  j                  |||j
                        j                  ddg      j                  t        d            }t%        ||      }t        j                  j                  |j
                  ||      j                  ddg      j                  t'        d            }t)        ||      }t        j                  j                  |j
                  ||      j                  ddg      j                         }t+        ||      }t-        ||      }d}|	r|rt!        |	|z  dz  d      }t        j                  j                  |j
                  |      j                  ddg      j                  t'        d            }d}|d   rt!        |d   d      }t        j                  j                  |j
                  |      j                  ddg      j                  d      j/                  t        d            j1                  d       d d! }|D ]  }|d"   s	t!        |d"   d      |d"<    i d#|d$|d%|	d&|
d'|d(|d)|d|d*|d+|d,|d-|d.|d/|d0|d1d2d3|}|S y )4Nunit_admin_userunit_admin_user__uuidr   Yesproduct_viewr  r  r  )created_date__dater  	Confirmed)r  order_statusr  r   	Deliveredr  ViewedOrder Packed)r  r	  r  )r  r
  r   r   r      days)created_date__date__gtecreated_date__date__lter  r   r   )r  r'  r(  r   r   )r  r  store_uuid__unit_nametotal_amount-total_amountr   r.  r   new_order_todayfulfiled_ordercurrently_unassigned_orderfailed_orderavg_failed_ordertotal_ordersr  grand_total_by_storer   r   delivery_success_percentageavg_today_revenuer   home_activeactivenew_order_data)rL   r  prefetch_relatedr  r   r   sessionrb   r  countlistvalueslenr   r  r   r   rr   r   r   r   r  r  annotateorder_by)r   r  shop_id_verifyr  r   r;  r0  r   r   r1  r2  r5  r   today_revenue_datalast_week_startweek_before_last_weekr   r   r   r   r   r   r   r  r7  r8  avg_today_revenue_dataresultsicontexts                                 r   shop_admin_homepagerL    s   N \\223DELL%ll// M 1N #*/' ~~--+?V-W^^$ _ ??Duw 	 fnn33u[f?F|| 4 MMSVT^Macn- $^^22eZb>Ell 3 LLQEG 	 6lDVW
  ..%Va:A,, / HHM 	 &,^^%:%:eLsFMll &; &TTYTYT[ 	#
 ~~,,,EMM)] N ,,1EG 	--SZS_S_-`hh)84 i 66?im, 7@ 7. 	 )!&WfIg}_'Emnpq!r)"33 /)2C C~~,,_EJW^WcWc - eelel)84 fm f66?i]+ 7@ 7- 	
 )/(=(=VkVeIP )> )WW^W^)84 X_ X66?i!-0 7@ 72 	& %?|Mj$k! !' 5 5N]NS !6 !UU\U\)84 V] V66?iVYZgVhi6i 	  8G\]"(.."7"77<<P_PU #8 #WW^W^)84 X_ X66;eg 	  4LBYZ)%9&'#l*/,1NRU0UWX*Y'"NN11W\\^c1dll)84 m 66?im, 7@ 7. 	 "#_-%*+<_+Mq%Q"..''7<<TY'Zbb)84 c 66<f=T6UV^V^]+ W_ W--5X.a!
 A $)!N*;Q$?.! 5>< 51BO 5#^5/1K5 "#55 &'8	5
 "<5
 2ABT5 #M5 4J75 34F5 56J5 12M5 '(>5 /0I5 LYZb5 $^5 I r   c                    d| j                   d<   t        j                  j                  ddg      j	                  |      j                         }t        t        j                  j	                  |d      j                  d	            }t        |      }t        j                  j	                  |d      j                         }t        ||      }t        j                  j	                  |d
      j                         }t        j                  j	                  g d|      j                         }|t        d      z
  }	|	t        d      z
  }
t        j                  j	                  |	|      j                  ddg      j                  t        d            }t        j                  j	                  |
|	      j                  ddg      j                  t        d            }i }|d   rV|d   rQt        |d   |d   z  dz  d      }|dkD  r|dz
  }t        |d      |d<   d|d<   nQd|z
  }t        |d      |d<   d|d<   n7|d   r|d   sd}t        |d      |d<   d|d<   nd}t        |d      |d<   d|d<   t        j                  j	                  |	|      j                  ddg      j                  t        d            }t        j                  j	                  |      j                  ddg      j                  t        d            }d}|d   rt        |d   d      }i }|d   rV|d   rQt        |d   |d   z  dz  d      }|dkD  r|dz
  }t        |d      |d <   d|d<   nQd|z
  }t        |d      |d <   d|d<   n7|d   r|d   sd}t        |d      |d <   d|d<   nd}t        |d      |d <   d|d<   t        j                  j	                  |	|      j                  ddg      j                         }i }|rM|rKt        ||z  dz  d      }|dkD  r|dz
  }t        |d      |d!<   d|d<   nKd|z
  }t        |d      |d!<   d|d<   n1|r|sd}t        |d      |d!<   d|d<   nd}t        |d      |d!<   d|d<   d}|r|rt        ||z  dz  d      }t        j                  j	                  |      j                  ddg      j                  t        d            }d}|d   rt        |d   d      }t        j                  j                  dg      j                         }t        j                  j	                  |j                  |j                   d
"      j                  t        d      #      }t        |d$   r|d$   ndd      |d$<   t        j                  j	                  |d%&      j                  ddg      j                  d'      j#                  t        d      (      j%                  d)      d d* }|D ]  }|d+   s	t        |d+   d      |d+<    i d,|d-|d.|d/|d0|d1|d2|d|d$|d3|d!|d |d4|d5|d6|d7d8d9|}|S ):NNor  r  r  r  r  r  )r  r  r   r  r   )r	  r  r$  r%  )r'  r(  r
  r)  r*  r   r   r   r   r   r   r   r   r   r+  r#  r   r   r   r   )r  r  r  r  r  Local Ordersr  
order_typer,  r-  r/  r   r.  r   r0  r1  r2  r3  r   r5  r6  r7  r8  r   r9  r:  r;  r=  rb   r  r  r  r>  r?  r@  rA  r   rr   r  r   r   r   r  r  rB  rC  )r   r  r   r;  r0  r   r   r1  r2  rF  rG  r   r   r   r   r   r   rE  r   r   r   r   r   r7  r8  rH  r5  r  rI  rJ  rK  s                                  r   nbc_admin_homepagerT  |  sO    +/'~~--+?V-W^^$ _ &&+eg 	fnn33uZe3gnnoy|}n-#^^22eZb2ciik5lDVW..%Va.bhhj%+^^%:%:LsNS &; &UUZUZU\ 	#)"33 /)2C C~~,,_EJ - LLSG)84 MT M66?i]+ 7@ 7- 	 )/(=(=VkVe )> )ggngn)84 ho h66?i!-0 7@ 72 	& %'!',IJ],^-2n-0MNa0bbfiikl.n*-31ORU1U.BGHfhiBj)*>?4>)&1147U1U.BGHfhiBj)*>?4>)&1 N+4QRe4f14.BGHfhiBj)*>?4>)&112.BGHfhiBj)*>?4>)&1 & 5 5oNS !6 !UU\U\)84 V] V66?i"%m"4 7@ 76 	 ---GOO)84 P 66?icR_N`i6a 	)!&}_'Eq!I!).CD[.\.3/2GH_2``dggij/l+.42QTW2W/JOPoqrJs$%FG/9$V,258W2W/JOPoqrJs$%FG/9$V, _-6KLc6d25/JOPoqrJs$%FG/9$V,23/JOPoqrJs$%FG/9$V,"(.."7"7P_PU #8 #WW^W^)84 X_ X66;eg 	   3,1<BY3Y]`2`bc,d),s20MPS0S-FKLiklFm"#BC-7"6*036S0S-FKLiklFm"#BC-7"6*$;03-FKLiklFm"#BC-7"6*01-FKLiklFm"#BC-7"6*&'#l*/,1NRU0UWX*Y'"NN11U1KSS)84 T 66?icR_N`i6a 	 "#_-%*+<_+Mq%Q"~~--}-MSSU--BG++\g . iirirm, js j. 	 */Q^_nQo}_/Muv/0*2o&..''5^'\dd)84 e 66<f=T6UV^V^]+ W_ W--5X.a! A $)!N*;Q$?.! N>< N1BO NUegu N/1KN "#5N '(9	N
 "<N
 2ABTN #MN 4J7N 34FN 56JN 12MN '(>N A\]vN !(N -=nN r   c                    d| j                   d<   t        j                  j                  ddg      j	                  d|      j                         }t        t        j                  j	                  |dd	      j                  d
            }t        |      }t        j                  j	                  |dd	      j                         }t        j                  j	                  |dd	      j                         }t        ||      }t        j                  j	                  g d|d      j                         }|t        d      z
  }	|	t        d      z
  }
t        j                  j	                  d|	|      j                  ddg      j                  t        d            }t        j                  j	                  d|
|	      j                  ddg      j                  t        d            }i }|d   rV|d   rQt        |d   |d   z  dz  d      }|dkD  r|dz
  }t        |d      |d<   d|d<   nQd|z
  }t        |d      |d<   d|d<   n7|d   r|d   sd}t        |d      |d<   d|d<   nd}t        |d      |d<   d|d<   t        j                  j	                  d|	|      j                  ddg      j                  t        d            }t        j                  j	                  d|      j                  ddg      j                  t        d            }d}|d   rt        |d   d      }i }|d   rV|d    rQt        |d   |d    z  dz  d      }|dkD  r|dz  }t        |d      |d!<   d|d<   nQd|z  }t        |d      |d!<   d|d<   n7|d   r|d    sd}t        |d      |d!<   d|d<   nd}t        |d      |d!<   d|d<   t        j                  j	                  d|	|d"      j                         }i }|rM|rKt        ||z  dz  d      }|dkD  r|dz
  }t        |d      |d#<   d|d<   nKd|z
  }t        |d      |d#<   d|d<   n1|r|sd}t        |d      |d#<   d|d<   nd}t        |d      |d#<   d|d<   d}|r|rt        ||z  dz  d      }t        j                  j	                  d|      j                  ddg      j                  t        d            }d}|d   rt        |d   d      }t        j                  j	                  d$      j                  dg      j                         }t        j                  j	                  d|j                  |j                   %      j                  ddg      j                  t        d      &      }t        |d'   r|d'   ndd      |d'<   t        j                  j	                  |d(      j                  ddg      j                  d)      j#                  t        d      *      j%                  d+      d d, }|D ]  }|d-   s	t        |d-   d      |d-<    i d.|d/|d0|d1|d2|d3|d4|d|d'|d5|d#|d!|d6|d7|d8|d9d:d;|}|S )<NrN  r  r  r  r  Long Distance Orders)rR  r  r  )r  r  rR  r   r  r   )r	  r  rR  r$  r%  )rR  r'  r(  r
  r)  r*  r   r   r   r   r   r   r   r   r   r+  r#  r   r   r   )rR  r'  r(  r  r   rR  )rR  r  r  r  r  rQ  pu_uuid__pu_namer-  r/  r   r.  r   r0  r1  r2  r3  r   r5  grand_total_by_pur7  r8  r   r9  r:  r;  rS  )r   r  r   r;  r0  r1  r   r   r2  rF  rG  r   r   r   r   r   r   rE  r   r   r   r   r   r7  r8  rH  r5  r  rI  rJ  rK  s                                  r   pu_admin_home_pagerZ    s   &*GOON#>>))Hk;R)SZZ)  [ ""'%'  &..//5Wb;Q 0 SSYSYZdSgiN.)O^^**eR]6L + NNSeg ..%V^:P / RRWRWRY  2,@RS!'!6!6HoJOBX "7 "ZZ_Z_Za  iQ//O+iQ.??>>((4JdsAF ) HHO%x0 IP I22;)' 3< 3)  %+NN$9$9E[RgRa %: %ccjcj%x0 dk d22;)m, 3< 3. "
 !#N#(EFY(Z)..),IJ],^^beegh*j&)C/-Kc-Q*>CDbde>f%&:;0:%f--03Q-Q*>CDbde>f%&:;0:%f- '0MNa0b-0*>CDbde>f%&:;0:%f--.*>CDbde>f%&:;0:%f-"NN11=SJYJO 2 QQXQX%x0 RY R22;)!-0 3< 32 
 NN))5K`e)fnn%x0 o 22;)#mJ\)2] _%"=#A1E_%*?@W*X*/1ORg#S% 2%(+1,-.+0'*S0.MPS.S+FKLkmnFo !BC+5 (.14S.S+FKLkmnFo !BC+5 ( )2GH_2`.1+FKLkmnFo !BC+5 (./+FKLkmnFo !BC+5 ($nn33?UL[LQ`k 4 mmrmrmt  /(-|>U/UY\.\^_(`%(3.,IC,O)BGHeghBi>?)3v&,/2O,O)BGHeghBi>?)3v& 7,/)BGHeghBi>?)3v&,-)BGHeghBi>?)3v&"#,&+^l-Jc,QST&U#--9Odi-jrr%x0 s 22;)#mJ\)2] )!&'8'I1!M>>((4J(KSS% T ((-  NN))5K`e`j`j>Ckk * KKR7%x0 LS L22;)-( 3< 3*  &+][jMk=+Iqr+,&.M/"nn##uI_#`hh%x0 i 228&9K2LXX' NV N))1*!G ^ %a&7 ;An 
J~| 
J-> 
JQacq 
J+-G
J1
J #$5
J |	
J .=>P	
J
 
J
 0CG
J /0B
J 12F
J -.I
J #$:
J =XYr
J h
J )9.
JG Nr   )Super Admin	NBC Admin
Shop AdminPU Adminc                 x   i }t        j                         j                         }| j                  j                  dk(  rt        | |      }nd| j                  j                  dk(  s| j                  j                  dk(  rt        | |      }n%| j                  j                  dk(  rt        | |      }t        | d|      S )Nr]  r\  r[  r^  z
index.html)	r   nowr   r   r   rL  rT  rZ  r   )r   rK  r  s      r   	home_pagera    s     GLLN!E ||-%gu5 
		;	.',,2H2HM2Y$We4 
		:	-$We4'<11r   r[  r\  c                 l   t         j                  j                  d      }t        |d      }| j                  j                  d      }	 |j                  |      }|dd}t        | d|      S # t        t        f$ r |j                  d      }Y 4t        $ r |j                  |j                        }Y Yw xY w)N-created_at
   pager   r:  )	shop_datasales_unit_activezshop_list.html)rL   r  rC  r   GETr   get_pager!   	TypeErrorr    	num_pagesr   )r   shops	paginatorre  rK  s        r   	shop_listrn    s     LL!!-0E%$I;;??6"D8""4(
 "AG'+W55 i( &""1% 8""9#6#678   A+ + B3#B32B3c           	         g }t         j                  j                         D ]  }t        j                  j                  |      j	                         }|r|j
                  }n|j                  }|j                  dk(  r|j                  t        | |||             z|j                  dk(  r|j                  t        | |||             |j                  dk(  s|j                  t        | |||              |S )NskuVisible)
sales_unitrr  r   shop_admin_statusDisabledzOut of Stock)rX   r  r  rR   firstr   
sku_statusappend)shopproduct_enter_listrJ  sales_statusr   s        r   shop_status_initializationr}    s    [[!088??A?FLLN!((F\\F<<9$%%)Tqcijl\\Z'%%)Tqcijl\\^+%%)Tqcijl "  r   c                 .   t        | j                  j                               }|)t        |j                  j                               }||z   }ng }|}g d}g d}t        |      t        |      z  }t        |      t        |      z  }d}	|rd}	|	S |rd}	|	S )z
    Determines which page/step has errors in the multi-step form
    Returns: page index (0 for personal details, 1 for location details, 2 for bank details)
    )		unit_name	unit_codeunit_locationr   
contact_nor   r  delivery_modedelivery_radius)latitude	longitudestreetcitystate_or_provincedistrictpin_coder   r   )r?  errorskeysset)
	shop_form	bank_formshop_error_columnsbank_error_columns
error_liststep1_columnsstep2_columnsstep1step2re  s
             r   shop_add_error_page_findr    s    
 i..3356 !)"2"2"7"7"9:'*<<
'
LMlM 
Oc-00E
Oc-00E D K 
 Kr   c                    g }t               }| j                  dk(  rt        | j                        }t	        d| j                         t	        d|j                                t	        d|j                         |j                         r|j                         }t        |      }t        j                  j                  |       d}d}|j                  j                         D ]!  }t        ||t        |j                   gd       # 	 | j"                  }	d	}
d
}d|j$                   d|j&                   }t(        j                  j+                  |	|
||       t/        d      S |j1                  |j                         t3        |d       }|||dd|d}t5        | d|      S t               }g }|||dddd}t5        | d|      S # t,        $ r"}t	        d|        Y d }~t/        d      S d }~ww xY w)Nr   z
POST Data:zForm is valid:zForm errors:zShop createdz,New shop assigned you as the unit admin userTr   rz  zShop CreatedShop z created with code r   log_typer   r   zLogging error: rn  
modal_hider:  )r  r  user_modal_form
show_modalrg  re  shop_add.htmlr   )r5   r   r0   r   r   is_validr  saver}  rR   r  bulk_creater  allrp   rq   r   r   r  r  r   creater   r   ry  r  r   )r   r  r  r  rz  r{  r   r   r   log_userr  r   r   re  rK  s                  r   shop_addr    s    F#oO~~W\\*	 	lGLL)	 2 2 45ni../ >>#D "<D!A%--99:LM %GDG,,002Wo

|SW 3
"<<!( %dnn%55HHXY ((//!%# +	 0  K(( MM)**+ ,It<D !&#2*%-G '?G<< J	 *"%G '?G44W  s+,K((	s   AF> >	G)G$$G)c                    t         j                  j                  |      }|rt        j                  j                  |      j	                          |j                         }|j	                          	 	 t        j                  d|j                         | j                  }d}d}d|j                   d	|j                   d
}t        j                  j!                  ||||       t#        d      S t#        d      S # t        $ r"}t        j                  d|        Y d }~d }~ww xY w# t        $ r,}t        j                  d|        Y d }~t#        d      S d }~ww xY w)Nr   )rt  zShop Delete)senderr  z.Signal Status Updation on Shop Delete Failed: rz  zShop Deletedr    with code  deletedr  zShop Deletion Error: rn  )rL   r  r  rR   deleterw  r   sendr   r   r   r   r   r  r  r   r  r   )	r   r  rz  rf  r   r  r  r   r   s	            r   shop_deleter  i  s?    <<'*D 	"))00G0DKKMJJL		T&++=)..Y ||HH$G!)"5"5!6l9CVCVBWW_`K$$++HV]kv+w
 K  8K    T NqcRSST  	MM1!56K  		s=   3!C: AD( :	D%D D(  D%%D( (	E1EEc                 Z    	 t         j                  j                  | |||       y #  Y y xY w)Nr  )r   r  r  )r  r  r   r   s       r   logr    s0      ''XRYgr'ss   #& *c                    t        t        |      }t        j                  j	                  |      }|r!t        j                  | d       t        d      S |rl|j                          | j                  }d}d}d|j                   d|j                   d}t        ||||       t        j                  | d	       t        d      S t        j                  | d
       t        d      S )Nr   categoryz$Couldn't delete subcategories existsproductzCategory Deletedz	Cagegory r  r  zCategory deleted successfullyzSomething went wronglist_category)r   rO   rP   r  r  r   warningr  r   category_namecategory_coder  successr   )r   category_idr  sub_categoryr  r  r   r   s           r   category_deleter    s     !{CH%--44h4GL"HI O$$ 
 <<$!("8"8!9hF\F\E]]efHh5"AB O$$ 	"89O$$r   c                    t         j                  j                  |      }|j                  j                  }|ry|j                          	 | j                  }d}d}d|j                   d|j                   d|j                  j                   d|j                  j                   }t        ||||       t        dt        |       d	      S #  Y xY w)
Nr  r  zSub category deletedSub category r   deleted for category  with code /adminportal/add-sub-category//)rP   r  r   r  r   r  r   sub_category_namesub_category_coder  r  r  r   str)r   sub_category_idr  r  r  r  r   r   s           r   sub_category_deleter    s   %--111GL'',,K	||H H,G),*H*H)IVbVtVtUu  vL  MY  Mb  Mb  Mp  Mp  Lq  q|  }I  }R  }R  }`  }`  |a  bK(G[9 4S5E4FaHII	s   
A(C
 
Cc                     | |j                   k7  r]|j                  j                         D ]?  }d}d|j                   d|j                    }t	        ||t
        |j                  gd       A y y )NzShop status updatedz
Your shop z changed their status to Tr  )r   r  r  r  rp   rq   r   )existing_shop_statusrz  r   r   r   s        r   send_email_on_status_changer    sf    t{{*((,,.D+G"4>>"22KDKK=YG/DJJ<t / +r   c                    t        t        |      }|j                  }t        j                  j                  |      j                         }g }| j                  dk(  rMt        | j                  |      }t        | j                  |      }|j                         r|j                         r|j                         }|j                  d      }||_        |j                          t        ||       	 | j                  }d}	d}
d	|j                    d
|j"                   d d	|j                    d
|j"                   d}t%        ||	|
|       t-        d      S |j/                  |j0                         |j/                  |j0                         t3        ||      }||d|d}t5        | d|      S t        |      }t        |      }||ddd}t5        | d|      S # t&        $ r,}t)        j*                  d|        Y d }~t-        d      S d }~ww xY w)Nr  rz  r   instanceFcommitrz  zShop Updatedr  r  r   updatedz&Shop Updation Error(logging section): rn  r:  )r  r  rg  re  zshop_edit.htmlr   )r   rL   r   rM   r  r  rw  r   r0   r   r6   r  r  rz  r  r   r  r  r  r   r   r   r   ry  r  r  r   )r   r  rz  r  bank_detailsr  r  r  r  r  r   r   r   re  rK  s                  r   	shop_editr    s   
 Tg.D;;&&--4-8>>@LF~~W\\D9	#GLL<H	I$6$6$8>>#D$>>>7L $L ((<dC"<<!('|DNN3C8L %dnn%5\$..AQQYZHh= K((MM)**+MM)**++IyAD$-I\dnrsG'#3W==d+	#\:	%IT\fghG'+W55#   FqcJK K((s   2AG 	H HHc                    t         j                  j                  d      j                  d      }t	        |d      }| j
                  j                  d      }	 |j                  |      }|dd}t        | d	|      S # t        t        f$ r |j                  d      }Y 4t        $ r |j                  |j                        }Y Yw xY w)
NCustomer)user_type__exact-created_daterd  re  r   r:  )usersusers_activez
users.html)Usersr  r  rC  r   rh  r   ri  r!   rj  r    rk  r   )r   r  rm  re  rK  s        r   r  r     s     MM!!:!>GGXE%$I;;??6"D8""4( x8G'<11 i( &""1% 8""9#6#678s   A; ; C#CCc                 B   g }t        t        |      }| j                  dk(  r^t        | j                  |      }|j                         r|j                          t        d      S |j                  |j                         nt        |      }||d|d}t        | d|      S )Nr  r   r  r  r:  r  formpublic_users_activeuser_idedit_users.html)r   r  r   r3   r   r  r  r   ry  r  r   )r   r  r  r   r  rK  s         r   	user_editr    s     FUw/D~~GLL48==?IIKG$$ MM$++&T*h[bcG',g66r   c                    g }| j                   dk(  rt        | j                        }|j                         r|j                  d   }|j                  d   }|j                  d   }|j                  d   }|j                  d   }|j                  d   }t        ||||||      }	t               }
|	j                  |
       d	}d
|
 }t        |	j                        }	 t        ||t        |gd       |	j                          t        d      S |j                  |j                          nt               }g }||d}t        | d|      S #  ddgig}||d}t        | d|      cY S xY w)Nr   
first_name	last_namer   r   phone_numberr   )r  r  r   r   r  r   #Orderpicky Registration Successful NCongratulations, your account has been successfully created. Your password is Fr  r  zPlease enter valid email)r  	user_formzadd_user.html)r   r4   r   r  cleaned_datar  r   set_passwordr  r   rp   rq   r  r   r   ry  r  )r   r  r  r  r  r   r   r  r   user_objmy_passwordr   r   	recepientrK  s                  r   user_addr  %  s    F~~W\\*	"//=J!..{;I**73E!..{;I$11.AL++H5F%##)H 34K!!+.;GfgrfstGHNN+IAWo	{RW (( MM)**+J	 G '?G44+A"%?$@AB %!* g@@s   /E E!c                 |    t         j                  j                  |      }|r|j                          t	        d      S )Nr  r  )r  r  r  r  r   )r   r  r   s      r   user_deleter  a  s2     ==7+DGr   c                    g }t               }| j                  dk(  rt        | j                        }|j	                         ro|j                         }t               }||_        d}d| }t        |j                        }t        ||t        |gd       t               }d||d}	t        | d|	      S |j                  |j                         nt               }g }|||d	d
}	t        | d|	      S )Nr   r  r  Tr  r  )r  r  r  r  
modal_show)r  r  r  r  )r0   r   r5   r   r  r  r   r   r  r   rp   rq   r   ry  r  )
r   r  r  r  r  r  r   r   r  rK  s
             r   user_add_modalr  k  s     F
I~~'5##%&++-H 34K +H <GfgrfstGHNN+I/I;d
 ,oO*&#2G
 '?G<<MM/001'/ *"	G '?G44r   c                 .    t        |        t        d      S )Nz/adminportal/login/)r   r   r   s    r   admin_logoutr    s    
7O)**r   c                 j   g }t        t        |      }t               }|j                  |       |j	                          d}d| }t        |j                        }t        ||t        |gd       t        j                  | t        j                  d       t        |      }||d|d	}	t        | d
|	      S )Nr  z%Navya Bakers Registration Successful r  Fr  zGPassword Reset Successfully. You will receive a mail with the password.r  r:  r  r  )r   r  r   r  r  r  r   rp   rq   r   add_messageSUCCESSr3   r   )
r   r  r  r   r  r   r   	recipientr  rK  s
             r   reset_passwordr    s     FUw/D +,Kk"IIK 6G^_j^klGDJJIgw)ER ("2"2bd &Dh[bcG',g66r   c                 l   t         j                  j                  d      }t        |d      }| j                  j                  d      }	 |j                  |      }|dd}t        | d|      S # t        t        f$ r |j                  d      }Y 4t        $ r |j                  |j                        }Y Yw xY w)Nr  rd  re  r   r:  )category_listcategory_activezcategory_list.html)rO   r  rC  r   rh  r   ri  r!   rj  r    rk  r   )r   category_datarm  re  r  rK  s         r   r   r     s     $++44_EM-,I;;??6"D;%%d+
 !)XFG'/99 i( )%%a( ;%%i&9&9:;ro  c                    g }t        t        |      }t        j                  j	                  |      }t               }| j                  dk(  rTt        | j                  | j                  |      }|j                         r| j                  j                  dd      rd |j                  _        | j                  j                  dd      rd |j                  _        | j                  j                  dd      rd |j                  _        |j!                         }	 | j"                  }d	}d
}	d|j$                   d|j&                   d}
t)        |||	|
       t+        d      S |j-                  |j.                         |d|j0                  |dt3        |      d}t5        | d|      S t        |      }|d|j0                  |d}t5        | d|      S #  Y t+        d      S xY w)Nr  r  r   r  image1r   image2image3r  zCategory updated	Category r  r  r  T)category_formsubcategory_statusr  sub_category_formsubcategory_addr  category_add.htmlr  r	  r  r
  )r   rO   rP   r  r  r8   r   r7   r   FILESr  r   r  iconstandard_imagebanner_imager  r   r  r  r  r   ry  r  r   r?  r   )r   r  r  r  sub_category_listr
  r  r  r  r   r   rK  s               r   category_editr    s    F [AH*229989L.0~~GLL'--(K==?||"-%)"||"-/3,||"--1*yy{H	"<<$, )(*@*@)AhNdNdMeemnHh= O,, MM$++&(,DYaYfYf,=RV'+,='>@G '#6@@X. $DQYQ^Q^$57G'.88O,,s   ;G Gc                 d   g }| j                   dk(  rt        | j                  | j                        }t	               }|j                         r|j                         }	 | j                  }d}d}d|j                   d|j                   d}	t        ||||	       t        t        |j                        }
t        |
      }|d	|j                  |d
}t        | d|      S |j                  |j                          ||dd}t        | d|      S t               }g }||ddd}t        | d|      S #  Y xY w)Nr   r  zCategory createdr  r  z createdr  r  Tr  r  r   )r  r  r  F)r  r  r	  r  )r   r7   r   r  r8   r  r  r   r  r  r  r   rO   r   r   ry  r  )r   r  r  r  r
  r  r  r  r   r   category_instancerK  s               r   add_categoryr    sJ    F~~$W\\7==A24!!#$))+H"<<$, )(*@*@)AhNdNdMeemnHh= !2/hmm T(2CDM(5Tbjbobo,=?G'#6@@MM-../ !.!G '#6@@$&#	G '.883s   ;D+ +D/c           	         g }t        t        |      }| j                  dk(  rRt        | j                        }t
        j                  j                  |      }t        |      }|j                         r|j                  d      }||_        |j                          	 | j                  }d}	d}
d	|j                   d
|j                   d|j                  j                   d|j                  j                    }t#        ||	|
|       t               }|d||dt%        |      d}t'        | d|      S |j)                  |j*                         |r||d||dt%        |      d}n||d||d}t'        | d|      S t        |      }t               }t
        j                  j                  |      }g }|d||dt%        |      d}t'        | d|      S #  Y xY w)Nr  r   r  r  Fr  r  Sub category createdr  r   created for category r  T)r
  r	  r  r  r  r  r  )r  r
  r	  r  r  r  r  )r  r
  r	  r  r  )r   rO   r   r8   r   rP   r  r  r7   r  r  r  r   r  r  r  r  r  r?  r   ry  r  )r   r  r  r  r
  r  r  r  r  r  r   r   rK  s                r   add_sub_categoryr  0  sB    F {CH~~27<<@ /66==x=P$h7%%',111?L$,L!"<<$0 -l.L.L-M\ZfZxZxYy  zP  Q]  Qf  Qf  Qt  Qt  Pu  u@  AM  AV  AV  Ad  Ad  @e  fHh= !7 8,=UY(5kfj'+,='>@G '#6@@ MM+223 $):*._j'+TBS=T	 %):*._j '#6@@ %h724.66==x=P(9QUhu"-$X\]nXoq '.88Ms   A(G Gc                    t        t        |      }|j                  j                  }g }| j                  dk(  rt        | j                  | j                  |      }|j                         r|j                          	 | j                  }d}d}d|j                   d|j                   d|j                  j                   d	|j                  j                   }	t        ||||	       t!        d
t#        |       d      S |j%                  |j&                         nt        |      }||d||d}
t)        | d|
      S #  Y YxY w)Nr  r   r  r  zSub category updatedr  r   updated for category r  r  r  r:  )r  r
  r  r  r  zedit_sub_category.html)r   rP   r  r   r   r8   r   r  r  r  r   r  r  r  r  r  r   r  ry  r  r   )r   r  r  r  r  r  r  r  r   r   rK  s              r   edit_sub_category_rowr  t  so    %%7oNL'',,KF~~%gllGMMLY==?IIK"<<$0 -l.L.L-M\ZfZxZxYy  zP  Q]  Qf  Qf  Qt  Qt  Pu  u@  AM  AV  AV  Ad  Ad  @e  fHh= <S=M<NaPQQ MM$++&%|<dS["1+OG'3W==s   <A(D9 9D=c                    g }d}d}d}| j                   dk(  r| j                  j                  d      }|r4t        t        |      }t        | j                  | j                  |      }n t        | j                  | j                        }|j                         rN|j                         }| j                  j                  d      }|D ]#  }t        j                  j                  ||	       % | j                  j                  d
      }	|	D ]#  }
t        j                  j                  ||
       % d}d}	 | j                  }d}d}d|j                   d|j                    d|j"                  j$                   d|j"                  j&                   d|j(                  j*                   d|j(                  j,                   d}t/        ||||       t1        d||d|j2                  id      S |j5                  |j6                         t1        d|j6                  d      S t               }||d|||d}t9        | d|      S #  Y sxY w)a)  
    In the products listing on side bar. we have master product listing section.
    On clicking the master product, master product listing will open.
    On the listing page we have a add button.
    We can add an new master product by clicking this button.
    :param request:
    :return:
    FTNr   
product_idr  r  imagesr  imagevideosr  videor  zMaster Product AddedProduct r  z added for category  () and sub category ) idr  
sku_activedetails_activer  r  r  r:  )r  product_formr  r,  r-  r  zproduct_add.html)r   r   r   r   rQ   r9   r  r  r  getlistrS   r  r  rT   r   	item_name	item_codeitem_categoryr  r  item_sub_categoryr  r  r  r   r*  ry  r  r   )r   r  r,  r-  r  r  r/  r   r"  r#  r%  r  r  r   r   rK  s                   r   master_product_addr5    s    FJNG~~\\%%l3
'Z@G&w||W]]WUL 'w||W]]CL  ""'')G ]]**84F$$++G5+I   ]]**84F$$++G5+I   J"N"<<$0 ():):(;<HYHYGZZnov  pE  pE  pS  pS  oT  TV  W^  Wl  Wl  Wz  Wz  V{  {N  OV  Oh  Oh  Oz  Oz  N{  {}  ~E  ~W  ~W  ~i  ~i  }j  jl  mHh=  ("0'**	!   MM,--.E\=P=P QRR"} $# (G '-w775s   6BH< <I c           
         t        t        |      }| j                  dk(  rOt        | j                        }|j                         r|j                  d      }|j                  dkD  r|j                  dk(  rd|_	        ||_
        |j                         }t        j                  j                         D ]  }t        j                  j                  |||j                  |j                  d	      \  }}|j                  dk(  r|j                  j                   j#                  |       |j                   j#                  |       |j                  j$                  j                   j#                  |       |j                  j&                  j                   j#                  |       |j                  rt        j                  j)                  |j                  j*                  
      j-                  d       t.        j                  j)                  |j                  j$                  j0                        j-                  d       t2        j                  j)                  |j                  j&                  j0                        j-                  d       |j                           	 | j4                  }	d}
d}d|j6                   d|j8                   d|j                  j:                   d|j                  j<                   d	}t?        |	|
||       tA        d|j6                  |j8                  |jB                  |jD                  |jF                  |j*                  d      S tA        d|jH                  d      S tA        ddd      S #  Y yxY w)a5  
    Sku is different sub category of product.
    for eg: if we consider a biscuit. Same biscuit have 50g, 60g packet etc......
    We can add sku from submitting a modal from from master product create and edit form
    in master product listing

    :param request:
    :param product_id:
    :return:
    r  r   Fr     rs  Tru  r   rt  rr  defaultsr*  long_distance_availabilityr  r  z	SKU AddedSKU r  z added for product (r)  r  )r   sku_namesku_codesku_quantitysku_unitsku_mrpsku_idr   r   r  Invalid request methodr   r   )%r   rQ   r   r>   r   r  r  sku_expiry_durationrx  r=  r  rL   r  r  rR   get_or_creatert  addr3  r4  r  r*  updaterO   r   rP   r   r@  rA  r1  r2  r  r   rB  rC  rD  r  )r   r  r  r  rr  sku_datarJ  sales_productr   r  r  r   r   s                r   add_skurO    s      Z8G~~ w||$==?))5))C&&+)0K15.!CKxxzH \\%%'#<#D#D#R#R c36>>S^^\ $S $ q >>Y.KK**..q1NN&&q)KK--88<<Q?KK11<<@@C11$$++s{{~~+>EEaeEf#++228Q8Q8V8V2W^^37 _ 9&..553;;;X;X;];]5^ee37 f 9 
3 (8"<<$% $S\\N,s||nL_`c`k`k`u`u_vvwx{  yD  yD  yN  yN  xO  OQ  RHh=  #LLLL # 0 0LL;;&&!    7dkk JKK77OPQQs   !A)M? ?Nc           
      *   t         j                  j                  |      j                  d      }|D cg c]G  }|j                  |j
                  |j                  |j                  |j                  |j                  dI }}t        d|d      S c c}w )z
    Used to list the skus in master product add and edit form.
    Master product add : product_add.html,
    Master product edit : product_edit_01.html
    :param request:
    :param product_id:
    :return:
    r  
created_at)rE  r@  rA  rB  rC  rD  r  )r   skus)rX   r  r  rC  r*  r@  rA  rB  rC  rD  r   )r   r  rS  rr  sku_lists        r   get_skusrU  ?  s     ;;4==lKD  # &&LLLL((LL;;    9h?@@s   ABc           	         | j                   dk(  r=| j                  j                  d      }t        t        |      }|j
                  j                  }|j
                  j                  j                  }|j
                  j                  j                  }|j                          t        j                  |||gd       t        j                  |||gd       	 | j                  }d}d}d|j                   d	|j                    d
|j
                  j"                   d|j
                  j$                   d	}	t'        ||||	       t)        ddi      S t)        ddd      S #  Y xY w)z
    Delete Sku function used to delete an sku from product edit and product add section.
    product edit : product_edit_01.html,
    product add : product_add.html
    :param request:
    :return:
    r   rE  r;  r   r   r  zSKU Deletedr>  r  z deleted for product r?  r)  r   r  r   zInvalid requestrH  )r   r   r   r   rX   r  r*  r3  r   r4  r  r   r   r   r   r@  rA  r1  r2  r  r   )
r   rE  rr  sku_product_idsku_category_idsku_sub_category_idr  r  r   r   s
             r   
delete_skurZ  W  s`    ~~!!(+/ ++..++3388!kk;;@@ 	

 	*55NK^`o;q}~'33.J]_n9o{|}	||H H#G l3<<.H]^a^i^i^s^s]ttuvy  wB  wB  wL  wL  vM  MO  PK(G[9 Xy12277HIJJ	s   A)E E c                    	 t         j                  j                  |      }d|j                  |j                  |j
                  |j                  |j                  |j                  |j                  |j                  |j                  |j                  d
d}t        |      S # t         j                  $ r t        ddd      cY S w xY w)z3
    Used to get a sku detail with the sku id.
    r;  r  )
r@  rA  rB  rC  rD  rI  sku_bulk_qty_limitsame_day_deliverycustomization_availablerx  )r   rr  r   zSKU not found.rH  )rX   r  r   r@  rA  rB  rC  rD  rI  r\  r]  r^  rx  r   DoesNotExist)r   rE  rr  datas       r   get_skura    s    Nkkooo(  LLLL # 0 0LL;;'*'>'>&)&<&<%(%:%:+.+F+F!nn
 D!! Nw;KLMMNs   BB! !!CCc                    t         j                  j                         D ]  }t        j                  j	                  || | j
                  | j
                  d      \  }}| j
                  |_        | j
                  |_        |j                          t        j                  | j                  gd       | j
                  dk(  rt         j                  j                         D ]  }t        j                  j                  | |      j                         }|r|j                  dk(  r| j                  j                  j!                  |       | j                  j!                  |       | j                  j"                  j                  j!                  |       | j                  j$                  j                  j!                  |       | j                  j'                  |       t)        j                  | j                  gd       "t         j                  j                         D ]  }| j                  j'                  |        t)        j                  | j                  gd        It         j                  j                         D ]  }| j                  j'                  |        t)        j                  | j                  gd        y)aQ  
    On sku change we need to update the status to every shop the sku is assigned
    to.
    Based on the sku and shop admin status we are checking the availability of product.
    If shop_admin status is not visible we check for long distance availability based on
    sku status.
    :param sku:
    :param sku_data:
    :return:
    r8  r9  r   r   rs  rr  rt  N)rL   r  r  rR   rJ  rx  ru  r   r  r   r   r*  r  rw  r  rt  rK  r3  r4  remover   )rM  rJ  rN  r   rf  sales_unit_status_checkrz  s          r   sku_update_status_changesrf    s"    \\ 5<<JJh+3+>+>(J]J]^ K 
q
 +3*=*=''224@@x{{m_`a )+!\\--/	*C*K*K*R*RW_^g +S +iininip (* /@@IM !((3377	B ++//	: ((66AAEEiP ((::EEII)T ++229=0<<8;;-[\] $ 0 0 2 ++2248 !3,88x{{mWXY+ 00 "\\--/	##**95 0$00x{{mqQS  r   c           	      ^   t        t        |      }| j                  dk(  rt        | j                  |      }|j                         r|j                         }t        |       	 | j                  }d}d}d|j                   d|j                   d|j                  j                   d	|j                  j                   d
	}t        ||||       t%        ddd      S t%        d|j&                  d      S t%        ddd      S # t        $ r"}	t!        j"                  d|	        Y d}	~	Zd}	~	ww xY w)z
    Update an sku listed in the master product listing.
    update the sku in edit or add sku page.
    product edit : product_edit_01.html,
    product add : product_add.html

    :param request:
    :param sku_id:
    :return:
    r;  r   r  r  zSKU Updatedr>  r  z updated for product r?  r)  zSKU Updated Error (logging): Nr  zSKU updated successfully.rH  r   rF  rG  )r   rX   r   r>   r   r  r  rf  r   r@  rA  r  r1  r2  r  r   r   r   r   r  )
r   rE  rr  r  rM  r  r  r   r   r   s
             r   
update_skurh    sM    CF
+C~~w||c2==?yy{H &h/"<<$' $X%6%6$7|HDUDUCVVkltl|l|  mG  mG  lH  HI  JR  JZ  JZ  Jd  Jd  Ie  eg  hHh=  9A\ ]^^7dkk JKK77OPQQ   =aSAB	s   $A)D 	D,
D''D,c                    t        t        |      }| j                  dk(  r| j                  j	                  d      }|||_        |j                          t        |       	 | j                  }d}d}d|j                   d|j                   d| d	|j                  j                   d
|j                  j                   d}t        ||||       t        ddd      S t        ddd      S t        ddd      S #  Y .xY w)z
    Sku status update from product listing.
    When we click on the drop down on product listing, sku will list.
    On the sku list we have the option to change the sku status.

    :param request:
    :param sku_id:
    :return:
    r;  r   rx  r  zSKU Status Updatedr>  r  z updated status to  for product r?  r)  r  z SKU status updated successfully.rH  r   z"No status provided in the request.z-Invalid request method. Only POST is allowed.)r   rX   r   r   r   rx  r  rf  r   r@  rA  r  r1  r2  r  r   )r   rE  rr  r   r  r  r   r   s           r   update_sku_from_product_listrk    s>    CF
+C~~!!,/ #CNHHJ &c*"<<$. $S\\N,s||nL_`f_ggtux  vA  vA  vK  vK  uL  LM  NQ  NY  NY  Nc  Nc  Md  df  gHh=  9Ac dee7?c dee77fghhs   !A,C7 7C;c                 t   t        t        |      }g }d}d}|j                  }|j                  }| j                  j                  d      }| j                  j                  d      }	| j                  dk(  rt        | j                  | j                  |      }
|
j                         r|
j                         }| j                  j                  d      }|D ]#  }t        j                  j                  ||	       % | j                  j                  d
      }|D ]#  }t        j                  j                  ||       % d}d}t!        j"                  |j$                  |j$                  |j&                  g       t)        j"                  |j$                  |j$                  |	|gd       	 | j*                  }d}d}d|j,                   d|j.                   d|j                  j0                   d|j                  j2                   d|j                  j4                   d|j                  j6                   d}t9        ||||       t;        d||d|j&                  id      S |j=                  |
j>                         t;        d|
j>                  d      S t        |      }
||
d||||d}tA        | d|      S #  Y vxY w)a  
        Editing the product from the product listing page.
        In the side bar we have master product section
        On opening the master product we have the option to edit
        the product.
    :param request:
    :param product_id:
    :return:
    r  FTr3  r4  r   r  r   r!  r#  r$  r   r   r   r  zMaster Product Updatedr&  r  r  r'  r(  r)  r*  r+  r.  r:  )r  r/  r  r,  r-  r  r  zproduct_edit_01.html)!r   rQ   r3  r4  r   r   r   r9   r  r  r  r0  rS   r  r  rT   r   r   r   r*  r   r   r1  r2  r  r  r  r  r  r   ry  r  r   )r   r  r  r  r,  r-  existing_categoryexisting_sub_categoryto_categoryto_sub_categoryr/  r   r"  r#  r%  r  r  r   r   rK  s                       r   master_product_editrr  1  s4     Z8GFJN  --#55,,""?3Kll&&':;O ~~"7<<Q  ""'')G ]]**84F$$++G5+I   ]]**84F$$++G5+I   J"N .99@Q@V@VWlWqWqryr|r|?}~:FFOdOiOij{  kA  kA  BQ  S^  O`  lm  n"<<$2 ():):(;<HYHYGZZpqx  rG  rG  rU  rU  qV  VX  Y`  Yn  Yn  Y|  Y|  X}  }P  QX  Qj  Qj  Q|  Q|  P}  }  @G  @Y  @Y  @k  @k  l  ln  oHh=  ("0'**	!   MM,--.E\=P=P QRR0L $# ( G '17;;7s   *BJ3 3J7c                 @   t        t        |      }|j                  j                  }|j	                          	 | j
                  }d}d}d|j                  j                   d|j                  j                   d|j                  j                  j                   d|j                  j                  j                   d|j                  j                  j                   d|j                  j                  j                   d	}t        ||||       t        d
|      S #  Y xY w)zV
    deleting product image
    :param request:
    :param image_id:
    :return:
    r;  r  zMaster Product Image deletedr&  r  z  deleted its image for category r'  r(  r)  edit_master_productrQ  )r   rS   r  r*  r  r   r1  r2  r3  r  r  r4  r  r  r  r   )r   image_idr"  r  r  r  r   r   s           r   delete_imagerv    s    lx8E!!J	LLN<<0 !8!8 9emmF]F]E^^~  @E  @M  @M  @[  @[  @i  @i  j  jl  mr  mz  mz  mH  mH  mV  mV  lW  Wj  kp  kx  kx  kJ  kJ  k\  k\  j]  ]_  `e  `m  `m  `  `  `Q  `Q  _R  RT  UHh5 )jAA   CD Dc                 @   t        t        |      }|j                  j                  }|j	                          	 | j
                  }d}d}d|j                  j                   d|j                  j                   d|j                  j                  j                   d|j                  j                  j                   d|j                  j                  j                   d|j                  j                  j                   d	}t        ||||       t        d
|      S #  Y xY w)zZ
    deleting the product video
    :param request:
    :param video_id:
    :return:
    r;  r  zMaster Product Video deletedr&  r  z  deleted its video for category r'  r(  r)  rt  rQ  )r   rT   r  r*  r  r   r1  r2  r3  r  r  r4  r  r  r  r   )r   video_idr%  r  r  r  r   r   s           r   delete_videorz    s    lx8E!!J	LLN<<0 !8!8 9emmF]F]E^^~  @E  @M  @M  @[  @[  @i  @i  j  jl  mr  mz  mz  mH  mH  mV  mV  lW  Wj  kp  kx  kx  kJ  kJ  k\  k\  j]  ]_  `e  `m  `m  `  `  `Q  `Q  _R  RT  UHh5 )jAArw  c                    | s;t         j                  j                  |j                        j	                  d       nd}| D ]q  }t
        j                  j                  |d      j                         }|s5t         j                  j                  |j                        j	                  d       d} n |s:t         j                  j                  |j                        j	                  d       t        j                  j                  |dd      }|s;t        j                  j                  |j                        j	                  d       y	d}|D ]q  }t
        j                  j                  |d      j                         }|s5t        j                  j                  |j                        j	                  d       d} n |s:t        j                  j                  |j                        j	                  d       y	)
z
    long distance product availability check and update the availability
    :param long_dist_sku_sub_category:
    :param product_category:
    :param product_sub_category:
    :return:
    r  Fr<  rs  rr  r   Tr7  product__item_categoryrx  sku_expiry_duration__gtN)	rP   r  r  r   rL  rR   rw  rX   rO   )	long_dist_sku_sub_categoryproduct_categoryproduct_sub_categorylong_dist_sub_category_flagrJ  long_dist_sales_check_sublong_dist_sku_categorylong_dist_sku_category_flaglong_dist_sales_check_cats	            r   #long_distance_master_product_deleter    s    &""))/C/H/H)IPP', 	Q 	. ',#+A(A(I(I(P(PUV_h(P(i(o(o(q%("**117K7P7P1QXX/3 Y 5.2+ , +&&--3G3L3L-MTT+0 U 2 ![[//GW;D^` 0 b!&&,<,A,A&BII', 	J 	.  ',#'A(A(I(I(P(PUV_h(P(i(o(o(q%(''..4D4I4I.JQQ/3 R 5.2+ ( +##**0@0E0E*FMM+0 N 2
r   c                    t         j                  j                  |      }|j                         }|j                  }|j
                  }|rat        j                  j                  |      }|r0t        j                  | t        j                  d       t7        d      S |j                          t        j                  j                  |dd      }t        |||       t        j                  |j                  |j                  gd       	 | j                   }d	}	d
}
d|j"                   d|j$                   d|j                  j&                   d|j                  j(                   d|j
                  j*                   d|j
                  j,                   d}t/        ||	|
|       t7        d      S t7        d      S # t0        $ r,}t3        j4                  d|        Y d}~t7        d      S d}~ww xY w)z]
    deleting the master product
    :param request:
    :param product_id:
    :return:
    r  )Productz1Your Product used in ads! couldn't delete productrs  r7  product__item_sub_categoryrx  r  r   r   r  zMaster Product deletedr&  r  r  r'  r(  r)  z&Master Product Delete Error(logging): Nlist_master_product)rQ   r  r  rw  r3  r4  rg   r   r  WARNINGr  rX   r  r   r   r   r   r1  r2  r  r  r  r  r  r   r   r   r   )r   r  r  product_datar  r  adsr  r  r  r   r   r   s                r   master_product_deleter    sX    %%%4G==?L#11'99kk   4  (*:*:!TV@ )**9 NN
 *-););WkGPjl *< *n& 00JL\^rs:FFOcOhOhiyi~i~  OA  MN  O	"<<$2 ()?)?(@\McMcLddz  |H  |V  |V  |d  |d  {e  eg  ht  hB  hB  hP  hP  gQ  Qd  eq  eC  eC  eU  eU  dV  VX  Ye  Yw  Yw  YI  YI  XJ  JL  MHh= )**8)**   FqcJK)**s   BF8 8	G-G((G-)r   c           
         | j                   j                  d      }| j                   j                  d      }| j                   j                  d      }| j                   j                  d      }t        j                  j	                  |      j                  d      }|r|j	                  ||      }n|j	                  |      }g }|j	                         D ]  }|j                  |j                  |j                  |j                  j                  |j                  j                  g d	}g }	|j                  j                         D ]J  }
|
j                  |
j                  |
j                   |
j"                  |
j$                  |
j&                  |
j(                  d
}	 t*        j                  j-                  ||
ddd      \  }}|j.                  dk(  r|
j0                  j3                  |j0                         |
j4                  j0                  j3                  |j0                         |
j4                  j                  j0                  j3                  |j0                         |
j4                  j                  j0                  j3                  |j0                         n7t7        j8                  |
j:                  |j0                  j<                  gd       |j>                  dk(  rG|
j@                  dkD  rd|
_!        |
jE                          t        j                  j	                  |
j4                  j:                        jG                  d       tH        j                  j	                  |
j4                  j                  j<                        jG                  d       tJ        j                  j	                  |
j4                  j                  j<                        jG                  d       nztL        j                  j	                  |
j:                        jG                  d       tL        j                  j	                  |
j4                  dd      }|sEt        j                  j	                  |
j4                  j:                        jG                  d       nd}|D ]{  }t*        j                  j	                  |d      jO                         }|s5t        j                  j	                  |
j4                  j:                        jG                  d       d} n |sDt        j                  j	                  |
j4                  j:                        jG                  d       tL        j                  j	                  |
j4                  j                  dd      }|sOtJ        j                  j	                  |
j4                  j                  j<                        jG                  d       nd}|D ]  }t*        j                  j	                  |d      jO                         }|s5tJ        j                  j	                  |
j4                  j                  j<                        jG                  d       d} n |sNtJ        j                  j	                  |
j4                  j                  j<                        jG                  d       tL        j                  j	                  |
j4                  j                  dd      }|sPtH        j                  j	                  |
j4                  j                  j<                        jG                  d       nd}|D ]  }t*        j                  j	                  |d      jO                         }|s5tH        j                  j	                  |
j4                  j                  j<                        jG                  d       d} n |stH        j                  j	                  |
j4                  j                  j<                        jG                  d       n;tL        j                  j	                  |
j:                        jG                  d       tL        j                  j	                  |
j4                  dd      }|sEt        j                  j	                  |
j4                  j:                        jG                  d       nd}|D ]{  }t*        j                  j	                  |d      jO                         }|s5t        j                  j	                  |
j4                  j:                        jG                  d       d} n |sDt        j                  j	                  |
j4                  j:                        jG                  d       tL        j                  j	                  |
j4                  j                  dd      }|sOtJ        j                  j	                  |
j4                  j                  j<                        jG                  d       nd}|D ]  }t*        j                  j	                  |d      jO                         }|s5tJ        j                  j	                  |
j4                  j                  j<                        jG                  d       d} n |sNtJ        j                  j	                  |
j4                  j                  j<                        jG                  d       tL        j                  j	                  |
j4                  j                  dd      }|sOtH        j                  j	                  |
j4                  j                  j<                        jG                  d       nd}|D ]  }t*        j                  j	                  |d      jO                         }|s5tH        j                  j	                  |
j4                  j                  j<                        jG                  d       d} n |sNtH        j                  j	                  |
j4                  j                  j<                        jG                  d       |j>                  |d<   |j.                  |d<   |	jQ                  |       M |	|d<   |jQ                  |        tS        |d      }|jU                  d      }tW        d d!|i      }| jX                  jZ                  d"k(  rtW        d#d!|i      } ntW        d$d!|i      } t]        | |d%d&      S #  d|d<   d|d<   |	jQ                  |       Y xY w)'a  
    this is a function to filter and list the products based on sub category
    we have this drop down menu having the list of sub categories
    if we select one sub category based on that sub category product will list on the below table.
    :param request:
    :return:
    r  subcategory_idr  product_typer  r  )r3  r4  r3  r   r1  r2  r  r  rr  r   r@  rA  rB  rC  rD  rx  rs  r8  r9  r   r   r7  Tr;  r<  r  Fr  rx  r  r|  r  r}  r   ru  rv  rr  rd  r   pagination.htmlr  r]  product_list_page.htmlproduct_page.htmltbody
paginationsafe)/rh  r   rQ   r  r  rC  r   r1  r2  r3  r  r4  r  rS  r  r@  rA  rB  rC  rD  rx  rR   rJ  ru  rt  rK  r  r   r   r*  r   r   rI  r=  r  rL  rO   rP   rX   rw  ry  r   ri  ry   r   r   r   )!r   r  r  r  r  product_list	list_datarJ  r  rT  jrM  rN  r   long_dist_sku_productlong_dist_product_flagxlong_dist_sales_checkr  r  ar  r  r  br  cdr   rm  productsr  r  s!                                    r   subcategory_product_listr    s    ++//-0K[[__%56Nkkooi(G;;??>2L##***ENN_L#**Xf*g#***EI  "dd1;;)*)F)F-.-@-@-R-R[]_ Add



dedrdr$%JJ199TUT`T`bHo*#<#D#D#R#R&A3<	R $S $ q
 !22i?LL$$]%=%=>II((,,]-E-EFII++66::=;S;STII//::>>}?W?WX:FFQTTS`SkSkSpSpLq}~ !''94,,r17;4 ((//199<</@GGcgGh'//66AII<S<S<X<X6Y``7; a =*2299qyy?Z?Z?_?_9`gg7; h = **add*3::V[:\030B0B199NW[] 1C 1_-  5$,,33qyy||3DKK;@ L B 6;2%:8Q8Y8Y8`8`efpy8`8z  9A  9A  9C 5#8$,$4$4$;$;qyy||$;$L$S$SCG %T %I=A$:$) &; $: ( 0 0 7 7199<< 7 H O O?D !P !F 69[[5G5G78yy7R7R'0" 6H 6N2  :.66==%&YY%@%@%E%E > GGMv;@ HN HB ;@7%?<U<]<]<d<dijs|<d<}  =D  =D  =F 9#<$6$>$>$E$E-.YY-H-H-M-M %F %OOUvCG PV PIBF$?$) &@ $? 2 : : A A)*)D)D)I)I !B !KKQ6?D LR LF 251C1C34993J3J'0" 2D 2N.  6+33::%&YY%<%<%A%A ; CCI6;@ DJ DB ;@7%;<U<]<]<d<diju~<d<  =F  =F  =H 9#<$3$;$;$B$B-.YY-D-D-I-I %C %KKQ6CG LR LIBF$?$) &< $? / 7 7 > >)*)@)@)E)E !? !GGMv?D HN HF KK&&!$$&/66RW6X,/KK,>,>qyyJSWY -? -[) 1 ((//199<</@GG7< H > 27.!6A4M4U4U4\4\abmv4\4w4}4}414 ( 0 0 7 7199<< 7 H O O?C !P !E9= 6 % "7  6$,,33qyy||3DKK;@ L B 251C1C34993N3N#,b 2D 2J. 6*2299!"!<!<!A!A : CCI67< DJ D> 7<3!;A8Q8Y8Y8`8`efqz8`8{  9B  9B  9D58 2 : : A A)*)D)D)I)I !B !KKQ6?C LR LE>B ; % "<  ;.66==%&YY%@%@%E%E > GGMv;@ HN HB .1[[-?-?/0yy/F/F#,b .@ .J* 2'//66!"!8!8!=!= 7 ??Ev7< @F @> 7<3!7A8Q8Y8Y8`8`efqz8`8{  9B  9B  9D58 / 7 7 > >)*)@)@)E)E !? !GGMv?C HN HE>B ; % "8  ;+33::%&YY%<%<%A%A ; CCI6;@ DJ DB &3%9%9" 1>0O0O,-)[ h 'U&w #x )R(I!!!$H!"3nh5OPJ||- !9NH;UV !4~x6PQ%zBOO'*%/"0:,-)s7   L2tEtE#t FtEtE"t>Ctt=c           
         | j                   j                  d      }| j                   j                  d      }| j                   j                  d      }t        j                  j	                  |      j                  d      }g }|rB|j	                  |      }t        j                  j	                  |      j                  dd	      }g }|j	                         D ]  }g }|j                  |j                  |j                  |j                  j                  |j                  j                  g d
}	|j                  j!                         D ]n  }
|
j                  |
j"                  |
j$                  |
j&                  |
j(                  |
j*                  |
j,                  d}	 t.        j                  j1                  ||
ddd      \  }}|j2                  dk(  r|
j4                  j7                  |j4                         |
j8                  j4                  j7                  |j4                         |
j8                  j                  j4                  j7                  |j4                         |
j8                  j                  j4                  j7                  |j4                         n7t;        j<                  |
j>                  |j4                  j@                  gd       |jB                  dk(  rk|
jD                  dkD  rtF        j                  j	                  |
j>                        jI                  d       t        j                  j	                  |
j8                  j>                        jI                  d       tJ        j                  j	                  |
j8                  j                  j@                        jI                  d       t        j                  j	                  |
j8                  j                  j@                        jI                  d       nztF        j                  j	                  |
j>                        jI                  d       tF        j                  j	                  |
j8                  dd      }|sEt        j                  j	                  |
j8                  j>                        jI                  d       nd}|D ]{  }t.        j                  j	                  |d      jM                         }|s5t        j                  j	                  |
j8                  j>                        jI                  d       d} n |sDt        j                  j	                  |
j8                  j>                        jI                  d       tF        j                  j	                  |
j8                  j                  dd      }|sOt        j                  j	                  |
j8                  j                  j@                        jI                  d       nd}|D ]  }t.        j                  j	                  |d      jM                         }|s5t        j                  j	                  |
j8                  j                  j@                        jI                  d       d} n |sNt        j                  j	                  |
j8                  j                  j@                        jI                  d       tF        j                  j	                  |
j8                  j                  dd      }|sPtJ        j                  j	                  |
j8                  j                  j@                        jI                  d       nd}|D ]  }t.        j                  j	                  |d      jM                         }|s5tJ        j                  j	                  |
j8                  j                  j@                        jI                  d       d} n |stJ        j                  j	                  |
j8                  j                  j@                        jI                  d       n;tF        j                  j	                  |
j>                        jI                  d       tF        j                  j	                  |
j8                  dd      }|sEt        j                  j	                  |
j8                  j>                        jI                  d       nd}|D ]{  }t.        j                  j	                  |d      jM                         }|s5t        j                  j	                  |
j8                  j>                        jI                  d       d} n |sDt        j                  j	                  |
j8                  j>                        jI                  d       tF        j                  j	                  |
j8                  j                  dd      }|sOt        j                  j	                  |
j8                  j                  j@                        jI                  d       nd}|D ]  }t.        j                  j	                  |d      jM                         }|s5t        j                  j	                  |
j8                  j                  j@                        jI                  d       d} n |sNt        j                  j	                  |
j8                  j                  j@                        jI                  d       tF        j                  j	                  |
j8                  j                  dd      }|sOtJ        j                  j	                  |
j8                  j                  j@                        jI                  d       nd}|D ]  }t.        j                  j	                  |d      jM                         }|s5tJ        j                  j	                  |
j8                  j                  j@                        jI                  d       d} n |sNtJ        j                  j	                  |
j8                  j                  j@                        jI                  d       |jB                  |d<   |j2                  |d<   |jO                  |
       q ||	d<   |jO                  |	        tQ        |d      }|jS                  d       }tU        d!d"|i      }| jV                  jX                  d#k(  rtU        d$d"|i      } ntU        d%d"|i      } |rt[        t]        |      | |d&d'      S t[        g | |d&d'      S #  d|d<   d|d<   |jO                  |       Y 9xY w)(z
    get the list of subcategories from a category
    on selecting the category from drop down a list of sub category loaded on drop down subcategory
    could be more efficient with processing limit to the page

    :param request:
    :return:
    r  r  r  r  r  r  r  r   r  r  r  rs  r8  r9  r   r   r7  r;  Tr<  r  Fr  r|  r  r}  r   ru  rv  rr  rd  r   r  r  r]  r  r  )subcategoriesr  r  r  )/rh  r   rQ   r  r  rC  rP   r@  r   r1  r2  r3  r  r4  r  rS  r  r@  rA  rB  rC  rD  rx  rR   rJ  ru  rt  rK  r  r   r   r*  r   r   rI  rX   rL  rO   rw  ry  r   ri  ry   r   r   r   r?  )!r   r  r  r  r  r  r  rJ  rT  r  r  rM  rN  r   r  r  rr  r  r  nr  r  r  lr  gowrm  r  r  r  s!                                    r   load_subcategoriesr  	  s    ++//-0Kkkooi(G;;??>2L##***ENN_LM#***E*2299k9RYYZ`buvI  "dd1;;)*)F)F-.-@-@-R-R[]_ Add



dedrdr$%JJ199TUT`T`bHi*#<#D#D#R#R&A3<	R $S $ q
 !22i?LL$$]%=%=>II((,,]-E-EFII++66::M<T<TUII//::>>}?W?WX ;FFQTTS`SkSkSpSpLq}~ ''94,,r1**add*3::VZ:[ ((//199<</@GGcgGh'//66AII<S<S<X<X6Y``7; a =*2299qyy?Z?Z?_?_9`gg7; h = **add*3::V[:\030B0B199NW[] 1C 1_-  5$,,33qyy||3DKK;@ L B 6;2%:8Q8Y8Y8`8`efqz8`8{  9B  9B  9D 5#8$,$4$4$;$;qyy||$;$L$S$SCG %T %I=A$:$) &; $: ( 0 0 7 7199<< 7 H O O?D !P !F 69[[5G5G78yy7R7R'0" 6H 6N2  :.66==%&YY%@%@%E%E > GGMv;@ HN HB ;@7%?<U<]<]<d<diju~<d<  =F  =F  =H 9#<$6$>$>$E$E-.YY-H-H-M-M %F %OOUvCG PV PIBF$?$) &@ $? 2 : : A A)*)D)D)I)I !B !KKQ6?D LR LF 251C1C34993J3J'0" 2D 2N.  6+33::%&YY%<%<%A%A ; CCI6;@ DJ DB ;@7%;<U<]<]<d<diju~<d<  =F  =F  =H 9#<$3$;$;$B$B-.YY-D-D-I-I %C %KKQ6CG LR LIBF$?$) &< $? / 7 7 > >)*)@)@)E)E !? !GGMv?D HN HF KK&&!$$&/66RW6X,/KK,>,>qyyJSWY -? -[) 1 ((//199<</@GG7< H > 27.!6A4M4U4U4\4\abmv4\4w4}4}414 ( 0 0 7 7199<< 7 H O O?C !P !E9= 6 % "7  6$,,33qyy||3DKK;@ L B 251C1C34993N3N#,b 2D 2J. 6*2299!"!<!<!A!A : CCI67< DJ D> 7<3!;A8Q8Y8Y8`8`efqz8`8{  9B  9B  9D58 2 : : A A)*)D)D)I)I !B !KKQ6?C LR LE>B ; % "<  ;.66==%&YY%@%@%E%E > GGMv;@ HN HB .1[[-?-?/0yy/F/F#,b .@ .J* 2'//66!"!8!8!=!= 7 ??Ev7< @F @> 7<3!7A8Q8Y8Y8`8`efqz8`8{  9B  9B  9D58 / 7 7 > >)*)@)@)E)E !? !GGMv?C HN HE>B ; % "8  ;+33::%&YY%<%<%A%A ; CCI6;@ DJ DB &3%9%9"0=0O0O,-"O \ 'U&k #l )R(I!!!$H!"3nh5OPJ||- !9NH;UV !4~x6PQd=.AEakl!&( 	( b5PZ[bghh+*%/"0:,-)s7   Mu!4Eu!E#u!'Fu!3Eu!E"u!%Cu!!vc                     | j                   j                  d      }|rFt        j                  j	                  |      j                  dd      }t        t        |      d      S t        g d      S )Nr  r  r   r  Fr  )rh  r   rP   r  r  r@  r   r?  )r   r  r  s      r   load_subcategories_productr  	  s^    ++//-0K*2299k9RYYZ`buvD/e<<BU++r   c                 l   t         j                  j                  d      }t        |d      }| j                  j                  d      }	 |j                  |      }|dd}t        | d|      S # t        t        f$ r |j                  d      }Y 4t        $ r |j                  |j                        }Y Yw xY w)Nrc  rd  re  r   r:  r  r  product_list.html)rQ   r  rC  r   rh  r   ri  r!   rj  r    rk  r   )r   r  rm  re  rK  s        r   master_product_listr  	  s     ((7H(B'I;;??6"D;%%d+
  (HEG'.88 i( )%%a( ;%%i&9&9:;ro  c           	      X   | j                   j                  dd      }| j                   j                  dd      }| j                   j                  dd      }t        j                  j	                  d      j                  d      }|r_t        j                  j	                  t        |      t        |	      z  t        |
      z  t        |      z        j                  d      }|r(t        j                  |d      }|j	                  |      }|r|j	                  |      }t        |d      }| j                   j                  d      }	 |j                  |      }	t        d      }
| j                   j!                         }d|v r|d= |	j"                  j$                  D cg c]  }||
 d|j'                  d       d| d! }}|	||||dd}t)        | d|      S # t        t        f$ r |j                  d      }	Y t        $ r |j                  |j                        }	Y w xY wc c}w )z
    In the product section in side bar. if we click on the master product.
    We will get the list of master products.
    :param request:
    :return:
    searchr   product_dateproduct_statusMaster Productr  r  item_name__icontainsitem_code__icontains'item_category__category_name__icontains/item_sub_category__sub_category_name__icontains%Y-%m-%drO  r  rd  re  r   r  ?r  r  &page=page_numberurlr:  )r  search_queryr   r  pagination_linksr  r  )rh  r   rQ   r  r  rC  rw   r   strptimer   ri  r!   rj  r    rk  rt   copyrm  
page_range	urlencoder   )r   product_splitr  r  r  r  formatted_daterm  re  r  base_urlquery_paramsr  r  rK  s                  r   r  r  	  s9    ;;??8R0L;;??>26L[[__%5r:N ##**8H*IRRSbcL ''..<0<01lCD lKL

 (?
# 	 !**<D#**n*M#**.*I,+I ;;??6"D;%%d+ ,-H;;##%L  $--88
 9K 'Zq!7!7S!7!A B&V	
 9   !$(,#G '.885 i( )%%a( ;%%i&9&9:;s   G  $H' H$>#H$#H$)r[  r\  r]  c           
      H    | j                   j                  dd      }t        j                  j	                  |      j                  d      }| j                  j                  dk(  r[t        j                  j                  d      j	                  | j                  j                        j                         j                  }t        j                  j                         j                  d      }t        t        |	      }|j                  }|j                   }|rot        j                  j	                  |      j	                  t#        |
      t#        |      z  t#        |      z  t#        |      z        j                  d      }| j                   j                  d      }	|	r|j	                  |	      }| j                   j                  d      }
|
r|j	                  |
      }g }|D ]"  }|j$                  |j&                  |j(                  |j*                  j,                  |j.                  j0                  g d}g }|j2                  j                         D ]  }	 |j$                  |j4                  |j6                  |j8                  |j:                  |j<                  |j>                  d}t@        j                  jC                  ||ddd      \  }}|jD                  dk(  r|jF                  jI                  |       |jJ                  jF                  jI                  |       |jJ                  j*                  jF                  jI                  |       |jJ                  j.                  jF                  jI                  |       n7tM        jN                  |jP                  |jF                  j                  gd       |jR                  dk(  r|jT                  dkD  rptV        j                  j	                  |jP                        j                         }d|_,        |j[                          t        j                  j	                  |jJ                  jP                        j                         }d|_,        |j[                          t        j                  j	                  |jJ                  j*                  j                  	      j                         }d|_,        |j[                          t\        j                  j	                  |jJ                  j.                  j                  	      j                         }d|_,        |j[                          nztV        j                  j	                  |jP                        j_                  d       tV        j                  j	                  |jJ                  dd      }|sEt        j                  j	                  |jJ                  jP                        j_                  d       nd}|D ]{  }t@        j                  j	                  |d      j                         }|s5t        j                  j	                  |jJ                  jP                        j_                  d       d} n |sDt        j                  j	                  |jJ                  jP                        j_                  d       tV        j                  j	                  |jJ                  j.                  dd       }|sOt\        j                  j	                  |jJ                  j.                  j                  	      j_                  d       nd}|D ]  }t@        j                  j	                  |d      j                         }|s5t\        j                  j	                  |jJ                  j.                  j                  	      j_                  d       d} n |sNt\        j                  j	                  |jJ                  j.                  j                  	      j_                  d       tV        j                  j	                  |jJ                  j*                  dd!      }|sPt        j                  j	                  |jJ                  j*                  j                  	      j_                  d       nd} |D ]  }!t@        j                  j	                  |!d      j                         }"|"s5t        j                  j	                  |jJ                  j*                  j                  	      j_                  d       d}  n | st        j                  j	                  |jJ                  j*                  j                  	      j_                  d       n;tV        j                  j	                  |jP                        j_                  d       tV        j                  j	                  |jJ                  dd      }|sEt        j                  j	                  |jJ                  jP                        j_                  d       nd}|D ]{  }#t@        j                  j	                  |#d      j                         }|s5t        j                  j	                  |jJ                  jP                        j_                  d       d} n |sDt        j                  j	                  |jJ                  jP                        j_                  d       tV        j                  j	                  |jJ                  j.                  dd       }|sOt\        j                  j	                  |jJ                  j.                  j                  	      j_                  d       nd}|D ]  }$t@        j                  j	                  |$d      j                         }|s5t\        j                  j	                  |jJ                  j.                  j                  	      j_                  d       d} n |sNt\        j                  j	                  |jJ                  j.                  j                  	      j_                  d       tV        j                  j	                  |jJ                  j*                  dd!      }|sOt        j                  j	                  |jJ                  j*                  j                  	      j_                  d       nd} |D ]  }%t@        j                  j	                  |%d      j                         }"|"s5t        j                  j	                  |jJ                  j*                  j                  	      j_                  d       d}  n | sNt        j                  j	                  |jJ                  j*                  j                  	      j_                  d       |jR                  |d"<   |jD                  |d#<   |ja                  |        ||d'<   |ja                  |       % ti        |d(      }'| j                   j                  d)      }(	 |'jk                  |(      })tu        d+|d,d-.      }*| j                   jw                         }+d)|+v r|+d)= |)jx                  jz                  D ,cg c]  },|,|* d/|+j}                  d01       d2|, d3! }-},|)||-|d4||||d5	}.| j                  j                  dk(  rV| j~                  j                  d6      d7k(  r+t        d8|)|-d9      }/t        d:d;|)i      }0t        |/|0d<      S t        | d=|.      S | j~                  j                  d6      d7k(  r+t        d>|)|-d9      }/t        d:d;|)i      }0t        |/|0d<      S t        | d?|.      S # tb        $ r>}&te        jf                  d$|&        d%d"<   d%|d#<   |ja                  |       Y d&}&~&rd&}&~&ww xY w# tl        tn        f$ r |'jk                  d*      })Y tp        $ r |'jk                  |'jr                        })Y w xY wc c},w )@z
    get the product list on shop admin product listing.
    we can view the product menu on the side bar.
    :param request:
    :param shop_id:
    :param product_type:
    :return:
    r  r   r  r  r]  r  r  rc  r  r  r  r  r  category_pager  subcategory_pager4  r  r  rs  r8  r9  r   r   r7  r;  TFr<  r  r|  r  r}  r   ru  z'SKU Status Issue(display as disabled): rv  Nrr  rd  re  r   list_shop_productr  )r  r  kwargsr  r  r  r  r  r:  )	r  r  r  r  rg  r  	shop_nameshop_locationr   x-requested-withXMLHttpRequestr  )r  r  r  r  r  zproduct_list_shop_admin.htmlr  zproduct_list_shop.html)Crh  r   rQ   r  r  rC  r   r   rL   r<  r   rw  rO   r  r   r  r  rw   r   r1  r2  r3  r  r4  r  rS  r@  rA  rB  rC  rD  rx  rR   rJ  ru  rt  rK  r  r   r   r*  r   rI  rX   r=  r  rP   rL  ry  r   r   r   r   ri  r!   rj  r    rk  rt   r  rm  r  r  headersry   r   r   )1r   r  r  r  r  r   shop_detailsr  r  r  sub_category_pager  rJ  r  rT  r  rM  rN  r   
sku_updateproduct_updateproduct_category_updateproduct_sub_category_updater  r  r  r  r  r  vr  r  r  r  r  stqr   rm  re  r  r  r  r  r  rK  r  r  s1                                                    r   r  r  @
  s    ;;??8R0L ##***ENN_L ||-,,//0ABII"),,"3"3 J 55:UWTT 	 $++//1::=IM %T8L&&I ..M ''..L.IPP<0<01lCD lKL

 (?
# 	 KKOOO4M #***G  (:;#**=N*O" Idd1;;)*)F)F-.-@-@-R-R[]_ AA*"#$$AJJAJJhihvhv()

qyyXYXdXdf $=#D#D#R#R+3<	R $S $ q
 !22i?LL$$W-II((,,W5II++66::7CII//::>>wG:FFQTTS`SkSkSpSpLq}~ !''94,,r1%([[%7%7144%7%@%F%F%H
@D
="))1)9)9)@)@AIILL)@)Q)W)W)YDHA&++-2A2I2I2P2P!"!8!8!=!= 3Q 3??Duw 0MQ/J/4466H6P6P6W6W!"!<!<!A!A 7X 7CCH57 4QU3N388: **add*3::V[:\030B0B199NW[] 1C 1_-  5$,,33qyy||3DKK;@ L B 6;2%:8Q8Y8Y8`8`efqz8`8{  9B  9B  9D 5#8$,$4$4$;$;qyy||$;$L$S$SCG %T %I=A$:$) &; $: ( 0 0 7 7199<< 7 H O O?D !P !F 69[[5G5G78yy7R7R'0" 6H 6N2  :.66==%&YY%@%@%E%E > GGMv;@ HN HB ;@7%?<U<]<]<d<dijt}<d<~  =E  =E  =G 9#<$6$>$>$E$E-.YY-H-H-M-M %F %OOUvCG PV PIBF$?$) &@ $? 2 : : A A)*)D)D)I)I !B !KKQ6?D LR LF 251C1C34993J3J'0" 2D 2N.  6+33::%&YY%<%<%A%A ; CCI6;@ DJ DB ;@7%;<U<]<]<d<diju~<d<  =F  =F  =H 9#<$3$;$;$B$B-.YY-D-D-I-I %C %KKQ6CG LR LIBF$?$) &< $? / 7 7 > >)*)@)@)E)E !? !GGMv?D HN HF KK&&!$$&/66RW6X,/KK,>,>qyyJSWY -? -[) 1 ((//199<</@GG7< H > 27.!6A4M4U4U4\4\abmv4\4w4}4}414 ( 0 0 7 7199<< 7 H O O?C !P !E9= 6 % "7  6$,,33qyy||3DKK;@ L B 251C1C34993N3N#,b 2D 2J. 6*2299!"!<!<!A!A : CCI67< DJ D> 7<3!;A8Q8Y8Y8`8`efpy8`8z  9A  9A  9C58 2 : : A A)*)D)D)I)I !B !KKQ6?C LR LE>B ; % "<  ;.66==%&YY%@%@%E%E > GGMv;@ HN HB .1[[-?-?/0yy/F/F#,b .@ .J* 2'//66!"!8!8!=!= 7 ??Ev7< @F @> 7<3!7A8Q8Y8Y8`8`efqz8`8{  9B  9B  9D58 / 7 7 > >)*)@)@)E)E !? !GGMv?C HN HE>B ; % "8  ;+33::%&YY%<%<%A%A ; CCI6;@ DJ DB &3%9%9"0=0O0O,-)o J 'U&W \ )R(I;;??6"D;%%d+ *wXh3ijH;;##%L  $--88
 9K 'Zq!7!7S!7!A B&V	
 9   !$,$%&&G ||-??126FF$%=6>Td%egE)*;nh=WXJ%z JKKg=wGG-.2BB !4xeu6vw%&7.(9ST
e:FGG '3W==  * GsKL &0"0:,-))** i( )%%a( ;%%i&9&9:;sf   O~0E~?E#~#F~/E~>E"~!C~7 $A@	3

 A@5#A@@A@c                 R   | j                   dk(  r| j                  j                  d      }| j                  j                  d      }| j                  j                  d      }	 t        j                  j                  ||      }	 ||_        ||_        |j                          |d	k(  rJ|j                  j                  d
kD  r0t        j                  j                  |      j                  d       t        j                  j                  |j                  j                   j"                        j                  d       t$        j                  j                  |j                  j                   j&                  j(                        j                  d       t*        j                  j                  |j                  j                   j,                  j(                        j                  d       nt        j                  j                  |      j                  d       t        j                  j                  |j                  j                   d	d
      }|sOt        j                  j                  |j                  j                   j"                        j                  d       nd}|D ]  }t        j                  j                  |d	      j/                         }|s5t        j                  j                  |j                  j                   j"                        j                  d       d} n |sNt        j                  j                  |j                  j                   j"                        j                  d       t        j                  j                  |j                  j                   j,                  d	d
      }	|	sYt*        j                  j                  |j                  j                   j,                  j(                        j                  d       nd}
|	D ]  }t        j                  j                  |d	      j/                         }|s5t*        j                  j                  |j                  j                   j,                  j(                        j                  d       d}
 n |
sXt*        j                  j                  |j                  j                   j,                  j(                        j                  d       t        j                  j                  |j                  j                   j&                  d	d
      }|sYt$        j                  j                  |j                  j                   j&                  j(                        j                  d       nd}|D ]  }t        j                  j                  |d	      j/                         }|s5t$        j                  j                  |j                  j                   j&                  j(                        j                  d       d} n |sXt$        j                  j                  |j                  j                   j&                  j(                        j                  d       |d	k(  r|j                  j0                  j3                  |j0                         |j                  j                   j0                  j3                  |j0                         |j                  j                   j&                  j0                  j3                  |j0                         |j                  j                   j,                  j0                  j3                  |j0                         np|j                  j0                  j5                  |j0                         t7        j8                  |j                  j"                  |j0                  j(                  gd       	 | j:                  }d}d|j0                  j<                   d|j0                  j>                   d}d|j                  j@                   d|j                  jB                   d| d|j                  j                   jD                   d|j                  j                   jF                   d}tH        j                  jK                  ||||       t        dd i      S y## t        j
                  $ r t        ddd      cY S w xY w#  Y 9xY w#  t        d!d"i      cY S xY w)$ac  
    it is the status which can be changed with the admin dashboard not shop admin
    we have the status details in the sales product selection table
    in that table we have a field status
    with this view we can change that status
    with this change of status shop admin status also change to the new status.

    :param request:
    :return:
    r   rE  r  r   rt  rr  FOperation not allowed.r  r   rs  r7  r;  Tr<  r  r  r|  r  r}  r   r   r  z Product Status Updated for Shop r?  r   r>  r   updated its status to rj  r'  r   r  r  r   Invalid request.N)&r   r   r   rR   r  r_  r   r   ru  r  rr  rI  rX   r  rL  rQ   r  r*  rO   r3  r   rP   r4  rw  rt  rK  rd  r   r   r   r  r  r@  rA  r1  r2  r   r  )r   rE  r  
new_statussales_unit_productr  r  rJ  r  r  r  r  r  r  r  r  r  r   r   s                      r   update_product_sales_statusr    s    ~~!!(+,,""9-\\%%h/
	W!:!B!B!F!FRY_e!F!fk	?(2%3=0##% Y&+=+A+A+U+UXZ+Z""f"-44PT4U  ''+=+A+A+I+I+L+L'MTTptTu''..4F4J4J4R4R4`4`4e4e.fmm/3 n 5"**117I7M7M7U7U7g7g7l7l1mtt/3 u 5 ""f"-44PU4V(+(:(:CUCYCYCaCanwSU ); )W%,$$++/A/E/E/M/M/P/P+QXX38 Y : .3*20I0Q0Q0X0X]^ir0X0s0y0y0{-0$,,337I7M7M7U7U7X7X3Y``;? a A592! 3 2 ((//3E3I3I3Q3Q3T3T/U\\7< ] > .1[[-?-?/A/E/E/M/M/_/_(" .@ .F* 2&..55/33;;MMRR 6 TTZTZ38 U[ U: 38/74M4U4U4\4\abmv4\4w4}4}414.66==%7%;%;%C%C%U%U%Z%Z > \\b\b;? ]c ]A:>7! 8 7*2299!3!7!7!?!?!Q!Q!V!V : XX^X^7< Y_ Y> *-););+=+A+A+I+I+W+W(" *< *F& .#++228J8N8N8V8V8d8d8i8i2jqq38 r : 38/34M4U4U4\4\abmv4\4w4}4}414+33::%7%;%;%C%C%Q%Q%V%V ; XX^X^;? Y_ YA:>7! 4 7'//66<N<R<R<Z<Z<h<h<m<m6nuu7< v > Y&"&&11556H6S6ST"&&..99==>P>[>[\"&&..<<GGKKL^LiLij"&&..@@KKOOPbPmPmn
 #&&11889K9V9VW 7BBI[I_I_IbIbdv  eB  eB  eG  eG  IH  TU  V"<<$<=O=Z=Z=d=d<eefgy  hE  hE  hO  hO  gP  PQ  R $%7%;%;%D%D$E\RdRhRhRqRqQr  sJ  KU  JV  Vc  dv  dz  dz  dB  dB  dL  dL  cM  MO  Pb  Pf  Pf  Pn  Pn  Px  Px  Oy  yz  { ((//XZa<G 0 I  9 566g   )55 	WE<T UVV	WT	?*< =>>sM   #!c' Id #E6d F
d %Hd Cd d '!d
ddd d&c           
      Z   | j                   j                  d      }| j                   j                  d      }| j                   j                  d      }t        j                  j	                  |      j                         }t        j                  j                  d      }|r|j	                  |      }|r|j	                  |      }t        j                  j	                  |      }g }g }	|D ]<  }
|
j                  |
j                  |
j                  |
j                  j                  |
j                  j                  g d	}g }|
j                   j#                         D ]  }|j                  |j$                  |j&                  |j(                  |j*                  |j,                  |j.                  d
}|j.                  dk(  r|j	                  |      j                         }||_        ||_        ||d<   ||d<   |j5                  |       |j5                  |       |dk(  r:|j6                  j9                  |       |j:                  dkD  rd|_        nd|_        n|j6                  j?                  |       d|_        n|j	                  |      j                         }|j0                  |d<   |d   dk(  r|j:                  dkD  rd|_        nd|_        |j2                  |d<   |j5                  |       |j5                  |       |jA                           ||d<   |	j5                  |       ? t        j                  jC                  |ddg       |rBtD        j                  j	                  |d      }|j	                  d      }|s1tF        j                  j	                  |      jI                  d       nd}|D ]g  }t        j                  j	                  |d      j                         }|s5tF        j                  j	                  |      jI                  d       d} n |s0tF        j                  j	                  |      jI                  d       |sNtF        j                  j	                  |      j                         }|r|j6                  j?                  |       nrd}|D ]G  }t        j                  j	                  ||      j                         }|s5|j2                  dk(  sEd} n |rNtF        j                  j	                  |      j                         }|r|j6                  j?                  |       ntF        j                  j	                  |      j                         }|r|j6                  j9                  |       ntF        j                  j#                         D ]d  }tD        j                  j	                  |d      }|j	                  d      }|sd|_        |jA                          nnd}|D ]N  }t        j                  j	                  |d      j                         }|s5d|_        |jA                          d} n |sd|_        |jA                          |s|j6                  j?                  |       d}|D ]G  }t        j                  j	                  ||      j                         }|s5|j2                  dk(  sEd} n |r|j6                  j?                  |       J|j6                  j9                  |       g |rBtD        j                  j	                  |d      }|j	                  d      }|s1tJ        j                  j	                  |      jI                  d       nd}|D ]g  }t        j                  j	                  |d      j                         } | s5tJ        j                  j	                  |      jI                  d       d} n |s0tJ        j                  j	                  |      jI                  d       |sNtJ        j                  j	                  |      j                         }|r+|j6                  j?                  |       nd}!|D ]G  }"t        j                  j	                  |"|      j                         }#|#s5|#j2                  dk(  sEd}! n |!rNtJ        j                  j	                  |      j                         }|r|j6                  j?                  |       nptJ        j                  j	                  |      j                         }|r?|j6                  j9                  |       n"|rtJ        j                  j	                  |      D ]s  }$tD        j                  j	                  |$d      }|j	                  d      }|sd|$_        |$jA                          n}d}|D ]]  }%t        j                  j	                  |%      j                         } | s4| j0                  dk(  sDd|$_        |$jA                          d} n |sd|$_        |$jA                          |s|$j6                  j?                  |       d}!|D ]G  }&t        j                  j	                  |&|      j                         }#|#s5|#j2                  dk(  sEd}! n |!r|$j6                  j?                  |       Y|$j6                  j9                  |       v ntJ        j                  j#                         D ]d  }$tD        j                  j	                  |$d      }|j	                  d      }|sd|$_        |$jA                          nnd}|D ]N  }'t        j                  j	                  |'d      j                         } | s5d|$_        |$jA                          d} n |sd|$_        |$jA                          |s|$j6                  j?                  |       d}!|D ]G  }(t        j                  j	                  |(|      j                         }#|#s5|#j2                  dk(  sEd}! n |!r|$j6                  j?                  |       J|$j6                  j9                  |       g g })g }*|D ]d  }+tD        j                  j	                  |+d      },|,j	                  d      }-|-sd|+_        |+jA                          nnd}.|-D ]N  }/t        j                  j	                  |/d      j                         } | s5d|+_        |+jA                          d}. n |.sd|+_        |+jA                          |,s|+j6                  j?                  |       d}0|,D ]G  }1t        j                  j	                  |1|      j                         }2|2s5|2j2                  dk(  sEd}0 n |0r|+j6                  j?                  |       J|+j6                  j9                  |       g 	 | jL                  }3d}4d}5d}6tN        j                  jQ                  |3|4|5|6        tS        |	d!      }7|7jU                  d"      }8| jV                  j                  d#      d$k(  r*tY        d%d&|8i      }9tY        d'd&|8i      }:t[        |9|:d(      S t]        d)|d*d+d,-      };t_        |;      S #  Y xY w).z;

    :param request:
    :param shop_id:
    :return:
    r  subcategorystatus_category_selectr  r  item_category__uuid)item_sub_category__uuidsales_unit__uuidr  r  rs  rq  r   ru  r7  TFrr  )product__item_category__uuidrx  )r  r<  r|  rc  )r~  rx  ) product__item_sub_category__uuidrx  )category__uuid)r  rx  )r  rx  r  z3Product Status Updated for Category or Sub CategoryzBulk Category updater  rd  r   r  r  r  r  r  r  r  r  r:  )r  r  rg  r  )0r   r   rL   r  r  rw  rQ   rC  rR   r   r1  r2  r3  r  r4  r  rS  r  r@  rA  rB  rC  rD  rx  r   ru  ry  rt  rK  rI  r=  rd  r  bulk_updaterX   rO   rL  rP   r   r   r  r   ri  r  ry   r   rt   r   )<r   r  r  r  r  rz  r  product_selectionupdate_list	show_listrJ  r  rT  r  rM  checksku_category_datar  r  zr  update_statuscategory_remove_flagr  sku_category_salescatyr  sku_sub_category_datar  r  ur  sub_category_remove_flagr  sku_sub_category_salessub_catr  hr  psku_category_listsku_sub_category_listr  sku_productsr  r  r   product_remove_flagsku_productsku_product_salesr  r  r   r   rm  r  r  r  r  s<                                                               r   category_based_update_statusr     s    ,,"":.Kll&&}5O!!":;J<<G,224D##,,_=L#**{*K#**?*S199@@RY@ZKIdd1;;)*)F)F-.-@-@-R-R[]_ Add



dedrdr$%JJ199TUT`T`bH||y()00Q07==?)*4' &0"0:,- ""5))*LL$$T*,,r17;47<4LL''-38A0 *00Q07==?%*\\"H%2q7L7Lr7Q37A038A0 160G0G,-""5))FFHQ T 'U&c f %%11+J]?^_ KK..K:C / E "3!9!9RT!9!U%##***<CC+0 D 2 +0'+,E,M,M,T,TYZen,T,o,u,u,w),#++222DKK37 L 926/ , /''..K.@GG/4 H 6 !+33:::LRRTM((//5#' &%>%F%F%M%MRS`d%M%e%k%k%m"%);;yH/4, ' $ / 7 7 > >K > P V V X !,,33D9 / 7 7 > >K > P V V X !,,006 #**..0C # 2 2#>G !3 !I &7%=%=VX%=%Y")16.
.3+/A0I0Q0Q0X0X]^ir0X0s0y0y0{-09=6
6:3 0 35:C2HHJ$%%d+'+$*A)B)J)J)Q)QVWdh)Q)i)o)o)q&)-??9L380! + (NN))$/NN&&t,O 1R  # 2 2-<  !3 !" &;%A%AZ\%A%]")&&--?-CJJ+0 K 2 +0'/,E,M,M,T,TYZen,T,o,u,u,w),&..55, 6 ..4f37 /5 /926/ 0 /"**111GNN/4 O 6 %.66==?=SYY[M((//5'+$*)B)J)J)Q)QVW]a *R *cchchcj ' *-??9L380 + ( 2 : : A A A W ] ] _ !,,33D9 2 : : A A A W ] ] _ !,,006 -55<<K<X(+(:(:V]FO ); )Q% .C-I-Ibd-I-e*19>G6LLN 38/74M4U4U4\4\ab4\4c4i4i4k148??9LEI B '>B ; % 8 7=B: -&&--d3/3,21J1R1R1Y1Y^_ei 2Z 2kkpkpkr / 25GG9T;@ 8 % 3 0**11$7**..t4W YZ .5599;(+(:(:V]FO ); )Q%-B-I-Ibd-I-e*19>G6LLN 38/74M4U4U4\4\abmv4\4w4}4}414AEG>#LLN:>7! 8 7=B: -&&--d3/3,21J1R1R1Y1Y^_ei 2Z 2kkpkpkr / 25GG9T;@ 8 % 3 0  **11$7**..t4W <^ {{))'i)P , 3 3B 3 O$16G.LLN &+"*,E,M,M,T,TYZen,T,o,u,u,w),9=G6LLN-1* + *5:2%%d+"&+$=$E$E$L$LQ\im$L$n$t$t$v!$(::iG.3+  , #""))$/""&&t,M  T<<G,  ''XRY4? 	( 	A
 )R(I!!!$H -.2BB !4~x6PQ%&7.(9ST
e:FGG**1CSjrsuHHs   05z& &z*c                 R   | j                   dk(  r| j                  j                  d      }| j                  j                  d      }| j                  j                  d      }	 t        j                  j                  ||      }	 ||_        |j                          |d	k(  r|j                  j                  j                  |j                         |j                  j                  j                  j                  |j                         |j                  j                  j                  j                  j                  |j                         |j                  j                  j                  j                  j                  |j                         np|j                  j                  j                  |j                         t!        j"                  |j                  j$                  |j                  j&                  gd
       	 | j(                  }d}d|j                  j*                   d|j                  j,                   d}d|j                  j.                   d|j                  j0                   d| d|j                  j                  j2                   d|j                  j                  j4                   d}t6        j                  j9                  ||||       t        ddi      S y # t        j
                  $ r t        ddd      cY S w xY w#  Y 9xY w#  t        ddi      cY S xY w)Nr   rE  r  r   r  Fr  r  rs  r   r   r  z+Product Shop Admin Status Updated for Shop r?  r   r>  r  r  rj  r'  r   r  r  r   r  )r   r   r   rR   r  r_  r   ru  r  rr  rt  rK  r  r3  r4  rd  r   r   r*  r   r   r  r  r@  rA  r1  r2  r   r  )	r   rE  r  r  r  r  r  r   r   s	            r   #update_product_product_admin_statusr"    sW   ~~!!(+,,""9-\\%%h/
	W!:!B!B!F!FRY_e!F!f	?3=0##% Y&"&&11556H6S6ST"&&..99==>P>[>[\"&&..<<GGKKL^LiLij"&&..@@KKOOPbPmPmn #&&11889K9V9VW6BBI[I_I_IbIbdv  eB  eB  eG  eG  IH  TU  V"<<$GHZHeHeHoHoGppq  sE  sP  sP  sZ  sZ  r[  [\  ] $%7%;%;%D%D$E\RdRhRhRqRqQr  sJ  KU  JV  Vc  dv  dz  dz  dB  dB  dL  dL  cM  MO  Pb  Pf  Pf  Pn  Pn  Px  Px  Oy  yz  { ((//XZa<G 0 I  9 566E   )55 	WE<T UVV	W4	?*< =>>s8   #!K' E;L CL L '!L
LLL L&r]  c           
         | j                   j                  d      }| j                   j                  d      }| j                   j                  d      }t        j                  j	                  |      j                         }t        j                  j                  d      }|r|j	                  |      }|r|j	                  |      }g }t        j                  j	                  |      }g }g }	|D ]  }
|
j                  |
j                  |
j                  |
j                  j                  |
j                  j                  g d	}g }|
j                   j#                         D ]N  }|j                  |j$                  |j&                  |j(                  |j*                  |j,                  |j.                  d
}|j.                  dk(  r|j	                  |      j                         }|j0                  dk(  r||_        |j0                  |d<   ||d<   n|j0                  |d<   |j2                  |d<   |j5                  |       |j5                  |       |j	                  |      j                         }|j0                  |d<   |j2                  |d<   |j5                  |       |j5                  |       Q ||d<   |	j5                  |        t        j                  j7                  |dg       t9        j:                  |j<                  |gd       t?        j:                  |j<                  ||gd       tA        j:                  |j<                  ||gd       tC        |	d      }|jE                  d      }	 | jF                  }d}d}d}tH        j                  jK                  ||||       | jL                  j                  d      dk(  r*tO        dd|i      }tO        dd|i      }tQ        ||d      S tS        d      }tU        |      S #  Y bxY w)Nr  r  r  r  r  r  r  r  r  r  rs  rq  r   ru  rr  r   r   rd  r   r  z<Product Status Updated for Category or Sub Category For ShopzBulk Category update for Shopr  r  r  r  r  r  r  list_product_shop_admin)+r   r   rL   r  r  rw  rQ   rC  rR   r   r1  r2  r3  r  r4  r  rS  r  r@  rA  rB  rC  rD  rx  r   ru  ry  r  r   r   r   r   r   r   ri  r   r   r  r  ry   r   rt   r   )r   r  r  r  r  rz  r  r	  r  r
  rJ  r  rT  r  rM  r  rm  r  r  r  r   r   r  r  r  s                            r   'category_based_shop_admin_update_statusr%    s    ,,"":.Kll&&}5O!!":;J<<G,224D##,,_=L#**{*K#**_*MK199@@RY@ZKIdd1;;)*)F)F-.-@-@-R-R[]_ Add



dedrdr$%JJ199TUT`T`bH||y()00Q07==?<<9,.8E+ */HX&4>H01
 */HX&494K4KH01""5)) *00Q07==? &+\\"050G0G,-""5))C F 'U&U X %%11+@S?TU+77		;?Wdef/;;$))_^iAjwxy%%diio-Vcde)R(I!!!$H<<P5  ''XRY4? 	( 	A
 -.2BB !9NH;UV%&7.(9ST
e:FGG01HHs   35P P
c                    | j                   j                  dd      }| j                   j                  dd      }| j                   j                  dd      }t        ddd	d
d      }t        ddddd      }t        ddddd      }g }| j                  j                  d      dk(  rt	        t
        |      }	t        | j                         }
t        j                  j                  |	      }|
j                         r|
j                  d      }|	|_        |j                          	 | j                  }d}d}d|j                   d|j                   d|j                  j                    d|j                  j"                   }t$        j                  j'                  ||||       t        dd |i      }t)        |g d!||||||d"	      S i }|
j*                  j-                         D ]  \  }}|d#   ||<    |j/                  |
j*                         |r#t        dd |i      }t)        ||d||||||d"	      S t)        g |d||||||d"	      S t)        g d$d%id||||||d"	      S #  Y xY w)&Nimage_link_1/media/icons/icon.jpgimage_link_2)/media/standard_images/standard_image.jpgimage_link_3/media/banners/banner.jpgimage_field.htmluploadimage_reset_button1r  
class_nameimage_reset_button
field_nameupload2image_reset_button2r  upload3image_reset_button3r  r  r  r  r  Fr  r  r  r  r  r  r  r  zsub_category_delete_list.htmlr  T)	r`  r  r  image_field1image_field2image_field3link_1link_2link_3r   r  zSomething went wrong try again)r   r   ry   r  r   rO   r8   rP   r  r  r  r  r  r   r  r  r  r  r   r  r   r  itemsry  )r   r  r;  r<  r=  r8  r9  r:  r  r  r
  r  r  r  r  r   r   sub_categoriesr   rJ  r`  s                        r   sub_category_creationr@    s   \\n.EFF\\n.YZF\\n.IJF#$63;Sh39%;<L $$63<Ti3C%EFL $$63<Ti3A%CDL F-.2BB$_;G27<<@.66==x=P%%',111?L$,L!"<<$0 -l.L.L-M\ZfZxZxYy  zP  Q]  Qf  Qf  Qt  Qt  Pu  u@  AM  AV  AV  Ad  Ad  @e  f ((//XZa<G 0 I ..MP^`qOrsN2RVht1=|+1Vv!W X X E,3399;47a < MM+223 !12QTbduSv!w# ."'#((4ldp"(Ff  $#$$0,`l$&%   *,LM(,Xd&
  	Es   &A=I I"c                 x   | j                   j                  dd       }|r!t        j                  j	                  |      }nt        j                  j                         }g }|D ]J  }|j                  |j                  |j                  |j                  |j                  j                  d       L t        d|i      S )Nr  r  )r*  r   pricer  r  )rh  r   rQ   r  r  r  ry  r*  r   rB  r  r   )r   r  r  r  r  s        r   filter_productsrC  a  s    ++//-6K ##**{*K##'') L**LL]]((--	
 	  \233r   c           	      2   | j                   j                  dd      }| j                   j                  dd      }| j                   j                  dd      }t        ddd	d
d      }t        dddd|d      }t        dddd|d      }t        ||||||d      S )Nr'  r(  r)  r*  r+  r,  r-  r.  r/  r  r0  r4  r5  r  r1  r2  r3  linkr6  r7  r  r8  r9  r:  r;  r<  r=  rh  r   ry   r   r   r;  r<  r=  r8  r9  r:  s          r   image_field_renderingrJ    s     [[__^-DEF[[__^-XYF[[__^-HIF#$63;Sh39%;<L $$63<Ti3CV%UVL $$63<Ti3A6%STL %|UamsV	-. .r   c                 l   t         j                  j                  d      }t        |d      }| j                  j                  d      }	 |j                  |      }|dd}t        | d|      S # t        t        f$ r |j                  d      }Y 4t        $ r |j                  |j                        }Y Yw xY w)z
    In the product section on the side bar. We have
    the product tags. We list the products based on the tags
    on app.
    :param request:
    :return:
    rc     re  r   r:  )tag_datar  ztag_list.html)rU   r  rC  r   rh  r   ri  r!   rj  r    rk  r   )r   tagsrm  re  rK  s        r   tag_listrO    s     <<  /D$"I;;??6"D7!!$'
  H=G'?G44 i( %!!!$ 7!!)"5"567ro  c                 |    t         j                  j                  |      }|r|j                          t	        d      S )zq
    delete a tag listed in product section on side bar.
    :param request:
    :param tag_id:
    :return:
    r  rO  )rU   r  r  r  r   )r   tag_idrN  s      r   
tag_deleterR    s2     <<&)DJr   c                    g }t        t        |      }| j                  dk(  rt        | j                  | j
                  |      }|j                         rH| j                  j                  dd      rd|j                  _	        |j                          t        d      S |j                  |j                         nt        |      }|dd	}t        | d
|      S )z
    If we click on the edit button on tag listing we are
    redirecting to edit form. We can change the tag details
    with the form.
    :param request:
    :param tag_id:
    :return:
    r  r   r  r  r   NrO  r:  )tag_formr  ztag_edit.html)r   rU   r   r:   r   r  r  r   r  r  r  r   ry  r  r   )r   rQ  r  rN  r  rK  s         r   tag_editrU    s     FTf-D~~w||W]]TB==? ||"-%)"IIKJ'' MM$++&%H=G'?G44r   c                 P   g }| j                   dk(  ryt        | j                  | j                        }|j	                         r|j                         }t        d      S |j                  |j                         ||dd}t        | d|      S t               }||dd}t        | d|      S )z
    In the tag list window we have a button add tag. on clicking
    the add tag button. we can add a new tag. fields are
    tag_name, icon, products.
    :param request:
    :return:
    r   rO  r:  )r  rT  r  ztag_add.html)
r   r:   r   r  r  r  r   ry  r  r   )r   r  rT  rN  rK  s        r   tag_addrW    s     F~~7<<7==?DJ''MM(//* $#+G
 '>7;;9 #G '>733r   c                 l   t         j                  j                  d      }t        |d      }| j                  j                  d      }	 |j                  |      }|dd}t        | d|      S # t        t        f$ r |j                  d      }Y 4t        $ r |j                  |j                        }Y Yw xY w)zIn app just like tags we have easy filters also. One of them is dynamic
    filter. for eg: black forest. if we select the black forest we will return the
    products associated with the filter.
    admin listing of dynamic filter.
    rc  rL  re  r   r:  )filter_datar  zdynamic_filter_list.html)rV   r  rC  r   rh  r   ri  r!   rj  r    rk  r   )r   filter_listrm  re  rK  s        r   dynamic_filter_listr[  4  s     #**33MBK+q)I;;??6"D>((.
 *hGG'5w?? i( ,((+ >(()<)<=>ro  c                 |    t         j                  j                  |      }|r|j                          t	        d      S )a=  
    Dynamic filter also listed on the product section on side bar.
    for each dynamic filter, There is a delete button on the listing.
    on clicking the delete button. a confirmation dialog box will appear.
    click yes and we could delete the filter.
    :param request:
    :param filter_id:
    :return:
    r  rZ  )rV   r  r  r  r   )r   	filter_idrZ  s      r   dynamic_filter_deleter^  H  s7     #**11Y1?KM""r   c                 >   g }t        t        |      }| j                  dk(  r^t        | j                  |      }|j                         r|j                          t        d      S |j                  |j                         nt        |      }|dd}t        | d|      S )a  
    Editing a dynamic filter. for each dynamic filter listed on
    dynamic filter list, we have a edit button. clicking on
    the edit button will open a form. fields are tag name and products.

    :param request:
    :param filter_id:
    :return:
    r  r   r  rZ  r:  )filter_formr  zdynamic_filter_edit.html)r   rV   r   r;   r   r  r  r   ry  r  r   )r   r]  r  rZ  r  rK  s         r   dynamic_filter_editra  [  s     F#$4CK~~ D==?IIKM** MM$++& +6"x@G'5w??r   c                 :   g }| j                   dk(  rnt        | j                        }|j                         r|j	                         }t        d      S |j                  |j                         ||dd}t        | d|      S t               }||dd}t        | d|      S )aJ  
    Adding a dynamic filter.
    On dynamic filter listing page which we can open by clicking
    on the product section on side bar have a add dynamic filter button.
    clicking will open the form enter the products and tag name on the form.
    on submission create a new dynamic filter.

    :param request:
    :return:
    r   rZ  r:  )r  r`  r  zdynamic_filter_add.html)	r   r;   r   r  r  r   ry  r  r   )r   r  r`  r  rK  s        r   dynamic_filter_addrc  w  s     F~~'5! %%'FM**MM+,,- *#+G
 '#<gFF') "#G '4g>>r   c                 l   t         j                  j                  d      }t        |d      }| j                  j                  d      }	 |j                  |      }|dd}t        | d|      S # t        t        f$ r |j                  d      }Y 4t        $ r |j                  |j                        }Y Yw xY w)z
    special list showed on the app. for eg:  Rolls - Chicken Spring Roll,
    special list will list when we click on the special list on product section
    on side bar.
    :param request:
    :return:
    rc  rL  re  r   r:  )special_datar  zspecial_list.html)rW   r  rC  r   rh  r   ri  r!   rj  r    rk  r   )r   special_product_listrm  re  rK  s        r   special_listrg    s     '..77F.2I;;??6"DG(11$7
  4QG'.88 i( 5(11!4 G(11)2E2EFGro  c                 |    t         j                  j                  |      }|r|j                          t	        d      S )a#  
    Deleting a special list. for each special list listed on
    special listing, we have a delete button. clicking on
    the delete button will open a confirm dialog box. if you confirm
    it will delete the special list.
    :param request:
    :param special_list_id:
    :return:
    r  rg  )rW   r  r  r  r   )r   special_list_idrf  s      r   special_list_deleterj    s8     '..555I##%N##r   c                 b   g }t        t        |      }| j                  dk(  rt        | j                  | j
                  |      }|j                         r| j                  j                  dd      rd|j                  _	        | j                  j                  dd      rd|j                  _
        | j                  j                  dd      rd|j                  _        |j                          t        d	      S |j                  |j                         nt        |      }|d
d}t!        | d|      S )a0  

    Editing a special list. for each special list listed on
    special listing, we have a edit button. clicking on
    the edit button will open a form. fields are special name and icon,
    standard image, banner image, and products.

    :param request:
    :param special_list_id:
    :return:
    r  r   r  r  r   Nr  r  rg  r:  )special_formr  zspecial_list_edit.html)r   rW   r   r<   r   r  r  r   r  r  r  r  r  r   ry  r  r   )r   ri  r  rf  r  rK  s         r   special_list_editrm    s     F,[_M~~w||W]]EYZ ==?||"-%)"||"-/3,||"--1*IIKN++ MM$++&(<=#AG'3W==r   c                 P   g }| j                   dk(  ryt        | j                  | j                        }|j	                         r|j                         }t        d      S |j                  |j                         ||dd}t        | d|      S t               }||dd}t        | d|      S )a`  
    Adding a special list.
    On special listing page which we can open by clicking
    on the product section on side bar have a add special list button.
    clicking will open the form enter the special name and icon,
    standard image, banner image, and products.
    on submission create a new special list.
    :param request:
    :return:
    r   rg  r:  )r  rl  r  zspecial_list_add.html)
r   r<   r   r  r  r  r   ry  r  r   )r   r  r  specialrK  s        r   special_list_addrp    s     F~~w||W]];==?iikGN++ MM$++&  $#+G
 '#:GDD  #G '2G<<r   c                       e Zd ZdZd Zy)SendVerificationEmailViewz7
    View to send delivery boy verification email.
    c                    |j                   }t        t        |      }|j                  dk(  rddd}t	        |d|      S t        j                  t        |j                        t        j                         t        d      z   d	t        j                  d
      }t        t        dd      }| t        d|g       }d}		 t!        j"                  d| |j$                  gd       dddd}d}	 t)        dd| t        j*                  |j,                  gd       |	r	|rdddd}n|	rdddd}n|rdddd}ndddd}t	        |d|      S # t&        $ r}
d}	Y d}
~
od}
~
ww xY w# t&        $ r}
d}Y d}
~
Xd}
~
ww xY w) a  
        On orders on side bar, we have a menu delivery details. if we click on
        delivery details we have the delivery boys listed. we can add new delivery
        boys. for assigning a order, adding alone not help. for that we have to
        verify the delivery boy. we will send the verification sms to the phone number using this view.

        :param request:
        :param delivery_boy:
        :return:
        r  verifiedzPhone  alreay verified .r   )r   r   phone_verification.html   )hours)delivery_boyexpHS256)	algorithmDOMAINzhttp://localhost/zverify-phonerm  Tzclick here to verify: r   r   z,Verification link sent to your phone number.r   )r   r   r  FNzVerify your emailz%Click the link to verify your email: r  zDVerification link sent to your phone number and email. Please check.z:Verification link sent to your phone number. Please check.z3Verification link sent to your email. Please check.zInvalid Phone number or email!)r   r   r_   r   r   jwtencoder  r   r   r`  rr   r   
SECRET_KEYgetattrrt   r   r   r  r   rp   DEFAULT_FROM_EMAILr   )selfr   rx  r   delivery_boysrK  tokendomainverification_linksms_flagr   
email_flags               r   postzSendVerificationEmailView.post   s    ||),<H:-"<JG'#<gFF 

C0@0@,A(,,.[dkm[nJno#..'C 8-@A%hw~UG'L&MN	OO$:;L:M"NP]PjPj!kvwx"P\]ghiG 
		#78I7JK++$$%# 
"htu  @A  BG"^jkuvwG"WcdnopG"BaYZ[G g8'BB;  	H	  	J	s0    ,E /,E# 	E EE #	E8,E33E8N)__name__
__module____qualname____doc__r  r   r   r   rr  rr    s    =Cr   rr  c                       e Zd ZdZd Zy)VerifyEmailViewz
    Delivery details menu on Orders section in the side bar will list the delivery boys.
    this view is to verify with the link.
    we send a link to verify the delivery boy on clicking that link, VerifyEmailView will
    verify.
    c           	      h   	 t        j                  |t        j                  dg      }t	        t
        |d         }d|_        |j                          t        |dddd	d
      S # t         j                  $ r t        |dd	dd	d
      cY S t         j                  $ r t        |dd	dd	d
      cY S w xY w)Nrz  )
algorithmsrx  r  rt  ru  r   z#Phone number verified successfully.r   )r   r   r  zVerification link has expired.zInvalid verification link.)r}  decoder   r  r   r_   r   r  r   ExpiredSignatureErrorInvalidTokenError)r  r   r  payloadr  s        r   r   zVerifyEmailView.geti  s    	jj(;(;	RG-lw~?VWM $.M  '#<@?  
 (( 	'#<;?  
 $$ 	'#<7?  	s   A"A% %$B1#B10B1N)r  r  r  r  r   r   r   r   r  r  b  s    r   r  r^  c                 &   t         j                  j                  d      j                  | j                  j
                        }|r|d   }nd}t        j                  j                  |      j                  d      }t        |d      }| j                  j                  d      }	 |j                  |      }|d
d}t!        | d|      S # t        t        f$ r |j                  d	      }Y 4t        $ r |j                  |j                        }Y Yw xY w)z
    Delivery details menu on Orders section in the side bar will list the delivery boys.
    It is only available for shop admin.
    each shop have their own delivery boys.
    :param request:
    :return:
    r  r  r   r   r  r  rL  re  r   r:  )delivery_boy_dataorders_activezdelivery_boy_list.html)rL   r  r<  r  r   r   r_   rC  r   rh  r   ri  r!   rj  r    rk  r   )r   rD  r  r  rm  re  rK  s          r   delivery_boy_listr    s    \\223DELL%ll// M 1N  # !((//W/=FFWM-+I;;??6"D@!**40
 %2HMG'3W== i( .!**1- @!**9+>+>?@s   %C  D*#DDc                 |    t         j                  j                  |      }|r|j                          t	        d      S )a8  
    Delivery details menu on Orders section in the side bar will list the delivery boys.
    Deleting a delivery boy. for each delivery boy listed on
    delivery boy list, we have a delete button. clicking on
    the delete button will open a confirm dialog box. if you confirm
    it will delete the boy.
    r  r  )r_   r  r  r  r   )r   delivery_boy_idrx  s      r   delivery_boy_deleter    s8      ''../.BL'((r   c                    g }t         j                  j                  |      j                         }| j                  dk(  rut        | j                  |      }|j                         r2|j                         }d|_	        |j                          t        d      S |j                  |j                         nt        |      }|dd}t        | d|      S )	a  
    Delivery details menu on Orders section in the side bar will list the delivery boys.
    Editing a delivery boy. for each delivery boy listed, we have a edit button. clicking on
    the edit button will open a form. fields are team member name and phone number,
    email.

    r  r   r  znot verifiedr  r:  )delivery_boy_formr  zdelivery_boy_edit.html)r_   r  r  rw  r   r=   r   r  r  r   r   ry  r  r   )r   r  r  rx  r  rK  s         r   delivery_boy_editr    s     F''../.BHHJL~~w||lC==?99;L"0L/00 MM$++&5$(8DG'3W==r   c                    g }| j                   dk(  rt        j                  j                  d      j	                  | j
                  j                        }|r|d   }nd}t        | j                        }|j                         r2|j                         }||_        |j                          t        d      S |j                  |j                         ||dd}t        | d	|      S t               }||dd}t        | d	|      S )
a4  
    Adding a delivery boy.
    On delivery boy listing page which we can open by clicking
    on the order section on side bar have a add delivery boy button.
    clicking will open the form enter the fields are team member name and phone number,
    email.
    on submission create a new delivery boy.
    r   r  r  r   r   r  r:  )r  r  r  zdelivery_boy_add.html)r   rL   r  r<  r  r   r   r=   r   r  r  rz  r   ry  r  r   )r   r  rD  r  r  rx  rK  s          r   delivery_boy_addr    s     F~~667HIPP"),,"3"3 Q 5$Q'GGw||,==?99;L 'L/00MM$++& %)!)G
 '#:GDD  !!G '2G<<r   c                    	 | j                   j                  d      }| j                   j                  dd      }t        j                  j	                  | j
                  j                        }|r|d   nd}g }| j                  j                  d      }| j                  j                  d      }| j                  dk(  rt        j                  j	                  |	      j                         }	t        j                  j	                  |
      j                         }
t        | j                  |	      }|j                         r+|j                  d      }|
|_        d|_        |j                          |
j$                  dk(  rd|
_        |
j                          d}d}t'        |
j(                  j*                  |
|||
j(                         t-        |||
j(                  j.                  gd       d}|
j(                  j0                  dk(  rMt3        j4                  |
j(                  j6                  |
j8                  |
j(                  j:                  |gd       t=        d||
j8                  d      S |j?                  |j@                         t=        d|j@                  d      S | j                   j                  dd      }| j                   j                  dd      }| j                   j                  dd      }| j                   j                  dd      }|s|}| j                   j                  dd      }|s|}tB        j                  jE                  d      jG                  tI        dtJ        j                  jM                                      }|r4t        j                  j	                  |d!d"g#      jO                  d$%      }n0t        j                  j	                  d&'      jO                  d$%      }|jE                  d(d)d*      jG                  tI        d+|             jQ                  d,      }|d-k(  r|j	                  d.%      }|rV|d/k(  r)|j	                  tS        d01      tS        d21      z        }n(|j	                  tS        d31      tS        d41      z        }| jT                  j                  d5      d6k(  r|rQ|j	                  tS        |7      tS        |8      z  tS        |9      z  tS        |:      z        jQ                  d,      }|r)	 tW        jX                  |d;      }|j	                  |<      }|r|j	                  |=      }|rd|rb|d>k(  r,|d(k(  r|jQ                  |d?z         }nC|jQ                  |      }n1|d(k(  r|jQ                  d@|z   d?z         }n|jQ                  d@|z         }t]        |dA      }| j                   j                  dB      }	 |j_                  |      }ti        dD      }| j                   jk                         }dB|v r|dB= |jl                  jn                  D cg c]  }|| dE|jq                  dFG       dH| dI! }}|D ]@  }
g } |
jr                  jM                         D ]  }!dJ}"	 |!jt                  jw                         r|!jt                  jM                         d   ndJ}"|!jz                  t}        |!ddJ      r-t}        |!j~                  dKdJ      r|!j~                  j                  ndt}        |!j~                  dLd      t}        |!j~                  dMd      |!j                  |!j                  |"r|"j                  nd|"r#t}        |"dNdJ      r|"j                  j                  ndJdO}#| j?                  |#        t        |
dP|        C t               }	 t        j                  j	                  dQ|R      }$|D 
cg c]   }
|
j$                  d.k(  sdS|
j8                  i" }%}
|||||||$dT||r|nd|%dU}&| jT                  j                  d5      d6k(  rc|d-k(  r/|D 
cg c]  }
dS|
j8                  i }%}
t        dV|||$|||%dW      }'nt        dX|||$|||%dW      }'t        dYd+|i      }(t=        |'|(dZ      S |d-k(  rt        | d[|&      S t        | d\|&      S # tZ        $ r Y xw xY w# t`        tb        f$ r |j_                  dC      }Y td        $ r |j_                  |jf                        }Y w xY wc c}w # tx        $ r dJ}"Y ]w xY w# tx        $ r g }$Y _w xY wc c}
w c c}
w # t        $ r g dTd]}&t        | d\|&      cY S w xY w)^a  
    List orders for shop admin / PU admin with product data and custom images (if present).
    Attaches `order.items` to each order in page results. Each item is a dict:
      {
        "product_name": ...,
        "sku_name": ...,
        "sku_quantity": ...,
        "sku_unit": ...,
        "quantity": ...,
        "price": ...,
        "custom_note": ...,
        "custom_image_url": ...  # None if no image
      }
    platformrR  r   r  r   r3  
sort_orderr   r   r  r  Fr  Courier Deliveryr"  
DespatchedzOrder Despatchedz"Your Order Despatched Successfullyout_for_delivery_generalTr   r   r  r   order_idOrderIDfailrF  r  r  r  rr  customizations)querysetrP  Pick Up)r  order_type__inr  r  rV  rW  r   drop_addressr  
order_datar  z
new ordersr  webWebr  OtherIOSAndriodr  r  order_ID__icontainsorder_type__icontainsorder_status__icontains user_uuid__first_name__icontainsr  rO  r  asc__first_name-rL  re  r   
order_listr  r  r  r  r  Nr@  rB  rC  custom_image)product_namer@  rB  rC  quantityrB  custom_notecustom_image_urlr>  rt  r   rz  r   r:  )courier_formr  r  r   r  r  ongoing_ordersr  r  rR  r;  znew_order_list_page.html)r  r  r  r  rR  r;  zorder_list_page.htmlorder_list_pagination.htmlr  znew_orders.htmlzorder_list.htmlr  r  )Krh  r   rL   r  r  r   r   COOKIESr   rc   rw  rb   r?   r   r  r  r   delivery_typer  r   r   r   r   r   opt_inr   r   r  r   r  r   ry  r  ra   select_relatedr<  rx   r`   r  r  rC  rw   r  r   r  
ValueErrorr   ri  r!   rj  r    rk  rt   r  rm  r  r  r  r  existsr   r  r  rr  r@  r  rB  r  r  r  setattrr_   ry   r   
IndexError))r   r  r  rR  shop_qsr  r  r3  r  order_deliveryr   r  delivery_datar   r   	temp_namer  
order_dater  sort_order_datafield_name_dataorderproducts_qsbase_qsr  r  rm  re  ordersr  r  r  r  r>  opcustomizationitemr  r;  rK  r  r  s)                                            r   r  r    s#	   "`;;;??:.[[__\26
,,%%GLL<M<M%N ''!*R__((6
__((6
 >>V#*22999IOOQNNN))X)6<<>E%gll^LD}} $			 7&+#.@+""$%%7)5E&JJL.E"FK$U__%>%>uk[`[j[jke[5??3H3H2I5Q :I--5-99@\@\^c^l^lnsn}n}  oI  oI  KT  @U  ab  d#' ($~~%   dkk*#v$MNN {{x4[[__^R8
{{'7<!++//,;(O!++//,;(O )00??FWW%0I0Q0Q0U0U0WX
 nn++" .	: ,  g;g/ 
 nn++1 , g;g/  ++KVgg\,<=

(?
# 	
 %#***DJ 5 '..q%/@1gCV/VW
 (..q%/@1iCX/XY
 ??126FF'..,7L9:l;< |DE
 (?+  %-%6%6z:%NN!+!2!2n!2!UJ '..l.K
?"e+&+5%/%8%8>9Y%Z
%/%8%8%I
&+5%/%8%89NQ_9_%`
%/%8%89N%O
 j!,	{{v&	=''-F <({{'')\!V$  &//::

  ;  +"1\%;%;%;%E$Ff[MZ  ; 	 
 EE&&**, $)BDBSBSBZBZB\B$5$5$9$9$;A$>bfM %'OO3:2ud3KPWXZX^X^`jlpPqwy$+BFFNB$G '
B ? "XX@M=#<#<SUJW\cdq  tB  DH  ]I(B(B(F(F  OS	 T"' -, E7E*1 6 "#	 )1188
QX8YN EKrF5uOaOaepOp:u~~6Fr ! (* 0,% (2*,
 ??126FF\)LR!SF5:u~~">F!S()C"((8&4 (",&4F  ))?"((8&4 (",&4B  **FW]H^_J%z JKK %'#4g>>g0'::o " . !), 	+''*F 	=''	(;(;<F	=
" ! )$(M).  	 N	  s& "T4  ;%
 g0'::;s   I*d2 -2d2  I-d2 (b" 6B!d2 b2 )Ad2 -$c?*d2 <9d5C.d2 $!d d2 	d(d(.;d2 )d->Ad2 d2 d2 "	b/+d2 .b//d2 2 c<d2 #c<8d2 ;c<<d2 dd2 dd2 d%!d2 $d%%d2 2eec                    | j                   j                  d      }g }d}t        j                  j	                  |      j                         }|r(t        |      }|j                  j                  dk(  rod}nlt        j                  j	                  |      j                         }t        j                  j                  d|	      }t        |      }|j                  dk(  rd}t        d
|||d      }t        d|d      S )Ncsrfmiddlewaretokenfalser  r  r"  truer  r  )r  r   zcourier_edit_form.html)r  r  button_statusTr  r  )r   r   rc   r  r  rw  r?   r   r  rb   r  ry   r   )	r   r  csrfr  r  r  r  r   r  s	            r   courier_details_editr    s     <<12DFM"**111AGGIN!>:,,>"M %%8%4::<&..55DV^c5d!>:/"M#$<59xbo$prL D,?@@r   c                       e Zd Zd Zd Zy)ShipperAutocompletec                     |j                    S r   )team_member_name)r  r  s     r   get_result_labelz$ShipperAutocomplete.get_result_label'  s    ''()r   c                     t         j                  j                  dd      }| j                  r|j                  | j                        }|S )Nrt  not assigned)r   delivery_boy_status)team_member_name__istartswith)r_   r  r  r  )r  r  s     r   get_querysetz ShipperAutocomplete.get_queryset+  sE    %--44J\j4k66+22QUQWQW2XNr   N)r  r  r  r  r  r   r   r   r  r  &  s    *r   r  c                    	 |r| j                   j                  }| j                   j                  }| j                  j                  }| j                  j                  }d| d| d| d| }|||| j                  d}	t        j                  |j                  |j                  |	gd      }	|	S y # t        $ r"}
t        j                  d|
        Y d }
~
y d }
~
ww xY w)Nz https://www.google.com/maps/dir/,r  )pick_up_addressr  google_place_linkr   r   r   r   )r  r  r  r  r   r   r   r  r  r   r   r   )r   r  r  rx  	START_LAT	START_LNGDEST_LATDEST_LNGr  r`  r   s              r   WhatsappMessageSendr  7  s    **33I**44I''00H''11H"B9+QykYZ[cZddefneo p'6):u~~WD5AAHaHaco  dA  dA  CG  HH  TU  VDK A!EFs   B(B, ,	C5CCc                    	 g }t         j                  j                  | d      }|D ]B  }	 |j                  j                  }|j                  j
                  }	|j                  ||	f       D |D cg c]  }|d    d|d     }
}dj                  |
      }d|j                   d}t        |j                  j                        }t        |j                  j
                        }	d	}| d
| d|	 d| d|	 d| d}d|j                   d| d| d| d	}t        j                  ||t        j                  |j                  gdgd      }|S #  Y )xY wc c}w # t         $ r"}t#        j$                  d|        Y d }~y d }~ww xY w)NDelivery Assigned)rx  r  r   r  r   |zOrder z Assinged to youz&https://www.google.com/maps/dir/?api=1z&origin=z&destination=z&waypoints=z&travelmode=drivingz The Order no: z5 assigned to you by NavyaBakeShop.
Pickup Location : z 
Delivery Location : z%

Please click link to track order : z!

Navya Bakers
                  Fr   r   z2Failed to Send Email While Assigning Delivery Boy:)rb   r  r  r  r  r  ry  r   r   r  r  r   r   r   rq   r   r   r   r   )shipper_uuidr   r  r  rx  location_listr  rJ  r  r  map_linkmap_link_joinr   basemap_link_to_sendr   r   r   s                     r   ShipperEmailSendr	  L  s   %&&LOb&cA>>22NN44	$$h	%:;	  /<<mqtfAadV$m<* 5>>**:;u''001((223	7"V8H:QykxjXYZcYddop}o~  R  S%enn%55kl{k|  }T  Ua  Tb  bI  JZ  I[ [  #..WgxG_G_bnbtbtauw|4}  JK  L
-<.  J1#NOs;   (E ?E*E 0ECE EE 	F!E>>Fc                 |   | j                   dk(  r| j                  j                  d      }| j                  j                  d      }| j                  j                  d      }| j                  j                  d      }	 t        j                  j                  |      j                         }| j                  j                  d      }t        j                  j                  |      j                         }|j                  d	v rt        d
dd      S |j                  dk(  rt        d
dd      S |j                  dk(  rt        d
dd      S |j                  dk(  rt        d
dd      S d|_        t        j                         |_        ||_        	 t        j                  j                  ||d|j                   i      }d|_        |j)                          |j)                          t        j                  j                  |j                        j                         }|r|j*                  rt-        |j*                  j.                        dz   t-        |j*                  j0                        z   dz   t-        |j*                  j2                        z   dz   t-        |j*                  j4                        z   dz   t-        |j*                  j6                        z   dz   t-        |j*                  j8                        z   dz   t-        |j*                  j:                        z   dz   t-        |j*                  j<                        z   nd}	|j>                  rt-        |j>                  j@                        dz   t-        |j>                  jB                        z   dz   t-        |j>                  jD                        z   dz   t-        |j>                  j2                        z   dz   t-        |j>                  j6                        z   dz   t-        |j>                  j8                        z   dz   t-        |j>                  j:                        z   nd}
d}d}tG        |jH                  jJ                  ||||jH                         tM        |||jH                  jN                  gd
       d }|jH                  jP                  d!k(  rMtS        jT                  |jH                  jV                  |jX                  |jH                  jZ                  |gd"#       t        d$|||d%      S t        d(d'i      S #  t        j                  j                  ||      j#                          t        j                  j%                  ||d|j                   i       Y xY w# t\        $ r2}t_        j`                  d&|        t        d'|||d%      cY d }~S d }~ww xY w))Nr   r  re  r  r  r  
order_uuidr  )r!  r  FzOrder not confirmed)r  r   r  zOrder already deliveredr  zOrder Failedr  zOrder already Assignedr  )rx  r   r:  )rx  r   assignedr;  z, r   r   r?  z), r  zOrder AssignedzFYour Order Assigned Successfully, Delivery Boy will reach you shortly!delivery_assigned_generalTr   r   True)r  re  r  r  z$Failed While Assigning Delivery Boy:Falser  )1r   r   r   r_   r  r  rw  rb   r  r   r   r`  order_assigntimerx  rc   rJ  rR  r  r  r  r  r  r  r   house_number_or_namer  	land_markr  r  r  r  r  r  r  r  r   r   r   r   r   r  r   r   r  r   r  r   r   r   )r   r  re  r  r  shipperr  r   rx  r  r  r   r   r  r   s                  r   save_shipperr  u  s   ~~||''7||'!!(+||''7L	t"**11\1BHHJG !)),7JNN))z):@@BE!!%<<#BW$XYY!![0#B[$\]]!!X-#.$QRR!!%88#BZ$[\\!4E%-\\^E"!-E,44BBPW_dIXZ_ZjZjHk  C  m +5G'LLNJJL'//66%:L:L6MSSUL
 5:4F4F	  #5#5#5#:#:;dBS&&;;F=  =?C DFI%J\J\JcJcFd egj kmp&&00n2 248 9;>u?Q?Q?V?V;W XZ] ^`c&&//a1 1 48 8 ;>e>P>P>b>b:c d gj j mp&&//m1 1 MO	  dicscs #&e&6&6&@&@"AC"G#$$..K0 #027#8:=e>N>N>\>\:]#^`c#dfi$$++g-#-/3#469%:J:J:O:O6P#QSV#WY\$$--Z/#/ 26#6 9<E<L<L<^<^8_#` z|   )f !:!:E5+W\WfWfg%u/D/D.EuM7	??))T1)55EOO<X<XZ_ZhZhinixix  jD  jD  EN  <O  Z[  ]*  FDFdp qrr Y011u%%,,7E,RYY[%%,,GU`oqv  rB  rB  `C,  Dd  	tMM@DEGTVeq rss	tsQ   >BV  V  .V  V  ('V  .T >MV  AU=:V   	V;	'V60V;6V;c           	         | j                   dk(  rO| j                  j                  d      }| j                  j                  d      }| j                  j                  d      }	 | j                  j                  d      }| j                  j                  d      j                         }t        j
                  j                  |      j                         }||_        |j                          |dk(  r	 t        j                  |j                  |j                        }|j                         t        j                         j                         z
  }|j!                         }	t#        |	d	      d
   }
|
d
k  r1d|_        t        j                         |_        |j                          nk|
dk  r6|
d
kD  r1d|_        t        j                         |_        |j                          n0d|_        t        j                         |_        |j                          |dk(  rd|_        t        j                         |_        |j                          	 |j(                  }t*        j
                  j                  |      j                         }|j,                  dk(  rd|_        |j                          |dv rd|_        t        j                         |_        |j                          |dk(  ru	 |j(                  }t*        j
                  j                  |      j                         }|j,                  dk(  rd|_        |j                          t.        j
                  j                         }|j0                  |j2                  k\  r|j0                  |j4                  k  rt.        j
                  j                         }dt7        t9        j:                  dd             }t<        j
                  j?                  |||j@                        }d}d| d}tC        |j@                  jD                  ||||j@                         tG        |||j@                  jH                  gd       |j                          	 tK                |dk(  rd}d}n|d k(  rd!}d"}n|dk(  rd#}d$}n	|dk(  rd%}d&}|}tC        |j@                  jD                  |||j@                         tG        |||j@                  jH                  gd       |j@                  jL                  d'k(  rMtO        jP                  |j@                  jR                  |jT                  |j@                  jV                  gd()       tY        d*|||d+      S y #  t        j                         }Y ]xY w#  Y xY w#  Y 4xY w#  Y !xY w# tZ        $ r$}tY        d,t7        |      |||d-      cY d }~S d }~ww xY w).Nr   re  r  r  r  selected_valuer  r"    r   Redr   OrangeWhiter  Dark Redr  r  r  )zDelivery Assingedr  r  r  	NavyaCoupi  i )coupon_codecouponr   zEligible for Coupon!zYou are eligible for Coupon (z).Forder_packed_generalzJYour Order Packed Successfully, Delivery Boy will pick your order shortly!r  r  zPYour Order Assigned Successfully, your order will reach your foot steps shortly!delivered_generalz^Your Order Delivered Successfully, Please give your valuable feed for better future endevours!deliveryfailedcase_generalzSorry! Your Order Failed!Tr   r   r  r   re  r  r  r  r   r   re  r  r  ).r   r   r   striprb   r  r  rw  r  r  r   combinedelivery_slot_datedelivery_slot_timer`  
astimezonetotal_secondsdivmodcolor_statuscolor_status_updation_timerx  r_   r  rm   r
  lower_limit_pricehigher_limit_pricer  randomrandintrn   r  r   r   r   r   r   rs   r  r   r   r  r   r  r   r   )r   re  r  r  r  r   r   combined_datetimetime_dif_with_del_slotduration_in_s_data	hours_delr  r  custom_coupon_checkcustom_coupon_settingscoupon_code_generationcustom_couponnotification_titlenotification_descriptionr  r   r   r   s                          r   save_order_statusr;    s;   ~~||'!!(+||''7d	q )),7J\\%%&67==?FNN))z):@@BE!'EJJL'7(0(8(89Q9QSXSkSk(l% *;)E)E)G(,,.JcJcJe)e&%;%I%I%K""#5t<Q?	q=).E&7?||~E4JJL]y1})1E&7?||~E4JJL)0E&7?||~E4JJL!%/"3;<<>0

#(#5#5L*2299\9JPPRG22j@6D3 II%,"3;<<>0

 [(','9'9"."6"6"="="="N"T"T"V"66*D:HG7#LLN.B.J.J.P.P.R+!--1D1V1VV]b]n]n  sF  sY  sY  ^Y5I5Q5Q5W5W5Y27@V^^TXYbEcAd@e5f2,8,@,@,G,GTj  tJ  QV  Q`  Q`,G  -aM 2H.9VWmVnnp7q4,U__-F-FOac{  ~C  ~M  ~M  N%&8:RUZUdUdUjUjTkmrs JJL"$ '2	j..7	p;&/	~8#8	9 EU__66ukSXSbSbce[5??+@+@*A5I%%-%118T8TV[VdVdejetetee  AJ  8K  VW  Y9dffr sttK  7(0%8<*  	q!#a&$&bnoq q	qs   #BV 3*U! D(V A U= &;V "E4V V '
V 1C.V !U:7V =V?V V
V VV 	WV=7W=Wc                    | j                   dk(  r	 | j                  j                  d      }| j                  j                  d      }t        j                  j                  |      j                         }|st        ddd      S |j                  dk(  rt        dd	d      S ||_        |j                          t        d
di      S y # t        $ r!}t        dt        |      d      cY d }~S d }~ww xY w)Nr   r  r  r  r  Order not foundr   	Contactedz;Order status cannot be changed after being set to Contactedr   r  )r   r   r   rb   r  r  rw  r   r  r  r   r  )r   r  r   r   r   s        r   save_customorder_statusr?  9  s    ~~	C )),7J\\%%&67FNN))z):@@BE#v>O$PQQ !![0#%.kln n "(EJJL9 566%  &  	C6#a& ABB	Cs*   A3C C "#C 	C1C,&C1,C1c                    | j                   dk7  rt        ddd      S | j                  j                  d      }t        j
                  j                  |      j                         }|st        ddd	      S | j                  j                  d
      }| j                  j                  d      }| j                  j                  d      }d }d |_        d |_	        |dk(  r0d}| j                  j                  d      }|rt        |      |_        n|dk(  r~d}| j                  j                  d      }| j                  j                  d      }	|rt        |      |_        |	r2	 t        j
                  j                  |	      }
|
j                  |_	        |j                          t        j
                  j!                  |      \  }}||_        ||_        ||_        |j                          t)        | j                  |      }|j+                         r|j                          t        ddd      S t        d|j,                  d      S # t        j                  $ r
 d |_	        Y w xY w)Nr   r   rG  rH  r   r   r  r=  r   r  quantity_unitr  pickupr  pickup_datehome_deliveryHome Deliverydelivery_date	time_slotr;  r  r  r  zOrder updated successfullyrF  )r   r   r   r   rb   r  r  rw  r&  r'  r   re   
start_timer_  r  r^   rJ  r  rB  r  rF   r  r  )r   r  r   r  rB  r  del_typerD  rG  slot_idslotcustom_trackcreatedr  s                 r   save_customorder_datarP  S  s   ~~w;STUU !!*-JNN!!:!6<<>Ev6GHII ||
+HLL$$_5MLL$$_5MH  $E#E  ll&&}5'1+'>E$	/	)"((9,,"";/'1-'@E$0#++//7/;+/??(
 
JJL 077EEuEUL'$L!.L!)L 7<<%8D}}		y=YZ[[w$++FGG-  ,, 0+/(0s   1I I"!I"c           	      t   | j                   dk(  rx| j                  j                  d      }| j                  j                  d      }| j                  j                  d      }	 t        j                  j                  |      j                         }|j                  dk(  rd|_        |j                          d}d	}d
}t        |j                  j                  ||||j                         t        |||j                  j                  gd       |j                  j                  dk(  rCt        j                   |j                  j"                  ||j                  j$                  |gd       t'        d|||d      S t'        d|||d      S y # t(        $ r$}	t'        dt+        |	      |||d      cY d }	~	S d }	~	ww xY w)Nr   re  r  r  rA  r  r!  zOrder Viewedz:Your Order Viewed by the Merchant and will be packed soon!custom_order_requestFTr   r   r  r"  r  r#  )r   r   r   rb   r  r  rw  r  r  r   r   r   r   r   r  r   r   r  r  r   r   r  )
r   r   re  r  r  r   r   r   r  r   s
             r   order_status_update_to_viewedrS    s   ~~||'!!(+||''7	qNN))7);AACE!![0%-"

 'Z1	 !:!:E5+W\WfWfg%u/D/D.EuM??))T1)55EOO<X<XY`afapapa{a{  }F  <G  RS  U $y$RXjv$wxx646co pqq7  <  	q!#a&$&bnoq q	qs%   #DF
 9F
 
	F7F2,F72F7c                 l   t         j                  j                  d      }t        |d      }| j                  j                  d      }	 |j                  |      }|dd}t        | d|      S # t        t        f$ r |j                  d      }Y 4t        $ r |j                  |j                        }Y Yw xY w)a?  
    Coupons  menu on Promotions section in the side bar will list the coupons.
    It is only available for super admin and nbc admin.
    nbc admin can create, edit and delete coupons.
    this defined coupons will list on apps.
    if they are eligible they can use the coupons.
    :param request:
    :return:
    rc  rL  re  r   r:  )coupon_datapromotion_activezcoupon_list.html)rd   r  rC  r   rh  r   ri  r!   rj  r    rk  r   )r   r  rm  re  coupon_list_datarK  s         r   coupon_listrX    s     __%%m4F&!$I;;??6"DC$--d3
 /HMG'-w77 i( 1$--a0 C$--i.A.ABCro  c                     t         j                  j                  |      }|rbt        j                  j                  |      }|r0t	        j
                  | t        j                  d       t        d      S |j                          t        d      S )aW  
     Coupons  menu on Promotions section in the side bar will list the coupons.
    Deleting a coupon. for each coupon listed on
    coupon list, we have a delete button. clicking on
    the delete button will open a confirm dialog box. if you confirm
    it will delete the coupon.
    :param request:
    :param coupon_id:
    :return:
    r  )Couponz/Your coupon used in ads! couldn't delete couponlist_coupons)	rd   r  r  rg   r   r  r  r  r   )r   	coupon_idr  r  s       r   coupon_deleter]    sy     __##y#1F kk  	 2  (*:*:!RT
 N## MMON##r   c                    g }t         j                  j                  |      j                         }| j                  dk(  rt| j
                  j                         }d|j                  dd      v r7|j                  dd      }|r|j                  d       |j                  d|       d|j                  dd      v r7|j                  dd      }|r|j                  d       |j                  d|       d|j                  dd      v r7|j                  dd      }|r|j                  d       |j                  d|       d|j                  dd      v r7|j                  dd      }|r|j                  d       |j                  d|       |j                  d	d      }		 |	d
k(  r
|d= |d= |d= n|	dk(  r|d= |d= n|	dk(  r|d= t        || j                  |      }
|
j                         r| j
                  j                  dd      rd|
j                  _        | j
                  j                  d      dk(  r#d|
j                  _        d|
j                  _        nd|
j                  _        	 |
j'                          t5        ddi      S |j9                  |
j6                         t5        d|
j6                  d      S t        |      }
||
|j:                  d|j<                  |j>                  d}tA        | d|      S #  Y =xY w# t(        $ rg}|j*                  }|
j-                  t/        |j1                               d   |j2                  d          t5        d|
j6                  d      cY d}~S d}~ww xY w)a  
    Coupons  menu on Promotions section in the side bar will list the coupons.
    Editing a coupon. for each coupon listed, we have a edit button. clicking on
    the edit button will open a form. fields are coupon_name and coupon_code,
    coupon_description, icon, coupon_on, applicable_category, applicable_subcategory,
    applicable_product, applicable_sku, minimum_total_bill_amount, coupon_type,
    discount_amount, no_of_users, validity_start_date, validity_end_date, terms_and_conditions.
    validations listed on the forms. applicable_category, applicable_subcategory,
    applicable_product, applicable_sku are dynamic fields based on coupon_on field.
    coupon maybe amount based or percentage based. the field used to indicate is
    coupon_type.

    Imp: image refresh and showing logic is handled via javascript.It is field wise and based on id.

    :param request:
    :param coupon_id:
    :return:
    r  r   r   ApplicableCategoryNApplicableSubCategoryApplicableProductApplicableSkuCouponOnCategorySubCategoryr  r  r"  
CouponTypeamountr   Fr.  r  Tr:  )r  coupon_formr\  rV  rU  coupon_typezcoupon_edit.html)!rd   r  r  rw  r   r   r  r0  rd  setlistr   r@   r  r  r  IconDiscountPercentageMaxDiscountAmountForPercentageDiscountAmountr  r   message_dict	add_errorr?  r  r   r   r  ry  r   rc  rf  r   )r   r\  r  r  	post_datar   r  r  rT  	coupon_onr  r   
error_datarK  s                 r   coupon_editrt    s6   * F__##y#1779F~~LL%%'	
 ""#7>>%--.BDIM$$R(2MB""#:DAA ) 1 12I4 P !((,57HI""#6==$,,-@$GL##B'1<@""?D99 (($?H#ox8MM*d3	
	J&6723/m+23/i'/ )W]]VD==?||,%)"||-9370?C</3,O		  D 122 MM$++&ET[[ IJJ6*YY$((G '-w77K	  $ O^^
tJOO$56q91::a=I#$MNNOs+   #K5 %K= 5K:=	M-AM("M-(M-c                 B   g }| j                   dk(  rr| j                  j                         }d|j                  dd      v r7|j                  dd      }|r|j	                  d       |j                  d|       d|j                  dd      v r7|j                  dd      }|r|j	                  d       |j                  d|       d|j                  dd      v r7|j                  dd      }|r|j	                  d       |j                  d|       d|j                  dd      v r7|j                  dd      }|r|j	                  d       |j                  d|       |j                  dd      }	 |d	k(  r
|d= |d= |d= n|d
k(  r|d= |d= n|dk(  r|d= t        || j                        }|j                         r| j                  j                  dd      rd|j                  _        | j                  j                  d      dk(  r#d|j                  _        d|j                  _        nd|j                  _        	 |j                          t-        ddi      S |j1                  |j.                         t-        d|j.                  d      S t               }g }||dd	dd}t3        | d|      S #  Y xY w# t         $ rg}	|	j"                  }
|j%                  t'        |
j)                               d   |	j*                  d          t-        d|j.                  d      cY d}	~	S d}	~	ww xY w)as  
    Coupons  menu on Promotions section in the side bar will list the coupons.
    adding a coupon.We have a add coupon button. clicking on
    the add button will open a form. fields are coupon_name and coupon_code,
    coupon_description, icon, coupon_on, applicable_category, applicable_subcategory,
    applicable_product, applicable_sku, minimum_total_bill_amount, coupon_type,
    discount_amount, no_of_users, validity_start_date, validity_end_date, terms_and_conditions.
    validations listed on the forms. applicable_category, applicable_subcategory,
    applicable_product, applicable_sku are dynamic fields based on coupon_on field.
    coupon maybe amount based or percentage based. the field used to indicate is
    coupon_type.

    Imp: image refresh and showing logic is handled via javascript.It is field wise and based on id.
    :param request:
    :return:
    r   r   r_  Nr`  ra  rb  rc  rd  re  r  r"  rf  rg  r   Fr.  r  Tr:  )r  rh  rV  rU  ri  zcoupon_add.html)r   r   r  r0  rd  rj  r   r@   r  r  r  rk  rl  rm  rn  r  r   ro  rp  r?  r  r   r   r  ry  r   )r   r  rq  r   r  r  rT  rr  rh  r   rs  rK  s               r   
coupon_addrv  _  s   & F~~LL%%'	 ""#7>>%--.BDIM$$R(2MB""#:DAA ) 1 12I4 P !((,57HI""#6==$,,-@$GL##B'1<@""?D99 (($?H#ox8MM*d3		J&6723/m+23/i'/ !GMM:!||,,0$$)||-9:>$$7FJ$$C6:$$3	V  "  D 122MM+,,-E[=O=O PQQ !l"$!G ',g66O	 $ V
 ^^
%%d:??+<&=a&@!**Q-P#ASAS$TUUVs+   ,#J& 5J. &J+.	L7ALLL)r[  r\  r^  c                 l   t         j                  j                  d      }t        |d      }| j                  j                  d      }	 |j                  |      }|dd}t        | d|      S # t        t        f$ r |j                  d      }Y 4t        $ r |j                  |j                        }Y Yw xY w)z
    In NBC admin dashboard, On the orders section we have order slot menu. clicking on the
    menu will open the slot list. we can add, edit and view the slots from here.
    :param request:
    :return:
    rc  rL  re  r   r:  )delivery_slot_datar  zdelivery_slot_list.html)re   r  rC  r   rh  r   ri  r!   rj  r    rk  r   )r   delivery_slotsrm  re  delivery_slotrK  s         r   delivery_slot_listr{    s     "))22=AN.!,I;;??6"D@!**40
 &3XNG'4g>> i( .!**1- @!**9+>+>?@ro  c                 |    t         j                  j                  |      }|r|j                          t	        d      S )aD  
    In NBC admin dashboard, On the orders section we have order slot menu.
    on the slots listed, for each slot we have a delete button. Clicking on
    the delete button will open a dialog box. clicking on the confirm will
    delete the delivery slot.

    :param request:
    :param delivery_slot_id:
    :return:
    r  r{  )re   r  r  r  r   )r   delivery_slot_idrz  s      r   delivery_slot_deleter~    s9     !((//3C/DM())r   c                 x   g }t         j                  j                  |      j                         }| j                  dk(  r^t        | j                  |      }|j                         r|j                         }t        d      S |j                  |j                         nt        |      }|dd}t        | d|      S )a  
    In NBC admin dashboard, On the orders section we have order slot menu.
    on the slots listed, for each slot we have a edit button. Clicking on
    the edit button will open a edit form. fields of the form are  start_time,
    end_time, is_available, status. based on the availability status, it is
    showing on the app(select Delivery slots).

    :param request:
    :param delivery_slot_id:
    :return:
    r  r   r  r{  r:  )delivery_slot_formr  zdelivery_slot_edit.html)re   r  r  rw  r   rA   r   r  r  r   ry  r  r   )r   r}  r  rz  r  del_slotrK  s          r   delivery_slot_editr    s     F ((//3C/DJJLM~~}E==?yy{H011 MM$++&7%)HEG'4g>>r   c                 :   g }| j                   dk(  rnt        | j                        }|j                         r|j	                         }t        d      S |j                  |j                         ||dd}t        | d|      S t               }||dd}t        | d|      S )a  
        In NBC admin dashboard, On the orders section we have order slot menu.
    Clicking on the Add Delivery Slot button will open a add delivery slot form.
    fields of the form are  start_time, end_time, is_available, status.

    :param request:
    :return:
    r   r{  r:  )r  r  r  zdelivery_slot_add.html)	r   rA   r   r  r  r   ry  r  r   )r   r  r  r  rK  s        r   delivery_slot_addr    s     F~~-==?yy{H011MM$++& &*!)G
 '#;WEE! "!G '3W==r   c                 l   t         j                  j                  d      }t        |d      }| j                  j                  d      }	 |j                  |      }|dd}t        | d|      S # t        t        f$ r |j                  d      }Y 4t        $ r |j                  |j                        }Y Yw xY w)a  
    Discount  menu on Promotions section in the side bar will list the discounts.
    It is only available for super admin and nbc admin.
    nbc admin can create, edit and delete discounts.
    this defined discount will shown on product listing with a strike.
    rc  rL  re  r   r:  )discount_datarV  zdiscount_list.html)rf   r  rC  r   rh  r   ri  r!   rj  r    rk  r   )r   discountrm  re  discount_list_datarK  s         r   discount_listr  <  s     ((7H(A&I;;??6"DE&//5
 !3QG'/99 i( 3&//2 E&//	0C0CDEro  c                    t         j                  j                  |      }|rPt        j                  j                  |      }t	        j
                  | t        j                  d       t        d      S |j                          t        d      S )ac  
    Discount  menu on Promotions section in the side bar will list the discounts.
    Deleting a discount. for each discount listed on
    discount list, we have a delete button. clicking on
    the delete button will open a confirm dialog box. if you confirm
    it will delete the discount.
    :param request:
    :param discount_id:
    :return:
    r  )rf   z3Your Discount used in ads! couldn't delete discountlist_discounts)	rf   r  r  rg   r   r  r  r  r   )r   discount_idr  r  s       r   discount_deleter  Q  s{     &&+&6H kk  + 6Wh&6&6R	T
 $%% 	$%%r   c                 <   g }t         j                  j                  |      j                         }| j                  dk(  r!| j
                  j                         }d|j                  dd      v r7|j                  dd      }|r|j                  d       |j                  d|       d|j                  dd      v r7|j                  dd      }|r|j                  d       |j                  d|       d|j                  dd      v r7|j                  dd      }|r|j                  d       |j                  d|       d|j                  dd      v r7|j                  dd      }|r|j                  d       |j                  d|       |j                  d	d      }		 |	d
k(  r
|d= |d= |d= n|	dk(  r|d= |d= n|	dk(  r|d= t        || j                  |      }
|
j                         rJ| j
                  j                  dd      rd|
j                  _        |
j!                          t#        ddi      S |j%                  |
j&                         t#        d|
j&                  d      S t        |      }
||
|j(                  d|j*                  d}t-        | d|      S #  Y xY w)a  
    Discount  menu on Promotions section in the side bar will list the discounts.
    Editing a discount. for each discount listed, we have a edit button. clicking on
    the edit button will open a form. fields are discount_name and discount_code,
    discount_description, discount_on, applicable_category, applicable_subcategory,
    applicable_product, applicable_sku,
    discount_percentage.
    validations listed on the forms. applicable_category, applicable_subcategory,
    applicable_product, applicable_sku are dynamic fields based on discount_on field.
    discount is percentage based.
     Imp: image refresh and showing logic is handled via javascript.It is field wise and based on id.
    :param request:
    :param discount_id:
    :return:
    r  r   r   r_  Nr`  ra  rb  
DiscountOnrd  re  r  r  r  r  TFr.  r:  )r  discount_formr  rV  r  zdiscount_edit.html)rf   r  r  rw  r   r   r  r0  rd  rj  r   rB   r  r  r  BannerImager  r   ry  r  r   r  r   )r   r  r  r  rq  r   r  r  rT  discount_onr  rK  s               r   discount_editr  j  s   $ F&&+&6<<>H~~LL%%'	
 ""#7>>%--.BDIM$$R(2MB""#:DAA ) 1 12I4 P !((,57HI""#6==$,,-@$GL##B'1<@""?D99 (($?H#ox8mmL$7	j(6723/-23/	)/ Iw}}xH==? ||"-,0)IIKD 122 MM$++&ET[[ IJJX.{{$!,,G '/993	s   #J Jc                    g }| j                   dk(  r| j                  j                         }d|j                  dd      v r7|j                  dd      }|r|j	                  d       |j                  d|       d|j                  dd      v r7|j                  dd      }|r|j	                  d       |j                  d|       d|j                  dd      v r7|j                  dd      }|r|j	                  d       |j                  d|       d|j                  dd      v r7|j                  dd      }|r|j	                  d       |j                  d|       |j                  dd      }	 |d	k(  r
|d= |d= |d= n|d
k(  r|d= |d= n|dk(  r|d= t        || j                        }|j                         rJ| j                  j                  dd      rd|j                  _        |j                          t        ddi      S |j                  |j                         t        d|j                  d      S t               }g }||dd	d}	t!        | d|	      S #  Y xY w)a  
    Discount  menu on Promotions section in the side bar will list the discounts.
    adding a discount.We have a add coupon discount. clicking on
    the add button will open a form. fields are discount_name and discount_code,
    discount_description, discount_on, applicable_category, applicable_subcategory,
    applicable_product, applicable_sku,
    discount_percentage.
    validations listed on the forms. applicable_category, applicable_subcategory,
    applicable_product, applicable_sku are dynamic fields based on discount_on field.
    discount is percentage based.
     Imp: image refresh and showing logic is handled via javascript.It is field wise and based on id.
    r   r   r_  Nr`  ra  rb  r  rd  re  r  r  r  TFr.  r:  )r  r  rV  r  zdiscount_add.html)r   r   r  r0  rd  rj  r   rB   r  r  r  r  r  r   ry  r  r   )
r   r  rq  r   r  r  rT  r  r  rK  s
             r   discount_addr    su    F~~LL%%'	 ""#7>>%--.BDIM$$R(2MB""#:DAA ) 1 12I4 P !((,57HI""#6==$,,-@$GL##B'1<@""?D99 (($?H#ox8mmL$7
	j(6723/-23/	)/ %Y>!!# ||"-59&&2 D 122MM-../E]=Q=Q RSS %&$#	G '.883	s   ,#I Ic           	      2   | j                   j                  dd      }| j                   j                  dd      }| j                   j                  dd      }t        ddd	d
d      }t        dddd|d      }t        dddd|d      }t        ||||||d      S )Nr'  r(  r)  r*  r+  r,  r-  r.  r/  rk  r0  r4  r5  StandardImagerE  r6  r7  r  rG  rH  rI  s          r   image_field_styler  !  s     [[__^-DEF[[__^-XYF[[__^-HIF#$63;Sh39%;<L $$63<Ti3BF%TUL $$63<Ti3@&%RSL %|UamsV	-. .r   c                 l   t         j                  j                  d      }t        |d      }| j                  j                  d      }	 |j                  |      }|dd}t        | d|      S # t        t        f$ r |j                  d      }Y 4t        $ r |j                  |j                        }Y Yw xY w)aW  
    Ads menu on Promotions section in the side bar will list the ads.
    It is only available for super admin and nbc admin.
    nbc admin can create, edit and delete ads.
    These ads are used in carousel in the app and also the bottom banner.
    We are defining the placement of ads while creating.

    :param request:
    :return:
    rc  rL  re  r   r:  )ad_datarV  zad_list.html)rg   r  rC  r   rh  r   ri  r!   rj  r    rk  r   )r   adrm  re  ad_list_datarK  s         r   ad_listr  6  s     
		m	,B"a I;;??6"D? ))$/
 'HEG'>733 i( - ))!, ? )))*=*=>?ro  c                 |    t         j                  j                  |      }|r|j                          t	        d      S )a<  
    Ads  menu on Promotions section in the side bar will list the ads.
    Deleting a ad. for each ads listed on
    ads list, we have a delete button. clicking on
    the delete button will open a confirm dialog box. if you confirm
    it will delete the ad.
    :param request:
    :param ad_id:
    :return:
    r  list_ad)rg   r  r  r  r   )r   ad_idr  s      r   	ad_deleter  O  s2     
		u		%B	
		Ir   c                    g }t         j                  j                  |      j                         }| j                  dk(  rt        | j                  | j                  |      }| j                  j                  dd      }| j                  j                  dd      }| j                  j                  dd      }|j                         r+|j                  d	      }|j                  dk(  r7	 t        j                  j                  |      j                         }||_        n|j                  dk(  r7	 t        j                  j                  |      j                         }	|	|_        nE|j                  dk(  r6	 t        j                  j                  |      j                         }
|
|_        | j                  j                  d
d      rd|j"                  _        |j                          t'        d      S |j)                  |j*                         nt        |      }||d|j                  d}t-        | d|      S #  Y xY w#  Y xY w#  Y xY w)a  
    Ads menu on Promotions section in the side bar will list the ads.
    Editing a ad. for each ad listed, we have a edit button. clicking on
    the edit button will open a form. fields are placement_choices and AdTitle,
    AdDescription, AdPlacement, AdType, StandardImage,
    BannerImage, Discount,
    Coupon, Product.
    validations listed on the forms. Discount, Coupon, Product are dynamic fields based on AdType field.
    On submitting we can edit a ad already existing.
    Imp: image refresh and showing logic is handled via javascript.It is field wise and based on id.
    :param request:
    :param ad_id:
    :return:
    r  r   r  rZ  r   rf   r  Fr  r  Nr  r:  r  ad_formrV  r  zad_edit.html)rg   r  r  rw  r   rC   r   r  r   r  r  AdTyperd   rZ  rf   rQ   r  r  r  r   ry  r  r   )r   r  r  r  r  r  r  r  coupon_instancediscount_instanceproduct_instancerK  s               r   ad_editr  a  s   " F			u		%	+	+	-B~~gllGMMB?!!(B/<<##J3,,""9b1==?%(B yyH$&-oo&<&<&<&G&M&M&OO /BI j((0(8(8(?(?8(?(L(R(R(T%"3BK i''/'7'7'>'>''>'J'P'P'R$!1BJ ||"-,0)GGII&& MM$++&r"$99	G '>733Gs$   *5H9 05I  65I 9H= IIc                 ^   g }| j                   dk(  rt        | j                  | j                        }| j                  j	                  dd      }| j                  j	                  dd      }| j                  j	                  dd      }|j                         r+|j                  d      }|j                  dk(  r7	 t        j                  j                  |      j                         }||_        n|j                  dk(  r7	 t        j                  j                  |      j                         }||_        nE|j                  dk(  r6	 t        j                  j                  |      j                         }	|	|_        | j                  j	                  d	d      rd
|j                   _        |j                          t%        d      S |j'                  |j(                         ||d|j                   j                  d}
nt               }g }||ddd}
t+        | d|
      S #  Y xY w#  Y xY w#  Y xY w)a  
    Ad  menu on Promotions section in the side bar will list the ads.
    adding a ad.We have a add ad button. clicking on
    the add button will open a form. fields are placement_choices and AdTitle,
    AdDescription, AdPlacement, AdType, StandardImage,
    BannerImage, Discount,
    Coupon, Product.
    validations listed on the forms. Discount, Coupon, Product are dynamic fields based on AdType field.
    Imp: image refresh and showing logic is handled via javascript.It is field wise and based on id.

    r   rZ  r   rf   r  Fr  r  r  Nr  r:  r  zad_add.html)r   rC   r   r  r   r  r  r  rd   r  r  rw  rZ  rf   rQ   r  r  r  r   ry  r  r   )r   r  r  r  r  r  r  r  r  r  rK  s              r   ad_addr    s    F~~gllGMM2!!(B/<<##J3,,""9b1==?%(B yyH$&-oo&<&<&<&G&M&M&OO /BI
 j((0(8(8(?(?8(?(L(R(R(T%"3BK i''/'7'7'>'>''>'J'P'P'R$!1BJ ||"-,0)IIKI&&MM$++& !$,==//	G x (!	
 '='22Ws$   :5H  5H! 5H( H!H%(H,c                    g }| j                   dk(  r)t        | j                  | j                        }|j	                         r|j                         }| j                  j                  d      }|D ]#  }t        j                  j                  ||       % | j                  j                  d      }|D ]#  }t        j                  j                  ||       % 	 | j                  }d}	d}
d|j                   d	|j                   d
}t        ||	|
|       t        d      S |j!                  |j"                         n
t               }||dd}t%        | d|      S #  Y t        d      S xY w)a  
    Custom Products  menu on Products section in the side bar will list the custom products.
    adding a Custom Product.We have a Add Custom Product button. clicking on
    the add button will open a form. fields are item_name and item_code,
    item_description, veg_or_non_veg_status, min_size, max_size,
    size_unit, availability.
    Imp: Images are stored separately in CustomProductVideo and CustomProductImage.
    multiple image upload supported
    for validations please refer CustomProductForm


    r   r   custom_productr"  r#  r  r%  r  zCustom Product AddedzCustom Product r  z added custom_product_listingr:  )r  custom_product_formr  zcustom_product_add.html)r   rD   r   r  r  r  r0  rZ   r  r  r[   r   r1  r2  r  r   ry  r  r   )r   r  r  r  r   r"  r#  r%  r  r  r   r   rK  s                r   custom_product_addr    sj    F~~/gmmL'')0557N ]]**84F"**11W\1]   ]]**84F"**11W\1]  "<<$0 /0H0H/IVdVnVnUoovwHh=
 455 MM-445/1 2#G '4g>># 455s   ;E E'c                 l   t         j                  j                  d      }t        |d      }| j                  j                  d      }	 |j                  |      }|dd}t        | d|      S # t        t        f$ r |j                  d      }Y 4t        $ r |j                  |j                        }Y Yw xY w)a  
    Custom Products  menu on Products section in the side bar will list the custom products.
    It is only available for super admin and nbc admin.
    nbc admin can create, edit and delete custom products.
    custom product means, customer can define a product by directly contact
    with navya bakers.
    There is a section in the app to create a custom order. The admin can define the customization
    available products in the custom products section.
    :param request:
    :return:
    r  rL  re  r   r:  r  zcustom_product_list.html)rY   r  rC  r   rh  r   ri  r!   rj  r    rk  r   )r   r  rm  re  product_list_datarK  s         r   r  r  8  s     !((11/BL,*I;;??6"DD%..t4
  1XNG'5w?? i( 2%..q1 D%..y/B/BCDro  c                    t        t        |      }|}| j                  dk(  rW|j                          	 | j                  }d}d}d|j
                   d|j                   d}t        ||||       t        d
      S t        | dd|i      S # t        $ r,}t        j                  d|        Y d	}~t        d
      S d	}~ww xY w)a  
    Custom Products  menu on Products section in the side bar will list the custom products.
    Deleting a custom product. for each custom product listed on
    custom product list, we have a delete button. clicking on
    the delete button will open a confirm dialog box. if you confirm
    it will delete the custom product.
    :param request:
    :param product_id:
    :return:
    r  r   r  zCustom Product deletedCustom product r  z	 deleted z)Error on Custom Product Delete(logging): Nr  zdelete_confirmation.html)r   rY   r   r  r   r1  r2  r  r   r   r   r   r   )	r   r  r  r  r  r  r   r   r   s	            r   delete_custom_productr  V  s      *=GL~~
	||H H.G+L,B,B+C<P\PfPfOggpqK(G[9
 011'5	77KLL  	MMEaSIJ011		s   ;B	 		B>B99B>c                    g }t        t        |      }t        | j                  xs d| j                  xs d|      }| j
                  dk(  r|j                         r|j                         }| j                  j                  d      }|D ]#  }t        j                  j                  ||       % | j                  j                  d      }|D ]#  }t        j                  j                  ||       % 	 | j                  }	d	}
d
}d|j                   d|j                   d}t!        |	|
||       t#        d      S |j%                  |j&                         |||d}t)        | d|      S #  Y t#        d      S xY w)aR  
    Custom Products  menu on Products section in the side bar will list the custom products.
    Editing a Custom Product. for each custom product listed, we have a edit button. clicking on
    the edit button will open a form. fields are item_name and item_code,
    item_description, veg_or_non_veg_status, min_size, max_size,
    size_unit, availability.
        Imp: Images are stored separately in CustomProductVideo and CustomProductImage.
    multiple image upload supported
    for validations please refer CustomProductForm
    :param request:
    :param product_id:
    :return:
    r  Nr  r   r   r  r#  r  r  zCustom Product Updatedr&  r  z	 updated r  )r  r  r  zcustom_product_edit.html)r   rY   rD   r   r  r   r  r  r0  rZ   r  r  r[   r   r1  r2  r  r   ry  r  r   )r   r  r  r  r  r   r"  r#  r%  r  r  r   r   rK  s                 r   custom_product_editr  {  sx     F&}DN+GLL,@D'--BWSWbpq~~'')0557N ]]**84F"**11W\1]   ]]**84F"**11W\1]  "<<$2 ()A)A(B,~OgOgNhhqrHh= 455 MM-445 2(G '5w??455s   5;E) )E7c                 b   t        t        |      }|j                  j                  }|j	                          	 | j
                  }d}d}d|j                  j                   d|j                  j                   d}t        j                  j                  ||||       t        d|	      S #  Y xY w)
a  
        Custom Products  menu on Products section in the side bar will list the custom products.
        custom product have its associated images and videos which is not listed. when we try to
        add or edit a custom product it will be on form.
        These images and videos are stored in separate table and managed separately.
        access via id.
        Table: CustomProductImage

        We can remove the image with this api.
    :param request:
    :param product_id:
    :param image_id:
    :return:
    r;  r  zCustom Product Image deletedr  r  z deleted its imager  r  rQ  )r   rZ   r  r*  r  r   r1  r2  r   r  r  r   )	r   r  ru  r"  custom_product_idr  r  r   r   s	            r   delete_custom_imager    s      0X>E,,//	LLN<<0'(<(<(F(F'G|TYThThTrTrSs  tF  G  ''XRYgr's )6GHHs   A$B* *B.c                    t        t        |      }|j                  j                  }|j	                          	 | j
                  }d}d}d|j                  j                   d|j                  j                   d}t        ||||       t        d	|
      S # t        $ r"}	t        j                  d|	        Y d}	~	3d}	~	ww xY w)a  
    Custom Products  menu on Products section in the side bar will list the custom products.
    custom product have its associated images and videos which is not listed. when we try to
    add or edit a custom product it will be on form.
    These images and videos are stored in separate table and managed separately.
    access via id.
    Table: CustomProductVideo
    We can remove the video with this api.

    :param request:
    :param product_id:
    :param video_id:
    :return:
    r;  r  zCustom Product Video deletedr  r  z deleted its videoz&Custom Product Video Delete(logging): Nr  rQ  )r   r[   r  r*  r  r   r1  r2  r  r   r   r   r   )
r   r  ry  r%  r  r  r  r   r   r   s
             r   delete_custom_videor    s      0X>E,,// 
LLN
<<0'(<(<(F(F'G|TYThThTrTrSs  tF  GHh5
 )6GHH	  >qcBCs   AB 	C B;;C c                 l   t         j                  j                  d      }t        |d      }| j                  j                  d      }	 |j                  |      }|dd}t        | d|      S # t        t        f$ r |j                  d      }Y 4t        $ r |j                  |j                        }Y Yw xY w)at  
    Production unit means where products are manufacturing. Currently only one
    production unit available.
    production units  menu on Sales Unit section in the side bar will list the production unit.
    It is only available for super admin and nbc admin.
    nbc admin can create, edit and delete production unit. Only one production unit could be
    created now. creating more than one production unit is restricted. If no production unit created,
    a add button is available to create one else we hide that button.
    edit and delete button available for the production unit.

    :param request:
    :return:
    rc  rd  re  r   r:  )production_unit_datarg  zproduction_unit_list.html)rN   r  rC  r   rh  r   ri  r!   rj  r    rk  r   )r   production_unitrm  re  rK  s        r   r  r    s     %,,55mDO/2.I;;??6"DB#,,T2
 (7XVG'6@@ i( 0#,,Q/ B#,,Y-@-@ABro  c                 @   g }| j                   dk(  rot        | j                        }|j                         r|j	                          t        d      S |j                  |j                         ||ddd}t        | d|      S t               }g }||dd}t        | d|      S )a`  
    production units  menu on Sales Unit section in the side bar will list the production unit.
    adding a Production unit.We have a Add Production Unit button. clicking on
    the add button will open a form. fields are pu_name, pu_code, pu_location, street, city
    district, state_or_province, pin_code, latitude, longitude, gst, contact_no, email, status

    *NOt implemented yet (Only one production unit, not checking the status)
    We can change the status of pu by open, close or currently not accepting any order. it is by
    changing the status field.


    :param request:
    :return:
    r   production_unit_listr  r:  )r  production_unit_formr  rg  zproduction_unit_add.html)r  r  rg  )	r   rE   r   r  r  r   ry  r  r   )r   r  r  rK  s       r   production_unit_addr    s    " F~~1',,?((* %%'233MM.556 (<*%-	G '#=wGG13 4%G
 '5w??r   c                 |    t         j                  j                  |      }|r|j                          t	        d      S )a  
    production units  menu on Sales Unit section in the side bar will list the production unit.
    Deleting a production unit. for each production unit listed on
    production unit list, we have a delete button. clicking on
    the delete button will open a confirm dialog box. if you confirm
    it will delete the production unit.
    :param request:
    :param pu_id:
    :return:
    r  r  )rN   r  r  r  r   )r   pu_idpus      r   production_unit_deleter  =  s5     
			&	&%	&	0B	
		*++r   c                 >   t        t        |      }g }| j                  dk(  r^t        | j                  |      }|j                         r|j                          t        d      S |j                  |j                         nt        |      }|dd}t        | d|      S )a  
    production units  menu on Sales Unit section in the side bar will list the production unit.
    Editing a production unit. for each production unit listed, we have a edit button. clicking on
    the edit button will open a form. fields are pu_name, pu_code, pu_location, street, city
    district, state_or_province, pin_code, latitude, longitude, gst, contact_no, email, status
    :param request:
    :param pu_id:
    :return:
    r  r   r  r  r:  )pu_formrg  zproduction_unit_edit.html)r   rN   r   rE   r   r  r  r   ry  r  r   )r   r  r  r  r  rK  s         r   production_unit_editr  Q  s     
>e	4BF~~$W\\B?LLN233MM'..)$b1!AG'6@@r   c                 \    t         j                  j                         }t        | dd|i      S )a  
    Faq's are the possible questions raised by the user.
    Faq  menu on Settings in the side bar will list the Faq.
    It is only available for super admin and nbc admin.
    nbc admin can create, edit and delete faq.
    add button is available to create.
    edit and delete button available for each faq listed.
    This created faq will render on the faq section on app.

    :param request:
    :return:
    zfaq.htmlfaqs)r#   r  r  r   )r   r  s     r   faqr  l  s'     ;;??D':~66r   c                     | j                   dk(  rWt        | j                        }|j                         r|j	                          t        d      S t        j                  | d       n
t               }t        | dd|i      S )z
    Faq  menu on Settings in the side bar will list the Faq.
    adding a Faq.We have a Add Faq button. clicking on
    the add button will open a form. fields are category, question,
    answer
    :param request:
    :return:
    r   r  -There was an error with your form submission.zadd_faq.htmlr  )	r   r-   r   r  r  r   r   r   r   )r   r  s     r   add_faqr    sc     ~~w||$==?IIKE?"NN7$STy'>FD>::r   c                 ,   t        t        |      }| j                  dk(  rYt        | j                  |      }|j                         r|j                          t        d      S t        j                  | d       nt        |      }t        | d||d      S )a  
    Faq  menu on Settings in the side bar will list the Faq.
    editing a Faq.We have a edit Faq button for each faq listed. clicking on
    the edit button will open a form. fields are category, question,
    answer
    :param request:
    :param faq_id:
    :return:
    r;  r   r  r  r  zedit_faq.html)r  r  )r   r#   r   r-   r   r  r  r   r   r   r   )r   faq_idr  r  s       r   edit_faqr    su     CF
+C~~w||c2==?IIKE?"NN7$ST$'?T#,FGGr   c                 Z    t        t        |      }|j                          t        d      S )a  
    Faq  menu on Settings in the side bar will list the Faq.
    deleting a Faq.We have a delete Faq button for each faq listed. clicking on
    the delete button will open a form. fields are category, question,
    answer
    :param request:
    :param faq_id:
    :return:
    r;  r  )r   r#   r  r   )r   r  r  s      r   
delete_faqr    s#     CF
+CJJLE?r   c                 *   t         j                  j                         }t        j                  j                         }t        j                  j                         }t
        j                  j                         }t        j                  j                         }t        j                  j                         }| j                  dk(  rd| j                  v rNt        | j                  | j                  |      }|j                         r|j                          t'        d	      S d| j                  v rCt        | j                  |      }|j                         rQ|j                          t'        d	      S d| j                  v rCt        | j                  |      }	|	j                         r |	j                          t'        d	      S d| j                  v rBt!        | j                  |      }
|
j                         r|
j                          t'        d	      S d| j                  v rBt#        | j                  |      }|j                         r`|j                          t'        d	      S d| j                  v r7t%        | j                  |      }|j                         r|j                          t'        d	      S t        |      }t        |      }t        |      }	t!        |      }
t#        |      }t%        |      }t)        | d
||||||||	|
|||d      S )a+  
    About us describe about the Navya backers,
    Where there shops, contact details, app url,
    privacy polices, terms and conditions and what is their motto etc......

    each of this details are handled separately.
    we can edit each of this details.

    :param request:
    :return:
    r   edit_about_usr  edit_contact_usedit_app_urledit_privacy_policyedit_terms_conditionsedit_refund_policyabout_uszabout_us.html)r  
contact_usapp_urlprivacy_policyterms_and_conditionsabout_us_formcontact_us_formapp_url_formprivacy_policy_formterms_conditions_formrefund_policyrefund_policy_form)r$   r  rw  r&   r%   r'   r)   r(   r   r   r*   r  r  r  r,   r+   r.   r2   r/   r   r   )r   r  r  r  r  r  r  r  r  r  r  r  r  s                r   r  r    s    $$&H""((*Jnn""$G"**002N-55;;= ((..0M~~gll*'gmm19;M%%'""$, 
##+ ',,.+GLL:NO'')$$&$ 
### w||+%gllWEL$$&!!# 
## #gll2"3GLL>"Z"++-#((* 
## %4$:7<<Rf$g!$--/%**, 
## "W\\1!1',,!W!**,"'')
##  2M#Z8Ow/L+^D2<PQ)=A'? ( 4&*$2!6&0-  r   c                    t         j                  j                         }t        | j                  xs d|      }| j
                  dk(  r+|j                         r|j                          t        d      S t        | d||d      S )aD  
    In about us section we have the privacy policy view, in addition to that
    we have a separate menu on the settings, Privacy Policy. on clicking
    it will list current privacy policy, we have edit button on the list.
    by clicking edit we can edit the current privacy policy.

    :param request:
    :return:
    Nr  r   r  zprivacy_policy.html)r  policy)
r'   r  rw  r.   r   r   r  r  r   r   )r   r  r  s      r   privacy_policy_viewr    ss     ""((*FW\\1TFCD~~DMMO		())'03  r   c                    t         j                  j                         }t        | j                  xs d|      }| j
                  dk(  r+|j                         r|j                          t        d      S t        | d||d      S )a\  
        In about us section we have the Terms and condition view, in addition to that
    we have a separate menu on the settings, Terms and condition. on clicking
    it will list current terms and condition, we have edit button on the list.
    by clicking edit we can edit the current terms and condition.

    :param request:
    :return:
    Nr  r   r  zterms_conditions.html)r  terms)
r)   r  rw  r2   r   r   r  r  r   r   )r   r  r  s      r   terms_conditions_viewr  %  ss     &&,,.E!',,"6$GD~~DMMO		.//'25  r   c                     t        | d      S )zH
    * Not implemented yet........
    :param request:
    :return:
    delivery_settings.htmlr   r  s    r   delivery_settingsr  >  s     '344r   c           
      J	   	 | j                   j                  d      }t        j                  j	                  d      j                  | j                  j                        }|d   }g }| j                  j                  d      }| j                  j                  d      }| j                   j                  dd      }| j                   j                  d	d      }	| j                   j                  d
d      }
| j                   j                  dd      }|s|}| j                   j                  dd      }|s|}t        j                  j                  |d      j                  d      j                  ddd      j	                  d      j                  d      }|rV|dk(  r)|j                  t        d      t        d      z        }n(|j                  t        d      t        d      z        }| j                  j                  d      dk(  r|rQ|j                  t        |      t        |      z  t        |      z  t        |      z        j                  d      }|	r(t        j                   |	d       }|j                  |!      }|
r|j                  |
"      }|rd|rb|d#k(  r,|dk(  r|j                  |d$z         }nC|j                  |      }n1|dk(  r|j                  d%|z   d$z         }n|j                  d%|z         }t#        |d&      }| j                   j                  d'      }	 |j%                  |      }t/        d)      }| j                   j1                         }d'|v r|d'= |j2                  j4                  D cg c]  }|| d*|j7                  d+,       d-| d.! }}t9               }t:        j                  j                  d/|0      }||||	|
|d1||d2	}| j                  j                  d      dk(  r-t=        d3||||d4      }t=        d5d6|i      }t?        ||d7      S tA        | d8|      }|S # t&        t(        f$ r |j%                  d(      }Y t*        $ r |j%                  |j,                        }Y Dw xY wc c}w # tB        $ r g d1d9}tA        | d8|      cY S w xY w):Nr  r  r  r   r3  r  r  r   r  r  Custom Orders)r  rR  r  r  r  r   r  custom_orderr  r  r  r  r  r  r  r  r  r  r  r  r  r  rO  r  r  r  r  rL  re  r   custom_ordersr  r  r  r  r  rt  r  r:  )	
order_formr  r  r   r  r  r  r  r  zcustom_order_list_page.html)r  r  r  r  r  r  r  zcustom_orders.htmlr  )"rh  r   rL   r  r<  r  r   r   r  rb   r  r  rC  rw   r  r   r  r   ri  r!   rj  r    rk  rt   r  rm  r  r  rF   r_   ry   r   r   r  )r   r  r  rD  r  r  r3  r  r  r  r  r  r  r  r  rm  re  r  r  r  r  r  r  r  rK  r  r  responses                               r   r  r  I  s   q>;;??:.667HIPP"),,"3"3 Q 5 #__((6
__((6
{{x4[[__^R8
{{'7<!++//,;(O!++//,;(O NNVw?VCW+W.^,k>Jn-Xo& 	 5 (//E0B1wCW0WX
'..q5/A!iBX/XY
??126FF'..,7L9:l;< |DE
 (?+  !)!2!2:z!J'....Q
'..l.K
?"e+&+5%/%8%8>9Y%Z
%/%8%8%I
&+5%/%8%89NQ_9_%`
%/%8%89N%O
j!,	{{v&	=''-F ?+{{'')\!V$  &//::

  ;  +"1\%;%;%;%E$Ff[MZ  ; 	 
  %--44JW4U (* 0%, 

 ??126FF$%B4:P`8FT\&^_E **FW]H^_J%z JKK'#7AQ !), 	+''*F 	=''	(;(;<F	=
B  >%
 g3W==>sV   L#R &P2 7AR ;$Q?BR #R 2 Q<R #Q<8R ;Q<<R R"!R"c           	      j   | j                   j                  d      }|st        dddd      S t        j                  j                  dd	      }|D cg c]H  }|j                  |j                  j                  d
       d|j                  j                  d
       dJ }}t        d|d      S c c}w )Nr   r  zDate not providedrH    r~   Tr:  is_availabler   z%I:%M %pz - )r*  labelr  )r   slots)
rh  r   r   re   r  r  r*  rJ  strftimeend_time)r   selected_dater   rM  	slot_datas        r   get_available_delivery_slotsr    s    KKOOF+Mv:MNWZ[[  ''T('KE 
 D ''00<=SAWAWXbAc@de	
    9yABBs   AB0c                 
   | j                   dk(  rq| j                  j                  d      }t        j                  j                  |      j                         }d}|st        dddd	      S t        | j                  |
      }|j                         st        d|j                  d      S |j                          | j                  j                  d      }| j                  j                  d      }| j                  j                  d      }d }d }	d }
|dk(  rD| j                  j                  d      }d }	d }
d|_        d}|rt        |      nd |_        d |_        n|dk(  r| j                  j                  d      }	| j                  j                  d      }
d }d|_        d}|	rt        |	      nd |_        |
r3	 t         j                  j                  |
      }|j"                  |_        nd |_        nd }d }	d }
d |_        d |_        t&        j                  j)                  |      \  }}||_        ||_        ||_        |j                          d|_        |j                          d}d| }t3        |j4                  j6                  ||||j4                         t9        |||j4                  j:                  gd       d}t=        j>                  d|j4                  j@                   d|j4                  jB                          |j4                  jB                  dk(  rCtE        jF                  |j4                  jH                  ||j4                  jJ                  |gd !       t        d"|j@                  |jL                  d#      S | j                   d$k(  r| jN                  j                  d%      }t        j                  j                  |&      j                         }|rt        |
      }	 t&        j                  j                  |      }d}|j.                  dk(  rd}nd}d }d }	|dk(  r|j                  }d }	n|dk(  r|j                  }	d }d }|dk(  rh|j                  r\	 t         j                  j                  |j                  '      j                         }|r|jP                  }nt               }d }d}d }d }	d }t         j                  j                  dd()      jS                  d*      }tU        d+|||r|j0                  nd|||||	|d,	      }t        d|d-      S t        dd.d      S # t         j$                  $ r d |_        Y ?w xY w# t&        j$                  $ r d }Y Yw xY w#  Y xY w)/Nr   r   rA  r   r  r=  rH  i  r~   r  rF  r  rB  r  rC  rD  r  r  rE  rG  rH  rF  r;  rI  Bill Createdz#Bill Created for your custom order Fcustom_bill_createdzOpt-in status for user z: Tr   r   r  r  rh  r  r  )rJ  r:  r  rJ  zorder_status_update_form.html)	r  r  r  ry  custom_trackingexisting_delivery_typerD  rG  selected_slot_idr  rG  )+r   r   r   rb   r  r  rw  r   rF   r  r  r  rR  r   r&  r'  re   rJ  r_  r^   rJ  r  rB  r  r  r   r   r   r   r   r   r   r   r  r   r   r  r  r   rh  r*  rC  ry   )r   r   r  rK  r  r  rB  r  rD  rG  time_slot_idrM  rN  rO  r   r   r  r  r	  r
  r  available_slots	form_datas                          r   custom_order_editr    sc    ~~,,"":.--w-?EEG6>O PY\]] w||mD}}6T[[ IJJ		 <<##J/((9((9  H$!,,**=9K ML'6M$ HJUz+/F[_M,/3M,o-#LL,,_=M"<<++K8LK'6M$&HLYz-/H_cM,<'//33|3DD7;M4 480 K ML/3M,/3M, !4 ; ; I IS` I ag (%2"%-" &4" ;G9E00::M5R]_l_v_vw%}'>'>'D'D&EuM(	.}/F/F/K/K.LB}OfOfOmOmNnop""))T1!--M4K4K4X4XY`anaxax  bD  bD  EN  4O  Z[  ]%**$--
  	 
5	 ;;??:.--8-<BBD"M:D'"5"="="A"A="A"Y
 &(",,	9)1&)8& K M%1+>> $'?: - @ @"  $%8]=]=]'//66#0#C#C 7 eg  +/77(
 #$D"O%'"K M# '..554PX5Ybbcop$+"$>K : :QS"1#2*@*!.$4

	 i@AA66NOPP] $00 <7;M4<f '33 '"&':s1   :1T* * U AU' *UUU$#U$'U+c                     t        | d      S )Nzsystem_settings.htmlr  r  s    r   system_settingsr  s  s     '122r   c                   K   | j                   dk(  rm	 | j                          d {   }| j                  j                  d      }| j                  j                  d      }t        j                  t        j                         |j                         t        j                        j                         }t        j                  ||      rt        j                  |      }|d   j                  dd      }|rjt        j                   j#                  |      j%                         }d|_        |j)                          t*        j                   j-                  ||d	   d
       t/        ddid      S t/        dddd      S t/        dddd      S 7 i# t0        $ r$}t/        ddt3        |      dd      cY d }~S d }~ww xY ww)Nr   zutf-8zX-Razorpay-Signaturenotesr   r   rA  r  r  paid)r   razorpay_order_idpayment_statusr   r     r~   r   zPayment verification failedrH  r  zSomething went wrong!)r   r   r   r  zMethod not allowedrF  i  )r   jsonbodyr  r  r   hmacnewRAZORPAY_WEBHOOK_SECRETr~  hashlibsha256	hexdigestcompare_digestloadsrb   r  r  rw  r  r  rh   r  r   r   r  )	r   r`  r  received_signaturegenerated_signature
event_datar   r  r   s	            r   custom_order_paymentr%  y  s    ~~"	 'D<<&&w/D!(!4!45K!L #'(('..0# ik	   ""#68JK!ZZ-
w-++Ir:$*NN$9$97$9$K$Q$Q$SM1<M.!&&(OO**+*.z*:'- +  $Xy$9#FF# -JKTW  v9MNWZ[[I (<  	(?#a&! 	sQ   GF FEF /G0F ?GF 	G F;5G 6G;G  Gc                    | j                   j                  d      }|dk(  rnt        j                  j	                         D cg c]  }|j
                  |j                  d }}	 |rt        t        |      |dd      S t        g |dd      S |dk(  rnt        j                  j	                         D cg c]  }|j
                  |j                  d }}	 |rt        t        |      |dd      S t        g |dd      S |dk(  rnt        j                  j	                         D cg c]  }|j
                  |j                  d }}	 |rt        t        |      |dd      S t        g |dd      S y c c}w # t        $ r t        g |dd      cY S w xY wc c}w # t        $ r t        g |dd      cY S w xY wc c}w # t        $ r t        g |dd      cY S w xY w)	Nr   rf   )r*  r   )tablestypeFr  rZ  r  )rh  r   rf   r  r  r*  DiscountNamer   r?  StopIterationrd   
CouponNamerQ   r1  )r   r   rJ  discount_choicecoupon_choiceproduct_choices         r   choice_listr/    s   [[__X&FIQIYIYI]I]I_`I_A!$$?I_`	L#tO/Df$U).0 0 $r6$BOO
 EL__EXEXEZ[EZall;EZ[	L#tM/BF$S).0 0 $r6$BOO
 EMEUEUEYEYE[\E[q{{;E[\	L#tN/CV$T).0 0 $r6$BOO / a  	L2v >UKK	L \  	L2v >UKK	L
 ]  	L2v >UKK	LsZ    E6$E; ?E; 4 FF 2F ' F>
G %G ;FFF;:F;GGc                    t        j                         }t        j                  j	                  g d      }g d}|D ]  }	 |j
                  r|j
                  rst        j                  |j                  |j
                        }|j                         t        j                         j                         z
  }|j                         }|dz  }nd}|j                  dk(  s|j                  dk(  r|dk  rM|j                  d	k7  r>|j                  |vr0d
|_        t        j                         |_        |j                          |dk  r>|j                  |vr0d|_        t        j                         |_        |j                          |dk  rC|dkD  r>|j                  |vr0d|_        t        j                         |_        |j                          |dkD  r0d|_        t        j                         |_        |j                          |j                  d	k(  r|dk  r>|j                  |vr0d|_        t        j                         |_        |j                          |dk  rC|dkD  r>|j                  |vr0d|_        t        j                         |_        |j                          |dkD  r0d|_        t        j                         |_        |j                          |j                  dk(  r0d|_        t        j                         |_        |j                           t!        ddi      S #  |j                  dk(  r0d|_        t        j                         |_        |j                          Y %xY w)N)r  r!  r"  r  r  )r  r  r>  r  r  r  r  r   r  r!  r   r"  Yellowr  r   r  r  r  r  StatusT)r   r  rb   r  r  r'  r   r%  r&  r(  r`  r)  r  r+  r,  r  r   )	r   r  r  status_excludedrJ  r1  r2  r3  r4  s	            r   my_polling_taskr4    s   JJLE^^""4e"fFmOB	$$)=)=$,$4$4Q5I5I1K_K_$`!):)E)E)G(,,.JcJcJe)e&%;%I%I%K".5	 	~~,(0Jq=~~7ANNRa<a)17?||~4>~~_<).7?||~4q=Y]~~_<)17?||~4q=%,AN3;<<>A0FFH ~~/>~~_<).7?||~4q=Y]~~_<)17?||~4q=%,AN3;<<>A0FFH ~~)!+/7||~,{ J 4())	~~)!+/7||~,s   KLAM"c                    t         j                  j                  dd      j                  d      j	                  d      }t        |d      }| j                  j                  d      }|j                  |      }|dd}t        | d	|      S )
Nr   r   message__adsrc  rL  re  r:  )msg_datarV  zcommunication_list.html)
ri   r  r  r<  rC  r   rh  r   ri  r   )r   r   rm  re  msg_list_datarK  s         r   list_communicationr9    s|    



.
.vy
A
R
RSa
b
k
kC#q!I;;??6"D&&t,M(hGG'4g>>r   c                     | sy| j                  dd      j                  dd      }t        j                  d|      syh d}||v ry|S )z
    Validate Indian mobile numbers:
    - Must start with 6, 7, 8, or 9
    - Must be 10 digits
    - Reject spam patterns: 0000000000, 1111111111, 1234567890
    Fr   r   z+91z
[6-9]\d{9}>   
0000000000
1111111111
1234567890
2222222222
3333333333
4444444444
5555555555
6666666666
7777777777
8888888888
9876543210
9999999999)replacere	fullmatch)r   cleanedspam_numberss      r   is_valid_indian_mobilerL  '  sU      nnS"%--eR8G <<w/L ,Nr   c           
         | j                   dk(  rt        | j                        }| j                  j                  d      xs d}|j	                         r5|j                         }t        j                  j                  d      }|j                  dk(  ri }|D ],  }|j                  }|s	 t        |       |j                  ||<   . |j                         D ]  \  }}	 t        j                  j                  |      }d|j                   d	|j                    }	t#        j$                  ||	t&        j(                  |gd
dd       t*        j                  j-                  ||        n|j                  dk(  rt7               }|D ]7  }t9        |j:                        }|s|j=                  |j                  |f       9 |D ]  \  }}	 t        j                  j                  |      }d|j                   d|j                    }t?        j$                  ||j:                  gd       t*        j                  j-                  ||        | j@                  j                  d      dk(  rtC        dtE        d      d      S tG        d      S | j@                  j                  d      dk(  r(tC        d
|jH                  jK                         dd      S tM        | dd|i      S t               }tM        | dd|i      S # t        $ r Y lw xY w# t.        $ r/}
t1        j2                  d| dt5        |
              Y d }
~
dd }
~
ww xY w# t.        $ r/}
t1        j2                  d| dt5        |
              Y d }
~
d }
~
ww xY w)Nr   r   zNotification from Navya Bakersr  r   Emailr  zDear z,

F)r   r   
from_emailrecipient_listr   r   )r  r   )r   r   zEmail Broadcast Error: z | Smsz,
r   zSMS Broadcast Error: zX-Requested-Withr  Tcommunication_list)r  redirect_urlr.  r  r~   zsend_message.htmlr  )'r   rG   r   r   r  r  r  r  r  message_typer   r   r   r   r>  r  r   r   r   r   rq   ri   r  r   r   r   r  r  rL  r  rK  r   r  r   rt   r   r  get_json_datar   )r   r  r   msg_form	customersvalid_emailscustomerr   r  r  r   valid_numbersrJ  r  sms_bodys                  r   send_messager\  P  sK   ~~7<<(,,""9-Q1Q==?yy{H ,,z,BI
 $$/! )H$NNE  !&u-
 +3--L' !*  '3&8&8&:NE7!#(==#4#4'#4#B!&x':':&;5AQAQ@RS%11'.'+*2*B*B/4g-2  #$	 &--44(H4U' ';8 &&%/ # )H4X5J5JKG" !%%x}}g&>? !* .;)G\
Y#(==#4#4'#4#B%*8+>+>*?s8CSCSBT#Ux9N9N.O[\^%--44(H4U .; ""#56:JJ##$+,@$A%  
 011 ""#56:JJ#AZAZA\$]fijj'#6GG =D'.??] + ! !8 % !(?wc#a&&RS !: % Y(=l^3sSTvh&WXXYsD   ,K9B	L		B M9	LL		M$L<<M	M<$M77M<c                     t        | |t        j                  |      }|j                  |       |j	                          y )N)r   r  rO  to)r   r   rq   attach_filer  )r   r  to_emailfilepathmails        r   send_email_attachmentrc    s0    dx?W?W\deDXIIKr   r   c                 
   	 | j                   j                  dd       }| j                   j                  dd       }| j                   j                  dd       }| j                   j                  dd       }| j                   j                  dd       }d|v r|j                  d       d|v r|j                  d       d|v r|j                  d       d|v r|j                  d       |dk(  rot        j                  j                  dd      }|D ]  }t        |d         |v rd	|d
<   d|d
<    t        j                  j                  |      j                  dd      }|D ]  }	t        |	d         |v rd	|	d
<   d|	d
<    t        j                  j                  |      j                  dd      }
|
D ]  }t        |d         |v rd	|d
<   d|d
<    t        j                  j                  |      j                  dd      }|D ]  }t        |d         |v rd	|d
<   d|d
<    t        t        |      t        |      t        |
      t        |      |dd      S |dk(  rot        j                  j                  dd      }|D ]  }t        |d         |v rd	|d
<   d|d
<    t        j                  j                  |      j                  dd      }|D ]  }	t        |	d         |v rd	|	d
<   d|	d
<    t        j                  j                  |      j                  dd      }
|
D ]  }t        |d         |v rd	|d
<   d|d
<    t        j                  j                  |      j                  dd      }|D ]  }t        |d         |v rd	|d
<   d|d
<    t        t        |      t        |      t        |
      t        |      |dd      S |dk(  rot        j                  j                  dd      }|D ]  }t        |d         |v rd	|d
<   d|d
<    t        j                  j                  |      j                  dd      }|D ]  }	t        |	d         |v rd	|	d
<   d|	d
<    t        j                  j                  |      j                  dd      }
|
D ]  }t        |d         |v rd	|d
<   d|d
<    t        j                  j                  |      j                  dd      }|D ]  }t        |d         |v rd	|d
<   d|d
<    t        t        |      t        |      t        |
      t        |      |dd      S y # t        $ r#}t        dt        |      dd      cY d }~S d }~ww xY w)Nr  r  r  rr  triggerr   r   r  r  checkedr  )category_id__inr  )item_category__inr*  r1  )product__item_category__inr@  )
categoriesr?  r  rr  re  Fr  )item_sub_category__in)product__item_sub_category__in)product_id__in)r   r   )r`  r   rd  rO   r  r@  r  rP   r  rQ   rX   r   r?  r   )r   category_idssub_category_idsproduct_idssku_idsre  rj  rJ  r  r  r  krr  r  r   s                  r   coupon_subcategory_listrs    s   zL||''
D9"<<++NDAll&&y$7,,""5$/,,""9d3#!!##B'r"=NN2j (0077PJqy>\1#)AiL#*AiL	  
 /66==l=[bbcicvxM #qy>%55#)AiL#*AiL	 #
  ''...NUUVZ\ghHqw<;.#)AiL#*AiL	  ++$$$MTTUY[efCqw<7*#)AiL#*AiL	   #J/4CVdhiqdrS	g7=BD D &(0077PJqy>\1#)AiL#*AiL	  
 /66==l=[bbcicvxM #qy>%55#)AiL#*AiL	 #
  ''..EU.V]]^bdopHqw<;.#)AiL#*AiL	  ++$$DT$U\\]acmnCqw<7*#)AiL#*AiL	   #J/4CVdhiqdrS	g7=BD D 	!(0077PJqy>\1#)AiL#*AiL	  
 /66==l=[bbcicvxM #qy>%55#)AiL#*AiL	 #
  ''..EU.V]]^bdopHqw<;.#)AiL#*AiL	  ++$$K$@GGjYCqw<7*#)AiL#*AiL	   #J/4CVdhiqdrS	g7=BD D= "F  Lus1v>UKKLs,   IU E4U E4U 	U.U)#U.)U.c                 B   | j                   dk(  r	 t        j                  j                  |      j	                         }t
        j                  j                  |      }|j                  dk(  rg|dk(  rd|_        d|_        |j                          n2|dk(  rd|_        d|_        |j                          nt        dd	d
      S |j                          nH|j                  dk(  rt        ddd
      S |j                  dk(  rt        ddd
      S t        dd	d
      S d}d| d}t        |j                  j                  ||||j                         t        |||j                  j                  gd       d}|j                  j                  dk(  rCt!        j"                  |j                  j$                  ||j                  j&                  |gd       t        dd| d
      S t        ddd
      S # t(        $ r"}t        ddt+        |      d      cY d }~S d }~ww xY w)Nr   rA  r  r  r  Paidr  r   zStatus change not allowedr   z Status already updated to Failedr  z#Status already updated to DeliveredzOrder DeliveredzYour Order z Delivered!Fr   Tr   r   r   z Status of your order changes to zsomething went wrong)r   r   r   zmethod not allowed)r   rb   r  r  rw  rh   r  r  r  r   r   r   r   r   r   r  r   r   r  r  r   r  )	r   r   r   r   paymentr   r   r  r   s	            r    order_status_update_to_deliveredrw  S  s   ~~%	_NN))7);AACEoo,,5,9G!!%88[()4E&-3G*LLN x')1E&-5G*LLN'1=X(YZZ

##x/#q8Z$[\\##{2#yAf$ghh#q9T$UVV &E'y<KU__66ukSXSbSbce[5??+@+@*A5I*I%%-%118T8TU\]b]l]l]w]w  yB  8C  NO  Q17WX^W_5` abb q1EFGG  	_15KVYZ[V\ ]^^	_s7   B2G3 -G3 3G3 G3 CG3 3	H<HHHc                 l   t         j                  j                  d      }t        |d      }| j                  j                  d      }	 |j                  |      }|dd}t        | d|      S # t        t        f$ r |j                  d      }Y 4t        $ r |j                  |j                        }Y Yw xY w)aq  
    Liked List menu on Product section in the side bar will list the You may also like list.
    It is only available for NBC admin.
    from Liked list we can add a product and we can map product related to that product.
    if one person orders a jam, liked products will contain bread it will be defined in
    the liked list

    :param request:
    :return:

    rc  rL  re  r   r:  )	like_listr  zpeople_also_like_list.html)r\   r  rC  r   rh  r   ri  r!   rj  r    rk  r   )r   
liked_datarm  re  r`  rK  s         r   you_may_also_like_listr{    s      ''00?J*a(I;;??6"D7!!$'
 !X>G'7AA i( %!!!$ 7!!)"5"567ro  c                 |    t         j                  j                  |      }|r|j                          t	        d      S )a8  
    Liked List menu on Product section in the side bar will list the You may also like list.
    Deleting a Liked Data. for each liked data listed on
    liked list, we have a delete button. clicking on
    the delete button will open a confirm dialog box. if you confirm
    it will delete the liked data.
    r  you-may-also-like)r\   r  r  r  r   )r   r*  you_may_also_like_datas      r   you_may_also_like_deleter    s9     ,33::b:A%%''((r   c                    g }t        t        |      }| j                  j                         }d|j	                  dg       v r7|j	                  dg       }|r|j                  d       |j                  d|       | j                  dk(  rTt        ||      }|j                         r|j                          t        d      S |j                  |j                         nt        |      }|dd}t        | d	|      S )
a	  
    Liked List menu on Product section in the side bar will list the You may also like list.
    Editing a Liked data. for each liked data listed, we have a edit button. clicking on
    the edit button will open a form. fields are product and liked products.

    r  r   liked_productsr   r  r}  r:  )	like_formr  zpeople_also_like_edit.html)r   r\   r   r  r0  rd  rj  r   rH   r  r  r   ry  r  r   )r   r*  r  r~  request_postliked_product_listr  rK  s           r   you_may_also_like_editr    s     F.~"E<<$$&L 
\!!"2B77*223CRH%%b)-/AB~~!,9OP==?IIK/00 MM$++&!+AB X>G'7AAr   c                    g }| j                   j                         }d|j                  dg       v r7|j                  dg       }|r|j                  d       |j	                  d|       | j
                  dk(  rdt        |      }|j                         r|j                          t        d      S |j                  |j                         ||dd}t        | d|      S t               }||dd}t        | d|      S )a  
    Adding a liked product.
    Liked List menu on Product section in the side bar will list the You may also like list.
    clicking on add Liked list will open the form. fields are product and liked products.
    on submission create a liked product data.
    r   r  r   r}  r:  )r  r  r  zpeople_also_like_add.html)r   r  r0  rd  rj  r   rH   r  r  r   ry  r  r   )r   r  r  r  r  rK  s         r   you_may_also_like_addr    s     F<<$$&L 
\!!"2B77*223CRH%%b)-/AB~~!,/==?IIK/00MM$++& !#+G
 '#>HH"$ #G '6@@r   c                 J   t         j                  j                         }|st         j                  j                         }t        j                  j                         j                  d      }| j                  dk(  r d| j                  v rBt        | j                  |      }|j                         r|j                          t        d      S d| j                  v r@t        | j                        }|j                         r|j                          t        d      S d| j                  v rj| j                  j                  d      }t        j                  j                  |	      j!                          t        d      S t        |      }t               }|d
}t#        | d|      S )a  
    delivery settings.
    delivery settings menu on Settings section in the side bar will list Delivery setting.
    delivery fee configuration, current delivery fee discount, add delivery discount option are
    listed on the delivery settings.
    :param request:
    :return:
    min_order_valuer   save_settingsr  r  add_discountdelete_discountr  r;  )settings_formr  delivery_discountsr  )rl   r  rw  r  rk   r  rC  r   r   rI   r  r  r   rJ   r   r  r  r   )r   r   	discountsr  r  r  rK  s          r   delivery_settings_viewr    sc     ''--/H#++224 ((,,.778IJI~~ gll*0QM%%'""$ 344 W\\)0>M%%'""$ 344 ,!,,**=9K$$++{+;BBD/00 -h?,. '&'G '3W==r   c                 Z   t         j                  j                         }|st         j                  j                         }| j                  dk(  rBt        | j                  |      }|j                         r'|j                          t        d      S t        |      }d|i}t        | d|      S )a  
    custom coupon settings.
    Custom Coupon settings menu on Promotions section in the side bar will list Custom coupon list.
    if a customer buys a product between a price range and there is a
    coupon for that price range. A coupon code will send through the email, whatsapp or sms.
    settings view for entering the price range is here

    :param request:
    :return:
    r   r  zcoupon-settingsrh  zcustom_coupon_setting.html)rm   r  rw  r  r   rK   r   r  r  r   r   )r   coupon_settingsr  rK  s       r   coupon_settings_viewr  /  s     +2288:O.66==? ~~'Q==?IIK-..'A 	tG '7AAr   c                 z    t         j                  j                         j                  d      }t	        | dd|i      S )Nz-updated_atzpayment_modes_list.htmlmodes)ro   r  r  rC  r   )r   r  s     r   payment_mode_listr  R  s6      $$&//>E'4w6FGGr   c                 r   | j                   dk(  r| j                  j                  d      }| j                  j                  d      dk(  }|s!t        j                  | d       t        d      S t        j                  j                  ||       t        j                  | d       t        d      S t        d      S )	Nr   	mode_namer   r  zMode name is requiredr  )r  r   zPayment Mode added successfully)
r   r   r   r   r   r   ro   r  r  r  )r   r  r   s      r   add_payment_moder  V  s    ~~LL$$[1	!!(+v5NN7$;</00## 	$ 	
 	"CD+,,'((r   c                     t        t        |      }|j                   |_        t        j                         |_        |j                          t        j                  | d       t        d      S )Nr;  zStatus updatedr  )
r   ro   r   r   r`  
updated_atr  r   r  r   )r   mode_idmodes      r   toggle_payment_statusr  j  sN    \g6Dkk/DKllnDOIIKW./'((r   )   r   )F)Nr  (U  django.shortcutsr   r   django.contrib.authr   r   r   r   django.contrib.auth.decoratorsr   r	   rest_framework.decoratorsr
   django.views.decorators.httpr   django.forms.modelsr   django.db.modelsr   r   r   django.core.validatorsr   django.core.exceptionsr   r   razorpayr  r  r  twiliodjango.views.decorators.csrfr   r   r   r   signals.custom_signalsr   requestsr/  	itertoolsr   r   django.confr   django.httpr   r   django.contribr   django.utilsdjango.core.paginatorr   r    r!   django.appsr"   
cms.modelsr#   r$   r%   r&   r'   r(   r)   formsr*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   shops.modelsrL   rM   rN   products.modelsrO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   accounts.modelsorders.modelsr^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   django.core.mailrp   NavyaBackers.settingsrq   r   r   rr   accounts.viewsrs   django.urlsrt   django.contrib.auth.modelsru   rv   rw   rx   django.template.loaderry   dalrz   rest_framework.permissionsr{   r}  rest_framework.viewsr|   rest_framework.responser}   rest_frameworkr   r   django.utils.dateparser   r   osceleryr   adminportal.tasksr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  rL  rT  rZ  ra  rn  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r5  rO  rU  rZ  ra  rf  rh  rk  rr  rv  rz  r  r  r  r  r  r  r  r  r   r"  r%  r@  rC  rJ  rO  rR  rU  rW  r[  r^  ra  rc  rg  rj  rm  rp  rr  r  r  r  r  r  r  r  Select2QuerySetViewr  r  r	  r  r;  r?  rP  rS  rX  r]  rt  rv  r{  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r%  r/  r4  r9  rH  rL  r\  rc  rs  rw  r{  r  r  r  r  r  r  r  r  r   r   r   <module>r     s|   - I I K . 5 5 4 4 1 2       4 - - :   .   2 # ! H H  g g g{ { { { { { { { {
 ; :    q q q q q & 1   -   , 1 1 3   6 
   &  ( , !  - ) 	  ,X X X X X A,F0&%6 66k\M`Sr /"XYZ2 [ 2, /=+">?@6 A 6.#P /=+">?@V5 A V5t /=+">?@! A  !8 /=+">?@% A  %.J& /=+">?@-6 A -6l /=+">?@2 A 2 /=+">?@7 A 7$ /=+">?@65 A 65t /=+">?@ A   /=+">?@*5 A *5\ + +
 /=+">?@7 A 7@ /=+">?@: A :$ /=+">?@&9 A &9T /=+">?@'9 A '9V /=+">?@>9 A >9D /=+">?@> A >> /=+">?@J8 A J8\ /=+">?@UR A URp /=+">?@A A A, /=+">?@'K A 'KT /=+">?@N A N:6Rt /=+">?@'R A 'RT%iR /=+">?@T< A T<n B B, B B,+\ /=+">?@/+ A /+d %
ZPDW~, /=+">?@9 A 9 /=+">?@@9 A @9H /"LMN~> O ~>N
 /"LMNA? O A?H /=+">?@@ A @F%?P /<.12T 3 Tn /=+">?@H AHV4h /=+">?@. A .& /=+">?@5 A5* /=+">?@
  A  
  /=+">?@5 A 5< /=+">?@4 A 4D /=+">?@@ A@& /=+">?@# A  #  /=+">?@@ A @4 /=+">?@"? A "?J /=+">?@9 A9* /=+">?@$ A  $  /=+">?@!> A !>H /=+">?@#= A #=TDC DCR g  F /<"<=>> ?>D /<.12) 3  ) /<.12> 3 >4 /<.12(= 3 (=x /<"<=>o; ? o;n /:,/0A 1 A0
,:: 
"*&RU2piqX C C2 AH AHF!qH /=+">?@8 A 8, /=+">?@$ A $6 /=+">?@j8 A j8Z /=+">?@i7 A i7X /"JKL? M?* /=+">?@* A  *" /=+">?@? A ?< /=+">?@!> A !>F /=+">?@: A :& /=+">?@& A &. /=+">?@Y: A Y:x /=+">?@T9 A T9n /=+">?@. A .& /=+">?@4 A 4. /=+">?@ A   /=+">?@F4 A F4R /=+">?@H3 A H3\ /=+">?@6? A 6?t /=+">?@@ A @8 /=+">?@M A MF /=+">?@4@ A 4@n I I:  I  IF A A6 /=+">?@&@ A &@R /=+">?@, A  ," /=+">?@A A A2 /=+">?@7 A 7" /=+">?@; A ;, /=+">?@H A H0 /=+">?@ A " /=+">?@D A DN /=+">?@ A , /=+">?@ A . /=+">?@5 A 5 /<"<=>r> ? r>jC" /<.12]Q 3 ]Q@ /=+">?@3 A 3 '\ '\T&LRK*\? 
$Ri@r 
6({L {L| 
6()H )H\ /=+">?@B AB2 /=+">?@) A  ) /=+">?@B A B> /=+">?@'A A 'AV0>hB@ $H)()r   