
    .i(                         d dl 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 d d	lmZ d d
lmZ d dlmZ  G d d      Zy)    N)List)load_workbook)Session)schema)RecurringOperatingBaseTblRecurringOperating)remove_external_linkssafe_load_workbook)CustomResponse)Messages)HTTPException)JWTPayloadSchemac                       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ej                     fdZd	e
fd
Zy)RecurringOperatingServicedbtokenc                      || _         || _        y )N)r   r   )selfr   r   s      S/var/www/html/retail-simulation-api/app/api/recurring_operating_expenses/service.py__init__z"RecurringOperatingService.__init__   s    
    requestc                 P  K   g }|D ]3  }t        j                  || j                        }|j                  |       5 | j                  j	                          d}d}t        ||      }t        |       |j                  |       |d   }dddddd	d
d}	d}
|D ]>  }|	j                  |j                        }|s!|j                  ||<   |
|j                  z  }
@ |
|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 OnlineG17G18G19G20G21G22G23zMarketing SpendzWebsite Maintenance CostszCommissions for AggregatorszCommissions for MarketplacezLoss from Returns and ExchangeszLogistics and Delivery	Packagingr   G24#   ✅ Excel updated successfully at: 1statusmessage)r   create_recurring_operatingr   appendcommitr
   r	   savegetexpenses_typepercentage_of__salescloseprintr   r   RECURRING_OPERATING)r   r   created_recurring_operatingitemsaleOUTPUT_PATH
EXCEL_PATHworkbooksheetformat_cell_map
total_costcells               r   r,   z4RecurringOperatingService.create_recurring_operating   s,    &(#D(CCD$''RD'..t4  	SB
%k:>h'k" ./$).+0+0.3%*	
 
D"&&t'9'9:D"77dd777
	  "e 	k"3K=ABS(2N2NOOs   B4D&7A/D&group_idc                    K   t        j                  || j                        }|st        dd      |D cg c]!  }t        j
                  j                  |      # c}S c c}w w)Ni  zGet droup ID not found)status_codedetail)r   get_recurring_operatingr   r   r   RecurringOperatingResponsemodel_validate)r   r@   new_get_recurring_operating	get_groups       r   rD   z1RecurringOperatingService.get_recurring_operatingE   s^     &;&S&ST\^b^e^e&f#*C8PQQ]xy]xPY11@@K]xyyys   4A$&AA$c                   K   |D ]y  }t        j                  |j                               }|j                  t	        dt
        j                        c S t        j                  |j                  || j                         { | j                  j                          | j                  j                         d}d}t        ||      }t        |       |j                  |       |d   }dddd	d
ddd}d}	|D ]>  }
|j                  |
j                         }|s!|
j"                  ||<   |	|
j"                  z  }	@ |	|d<   |j                  |       |j%                          t'        d|        t	        dt
        j(                        S w)N-1r)   r   r   r   r   r   r   r    r!   r"   r#   r$   r   r&   r'   r(   )r   rF   
model_dumprecurring_idr   r   RECURRING_OPERATING_NOTr   update_recurring_operatingr   r.   refreshr
   r	   r/   r0   r1   r2   r3   r4   RECURRING_OPERATING_UPDATE)r   r   requpdated_recurring_operatingr9   r:   r;   r<   r=   r>   r7   r?   s               r   update_recurring_operating1z5RecurringOperatingService.update_recurring_operating1K   s    C*@*O*OPSP^P^P`*a'*77?%T8;[;[\\!<<=X=e=e  hC  EI  EL  EL  M	 
 	34SB
%k:>h'k" ./$).+0+0.3%*	
 
D"&&t'9'9:D"77dd777
	  "e 	k"3K=ABS(2U2UVVs   DFA/FrL   c                    K   t        j                  || j                        }|st        dt        j
                        S t        dt        j                        S w)NrJ   r)   r(   )r   delete_recurring_operatingr   r   r   rM   RECURRING_OPERATING_DELETE)r   rL   deleted_recurring_operatings      r   rU   z4RecurringOperatingService.delete_recurring_operating   sJ     &;&V&VWceielel&m#*!x7W7WXXS(2U2UVVs   AAN)__name__
__module____qualname__r   r   r   r   r   RecurringOperatingCreater,   intrD   RecurringOperatingUpdaterS   rU    r   r   r   r      sf    ' )9 1PtF<[<[7\ 1PfzS z6WV=\=\8] 6WpWC Wr   r   )ostypingr   openpyxlr   sqlalchemy.ormr   $app.api.recurring_operating_expensesr   ,app.models.main.recurring_operating_expensesr   r   app.utils.common_utilsr	   r
   app.utils.schemas_utilsr   app.locale.messagesr   fastapir   app.dependency.authanticationr   r   r^   r   r   <module>rj      s4    	  " " 7 f L 2 ( ! :zW zWr   