
    7d                     R   d dl Z d dlmZ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T d dlZ e            Ze                    d           ed          fd	ed
efd            Ze                    d          d	efd            Ze                    d          d	efd            ZdS )    N)	APIRouterRequestBodystatus)DictList)jsonable_encoder)JSONResponse)*z
/create_po.request
po_detailsc                   K   t          |          }| j        j                                        }|                    d          D ]I}t          |d                   dk    rt          |d                   }1t          |d                   dz   }Jd                    t          j                                        d          t          j                                        d          |          |d<   t          j        |d         d	          j	        |d<   t          j        |d
         d	          j	        |d
<   t          j
                                        d          j	        |d<   |                    d|d         |d         |d         |d
         |d         |d         d|d         	  	         | j        j                                         |d         D ]Q}|                    d||d         |d         |d         |d         |d         |d         |d         d|d                    R| j        j                                         |                                 t          d|i          S )Nz1SELECT IDENT_CURRENT('PurchaseOrderList') as cnt;r      zAVPL/PSD/{}/{}/{}YYYYMM	po_ref_nopo_datez
DD/MM/YYYYdelivery_datezAsia/Calcutta)tzinfoLast_updatez=insert into PurchaseOrderList values (?, ?, ?, ?, ?, ?, ?, ?)	vendor_idpurchase_eventprepared_byproduct_detailszCinsert into PurchaseOrderItem values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
product_idhsn_codeqtyuom
base_pricecgstsgstpo_no)r	   appmssqlcursorexecuteintformatarrowgetdatetimenowreplacecommitcloser
   )r   r   r%   itr	row_countprds         "D:\api_v1\routes\purchase_order.py	create_por4      sV     !*--J[%%''F ~~QRR ( (s1v;;!CFIICFaII1889K9KF9S9SUZU^U`U`UgUghlUmUmoxyyJ{!Ij&;\JJSJy"')J,G"V"V"_J %	 3 3? 3 K K TJ} NNRk*k*i(o../m,m,	 	 	 K +, 2 2\ <(:5z5z<(6{6{!-0
	2 
	2 
	2 
	2 K
LLNNN        z/get_po/{details}/{po_id}c                 t  K   | j         j                                        }i }|                    d|          }|j        dk    r|D ]}|rt          |          D ]\  }}|||j        |         d         <   t          |           g |d<   |dk    r|                    d|          }|j        dk    ro|D ]L}|rHi }	t          |          D ]\  }}||	|j        |         d         <   |d                             |	           Mt          |           t          |          c S  dS t          |          c S  dS d S dS )Nz=select * from PurchaseOrderList where PurchaseOrderListId = ?r   r   1z=select * from PurchaseOrderItem where PurchaseOrderListId = ?zRequested PO not found)
r#   r$   r%   r&   rowcount	enumeratecursor_descriptionjson_serializerappendr
   )
r   detailspo_idr%   r   rowsrowr0   itr_itmproducts
             r3   get_porC   D   s     [%%''FJ>>YZ_``D} 	0 	0C 0#,S>> I IKCAHJs5c:1=>>  
+++02
,-c>>!>>*ijoppD}))#' N NC" N*,4=cNN !V !VLCNUGC,B3,G,J$K$K *+< = D DW M M M'
333+J77777777'
33333///?	0 	0D ('r5   z/get_valid_poc                    K   | j         j                                        }g }|                    d          D ]}|                    |d                    |S )NzDselect PurchaseOrderListId from PurchaseOrderList where POStatus = 1r   )r#   r$   r%   r&   r<   )r   r%   r"   r0   s       r3   get_valid_porE   o   s[      [%%''FE~~dee  SVLr5   )r)   fastapir   r   r   r   typingr   r   fastapi.encodersr	   fastapi.responsesr
   
lib.commonjsonrouterpostr4   r*   rC   rE    r5   r3   <module>rO      sN    4 4 4 4 4 4 4 4 4 4 4 4         - - - - - - * * * * * *     	 \9=c 4 4W 4$ 4 4 4 4n '(('(' '( '( '( )('(T O      r5   