a
    exd+0                    @   s  d dl mZ d dlT 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 d	d
lm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 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! d dl"T d dl#m#Z# d dl$m%Z% d dl&m'Z' d dl(T d dl)m*Z+ d dl,T d dl-m.Z. d dl/Z/d dl0T d dl1m2Z2 d dl3T d dl#m4Z4 d dlm5Z5 d dl6m7Z7 d	dl8T d dl9m:Z: d dlmZ d dlm5Z5 d dl;m<Z< d dl=Z=d dlmZ d dl>Z>d dlmZ d dlm5Z5 d dl?m@Z@ d dlAZAd dlAmBZB d dlCZCd dlDmEZE d dl;m<Z< d d lFmGZG d d!lFmHZH d dl9Z9d dlIZId d"lJmKZK d dlLZLd dlMZMd dlJZNd d#lOmPZP d d$lQmRZR d%ZSd&d' ZTd(d) ZUd*d+ ZVd,d- ZWG d.d/ d/eZXG d0d1 d1eZYG d2d3 d3eZZG d4d5 d5eZ[G d6d7 d7eZ\d8d9 Z]G d:d; d;eZ^G d<d= d=eZ_G d>d? d?eZ`G d@dA dAeZaG dBdC dCeZbG dDdE dEeZcG dFdG dGeZdG dHdI dIeZeG dJdK dKeZfG dLdM dMeZgG dNdO dOeZhG dPdQ dQeZiG dRdS dSeZjG dTdU dUeZkG dVdW dWeZlG dXdY dYeZmG dZd[ d[eZnG d\d] d]eZoG d^d_ d_eZpG d`da daeZqG dbdc dceZrG ddde deeZsG dfdg dgeZtG dhdi dieZuG djdk dkeZvG dldm dmeZwG dndo doeZxG dpdq dqeZyG drds dseZzG dtdu dueZ{G dvdw dweZ|G dxdy dyeZ}G dzd{ d{eZ~G d|d} d}eZG d~d deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZd dlmZ G dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZdS )    )View)*)authenticateloginlogout)renderredirect)User)get_user_model)JsonResponse)HttpResponse   )formsN)render_to_string)mail)messages)settings)login_required)method_decorator)datetime)	Paginator)Q)django_pbkdf2_sha256)PermissionDenied)uploadTheCategory)date)get_template)client)BytesIO)pisa)Context)QRCode)EmailMultiAlternatives)default_storage)FileSystemStorage)urlopen)Image)FCMNotificationZ 27d7d01f7fb16de8e22b0b2de5a4a236c                 C   s(   t  }t|j dt| d  }|S )N0d   )r   todaystryear)user_idZtodays_dateuid r/   +/var/www/html/Beni/beni/store_apis/views.pyset_invoice_numberH   s    r1   c                 C   sD   | j d}tjj|dd }|dkr0tdS d}t|ddS d S )	Nemailr   )r2   is_superuserr   truez(This email already exist in our databaseFsafe)GETgetr	   objectsfiltercountr   r   )requesttextpostmessager/   r/   r0   checkEmailStoreM   s    r@   c                    s    fdd} j |_ |S )Nc                    s   d}t d d| jv rl| jd }| jd |krtjj|d }|rX| jdkrjtdS q| jdkrt|S nt d | jdkrt|S  | g|R i |S )N/store-loginz=1=r-   r-   /store-dashboardz=3=z/store-login/)printsessionStoresr9   r:   firstpathr   )r<   argskwargsZ	loginlinkZuserId	store_objfunctionr/   r0   wrapW   s    






zcheckIfLoginStore.<locals>.wrap)__doc__)rM   rN   r/   rL   r0   checkIfLoginStoreV   s    rP   c                    s    fdd}|S )Nc                    s.   | j d r  | g|R i |S t| dS d S )Nr-   z/store_login)rE   r   )r<   rI   rJ   	view_funcr/   r0   rN   {   s    
zstore_only.<locals>.wrapr/   )rR   rN   r/   rQ   r0   
store_onlyz   s    rS   c                   @   s   e Zd Zdd Zdd ZdS )storeLoginInc                 C   s
   t |dS )Nstore_login.htmlr   selfr<   r/   r/   r0   r8      s    zstoreLoginIn.getc                 C   s   t |j}| r|jd}tjj|jd|jddd	 }|j
dkrdt|d tdS |r|j}t||}|r|j|jd	< t|d
 tdS t|d tdS qt|d tdS n
t|dS d S )Npasswordisd_codephone_numberr   rZ   r[   	is_sellerr   z;Your store has been disabled by admin.Please contact admin.rA   r-   zLogin SuccessfullyrC   zInvalid CredentialszUser not existrU   )r   Zstore_loginPOSTis_validcleaned_datar8   r	   r9   r:   rG   statusr   errorr   rY   handlerverifyidrE   successr   )rX   r<   formrY   userObjnew_passcheckr/   r/   r0   r>      s&    &


zstoreLoginIn.postN__name__
__module____qualname__r8   r>   r/   r/   r/   r0   rT      s   rT   c                   @   s    e Zd Zeedddd ZdS )storeDashboarddispatchnamec                 C   s  t jj|jd dd }tjj|jd }tjj|jd d }tjjd|d }t	jj|jd }d}d}t
jjdd	}	|	D ](}
|
jjj|kr|d7 }|t|
j7 }qdd
lm} dd l}ddlm} ddlm} |j j}g d}g }g }|D ]V}t
jjd||d }|
jjj|kr2|| t	jj|j||d }|| q|jdkr|t|d tdd|iS t|d|||||||dS d S )Nr-   r   re   r]   rB   Tend_date__isnullstore_idstorer   isPaid)
TruncMonth)Sum)Decimal)010203040506070809101112)rz   created_at__yearcreated_at__month)rx   start_date__yearstart_date__monthFz"Please complete the profile first.z/store-profile
store_infozstore_dashboard.html)r   total_productstotal_service_requestorder_counttotal_earningordersservices)r	   r9   r:   rE   rG   rF   re   Productsr;   ServiceRequests	orderPackproductDetailproductrx   floattotalAmountdjango.db.models.functionsr{   r   django.db.modelsr|   decimalr}   nowr,   appendis_profile_completedr   rb   r   r   )rX   r<   r-   rK   r   r   r   r   r   	order_objorderr{   r   r|   r}   current_year
month_list
order_datar   mnth
all_ordersZall_servicer/   r/   r0   r8      s<    
zstoreDashboard.getNrl   rm   rn   r   rP   r8   r/   r/   r/   r0   ro      s   
ro   c                   @   s(   e Zd Zeedddd Zdd ZdS )storeProfilerp   rq   c                 C   sX   t jj|jd dd }tjj|jd }tjj|jd d }t|d||dS )Nr-   r   rs   rB   store_profile.html)rK   r   )r	   r9   r:   rE   rG   rF   re   r   )rX   r<   r-   rK   r   r/   r/   r0   r8      s    zstoreProfile.getc                 C   sV  t |j}| rHtjj|jd dd }t	jj|j
dj|jd|jd|jd|jd|jd	|jd
|jd|jdt dd
 |jdrt|jd}ttjd | }t	jj|j
