
    oCi                     |    d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZmZ  G d	 d
      Zy)    )Session)Prescription)PrescriptionSearch)Product)PharmacyStock)Partner)PrescriptionProduct)funcdistinctc                   $    e Zd ZdefdZdefdZy)ProductServicedbc                     || _         y )N)r   )selfr   s     D/home/www/lebenam.kofcorporation.com/app/services/product_service.py__init__zProductService.__init__   s	        product_namec           
         | j                   j                  t              j                  t        j                  |k(        j                         }|sy | j                   j                  t        j                  t        j                              j                  t        j                  |j                  k(        j                         xs d}| j                   j                  t        j                  t        j                  t        j                  t        j                        j                  t              j                  t        j                  |j                  k(        j!                         }i }|D ]  \  }}}}| j                   j                  t        j"                  t%        t&        j(                                    j                  t&        j*                        j                  t&        j                  |j                  k(  t,        j.                  j1                  t2        j4                  |k(              j                         xs d}	|	||<    g }
|D ]-  \  }}}}|
j7                  ||||j9                  |d      d       / |j                  ||
dS )Nr   )partner_namephysical_addressstock_quantitydemand_count)r   global_stockpartner_distribution)r   queryr   filternamefirstr
   sumr   quantity
product_ididscalarr   r   joinallcountr   r	   prescription_idprescriptionr   searchesanyr   
partner_idappendget)r   r   productr   partner_stockspartner_demandsr   _r,   r   detailed_partner_infor   addressr!   s                 r   get_product_stock_statusz'ProductService.get_product_stock_status   s   ''--(//0LMSSUww}}TXXm.D.D%EFMM$$

2

&( 	 LL$$""JJ	

 $}
ff$$

2

#% 	 .< &	7*L!Q
6 djj2E2U2U)VWX)667'22gjj@ ))--&11Z?    +7OJ'M&	7R !#3A 	/D'8Z!(( $$+"* / 3 3J B	* 	 $LL($9
 	
r   N)__name__
__module____qualname__r   r   strr5    r   r   r   r      s    7 J
S J
r   r   N)sqlalchemy.ormr   app.models.prescriptionr   app.models.prescription_searchr   app.models.productr   app.models.pharmacy_stockr   app.models.partnerr   app.models.prescription_productr	   
sqlalchemyr
   r   r   r:   r   r   <module>rC      s+    # 0 = & 3 & ? %N
 N
r   