
    gh/                        d dl Zd dlmZmZ d dlmZmZmZ d dl	Z	d dl
m
Z
 d dlZ G d d      Zedk(  rR e       Z ed       ej                   D ]  Zej%                  e         ed	        ed
        ed        ed       yy)    N)load_workbookWorkbook)PatternFillFont	Alignment)datetimec                   "    e Zd Zd ZddZddZy)SrikaraConsolidatedReportc                     t        dd      | _        t        dd      | _        t	        dd      | _        g d	| _        y )
N1274bdsolid)fgColor	fill_typeFFFFFFT)colorboldcenter)
horizontalvertical)zSRIKARA MAINzSRIKARA BRANCH 1zSRIKARA BRANCH 2zSRIKARA BRANCH 3zSRIKARA BRANCH 4zSRIKARA BRANCH 5zSRIKARA BRANCH 6)r   header_fillr   header_fontr   	alignment	locations)selfs    SrikaraConsolidatedReport.py__init__z"SrikaraConsolidatedReport.__init__	   s7    &x7KhT:"hJ
    Nc           	      0   |'dt        j                         j                  d       d}t        d       t	        j                  t
        j                  j                  |d            }|st        d|        yg }|D ]  }	 t        |      }d|j                  v r|d   }g }g }	|j                  d	d	d
      D ]  }
t        |
      }	 n |j                  dd
      D ]+  }
|
d   s	|
d   dk7  s|j                  t        |
             - |rJt        j                  ||	      }t
        j                  j                  |      |d<   |j                  |       |j!                           |st        d       yt        j$                  |d
      }t'               }|j(                  }d|_        t        |j,                        }	t/        |	d	      D ]L  \  }}|j1                  d	||      }| j2                  |_        | j6                  |_        | j:                  |_        N t/        |j=                         d      D ]  \  }\  }}t/        |	d	      D ]  \  }}||   }t?        |t@              r&|jC                  d      r|j1                  |||       At?        |tD        tF        f      rd|v r|j1                  ||d|d       t|j1                  |||         |jI                  d      }|j,                  D cg c]  }d|v sd|v sd|v sd|v s	d|v sd |v s| }}d!|j,                  v r1|jK                  d!      |   jM                         jO                         }n<t        j                  ||   jM                         g|      }|jQ                  dd!d"       t        |j,                        }t/        |d	      D ]L  \  }}|j1                  d	||      }| j2                  |_        | j6                  |_        | j:                  |_        N t/        |j=                         d      D ]i  \  }\  }}t/        |d	      D ]R  \  }}||   }t?        |tD        tF        f      r|d	kD  r|j1                  ||d|d       ?|j1                  |||       T k tS        |      d#z   }|j1                  |d	d$       tU        d
%      |j1                  |d	&      _        tW        dtS        |      d	z         D ]c  }|j1                  d	|&      jX                  }d'| d(| |d	z
   d)}|j1                  |||       tU        d
%      |j1                  ||&      _        e |j[                  |       t        d*|        |S # t"        $ r}t        d| d|        Y d}~d}~ww xY wc c}w )+zFCompile all 7 locations settlement reports into one consolidated sheetN#Srikara_All_Locations_Consolidated_z%Y%m%d_%H%M%Sz.xlsxz-Compiling all locations settlement reports...z*Settlement_Comparison*.xlsxz(No settlement comparison files found in zConsolidated Report   T)min_rowmax_rowvalues_only   )r!   r#   r   TOTAL)columnsSource_FilezError processing file : z#No data found in settlement reports)ignore_indexzAll Locations Consolidatedrowcolumnvalue   ₹Amount,.2fSummaryVarianceMDRGSTEMI
CommissionLocationzAll Locations   zGRAND TOTALr   )r+   r,   z=SUM(z2:)z,All locations consolidated report saved to: ).r   nowstrftimeprintglobospathjoinr   
sheetnames	iter_rowslistappendpd	DataFramebasenameclose	Exceptionconcatr   activetitler&   	enumeratecellr   fillr   fontr   iterrows
isinstancestr
startswithintfloatcreate_sheetgroupbysumreset_indexinsertlenr   rangecolumn_lettersave)r   reports_folderoutput_filesettlement_filesconsolidated_data	file_pathworkbookwsdataheadersr+   dfeall_datawbcol_numheaderrO   row_num_row_datar-   
summary_wscolnumeric_columnslocation_summarysummary_headersgrand_total_row
col_lettertotal_formulas                                 r   compile_all_locations_reportz6SrikaraConsolidatedReport.compile_all_locations_report   s    ?@W@WXg@h?iinoK=>  99RWW\\.B`%ab<^<LMN * !	I (3(H,?,??!"78B D G  "||Aqd|S "&s)
  "||A4|H 3q6c!f&7 KKS	23
 \\$@,.GG,<,<Y,G=))004 ;!	F !78 99.TB ZYY/ x''((!4 	,OGV77q7?D((DI((DI!^^DN		, '00A0A0CQ&G 
	F"G]a#,Wa#8 	F ( eS)e.>.>u.EGGuGEU|4V9KGGU4L?QGRGGuGE	F
	F __Y/
 +3*:*:  k3h#oQ[_bQbfkorfrv{  @C  wC  GL  PS  GS  Wc  gj  Wj3  k  k )))'//
;OLPPR^^`  "||Xo-F-J-J-L,MWfg##Az?C /778(!< 	,OGV??q?GD((DI((DI!^^DN		, '00@0I0I0KQ&O 	N"G]a#,_a#@ N (ec5\2w{OOUSWLGYOZOOuOMN	N ./!3OA]K>Bo
OA6; QO 4q 89 	XG#Qw?MMJ#J<r*oa>O=PPQRMOO}OUHLRVJOOO@E		X 	<[MJKk  .ykA3?@R ks2   A"U+$U+-A8U+3VV+	V4VVc           	          |d|j                  dd       d}t               }|j                  }| d|_        g d}t	        |d      D ]L  \  }}|j                  d||      }| j                  |_        | j                  |_	        | j                  |_
        N g d	g d