djt|d |jdr4t|jd}ttjd | }t	jj|j
djt|d t|d tdS t|dS d S )Nr-   r   rs   rB   store_name_englishstore_description_englishstore_name_arabicstore_description_arabicstore_numberstore_emailcountryaddressT)
r   r   r   r   r   r   r   r   
start_dater   
store_logo/)r   store_banner)r   zStore updated successfullyrC   r   )r   Zstore_profiler^   r_   r	   r9   r:   rE   rG   rF   re   updater`   r8   r   r   FILESZuploadTheStoreLogor+   r   BASE_URLr   rf   r   r   )rX   r<   rg   r-   fileUrlr/   r/   r0   r>      s4    








zstoreProfile.postNrl   rm   rn   r   rP   r8   r>   r/   r/   r/   r0   r      s   

r   c                   @   s   e Zd Zdd ZdS )storeLogoutc                 C   s   |j d= t|d tdS )Nr-   zLogout SuccessfullyrA   )rE   r   rf   r   rW   r/   r/   r0   r8      s    zstoreLogout.getNrl   rm   rn   r8   r/   r/   r/   r0   r      s   r   c                   @   s(   e Zd Zeedddd Zdd ZdS )storeResetPasswordrp   rq   c                 C   s(   t jj|jd d }t|dd|iS )Nr-   rB   store_reset_password.htmlr   rF   r9   r:   rE   rG   r   rX   r<   r   r/   r/   r0   r8      s    zstoreResetPassword.getc                 C   sh   t |j}| rZ|jd}tjj|jd d}|| |	  t
|d tdS t|dS d S )NconfirmPasswordr-   re   z)You have successfully reset your passwordrC   r   )r   change_password_formr^   r_   r8   r	   r9   rE   set_passwordsaver   infor   r   )rX   r<   rg   rY   userr/   r/   r0   r>     s    
zstoreResetPassword.postNr   r/   r/   r/   r0   r      s   

r   c                 C   sJ   | j d}tjj| jd d}||dkr>d}t|ddS tdS d S )Nold_passwordr-   r   Fz%Does not match with the old password.r5   r4   )r7   r8   r	   r9   rE   check_passwordr   r   )r<   r   r   r?   r/   r/   r0   storeCheckPassword  s    r   c                   @   s   e Zd Zdd Zdd ZdS )storeForgetPasswordc                 C   s
   t |dS )Nstore_forget_password.htmlrV   rW   r/   r/   r0   r8     s    zstoreForgetPassword.getc                 C   s   t |j}| r|jd|jd< |jd|jd< tjj	|jd|jddd
 }|rtddd}||_|  t|d td	S t|d
 t|dS n
t|dS d S )NrZ   r[   Tr\     '     zOTP send successfully/forget-otp-verifyNo user foundr   )r   Zstoreforgetpasswordformr^   r_   r`   r8   rE   r	   r9   r:   rG   random	randrangeforgot_password_otpr   r   rf   r   rb   r   )rX   r<   rg   
user_checktheotpr/   r/   r0   r>     s    &	zstoreForgetPassword.postNrk   r/   r/   r/   r0   r     s   r   c                   @   s   e Zd Zdd ZdS )resendForgetOtpc                 C   sv   |j d }|j d }tjj||dd }|r^tddd}||_|  t	
|d td	S t	
|d
 td	S d S )NrZ   r[   Tr\   r   r   r   zOTP resend successfullyr   r   )rE   r	   r9   r:   rG   r   r   r   r   r   rf   r   )rX   r<   rZ   r[   r   r   r/   r/   r0   r8   8  s    

zresendForgetOtp.getNr   r/   r/   r/   r0   r   7  s   r   c                   @   s   e Zd Zdd Zdd ZdS )forgetOTPverifyc                 C   s
   t |dS )Nstore_forget_otp.htmlrV   )Selfr<   r/   r/   r0   r8   O  s    zforgetOTPverify.getc                 C   s   t |j}| r|jd }|jd }|jd}|jd}|jd}|jd}|| | | }	tjj	||d
 }
t|	t|
jkrt|d td	S t|d
 tdS n
t|dS d S )NrZ   r[   otp_oneotp_two	otp_threeotp_four)rZ   r[   zOTP verfied successfully/change-forget-passwordzIncorrect OTPr   r   )r   Zotpforgetformr^   r_   rE   r`   r8   r	   r9   r:   rG   intr   r   rf   r   rb   r   )rX   r<   rg   rZ   r[   r   r   r   r   Z	final_otpuser_objr/   r/   r0   r>   Q  s     


zforgetOTPverify.postNrk   r/   r/   r/   r0   r   N  s   r   c                   @   s   e Zd Zdd Zdd ZdS )changeForgetPasswordc                 C   s
   t |dS )Nstore_change_forget.htmlrV   rW   r/   r/   r0   r8   f  s    zchangeForgetPassword.getc                 C   s   t |j}| r|jd }|jd }tjj||dd }|j	
d}|j	
d}||kr|r|| |  t|d tdS qt|d	 td
S n
t|dS d S )NrZ   r[   r   r\   rY   confirm_passwordzPassword changed successfullyrA   z*Password and confirm password are not samer   r   )r   Zchangeforgetpasswordformr^   r_   rE   r	   r9   r:   rG   r`   r8   r   r   r   rf   r   rb   r   )rX   r<   rg   rZ   r[   customerObjnew_passwordr   r/   r/   r0   r>   h  s     




zchangeForgetPassword.postNrk   r/   r/   r/   r0   r   e  s   r   c                   @   s    e Zd Zeedddd ZdS )productListingStorerp   rq   c           	   
   C   s   zt jj|jd d }tjjd|dd}|jd}|rbtjt	|dt	|dB d}t
|d	}|jd
}||}t|d|||dW S  ty } zt| tdW  Y d }~S d }~0 0 d S )Nr-   rB   Trt   -idsearchproduct_name_english__icontainsproduct_name_arabic__icontains
   pagezstore_product_listing.html)product_objsearch_postr   /product-listing-store)rF   r9   r:   rE   rG   r   order_byr7   r8   r   r   get_pager   	ExceptionrD   r   )	rX   r<   r   data_objr   	paginatorpage_numberservice_objer/   r/   r0   r8   ~  s    "

zproductListingStore.getNr   r/   r/   r/   r0   r   }  s   
r   c                   @   s(   e Zd Zeedddd Zdd ZdS )addProductStorerp   rq   c           
   
   C   s   zt jj|jd d }tjjddd}tjjddd}tjjddd}tjjddd}t	j
  }|jrv|j}nd}d|jv rtjj|jddd
 }t|d	||||||d
W S  ty }	 zt|	 tdW  Y d }	~	S d }	~	0 0 d S )Nr-   rB   r   Tra   ru           main_idmaincategory_idru   store_add_product.html)main_categoriessub_categoriesbrandsr   stones	vat_valuer   )rF   r9   r:   rE   rG   MainCategoriesSubcategoriesBrandsStonesCommissionSectionallvat_percentager7   r8   r   r   rD   r   )
rX   r<   r   r  r  r  r  vat_objr  r   r/   r/   r0   r8     s     
zaddProductStore.getc                 C   sr  t |j}| rd|jd}|jd}tjj|jdd	 }t
jj|jdd	 }|jd}|jd}tjj|jdd	 }	|jd	}
|jd
}|jd}|jd}|jd}|jd}|jd}|jd}|rtjj|d	 }nd }tj 	 }|jr0|j}nd}|rdd}tt|d t| }t|| }nd}d }tt|d t| }t|| }tjj|jd d	 }tjj|||||||	|
||||||j||||d}g }|jdrP|jd}td| |D ]:}|jdkrqt|}ttjd | }|| q||_ |!  t"#|d t$dS t%|dS d S )Nproduct_name_englishproduct_name_arabicmaincategoryr   subcategorydescription_englishdescription_arabicbrandsize
model_nameweightcolorquantitypriceprice_discountstoner   Tr)   Fr-   rB   )r  r  r  r  r  r  r  r  r  r  r  r  is_offer_appliedrv   r  offer_discountr  r  images  P r   Product added successfullyr   r  )&r   
addProductr^   r_   r`   r8   r	  r9   r:   rG   r
  r  r  r  r  r  roundr   rF   rE   r   createre   r   getlistrD   r  uploadTheProductImagesr+   r   r   r   r"  r   r   rf   r   r   )rX   r<   rg   r  r  r  r  r  r  r  r  r  r  r  r  r  r!  stone_idr  r  r  r   calculate_vatround_off_discountrv   r   	form_datar"  imager   r/   r/   r0   r>     sh    

zaddProductStore.postNr   r/   r/   r/   r0   r     s   

r   c                   @   s(   e Zd Zeedddd Zdd ZdS )editProductStorerp   rq   c                 C   s   t jj|jd d }tjjddd}tjjddd}tjjddd}tjjddd}d|j	v r~tjj|j	
ddd }tjj|d }t|j}	tj  }
|
jr|
j}nd	}t|d
|||||	|||dS )Nr-   rB   r   Tr   r   r  r   r   zstore_edit_product.html)r  r  r  rK   product_imagesr   r  r  )rF   r9   r:   rE   rG   r	  r
  r  r  r7   r8   r  r   astliteral_evalr"  r  r  r   )rX   r<   re   r   r  r  r  r  rK   r0  r  r  r/   r/   r0   r8     s    
zeditProductStore.getc           "      C   s  t |j}| r|jd}|jd}tjj|jdd	 }t
jj|jdd	 }|jd}|jd}	tjj|jdd	 }
|jd	}|jd
}|jd}|jd}|jd}|jd}|jd}|jd}|rtjj|d	 }nd }tj 	 }|jr0|j}nd}|rdd}tt|d t| }t|| }nd}d }tt|d t| }t|| }tjj|jd d	 }tjj|dj||||||	|
|||||||j||||d}tjj|d	 }t|j}g }|D ]}|| q|jdr|jd}td| |D ]:} | jdkrVqBt| }!t t!j"d |! }!||! qBtjj|dj|d t#$|d t%dS t&|dS d S )Nr  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r   Tr)   Fr-   rB   )r  r  r  r  r  r  r  r  r  r  r  r  r  rv   r  r   r!  r  r"  r#  r   r"  r$  r   r  )'r   r%  r^   r_   r`   r8   r	  r9   r:   rG   r
  r  r  r  r  r  r&  r   rF   rE   r   r   re   r1  r2  r"  r   r   r(  rD   r  r)  r+   r   r   r   rf   r   r   )"rX   r<   re   rg   r  r  r  r  r  r  r  r  r  r  r  r  r  r!  r*  r  r  r  r   r+  r,  rv   r   product_obj_imager0  r-  imgr"  r.  r   r/   r/   r0   r>     sn    

