
    &0i                         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mZ d d
lmZ  G d d      Zy)    )List)HTTPException)func)Session)schema)JWTPayloadSchema)Messages)DepreciationBaseTblDepreciation)remove_external_linkssafe_load_workbook)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ej                     fd
Zde
fdZy)DepreciationServicedbtokenc                      || _         || _        y N)r   r   )selfr   r   s      C/var/www/html/retail-simulation-api/app/api/depreciation/service.py__init__zDepreciationService.__init__   s    
    requestc                   K   g }|D ]3  }t        j                  || j                        }|j                  |       5 | j                  j	                          d}d}t        ||      }t        |       |j                  |       |d   }j                  |d<   |d   }	|j                  |	d<   |j                  |       |j                          t        d|       t        dt        j                        S w)	N;uploaded_files/Simulation_Test_file_clean_final_output.xlsx+files/Simulation_Test_file_clean_final.xlsxAssu Sum Mod AI27Assu Sum Mod B"   ✅ Excel updated successfully at:1statusmessage)r   creater   appendcommitr   r   savedepreciation_yearscloseprintr   r	   DEPRECIATION_CREATE)
r   r   created_depreciationitemsaleOUTPUT_PATH
EXCEL_PATHworkbooksheet_asheet_bs
             r   create_depreciationz'DepreciationService.create_depreciation   s     !D"))$8D ''-  	SB
%k:>h'k"+,00+,00k"2K@S(2N2NOOs   C1C3depreciation_get_idc                    K   t        j                  || j                        }t        j                  j                  |      S wr   )r   get_depreciation_datar   r   DepreciationResponsemodel_validate)r   r6   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   r9   r:   )r   r=   new_get_group_depreciation	get_groups       r   get_group_depreciationz*DepreciationService.get_group_depreciation1   su     %)WW]]?%C%J%J?KcKcgoKo%p%t%t%v")C8PQQWqrWq)++::9EWqrrrs   A!B#&B	Bc                 r  K   |D ]y  }t        j                  |j                               }|j                  t	        dt
        j                        c S t        j                  |j                  || j                         { | j                  j                          d}d}t        ||      }t        |       |j                  |       |d   }j                  |d<   |d   }|j                  |d<   |j                  |       |j                          t!        d|       t	        d	t
        j"                        S w)
N-1r"   r   r   r   r   r   r    r!   )r
   r:   
model_dumpdepreciation_idr   r	   DEPRECIATION_UPDATE_NOTr   update_depreciationr   r'   r   r   r(   r)   r*   r+   DEPRECIATION_UPDATE_SUC)	r   r   requpdated_depreciation_datar0   r1   r2   r3   r4   s	            r   update_depreciation_dataz,DepreciationService.update_depreciation_data7   s
    C(8(G(GHX(Y%(88@%T8;[;[\\//0I0Y0YZstxt{t{|	 
 	SB
%k:>h'k"+,//+,//k"2K@S(2R2RSSs   D5D7depreciation_delete_idc                    K   t        j                  || j                        }|st        dt        j
                        S t        dt        j                        S w)NrH   r"   r!   )r   delete_depreciation_datar   r   r	   rK   DEPRECIATION_DELETE_SUC)r   rQ   deleted_depreciations      r   delete_depreciationz'DepreciationService.delete_depreciationL   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   DepreciationCreater5   intr<   rF   DepreciationUpdaterP   rV    r   r   r   r      sr    ' )9 PV5N5N0O P8P PsC sTT&:S:S5T 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.common_utilsr   r   app.utils.schemas_utilsr   r   r]   r   r   <module>rh      s1     !  " ' : ( J L 2DT DTr   