
    h	                         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 d d	lmZ  G d
 d      Zy)    )List)HTTPException)func)Session)schema)JWTPayloadSchema)Messages)DepreciationBaseTblDepreciation)CustomResponsec                       e Zd ZdedefdZdeej                     fdZ	de
fdZde
fd	Zdej                  fd
Zde
fdZy)DepreciationServicedbtokenc                      || _         || _        y N)r   r   )selfr   r   s      7/var/www/html/RetailAPI/app/api/depreciation/service.py__init__zDepreciationService.__init__   s    
    requestc                    K   g }|D ]3  }t        j                  || j                        }|j                  |       5 | j                  j	                          t        dt        j                        S w)N1statusmessage)r   creater   appendcommitr   r	   DEPRECIATION_CREATE)r   r   created_depreciationitemsales        r   create_depreciationz'DepreciationService.create_depreciation   s]     !D"))$8D ''-  	S(2N2NOOs   A0A2depreciation_get_idc                    K   t        j                  || j                        }t        j                  j                  |      S wr   )r   get_depreciation_datar   r   DepreciationResponsemodel_validate)r   r%   new_get_depreciations      r   get_depreciationz$DepreciationService.get_depreciation   s9     .DDEXZ^ZaZab**99:NOOs   A Agroup_idc                 &  K   | j                   j                  t              j                  t        j                  |k(        j                         }|st        dd      |D cg c]!  }t        j                  j                  |      # c}S c c}w w)Ni  zGet group ID not found)status_codedetail)
r   queryr   filterr,   allr   r   r(   r)   )r   r,   new_get_group_depreciation	get_groups       r   get_group_depreciationz*DepreciationService.get_group_depreciation   su     %)WW]]?%C%J%J?KcKcgoKo%p%t%t%v")C8PQQWqrWq)++::9EWqrrrs   A!B#&B	Bc                 ^  K   t        j                  |j                               }|j                  t	        dt
        j                        S t        j                  |j                  || j                         | j                  j                          t	        dt
        j                        S wNz-1r   r   )r
   r)   
model_dumpdepreciation_idr   r	   DEPRECIATION_UPDATE_NOTr   update_depreciationr   r   DEPRECIATION_UPDATE_SUC)r   r   updated_depreciation_datas      r   update_depreciation_dataz,DepreciationService.update_depreciation_data"   s     $4$C$CGDVDVDX$Y!$44<!x7W7WXX++,E,U,UVoptpwpwxS(2R2RSSs   B+B-depreciation_delete_idc                    K   t        j                  || j                        }|st        dt        j
                        S t        dt        j                        S wr7   )r   delete_depreciation_datar   r   r	   r:   DEPRECIATION_DELETE_SUC)r   r?   deleted_depreciations      r   delete_depreciationz'DepreciationService.delete_depreciation*   sJ     .GGH^_c_f_fg#!x7W7WXXS(2R2RSSs   AAN)__name__
__module____qualname__r   r   r   r   r   DepreciationCreater$   intr+   r5   DepreciationUpdater>   rD    r   r   r   r      sm    ' )9 PV5N5N0O PP PsC sTV5N5N TTs Tr   r   N)typingr   fastapir   
sqlalchemyr   sqlalchemy.ormr   app.api.depreciationr   app.dependency.authanticationr   app.locale.messagesr	   app.models.main.depreciationr
   r   app.utils.schemas_utilsr   r   rK   r   r   <module>rU      s,     !  " ' : ( J 2#T #Tr   