zeditProductStore.postNr   r/   r/   r/   r0   r/    s   

r/  c                   @   s    e Zd Zeedddd ZdS )removeImageProductrp   rq   c                 C   s   t |jd t |jd d|jv rtjj|jdd }t|j	}g }|jd
dd}t | |D ]"}t||krtt | || qtt | tjj|jddj|d tdS d S )N	file_name
product_idr   ' r3  rf   )rD   r7   r8   r   r9   r:   rG   r1  r2  r"  replacer+   r   r   r   )rX   r<   r4  r0  r-  yr5  r/   r/   r0   r8   C  s    
zremoveImageProduct.getNr   r/   r/   r/   r0   r6  B  s   
r6  c                   @   s   e Zd Zdd ZdS )changeProductStatusc                 C   sn   t jj|jd d}|jd |_|  |jdkrNt|d t|j	dS t
|d t|j	dS d S )Nr   r   ra   1zProduct is activatedHTTP_REFERERzProduct is deactivated)r   r9   r8   r^   ra   r   r   rf   r   METArb   )rX   r<   pubr/   r/   r0   r>   W  s    
zchangeProductStatus.postNrl   rm   rn   r>   r/   r/   r/   r0   r=  V  s   r=  c                   @   s    e Zd Zeedddd ZdS )deleteProductrp   rq   c                 C   s.   t jj|djt d t|d tdS )Nr   end_dateDeleted successfullyr   )	r   r9   r:   r   r   r   r   rf   r   rX   r<   re   r/   r/   r0   r8   e  s    zdeleteProduct.getNr   r/   r/   r/   r0   rC  d  s   
rC  c                   @   s    e Zd Zeedddd ZdS )viewProductrp   rq   c              
   C   s   zLt jj|jd d }tjj|d }t|j}t	|d|||dW S  t
y } zt| tdW  Y d }~S d }~0 0 d S )Nr-   rB   r   zstore_view_product.html)r   r0  r   r   )rF   r9   r:   rE   rG   r   r1  r2  r"  r   r   rD   r   )rX   r<   re   r   r   r0  r   r/   r/   r0   r8   m  s    zviewProduct.getNr   r/   r/   r/   r0   rH  l  s   
rH  c                   @   s(   e Zd Zeedddd Zdd ZdS )addStoreServicerp   rq   c                 C   sD   t jj|jd d }tjjddd}td| t|d||dS )Nr-   rB   Tr   r   add_store_service.html)servicer   )rF   r9   r:   rE   rG   ServicesrD   r   )rX   r<   r   r   r/   r/   r0   r8   y  s    
zaddStoreService.getc                 C   s   t jj|jd d }t|j}| rt	jj|j
dd }tjj|j|jd}|stjj|j|jd}t|d nt|d tdS t|d	d
|iS d S )Nr-   rB   
service_idr   )rv   serviceId_idService added successfullyThis service is already addedz/store-service-listingrJ  rg   )rF   r9   r:   rE   rG   r   ZstoreServiceFormr^   r_   rL  r`   r8   storeServicesre   r'  r   rf   warningr   r   )rX   r<   r   rg   rM  check_existingr   r/   r/   r0   r>     s    zaddStoreService.postNr   r/   r/   r/   r0   rI  x  s   

rI  c                   @   s    e Zd Zeedddd ZdS )storeServiceListingrp   rq   c                 C   s   t jj|jd d }tjjd|d}|jd}|rPtjjt|dd|d}t	|d}|jd}|
|}t|d	|||d
S )Nr-   rB   Trt   r   Z*serviceId__english_service_name__icontainsr   r   zstore_service_listing.htmlr   r   r   )rF   r9   r:   rE   rG   rQ  r7   r8   r   r   r   r   rX   r<   r   r   r   r   r   r   r/   r/   r0   r8     s    

zstoreServiceListing.getNr   r/   r/   r/   r0   rT    s   
rT  c                   @   s    e Zd Zeedddd ZdS )changeStoreServiceStatusrp   rq   c                 C   s   t jj|jd d }tjj||jd d }|jd |_|  |jdkrlt	
|d t|jdS t	|d	 t|jdS d S 
Nr-   rB   r   rx   re   ra   r>  zService status is activatedr?  zService status is deactivated)rF   r9   r:   rE   rG   rQ  r^   ra   r   r   rf   r   r@  r8   rb   rX   r<   r   rA  r/   r/   r0   r>     s    
zchangeStoreServiceStatus.postNrl   rm   rn   r   rP   r>   r/   r/   r/   r0   rX    s   
rX  c                   @   s(   e Zd Zeedddd Zdd ZdS )addServiceModelrp   rq   c                 C   s(   t jj|jd d }t|dd|iS )Nr-   rB   add_service_model.htmlr   r   r   r/   r/   r0   r8     s    zaddServiceModel.getc                 C   s   t jj|jd d }t|j}| r|j	
d}|j	
d}tjj|j|d}|s|tjj|j||d}t|d nt|d td	S t|d
d|iS d S )Nr-   rB   service_model_englishservice_model_arabic)rv   r_  )rv   r_  r`  zModel added successfullyzModel already added/service-model-listingr^  rg   )rF   r9   r:   rE   rG   r   storeServiceModelFormr^   r_   r`   r8   ServiceModelre   r'  r   rf   r   r   )rX   r<   r   rg   r_  r`  rS  r   r/   r/   r0   r>     s    zaddServiceModel.postNr   r/   r/   r/   r0   r]    s   

r]  c                   @   s(   e Zd Zeedddd Zdd ZdS )editServiceModelrp   rq   c                 C   s<   t jj|jd d }tjj|d }t|d||dS )Nr-   rB   r   edit_service_model.htmlr   r   )rF   r9   r:   rE   rG   rc  r   rX   r<   re   r   serviceModel_objr/   r/   r0   r8     s    zeditServiceModel.getc                 C   sf   t |j}| rX|jd}|jd}tjj|dj	||d}t
|d tdS t|dS d S )Nr_  r`  r   )r_  r`  zModel updated successfullyra  re  )r   rb  r^   r_   r`   r8   rc  r9   r:   r   r   rf   r   r   )rX   r<   re   rg   r_  r`  rh  r/   r/   r0   r>     s    zeditServiceModel.postNr   r/   r/   r/   r0   rd    s   