g dg dg}	t	        |	d      D ]h  \  }
}t	        |d      D ]T  \  }}t        |t        t        f      r%|dkD  r |j                  |
||dkD  rd|dnd       A|j                  |
||       V j |j                  d      }g ddd|z   dddddddddddddd d!d"d#d$d%d&d'dd(d)d*d+dd,d-d.d/d0}t	        |d      D ]T  \  }
}|j                  |
d|      }|
dk(  rt        d1d23      |_	        2|j!                  d4      sDt        d15      |_	        V |j#                  |       t%        d6| d7|        |S )8z=Create a template for location-specific settlement comparisonSrikara_ rq   z_Settlement_Template.xlsxz Settlement)DatezPayment Group NamezHIMS Collection AmountzHIMS Transaction CountzBank Gross AmountzBank Net AmountzBank MDRzBank GSTzBank EMIzPaytm AmountzPaytm Net AmountzPaytm Commissionz	Paytm GSTzSettlement VarianceRemarksr    r*   )
2024-01-01CardP  d   r   it  i  i,  r   r   r   r   r   r   Sample data)r   Online0u     r   r   r   r   r   r   ir  i  r   r   r   )
2024-01-02r   `  x   r   iX  i  ih  r   r   r   r   r   r   r   )r   r   @     r   r   r   r   r   r   i   iX  r   r   r   r$   r   r.   r0   Instructionsz3SRIKARA SETTLEMENT COMPARISON REPORT - INSTRUCTIONS zThis template is for location: DATA SOURCES:zG1. HIMS Collection Report - Summary of transactions from billing systemz=2. Bank Settlement Report - For Card transactions (Axis Bank)z83. Paytm Settlement Report - For Online/UPI transactionsCOLUMN DESCRIPTIONS:z- Date: Settlement datez-- Payment Group Name: Card, Online, or Othersz9- HIMS Collection Amount: Amount from HIMS billing systemz0- HIMS Transaction Count: Number of transactionsz6- Bank Gross Amount: Total amount from bank settlementz7- Bank Net Amount: Amount after deducting MDR, GST, EMIz2- Bank MDR: Merchant Discount Rate charged by bankz:- Bank GST: GST on MDR (sum of IGST+SGST+CGST if separate)z0- Bank EMI: EMI processing charges if applicablez2- Paytm Amount: Gross amount from Paytm settlementz=- Paytm Net Amount: Amount after deducting commission and GSTz/- Paytm Commission: Commission charged by Paytmz- Paytm GST: GST on commissionzE- Settlement Variance: Difference between HIMS and settlement amounts	FORMULAS:zDBank Net Amount = Bank Gross Amount - Bank MDR - Bank GST - Bank EMIz>Paytm Net Amount = Paytm Amount - Paytm Commission - Paytm GSTz9Settlement Variance = HIMS Amount - Settlement Net AmountUSAGE:z91. Replace sample data with actual data from your reportsz%2. Ensure date formats are consistentzT3. Use the SrikaraSettlementComparisonReport.py script to generate automated reportszC4. Use SrikaraConsolidatedReport.py to combine all location reportsT   )r   size)r   r   r   r   r9   zTemplate created for r(   )replacer   rL   rM   rN   rO   r   rP   r   rQ   r   rS   rV   rW   rX   r   rU   r`   r=   )r   location_nametemplate_filerm   rg   ri   rn   ro   rO   sample_datarp   rr   r-   instructions_wsinstructionsinstructions                   r   !create_location_specific_templatez;SrikaraConsolidatedReport.create_location_specific_template   s\     &}'<'<S#'F&GG`aMZYY#_K0
  )!4 	,OGV77q7?D((DI((DI!^^DN		, iihi	
 "+;!: 	FGX"+Ha"8 Fec5\2w{GGUZ]^U^U4L?QdeGfGGuGE	F	F //.9$
A$
$
 .=$
 	$

 $
 V$
 L$
 G$
 $
 #$
 &$
 <$
 H$
 ?$
 E$
  F!$
" A#$
$ I%$
& ?'$
( A)$
* L+$
, >-$
. -/$
0 T1$
2 3$
4 5$
6 S7$
8 M9$
: H;$
< =$
> ?$
@ HA$
B 4C$
D cE$
F RG$
L %.lA$> 	, G["''GA['QD!| d4	''(hi dO		, 	%m_B}oFGr   )N)__name__
__module____qualname__r   r{   r    r   r   r
   r
      s    
 FPZr   r
   __main__z)Creating templates for all 7 locations...zSetup complete!z-Templates created for all 7 Srikara locationsz1Use these templates to enter your settlement dataz@Then run the compilation script to generate consolidated reports)pandasrF   openpyxlr   r   openpyxl.stylesr   r   r   r?   r   r>   r
   r   consolidatorr=   r   locationr   r   r   r   <module>r      s     , 8 8 	  s sl z,.L 

56 ** A66x@A 

	
9:	
=>	
LM r   