
    u(i              
          d dl mZ d dlmZ d dlmZmZmZmZ ddl	m
Z
mZmZ d dlZ ej                  e      Zddeded	ed
ee
j$                     fdZded
ee
j(                     fdZded
ee
j,                     fdZded
ee
j0                     fdZdeded
ee
j,                     fdZdeded
ee
j6                     fdZddeded	ed
ee
j:                     fdZded
eeef   fdZ y)    )Session)func)ListOptionalDictAny   )modelsschemasservicesNdbskiplimitreturnc                 R    t        j                  |       }|j                  ||      S )zGet products with paginationr   r   )r   ProductServiceget_productsr   r   r   product_services       K/var/www/html/hubwallet-dev/src/smart_inventory/apps/products/controller.pyr   r   
   s(    --b1O''T'??    c                 L    t        j                  |       }|j                         S )zGet all locations)r   r   get_locationsr   r   s     r   r   r      s!    --b1O((**r   c                 L    t        j                  |       }|j                         S )zGet all vendors)r   r   get_vendorsr   s     r   r   r      s!    --b1O&&((r   c                 L    t        j                  |       }|j                         S )zGet all categories)r   r   get_categoriesr   s     r   r   r      s!    --b1O))++r   
product_idc                 V   | j                  t        j                        j                  t        j                  t        j                  j
                  t        j                  j
                  k(        j                  t        j                  j                  |k(        j                         }|S )zCGet vendors for a specific product with detailed vendor information)	queryr
   VendorjoinProductVendor	vendor_idfilterr    all)r   r    vendorss      r   get_product_vendorsr*   "   sv     hhv}}%**fmm559M9M9W9WWf'':5	ce	  Nr   c                     | j                  t        j                        j                  t        j                  j                  |k(        j                         S )z$Get locations for a specific product)r"   r
   ProductLocationr'   r    r(   )r   r    s     r   get_product_locationsr-   .   s?    88F**+22))Z7	cer   c                 R    t        j                  |       }|j                  ||      S )zGet all prices with paginationr   )r   r   get_all_pricesr   s       r   r/   r/   5   s(    --b1O))t5)AAr   c                    	 | j                  t        j                        j                         }| j                  t        j                        j                         }| j                  t        j
                        j                         }| j                  t        j                        j                         }| j                  t        j                        j                         }| j                  t        j                        j                         }| j                  t        j                  j                  t        j                  t        j                  j                        j                  d            j                  t        j                  t        j                  j                  t        j                  j                  k(        j!                  t        j                  j                        j#                         }| j                  t        j                  j$                  t        j                  t        j                  j                        j                  d            j!                  t        j                  j$                        j#                         }|||||||D 	
ci c]  \  }	}
|		|	|
 c}
}	|D 
ci c]  \  }}
|	||
 c}
}dS c c}
}	w c c}
}w # t&        $ r'}t(        j+                  dt-        |               d}~ww xY w)zGet product statisticscountN)total_productstotal_locationstotal_vendorstotal_categoriestotal_product_vendor_mappingstotal_product_location_mappings
categoriesbrandsz!Error in get_product_statistics: )r"   r
   Productr1   Locationr#   Categoryr%   r,   category_namer   idlabelr$   category_idfk_product_category_idgroup_byr(   
brand_name	Exceptionloggererrorstr)r   r2   r3   r4   r5   r6   r7   category_countsbrand_countscategoryr1   brandes                r   get_product_statisticsrM   ;   s   "&..1779((6??399;/55788FOO4::<(*1E1E(F(L(L(N%*,((63I3I*J*P*P*R' ((OO))JJv~~(()//8
 $NNFOO776>>;`;``

(6??00
1##% 	 xxNN%%JJv~~(()//8
 (6>>,,
-cce 	 -.* 0-J/NBQjxU]Ui8U?j8DZuHYue|Z	
 		
 kZ 8QABsB   JK 
K)K.K 6
KKK K 	L!"LL)r   d   )!sqlalchemy.ormr   
sqlalchemyr   typingr   r   r   r    r
   r   r   logging	getLogger__name__rE   intr:   r   r;   r   r#   r   r<   r   r*   r,   r-   ProductPricer/   rG   rM    r   r   <module>rY      sC   "  , , ' ' 			8	$@W @C @C @$v~~BV @+g +$v"7 +)G )V]] 3 ),w ,4#8 ,	G 	 	fmm9L 	g 3 4@V@V;W Bw Bc Bc BDI\I\D] B$w $4S> $r   