rd  c                   @   s    e Zd Zeedddd ZdS )serviceModelListingrp   rq   c                 C   s   t jj|jd d }tjjd|d}|jd}|rZtjjt|dt|dB d|d}t	|d}|jd	}|
|}t|d
|||dS )Nr-   rB   Trt   r   )Z service_model_english__icontains)Zservice_model_arabic__icontainsr   r   zservice_model_listing.htmlrV  )rF   r9   r:   rE   rG   rc  r7   r8   r   r   r   r   rW  r/   r/   r0   r8     s    "

zserviceModelListing.getNr   r/   r/   r/   r0   ri    s   
ri  c                   @   s    e Zd Zeedddd ZdS )changeServiceModelStatusrp   rq   c                 C   s   t jj|jd d }tjj||jd d }|jd |_|  |jdkrlt	
|d t|jdS t	|d	 t|jdS d S )
Nr-   rB   r   rZ  ra   r>  zModel status is activatedr?  zModel status is deactivated)rF   r9   r:   rE   rG   rc  r^   ra   r   r   rf   r   r@  r8   rb   r[  r/   r/   r0   r>     s    
zchangeServiceModelStatus.postNr\  r/   r/   r/   r0   rj    s   
rj  c                   @   s    e Zd Zeedddd ZdS )deleteServiceModelrp   rq   c                 C   s.   t jj|djt d t|d tdS )Nr   rD  rF  ra  )	rc  r9   r:   r   r   r   r   rf   r   rG  r/   r/   r0   r8     s    zdeleteServiceModel.getNr   r/   r/   r/   r0   rk    s   
rk  c                   @   s(   e Zd Zeedddd Zdd ZdS )addStoneTyperp   rq   c                 C   s(   t jj|jd d }t|dd|iS )Nr-   rB   add_stone_type.htmlr   r   r   r/   r/   r0   r8     s    zaddStoneType.getc                 C   s   t jj|jd d }t|j}| r|j	
d}|j	
d}tjj|j|d}|s|tjj|j||d}t|d nt|d td	S t|d
d|iS d S )Nr-   rB   stone_type_englishstone_type_arabic)rv   rn  )rv   rn  ro  zStone added successfullyzStone already added/stone-type-listingrm  rg   )rF   r9   r:   rE   rG   r   storeStoneTypeFormr^   r_   r`   r8   	StoneTypere   r'  r   rf   r   r   )rX   r<   r   rg   rn  ro  rS  r   r/   r/   r0   r>     s    zaddStoneType.postNr   r/   r/   r/   r0   rl    s   

rl  c                   @   s(   e Zd Zeedddd Zdd ZdS )editStoneTyperp   rq   c                 C   s<   t jj|jd d }tjj|d }t|d||dS )Nr-   rB   r   edit_stone_type.htmlrf  )rF   r9   r:   rE   rG   rr  r   rg  r/   r/   r0   r8     s    zeditStoneType.getc                 C   sf   t |j}| rX|jd}|jd}tjj|dj	||d}t
|d tdS t|dS d S )Nrn  ro  r   )rn  ro  zStone updated successfullyrp  rt  )r   rq  r^   r_   r`   r8   rr  r9   r:   r   r   rf   r   r   )rX   r<   re   rg   rn  ro  rh  r/   r/   r0   r>     s    zeditStoneType.postNr   r/   r/   r/   r0   rs  
  s   

rs  c                   @   s    e Zd Zeedddd ZdS )stoneTypeListingrp   rq   c                 C   s   t jj|jd d }tjjd|d}td| |jd}|rdtjjt	|dt	|dB d|d}t
|d	}|jd
}||}t|d|||dS )Nr-   rB   Trt   r   r   )Zstone_type_english__icontains)Zstone_type_arabic__icontainsr   r   zstone_type_listing.htmlrV  )rF   r9   r:   rE   rG   rr  rD   r7   r8   r   r   r   r   rW  r/   r/   r0   r8     s    
"

zstoneTypeListing.getNr   r/   r/   r/   r0   ru    s   
ru  c                   @   s    e Zd Zeedddd ZdS )changeStoneTypeStatusrp   rq   c                 C   s   t jj|jd d }tjj||jd d }|jd |_|  |jdkrlt	
|d t|jdS t	|d	 t|jdS d S )
Nr-   rB   r   rZ  ra   r>  zStone status is activatedr?  zStone status is deactivated)rF   r9   r:   rE   rG   rr  r^   ra   r   r   rf   r   r@  r8   rb   r[  r/   r/   r0   r>   ,  s    
zchangeStoneTypeStatus.postNr\  r/   r/   r/   r0   rv  +  s   
rv  c                   @   s    e Zd Zeedddd ZdS )deleteStoneTyperp   rq   c                 C   s.   t jj|djt d t|d tdS )Nr   rD  rF  rp  )	rr  r9   r:   r   r   r   r   rf   r   rG  r/   r/   r0   r8   :  s    zdeleteStoneType.getNr   r/   r/   r/   r0   rw  9  s   
rw  c                   @   s(   e Zd Zeedddd Zdd ZdS )addServiceTyperp   rq   c                 C   s(   t jj|jd d }t|dd|iS )Nr-   rB   add_service_type.htmlr   r   r   r/   r/   r0   r8   A  s    zaddServiceType.getc                 C   s   t jj|jd d }t|j}| r|j	
d}|j	
d}tjj|j|d}|s|tjj|j||d}t|d nt|d td	S t|d
d|iS d S )Nr-   rB   service_type_englishservice_type_arabic)rv   rz  )rv   rz  r{  rO  rP  /service-type-listingry  rg   )rF   r9   r:   rE   rG   r   storeServiceTypeFormr^   r_   r`   r8   ServiceTypere   r'  r   rf   rR  r   r   )rX   r<   r   rg   rz  r{  rS  r   r/   r/   r0   r>   E  s    zaddServiceType.postNr   r/   r/   r/   r0   rx  @  s   

rx  c                   @   s(   e Zd Zeedddd Zdd ZdS )editServiceTyperp   rq   c                 C   s<   t jj|jd d }tjj|d }t|d||dS )Nr-   rB   r   edit_service_type.htmlrf  )rF   r9   r:   rE   rG   r~  r   rg  r/   r/   r0   r8   V  s    zeditServiceType.getc                 C   sf   t |j}| rX|jd}|jd}tjj|dj	||d}t
|d tdS t|dS d S )Nrz  r{  r   )rz  r{  zService updated successfullyr|  r  )r   r}  r^   r_   r`   r8   r~  r9   r:   r   r   rf   r   r   )rX   r<   re   rg   rz  r{  rh  r/   r/   r0   r>   \  s    zeditServiceType.postNr   r/   r/   r/   r0   r  U  s   

r  c                   @   s    e Zd Zeedddd ZdS )serviceTypeListingrp   rq   c                 C   s   t jj|jd d }tjjd|d}td| |jd}|rdtjjt	|dt	|dB d|d}t
|d	}|jd
}||}t|d|||dS )Nr-   rB   Trt   r   r   )Zservice_type_english__icontains)Zservice_type_arabic__icontainsr   r   zservice_type_listing.htmlrV  )rF   r9   r:   rE   rG   r~  rD   r7   r8   r   r   r   r   rW  r/   r/   r0   r8   i  s    
"

zserviceTypeListing.getNr   r/   r/   r/   r0   r  h  s   
r  c                   @   s    e Zd Zeedddd ZdS )changeServiceTypeStatusrp   rq   c                 C   s   t jj|jd d }tjj||jd d }|jd |_|  |jdkrlt	
|d t|jdS t	|d	 t|jdS d S rY  )rF   r9   r:   rE   rG   r~  r^   ra   r   r   rf   r   r@  r8   rb   r[  r/   r/   r0   r>   w  s    
zchangeServiceTypeStatus.postNr\  r/   r/   r/   r0   r  v  s   
r  c                   @   s    e Zd Zeedddd ZdS )deleteServiceTyperp   rq   c                 C   s.   t jj|djt d t|d tdS )Nr   rD  rF  r|  )	r~  r9   r:   r   r   r   r   rf   r   rG  r/   r/   r0   r8     s    zdeleteServiceType.getNr   r/   r/   r/   r0   r    s   
r  c                   @   s    e Zd Zeedddd ZdS )orderListingrp   rq   c              
   C   s  z`g }t jj|jd d }td| tjjddd}|j	d}|j	d}d	}td
| t
 }|r|rtd |t
||d | gdt
j tj|d}td| |j	d}	|	rtd tjt
|	dd}|D ],}
td|
jjj |
jjj|kr||
 qt|d}|j	d}||}tj  }t|d|||	|||jdW S  ty } zt| tdW  Y d }~S d }~0 0 d S )Nr-   rB   r   Try   r   r   rE  z11:59:59timeZdateser )created_at__rangeZ
datesearchr   )orderId__icontainsz!order.productDetail.product.storer   r   zstore_order_listing.html)	all_orderr   r   search_start
search_endr  rC   )rF   r9   r:   rE   rG   rD   r   r   r7   r8   r   addANDr   r   rx   r   r   r   r  r  r   r  r   r   )rX   r<   allDatar   r   r  r  r  lookupsr   r   r   r   r  r   r/   r/   r0   r8     s>    

 


zorderListing.getNr   r/   r/   r/   r0   r    s   
r  c                   @   s    e Zd Zeedddd ZdS )boxTypeLisitingrp   rq   c                 C   s   t jj|jd d }tjjd|d}td| |jd}|rdtjjt	|dt	|dB d|d}t
|d	}|jd
}||}t|d|||dS )Nr-   rB   Trt   r   r   )Zbox_name_english__icontains)Zbox_name_arabic__icontainsr   r   zbox_type_listing.htmlrV  )rF   r9   r:   rE   rG   GiftBoxTyperD   r7   r8   r   r   r   r   rW  r/   r/   r0   r8     s    
"

zboxTypeLisiting.getNr   r/   r/   r/   r0   r    s   
r  c                   @   s(   e Zd Zeedddd Zdd ZdS )
addBoxTyperp   rq   c                 C   s(   t jj|jd d }t|dd|iS )Nr-   rB   add_box_type.htmlr   r   r   r/   r/   r0   r8     s    zaddBoxType.getc           
      C   s   t jj|jd d }t|j}| r|j	
d}|j	
d}|j	
d}tjj|j|d}|stjj|j|||d}|j
drt|j
d}	ttjd	 |	 }	t|	|_|  t|d
 nt|d tdS t|dd|iS d S )Nr-   rB   box_name_englishbox_name_arabicbox_cost)rv   r  )rv   r  r  r  box_iconr   zBox added successfullyzBox already added/box-type-listingr  rg   )rF   r9   r:   rE   rG   r   storeGiftBoxTypeFormr^   r_   r`   r8   r  re   r'  r   r   r+   r   r   	box_imager   r   rf   r   r   )
rX   r<   r   rg   r  r  r  rS  r   r   r/   r/   r0   r>     s$    
zaddBoxType.postNr   r/   r/   r/   r0   r    s   

r  c                   @   s(   e Zd Zeedddd Zdd ZdS )editBoxTyperp   rq   c                 C   s<   t jj|jd d }tjj|d }t|d||dS )Nr-   rB   r   edit_box_type.htmlmain_objr   )rF   r9   r:   rE   rG   r  r   rX   r<   re   r   r  r/   r/   r0   r8     s    zeditBoxType.getc                 C   s   t |j}| rtjj|dj|j	d|j	d|j	dd |j
	drt|j
	d}ttjd | }tjj|djt|d t|d	 td
S t|dd|iS d S )Nr   r  r  r  )r  r  r  r  r   )r  Box updated successfullyr  r  rg   )r   r  r^   r_   r  r9   r:   r   r`   r8   r   r   r+   r   r   r   rf   r   r   rX   r<   re   rg   r   r/   r/   r0   r>     s    


zeditBoxType.postNr   r/   r/   r/   r0   r    s   

r  c                   @   s    e Zd Zeedddd ZdS )changeGiftBoxStatusrp   rq   c                 C   s   t jj|jd d }tjj||jd d }|jd |_|  |jdkrlt	
|d t|jdS t	|d	 t|jdS d S )
Nr-   rB   r   rZ  ra   r>  zBox status is activatedr?  zBox status is deactivated)rF   r9   r:   rE   rG   r  r^   ra   r   r   rf   r   r@  r8   rb   r[  r/   r/   r0   r>     s    
zchangeGiftBoxStatus.postNr\  r/   r/   r/   r0   r    s   
r  c                   @   s    e Zd Zeedddd ZdS )deleteGiftBoxrp   rq   c                 C   s.   t jj|djt d t|d tdS )Nr   rD  rF  r  )	r  r9   r:   r   r   r   r   rf   r   rG  r/   r/   r0   r8     s    zdeleteGiftBox.getNr   r/   r/   r/   r0   r    s   
r  c                   @   s    e Zd Zeedddd ZdS )giftPackagingListrp   rq   c                 C   s   t jj|jd d }tjjd|d}td| |jd}|rdtjjt	|dt	|dB d|d}t
|d	}|jd
}||}t|d|||dS )Nr-   rB   Trt   r   r   )Z!packaging_name_english__icontains)Z packaging_name_arabic__icontainsr   r   zgift_packaging_list.htmlrV  )rF   r9   r:   rE   rG   GiftPackingTyperD   r7   r8   r   r   r   r   rW  r/   r/   r0   r8     s    
"

zgiftPackagingList.getNr   r/   r/   r/   r0   r    s   
r  c                   @   s(   e Zd Zeedddd Zdd ZdS )addGiftPackagingrp   rq   c                 C   s(   t jj|jd d }t|dd|iS )Nr-   rB   add_gift_packaging.htmlr   r   r   r/   r/   r0   r8     s    zaddGiftPackaging.getc           
      C   s   t jj|jd d }t|j}| r|j	
d}|j	
d}|j	
d}tjj|j|d}|stjj|j|||d}|j
drt|j
d}	ttjd	 |	 }	t|	|_|  t|d
 nt|d tdS t|dd|iS d S )Nr-   rB   packaging_name_englishpackaging_name_arabicpackaging_cost)rv   r  )rv   r  r  r  r  r   zPackaging added successfullyzPackaging already added/gift-packaging-listr  rg   )rF   r9   r:   rE   rG   r   storeGiftPackingFormr^   r_   r`   r8   r  re   r'  r   r   r+   r   r   packaging_imager   r   rf   r   r   )
rX   r<   r   rg   r  r  r  rS  r   r   r/   r/   r0   r>     s$    
zaddGiftPackaging.postNr   r/   r/   r/   r0   r    s   

r  c                   @   s(   e Zd Zeedddd Zdd ZdS )editGiftPackagingrp   rq   c                 C   s<   t jj|jd d }tjj|d }t|d||dS )Nr-   rB   r   edit_gift_packaging.htmlr  )rF   r9   r:   rE   rG   r  r   r  r/   r/   r0   r8   /  s    zeditGiftPackaging.getc                 C   s   t |j}| rtjj|dj|j	d|j	d|j	dd |j
	drt|j
	d}ttjd | }tjj|djt|d t|d	 td
S t|dd|iS d S )Nr   r  r  r  )r  r  r  r  r   )r  r  r  r  rg   )r   r  r^   r_   r  r9   r:   r   r`   r8   r   r   r+   r   r   r   rf   r   r   r  r/   r/   r0   r>   5  s    


zeditGiftPackaging.postNr   r/   r/   r/   r0   r  .  s   

r  c                   @   s    e Zd Zeedddd ZdS )changeGiftPackagingStatusrp   rq   c                 C   s   t jj|jd d }tjj||jd d }|jd |_|  |jdkrlt	
|d t|jdS t	|d	 t|jdS d S )
Nr-   rB   r   rZ  ra   r>  zPackaging status is activatedr?  zPackaging status is deactivated)rF   r9   r:   rE   rG   r  r^   ra   r   r   rf   r   r@  r8   rb   r[  r/   r/   r0   r>   G  s    
zchangeGiftPackagingStatus.postNr\  r/   r/   r/   r0   r  F  s   
r  c                   @   s    e Zd Zeedddd ZdS )deleteGiftPackagingrp   rq   c                 C   s.   t jj|djt d t|d tdS )Nr   rD  rF  r  )	r  r9   r:   r   r   r   r   rf   r   rG  r/   r/   r0   r8   T  s    zdeleteGiftPackaging.getNr   r/   r/   r/   r0   r  S  s   
r  c                   @   s    e Zd Zeedddd ZdS )getStoreNotificationsrp   rq   c           
      C   s   t jj|jd d }tjjd|jdd}|j	d}t
 d}|j	d}|r|tjj||d	 | gdd
d}t|d}|j	d}||}	t|d|	|||dS )Nr-   rB   Trt   r   r   z%H:%M:%SrE  r  )start_date__rangeru   r   r   zget_store_notifications.html)
notify_objr  r  r   )rF   r9   r:   rE   rG   StoreNotificationsre   r   r7   r8   r   r   strftimer   r   r   )
rX   r<   r   not_objr  r  r  r   r   r  r/   r/   r0   r8   [  s    "

zgetStoreNotifications.getNr   r/   r/   r/   r0   r  Z  s   
r  c                   @   s    e Zd Zeedddd ZdS )deleteStoreNotificationsrp   rq   c                 C   sp   t jj|jd d }|jd}|r\dd |dD }tjj|d	  t
|d nt
|d	 td
S )Nr-   rB   	delete_idc                 S   s   g | ]}t |qS r/   )r   ).0re   r/   r/   r0   
<listcomp>o      z0deleteStoreNotifications.get.<locals>.<listcomp>,)pk__inzDeleted Sucessfullyz*At least One notification must be selected/get-store-notifications)rF   r9   r:   rE   rG   r7   r8   splitr  deleter   rf   rb   r   )rX   r<   r   idsint_id_listr/   r/   r0   r8   j  s    zdeleteStoreNotifications.getNr   r/   r/   r/   r0   r  i  s   
r  c                   @   s    e Zd Zeedddd ZdS )readNotificationStorerp   rq   c                 C   sB   t jj|jd d }tjj|jd }d|_|	  t
dS )Nr-   rB   rv   Fr  )rF   r9   r:   rE   rG   r  re   lastis_readr   r   )rX   r<   r   r  r/   r/   r0   r8   w  s
    zreadNotificationStore.getNr   r/   r/   r/   r0   r  v  s   
r  c                   @   s    e Zd Zeedddd ZdS )serviceRequestListrp   rq   c                 C   s   t jj|jd d }tjj|jdd}|j	d}|rjtjjt
|dt
|dB t
|dB d	|d
}t|d}|j	d}||}t|d|||dS )Nr-   rB   rw   r   r   rU  )Zcustomer__first_name__icontains)Zcustomer__last_name__icontainsTrt   r   r   zservice_request_list.html)req_objr   r   )rF   r9   r:   rE   rG   r   re   r   r7   r8   r   r   r   r   )rX   r<   r   r   r   r   r   r  r/   r/   r0   r8     s    ,

zserviceRequestList.getNr   r/   r/   r/   r0   r    s   
r  c                   @   s    e Zd Zeedddd ZdS )changeServiceStatusrp   rq   c                 C   s  t d|jd  tjj|jd d }tjj||jd }tjj|dj	|jd d |jd dkrnd}n|jd d	krd
}nd}|j
jj}ttj}|j
jjdkr.|j
jjdkrddd|jj d | d}t|dj||d}	|j
jjdkr.d}
d| f}ddd| d}t|dj||
||d}	tjj|j
jd }tjj|d|jj d | dd t|d t|jdS )Nactionr-   rB   re   rx   r   delivery_statusr(   Pendingr>  
On the way	Deliveredr   androidservice_statusSERVICE ACCEPTEDz"Your service request delivery for zis typetitler?   api_keyregistration_iddata_messageios)SERVICE STATUSz!Your service request delivery is r  r  message_titlemessage_bodyr   is Servicecustomerr?   notification_typeStatus changes successfullyr?  )rD   r^   rF   r9   r:   rE   rG   r   re   r   r  r   device_tokenr+   r   FIREBASE_SERVER_KEYnotification_enableddevice_type	serviceIdenglish_service_namer'   notify_single_deviceBuyerCustomerNotificationsr'  r   rf   r   r@  r8   )rX   r<   re   r   r   r  r  
server_keyr  resultr  r  	buyer_objr/   r/   r0   r>     s@    


"zchangeServiceStatus.postNr\  r/   r/   r/   r0   r    s   
r  c                   @   s   e Zd Zdd ZdS )testFcmc                 C   sB   d}d}dddd}t |dj||d}td	| td
d|dS )NzcLWvBCEzQHSqmlyM6-LKPM:APA91bFbX2gvrxC3QX6OcSlbZIflOPLS7Cdmpu-Cg6ryZ46Ucw1Uf61kqIHvnvzV-SeNl67Czcr1-EEWFEQCEJHZyRMIg2jbw_jOYnidQVGbBBn_LJIprpYjti8toMv6AX74KsPntlzSzAAAAyWeVa0M:APA91bHrD_vt7MqP2_R8PlFNAOsdvKR02IXEVjPhBaXZnUTjw6EmcEM4Vp8RJad8jrypS1geR29rcBvSfGlwX_h4z7VmfQpepemdEcQh8kjSwMNRwLR9FrVyh35HJdjXSckIHMqSErSer  r  z!Your service request delivery forr  r  r  z++++++++++++++++++++   r  )status_codestatus_messagedata)r'   r  rD   r   )rX   r<   r  r  r  r  r/   r/   r0   r8     s    
ztestFcm.getNr   r/   r/   r/   r0   r    s   r  c                   @   s    e Zd Zeedddd ZdS )viewServiceRequestrp   rq   c                 C   s@   t jj|jd d }tjj||jd }t|d||dS )Nr-   rB   r  zview_service_request.htmlr   r   rF   r9   r:   rE   rG   r   re   r   rX   r<   re   r   r   r/   r/   r0   r8     s    zviewServiceRequest.getNr   r/   r/   r/   r0   r    s   
r  c                   @   s    e Zd Zeedddd ZdS )acceptRequestListrp   rq   c           
      C   s   t jj|jd d }tjj||jd }d|_|  t	d}|}t
j}|jjj}d}	t|jjj tj|	|||g|d t|d td	S )
Nr-   rB   r  r   zservice_approved.htmlzSerivce Acceptedhtml_messagezSerivce accepted successfully/service-request-list)rF   r9   r:   rE   rG   r   re   r  r   r   r   EMAIL_HOST_USERr  r   r2   rD   r   	send_mailr   rf   r   
rX   r<   re   r   r   r  plain_message
from_emailtosubjectr/   r/   r0   r8     s    
zacceptRequestList.getNr   r/   r/   r/   r0   r    s   
r  c                   @   s    e Zd Zeedddd ZdS )rejectRequestListrp   rq   c           
      C   s   t jj|jd d }tjj||jd }d|_|  t	d}|}t
j}|jjj}d}	tj|	|||g|d t|d td	S )
Nr-   rB   r     zservice_rejected.htmlzService Rejectedr  zService rejected successfullyr   )rF   r9   r:   rE   rG   r   re   r  r   r   r   r  r  r   r2   r   r  r   rf   r   r  r/   r/   r0   r8     s    
zrejectRequestList.getNr   r/   r/   r/   r0   r    s   
r  c                   @   s    e Zd Zeedddd ZdS )dealSectionListrp   rq   c                 C   s   t jj|jd d }tjjd|jdd}|j	d}|rjtjjt
|dt
|dB d|jdd}t|d	}|j	d
}||}t|d|||dS )Nr-   rB   F)Ztoday_deal_start_date__isnullrv   r   r   r   r   r   r   zdeal_section_list.html)	today_objr   r   )rF   r9   r:   rE   rG   r   re   r   r7   r8   r   r   r   r   )rX   r<   r   r   r   r   r   r  r/   r/   r0   r8     s    *

zdealSectionList.getNr   r/   r/   r/   r0   r
    s   
r
  c                   @   s(   e Zd Zeedddd Zdd ZdS )addDealProductrp   rq   c                 C   s@   t jj|jd d }tjjddd|jd}t|d||dS )Nr-   rB   r   T)r   ru   ra   rv   add_deal_product.html)r   r   )rF   r9   r:   rE   rG   r   re   r   )rX   r<   r   Zproducts_objr/   r/   r0   r8     s    zaddDealProduct.getc                 C   sb   t |j}| rN|jd}tjj|dj	t
 d t|d tdS t|dd|iS d S )Nr8  r   today_deal_start_datezSepical deal added successfully/deal-section-listr  rg   )r   ZaddDealFormr^   r_   r`   r8   r   r9   r:   r   r   r*   r   rf   r   r   )rX   r<   rg   r8  r/   r/   r0   r>     s    zaddDealProduct.postNr   r/   r/   r/   r0   r    s   

r  c                   @   s    e Zd Zeedddd ZdS )deleteDealProductrp   rq   c                 C   s*   t jj|djd d t|d tdS )Nr   r  z!Sepical deal deleted successfullyr  )r   r9   r:   r   r   rf   r   rG  r/   r/   r0   r8   $  s    zdeleteDealProduct.getNr   r/   r/   r/   r0   r  #  s   
r  c                   @   s    e Zd Zeedddd ZdS )chatListrp   rq   c                 C   sd   t jj|jd d }tjj|jd}tjj|d	d}t
j }t }t|d||||dS )Nr-   rB   r   rw   z-last_message_timezchat_list.html)roomsr   
buyer_infoZ
today_date)rF   r9   r:   rE   rG   r	   r8   r-   	chat_roomr   r  r  r   r*   r   )rX   r<   r   r   r  r  Z	todayDater/   r/   r0   r8   ,  s    
zchatList.getNr   r/   r/   r/   r0   r  +  s   
r  )APIViewc                   @   s    e Zd Zeedddd ZdS )getMessageListrp   rq   c              
   C   s  zx|j }|d}|d}|s2tdddW S |sFtdddW S tjj|d}tjj|d}tjj|jd}tjj|jd}tjj	||d	
d
tjj	||d	
d
B }	g }
|	D ]}|j|krd}nd}td|jj td|jj tjt|jjdt|jjdB }|jdkrD|
|j|jd |j ||j|jd q|
|j|jd |j ||j|jd qtd|
iW S  ty } ztdt|dW  Y d }~S d }~0 0 d S )Nrv   r-     user_id is requiredr  r  store_id is requiredr   rB   )sender_userreceiver_user
created_atTFzmessage.sender_user.idzmessage.receiver_user.idr=   r  )r?   Zsender_namesenderr   r  r  500)query_paramsr8   r   r	   r9   rF   re   r  Messager:   r   r  rD   r  r   r  r   r?   
first_name	last_namer  r.  r   r+   )rX   r<   r  rv   r-   Z	storeChatchatuserstoreObjrh   r   r  r?   r  rr   r   r/   r/   r0   r8   ;  s6    

,
$**zgetMessageList.getNr   r/   r/   r/   r0   r  :  s   
r  c                   @   s   e Zd Zdd ZdS )addMessagesc              
   C   s  z@|j }|d}|d}|d}|s<tdddW S |sPtdddW S |sdtdddW S tjj|d	}tjj|d	}|d
}|stjj|||dd tjj||d}	||	_t	
 |	_d|	_|	  ndt|}
ttjd |
 }
t|
}tjj|||d
d tjj||d}	d |	_t	
 |	_d|	_|	  tddiW S  tyz } ztdt|dW  Y d }~S d }~0 0 d S )Nrv   r-   r?   r  r  r  r  zmessage is requiredr   r.  r=   )r  r  r?   r  )r   rx   r   r   )r  r  r.  r  rf   r   )r  r8   r   r	   r9   r"  r'  r  last_message_textr   r   last_message_timer  r   uploadThemessagepicturer+   r   r   r   )rX   r<   r  rv   r-   r?   rx   buyerr.  crr   	image_urlr   r/   r/   r0   r>   _  sB    






zaddMessages.postNrB  r/   r/   r/   r0   r'  ^  s   r'  c                   @   s    e Zd Zeedddd ZdS )changeOrderStatusrp   rq   c                 C   sp  t d|jd tjj|dj|jd d tjj|d }|jd dkrTd}n|jd dkrhd}nd}|j	j
}ttj}|j	jd	kr|j	jd
krddd|j d | d}t|dj||d}|j	jdkrd}	d|j d | f}
ddd|j d | d}t|dj||	|
|d}tjj|j	jd }tjj|d|j d | dd t|d t|jdS )Nr  r   r  r(   r  r>  r  r  r   r  order_statuszORDER STATUSz Your order request delivery for r  r  r  r  r  )r  r  rB   r  r  r  r?  )rD   r7   r8   r   r9   r:   r   r^   rG   r  r  r+   r   r  r  r  orderIdr'   r  r  re   r  r'  r   rf   r   r@  )rX   r<   re   r   r  r  r  r  r  r  r  r  r/   r/   r0   r>     s:    
 zchangeOrderStatus.postNr\  r/   r/   r/   r0   r.    s   
r.  c                   @   s    e Zd Zeedddd ZdS )
getInvoicerp   rq   c                 C   s  t jj|d }tjj|jd }tjj|jdd}tjj|j	d }t
|jd d t
t  t
|jd d  }td| tt|d }|dd	d}	tj|	d
}
dd l}|jt
tjd rn|t
tjd  |
jt
tjd |j d dd |jt
tj d |jd }td| ||_!|"  d|j! }|j|# |}t$|d}t%&|' }W d    n1 s0    Y  |d}t| |||||d}t(d}t)j*  }|+|||||d}t,dd}d|d< t-j.|dj/|t-0dgd |S )Nr   Tr0  rz   orderPack_id   ------------------r   utf-16surrogatepasscontent/media/qrCode/.png   scaleqrCode/r.  media/rbutf-8)invoicecustomer_obj
orders_objtrans_idr.  zgetinvoice.htmlzapplication/pdf)content_typezattachment; filename="file.pdf"zContent-Dispositionstringstatic/store/css/invoice.cssstylesheets)1r   r9   r:   rG   r  customer_idCartr0  CustomerTransactionre   r+   r#  r   r   r   rD   codecsunicode_escape_decodestring_utilsshuffleencodedecodepyqrcoder'  osrH   existsr   BASE_DIRmkdirpngjoin
MEDIA_ROOTqr_code_imager   getcwdopenbase64	b64encodereadr   r  r  r   r   
weasyprintHTML	write_pdfCSS)rX   r<   re   rD  rE  rF  rG  qr_unique_numbernew_strencodedparceldetailsurlrX  r.  path_to_imageabs_path_to_image
image_fileencoded_stringbase64_imager  templater  htmlresponser/   r/   r0   r8     s@    0
"

.

zgetInvoice.getNr   r/   r/   r/   r0   r1    s   
r1  c                   @   s    e Zd Zeedddd ZdS )viewOrderDetailsrp   rq   c              	   C   s|   t jj|jd d }tjj|d }tjj|jd }tjj|j	dd}t
jj|jd }t|d|||||dS )	Nr-   rB   r   Tr2  r3  zview_order_details.html)rD  rE  rF  rG  r   )rF   r9   r:   rE   rG   r   r  rN  rO  r0  rP  re   r   )rX   r<   re   r   rD  rE  rF  rG  r/   r/   r0   r8     s    zviewOrderDetails.getNr   r/   r/   r/   r0   ru    s   
ru  c                   @   s    e Zd Zeedddd ZdS )couponListingrp   rq   c                 C   s^   t jj|jd d }tjj|dd}t|d}|j	d}|
|}t|d||dS )	Nr-   rB   r  r   r   r   zcoupon_listing.html)
coupon_objr   )rF   r9   r:   rE   rG   StoreCouponsr   r   r7   r8   r   r   )rX   r<   r   couponr   r   rw  r/   r/   r0   r8     s    

zcouponListing.getNr   r/   r/   r/   r0   rv    s   
rv  c                   @   s(   e Zd Zeedddd Zdd ZdS )addCouponStorerp   rq   c                 C   sz   t jj|jd d }tjjd|dd}tjjd|d}tjjd|ddd	 }t
d| t|d	||||d
S )Nr-   rB   Trt   r   maincategory__id#maincategory__category_name_englishcategoryadd_coupon_store.html)productsrK  catgeoryr   )rF   r9   r:   rE   rG   r   r   rQ  valuesdistinctrD   r   )rX   r<   r   r  rK  r  r/   r/   r0   r8     s    
zaddCouponStore.getc                 C   sB  t jj|jd d }t|j}| r4|j	
d}|j	
d}|j	
d}|j	
d}|j	
d}|rtjj|d|d	 }	nd }	|j	
d
}
|
rtjj|
d }nd }|j	
d}|rtjj|d }nd }|j	
d}|j	
d}|j	
d}tjj||||||	|||||d t|d tdS t|dS d S )Nr-   rB   coupon_name_englishcoupon_name_arabiccoupon_typecoupon_discountr   Tre   ru   rv   rK  r   category_product	coupon_oncoupon_start_datecoupon_end_daterv   r  r  r  r  r   rK  r  r  r  r  zCoupon added successfully/coupon-listingr~  )rF   r9   r:   rE   rG   r   addCouponFormr^   r_   r`   r8   r   rL  r	  rx  r'  r   rf   r   r   )rX   r<   r   rg   r  r  r  r  r   r   rK  r   r  category_objr  r  r  r/   r/   r0   r>     s:    

zaddCouponStore.postNr   r/   r/   r/   r0   rz    s   

rz  c                   @   s(   e Zd Zeedddd Zdd ZdS )editCouponStorerp   rq   c              	   C   s   t jj|jd d }tjjd|dd}tjjd|d}tjjd|ddd	 }t
jj|d }td	| t|d
|||||dS )Nr-   rB   Trt   r   r{  r|  r   r}  edit_coupon_store.html)r  rK  r  rw  r   )rF   r9   r:   rE   rG   r   r   rQ  r  r  rx  rD   r   )rX   r<   re   r   r  rK  r  rw  r/   r/   r0   r8   )  s    
zeditCouponStore.getc                 C   sT  t jj|jd d }t|j}| rF|j	
d}|j	
d}|j	
d}|j	
d}|j	
d}	|	rtjj|	d|d	 }
nd }
|j	
d
}|rtjj|d }nd }|j	
d}|rtjj|d }nd }|j	
d}td| |j	
d}|j	
d}tjj|dj||||||
|||||d t|d tdS t|dS d S )Nr-   rB   r  r  r  r  r   Tr  rK  r   r  r  r  r  r  zCoupon Updated successfullyr  r  )rF   r9   r:   rE   rG   r   r  r^   r_   r`   r8   r   rL  r	  rD   rx  r   r   rf   r   r   )rX   r<   re   r   rg   r  r  r  r  r   r   rK  r   r  r  r  r  r  r/   r/   r0   r>   2  s<    


zeditCouponStore.postNr   r/   r/   r/   r0   r  (  s   

r  c                   @   s(   e Zd Zeedddd Zdd ZdS )createServiceInvoicerp   rq   c                 C   s@   t jj|jd d }tjj||jd }t|d||dS )Nr-   rB   r  service-invoice.htmlr  r  r  r/   r/   r0   r8   \  s    zcreateServiceInvoice.getc                 C   st  t jj|jd d }tj  }t|j	}|
 r`|jd}|jd}|jd}tjj||jd }	t|d t|j }
tjj|j|	d}|sLtjj|j|	d}t|j|_||_||_t|t|
 |_|	jj|_|	jj|_||_|	j|_|
|_|	j j!d	 |	j j" |_#|$  t%|j#d d
 t%t&'  t%|jd d
  t%|jd d
  }t(d| t)*t+,|d }|-dd.d}t/j|d}dd l0}|j12t%t3j4d rn|5t%t3j4d  |j6t%t3j4d |j d dd |j17t%t3j8d |jd }t(d| ||_9|$  d|j9j: }|j17|; |}t<|d}t=>|? }W d    n1 s0    Y  |.d}t(| ||||d}t@d}|A|}tBC }tDjE|djF|tDGdgd tHt3j8d}t%t3j4d d |j d! }|$||}||_I|$  tjj||jdjJd"d# tKL|d$ ntKL|d% tMd&S tA|d'd(|iS d S ))Nr-   rB   
unit_pricetotal_pricer  r  r)   )rv   service_request_idr  r5  r6  r   r7  r8  r9  r;  r<  r=  r>  r@  r.  rA  rB  rC  )rS  r.  	admin_vatr   service-invoice-pdf.htmlrI  rK  rL  )locationz/media/InvoicePdf/Zinvoice_z.pdfT)invoice_generatedz$Service invoice created successfullyzService Invoice already createdr   r  rg   )NrF   r9   r:   rE   rG   r  r  r   ZServiceInvoiceFormr^   r_   r`   r8   r   re   r   r  ServiceInvoicer'  r1   invoice_numberr  total_before_vatr   total_amountr  r  arabic_service_namer  notesdescription
vat_amountr  r#  r$  customer_namer   r+   r   r   rD   rQ  rR  rS  rT  rU  rV  rW  rX  rH   rY  r   rZ  r[  r\  r]  r^  qr_coderr   r`  ra  rb  rc  rd  r   r   ior   re  rf  rg  rh  r$   invoice_pdf_urlr   r   rf   r   )rX   r<   re   r   r  rg   r  r  r  rM  r  rS  ri  rj  rk  rl  rX  r.  rm  rn  ro  rp  rq  contextrr  rs  Z
pdf_outputstorageZpdf_file_nameZpdf_file_pathr/   r/   r0   r>   b  s|    


B
"
.

zcreateServiceInvoice.postNr   r/   r/   r/   r0   r  [  s   

r  c                   @   s   e Zd Zdd ZdS )
pdfInvoicec                 C   s
   t |dS )Nr  rV   rW   r/   r/   r0   r8     s    zpdfInvoice.getNr   r/   r/   r/   r0   r    s   r  )django.views.generic.baser   Zauth_apis.modelsdjango.contrib.authr   r   r   django.shortcutsr   r   r	   r
   django.httpr   django.http.responser   r:  r   r   django.template.loaderr   django.corer   django.contribr   django.confr   mathpytzrJ  django.contrib.auth.decoratorsr   django.utils.decoratorsr   Zadmin_panel.modelsr   django.core.paginatorr   r   r   store_apis.modelspasslib.hashr   rc   Zstore_apis.functionsdjango.core.exceptionsr   r1  Zpanel_apis.modelsZadmin_panel.functionsr   panel_apis.functionsr   r   Z
TaqnyatSmsr   	functionsr  r   	xhtml2pdfr   pdfkitre  django.templater    rW  r!   rQ  django.core.mailr"   django.core.files.storager#   r$   rS  urllib.requestr%   rb  requestsurllibPILr&   Zpyfcmr'   Zbearerr1   r@   rP   rS   rT   ro   r   r   r   r   r   r   r   r   r   r   r/  r6  r=  rC  rH  rI  rT  rX  r]  rd  ri  rj  rk  rl  rs  ru  rv  rw  rx  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  rest_framework.viewsr  r  r'  r.  r1  ru  rv  rz  r  r  r  r/   r/   r/   r0   <module>   s   	$	.&ZZ#)#$.'/
03n