
    ~
i                       d dl mZ d dlmZmZmZ d dlmZ d dlm	Z	 d dl
mZ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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& d dl'm(Z( d dl)m*Z* d dl+m,Z, d dl-m.Z. d dl/m0Z0 d dl1m2Z2 d dl3m4Z4 d dl5m6Z6 d dl7m8Z8 d dl9m:Z: d dl;m<Z< d dl=m>Z> d dl?m@Z@ d dlAmBZB d dlCmDZD d d lEmFZF d d!lGmHZH d"d#lImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZbmcZcmdZdmeZemfZfmgZgmhZhmiZimjZjmkZkmlZlmmZmmnZnmoZompZp d$eqd%erfd&Zs G d' d(      Zt G d) d*      Zu G d+ d,      Zv G d- d.      Zw G d/ d0      Zx G d1 d2      Zyy3)4    )Session)ListDictAnyBytesIOA4SimpleDocTemplate	ParagraphSpacerTable
TableStyle)getSampleStyleSheetParagraphStyleinchcolors)TblBrand)
TblSegment)TblStoreFormat)TblCivil)TblDisplayRackingUnit)TblCarpentry)TblElectricalCabling)TblCommercialEquipment)TblDisplayBoard)TblInfoTech)TblVisualMerchElements)TblPlumbing)TblDepreciation)TblCatchmentPotential)TblCompetitorIntensity)TblLocationDetails)TblSalesEstimate)TblRentExpenses)TblLocationSpillageFactor)TblProjectedMarketShare)TblCompetitorBenchmarking)TblCorporateConceptOffice)TblStoreLevelStaffNeeds)
TblUtility)TblOperatingExpenses   )'AdaptingSupplyChainDataBrandReportDataModule3ReportResponseModule4ReportResponseModule7ReportResponseModule9ReportResponseSegmentReportDataStoreFormatReportDataCapitalExpenseReportDataDepreciationReportDataModule1ReportResponseCustomerSegmentEstimateCatchmentPotentialDataCompetitorBenchmarkDataLocationCharacteristicsSalesEstimateDataRentExpenseDataModule2ReportResponseVendorPriorityMatrixDataVendorScorecardDataPrivateLabellingDataCategoryCaptainshipDataModule5ReportResponseModule6ReportDataCompetitorPricingAnalysisStoreFormatPricingCategoryPricingCompetitorPromotionsAnalysisYearlyPromotionCompetitorLoyaltyAnalysisLoyaltyProgramCorporateOfficeRoleDataConceptOfficeRoleDataStoreLevelStaffDataHRPolicyDataUtilityDataUtilitiesFormatDataOperatingExpenseDataModule8ReportResponsegroup_idreturnc                     	 ddl m} g d}|D ]3  }|j                   ||      d| i      }|j                         }|dkD  s3 y y# t        $ r Y yw xY w)z$Check if group_id exists in databaser   )text)z9SELECT COUNT(*) FROM tbl_brand WHERE group_id = :group_idz;SELECT COUNT(*) FROM tbl_segment WHERE group_id = :group_idzBSELECT COUNT(*) FROM tbl_sales_estimate WHERE group_id = :group_idrX   TF)
sqlalchemyr[   executescalar	Exception)rX   dbr[   tables_to_checkqueryresultcounts          E/var/www/html/retail-simulation-api/app/api/module_reports/service.pyvalidate_group_idrf   1   sb    #
 %EZZUj(-CDFMMOEqy	 %  s   >A A A 	AAc                       e Zd ZdefdZdedefdZdedee	   fdZ
dedeeef   fdZdededefd	Zdedefd
ZdedefdZdedefdZdedefdZy)Module1ReportServicer`   c                     || _         y Nr`   selfr`   s     re   __init__zModule1ReportService.__init__I   	        rX   rY   c                 "   | j                   j                  t              j                  t        j                  |k(        j                         }|st        dd      S t        |j                  xs d|j                  |j                  xs d      S )z#Get brand information for the groupNot SetNot provided)
brand_name	rationale)rt   
brand_logoru   )
r`   rb   r   filterrX   firstr2   rt   brand_imageru   )rm   rX   brands      re   get_brand_dataz#Module1ReportService.get_brand_dataL   ss    h'..x/@/@H/LMSSU"i>RR''49((oo7
 	
rp   c                    | j                   j                  t              j                  t        j                  |k(        j                         }g }|D ]t  }|j                  t        |j                  |j                  |j                  |j                  |j                  |j                  |j                  |j                               v |S )z#Get consumer segments for the group)nameisec_segmentchief_wage_earner_occupationhighest_educated_malehighest_educated_femalelocationtotal_populationother_details)r`   rb   r   rw   rX   allappendr7   r}   ISEC_Segmentr   r   r   r   r   r   )rm   rX   segmentssegment_datasegments        re   get_segments_dataz&Module1ReportService.get_segments_dataX   s    77==,33J4G4G84STXXZG 1\\$11-4-Q-Q&-&C&C(/(G(G ))!(!9!9%33	! 	   rp   c                    | j                   j                  t              j                  t        j                  |k(        j                         }d}d}|D ]  }t        |j                  |j                  |j                  |j                  |j                  |j                  |j                  |j                        }|j                  dk(  r|}x|j                  dk(  s|} |st        dddddd      }|st        dddddd      }||fS )z&Get store format data for both formatsN)
store_name
store_sizemerchandiser   additional_location_parametersservice_parameterstechnology_adoptionother_parametersStore Format AStore Format Brr           )r   r   r   r   r   r   )r`   rb   r   rw   rX   r   r8   r   r   r   r   r   r   r   r   store_format_type)rm   rX   store_formatsformat_aformat_bstore_formatdatas          re   get_store_formats_dataz+Module1ReportService.get_store_formats_datak   s   n5<<^=T=TX`=`aeeg)L )'22'22(44%../;/Z/Z#/#B#B$0$D$D!-!>!>
D --1AA//3CC+ *0 ,$)##,)H ,$)##,)H !!rp   r   c                 
   t               }| j                  j                  t              j	                  t        j
                  |k(  t        j                  |k(        j                         }t        d |D              |_	        | j                  j                  t              j	                  t        j
                  |k(  t        j                  |k(        j                         }t        d |D              |_        | j                  j                  t              j	                  t        j
                  |k(  t        j                  |k(        j                         }t        d |D              |_        	 | j                  j                  t              j	                  t        j
                  |k(  t        j                  |k(        j                         }t        d |D              |_        	 | j                  j                  t               j	                  t         j
                  |k(  t         j                  |k(        j                         }t        d |D              |_        	 | j                  j                  t$              j	                  t$        j
                  |k(  t$        j&                  |j)                  dd      k(        j                         }	t        d	 |	D              |_        	 | j                  j                  t,              j	                  t,        j
                  |k(  t,        j                  |k(        j                         }
t        d
 |
D              |_        	 | j                  j                  t0              j	                  t0        j
                  |k(        j                         }t        d |D              dz  |_        	 | j                  j                  t4              j	                  t4        j
                  |k(        j                         }t        d |D              dz  |_        |j                  |j                  z   |j                  z   |j                  z   |j"                  z   |j*                  z   |j.                  z   |j2                  z   |j6                  z   |j8                  z   |_        |S #  d|_        Y xY w#  d|_        Y qxY w#  d|_        Y xY w#  d|_        Y xY w#  d|_        Y 8xY w#  d|_        Y xY w)z6Calculate capital expenses for a specific store formatc              3      K   | ]7  }|j                   s|j                  s|j                   |j                  z   9 y wrj   )rate_per_sqft
total_sqft.0items     re   	<genexpr>zBModule1ReportService.calculate_capital_expenses.<locals>.<genexpr>   s?       "JS^4bfbtbty}  zI  zI$"4"4t"FS^   ???c              3      K   | ]7  }|j                   s|j                  s|j                   |j                  z   9 y wrj   number_of_unitscost_per_unitr   s     re   r   zBModule1ReportService.calculate_capital_expenses.<locals>.<genexpr>   sN       -acp[_tx  uI  uI  NR  N`  N`T-A-ADDVDV-Vcpr   c              3      K   | ]7  }|j                   s|j                  s|j                   |j                  z   9 y wrj   r   r   s     re   r   zBModule1ReportService.calculate_capital_expenses.<locals>.<genexpr>   sN       +aapY]tx  uI  uI  NR  N`  N`4+?+?$BTBT+Tapr   c              3   b   K   | ]'  }t        |d d      xs dt        |dd      xs dz    ) yw)havs_rate_unitr   	rate_unitNgetattrr   s     re   r   zBModule1ReportService.calculate_capital_expenses.<locals>.<genexpr>   sK       .]  L\  DHwt=Mq/Q/VUV[bcgitvw[x[}|}.~  L\s   -/r   c              3   >   K   | ]  }t        |d d      xs d  ywtotalr   Nr   r   s     re   r   zBModule1ReportService.calculate_capital_expenses.<locals>.<genexpr>   s%     /k[jSWgq0I0NQ0N[j   FormatFormatec              3   >   K   | ]  }t        |d d      xs d  ywr   r   r   s     re   r   zBModule1ReportService.calculate_capital_expenses.<locals>.<genexpr>   s%     1k]jUY'$2K2Pq2P]jr   c              3   >   K   | ]  }t        |d d      xs d  ywr   r   r   s     re   r   zBModule1ReportService.calculate_capital_expenses.<locals>.<genexpr>   s%     1f]eUY'$2K2Pq2P]er   c              3   >   K   | ]  }t        |d d      xs d  ywr   r   r   s     re   r   zBModule1ReportService.calculate_capital_expenses.<locals>.<genexpr>   s%     /d[cSWgq0I0NQ0N[cr      c              3   >   K   | ]  }t        |d d      xs d  ywr   r   r   s     re   r   zBModule1ReportService.calculate_capital_expenses.<locals>.<genexpr>   s"     #^~tGD'1$=$B$B~r   )r9   r`   rb   r   rw   rX   r   r   sum
civil_workr   racking_display_unitsr   carpentry_furniturer   electrical_cablingr   commercial_equipmentr   store_formate_typereplacesignage_display_boardsr    information_technologyr!   visual_merchandisingr"   plumbingothersr   )rm   rX   r   expensescivil_itemsracking_itemscarpentry_itemselectrical_itemsequipment_itemsdisplay_itemsit_itemsvm_itemsplumbing_itemss                re   calculate_capital_expensesz/Module1ReportService.calculate_capital_expenses   s   +- ggmmH-44)&&*;;
 #% 	 "  "JS^  "J  J &;<CC!**h6!337HH
 #% 	 *-  -acp  -a  *a& ''--5<<!!X-**.??
 #% 	 (+  +aap  +a  (a$	.#ww}}-ABII$--9$66:KK  ce  +.  .]  L\  .]  +]H'
	0"ggmm,BCJJ&//8;&88<MM ce  -0/k[j/k,kH)
	2 GGMM/:AA((H4226G6O6OPXZc6dd ce  /21k]j1k.kH+
	2ww}}[188$$0--1BB ce  /21f]e1f.fH+
	0ww}}%;<CC&//8;ce  -0/d[c/d,dgh,hH)
	$!WW]];7>>$$0ce  !$#^~#^ ^ab bH ("@"@@(()+3+F+FG))*,4,K,KL ++, /7.K.KL 	 !)	0 	 y	.*-H'	0,/H)	2.1H+	2.1H+	0,/H)	$ #HsN   .A6R1 %A6S  BS #A6S A'S- A'S< 1	R= 	S	S	S*-	S9<	Tc           	         | j                   j                  t              j                  t        j                  |k(        j                         }|st        dd      S t        t        |dd      t        |dd      t        |dd            S )	zGet depreciation informationzStraight Line Method
   )depreciation_methoddepreciation_yearsr   r   other_methodsN)r   r   r   )r`   rb   r#   rw   rX   rx   r:   r   )rm   rX   depreciations      re   get_depreciation_dataz*Module1ReportService.get_depreciation_data   s    ww}}_5<<_=U=UYa=abhhj)$:#% 
 & '6KMc d&|5I2N!,F
 	
rp   c           	      P   ddl m} t        || j                        s |dd| d      | j	                  |      }| j                  |      }| j                  |      \  }}| j                  |d      }| j                  |d      }| j                  |      }	t        |||||||		      S )
z!Generate complete Module 1 reportr   HTTPException  	Group ID  not found in databasestatus_codedetailr   r   )brand_detailsconsumer_segmentsstore_format_astore_format_bcapital_expenses_format_acapital_expenses_format_br   )
fastapir   rf   r`   r{   r   r   r   r   r;   )
rm   rX   r   
brand_datasegments_datar   r   capital_expenses_acapital_expenses_bdepreciation_datas
             re   generate_module1_reportz,Module1ReportService.generate_module1_report  s    ) !4773C)H:Mc8dee ((2
..x8!88B(!<<XGWX!<<XGWX 66x@$$+##&8&8*
 	
rp   c                    ddl m} t        || j                        s |dd| d      | j	                  |      }t               }t        |t        dddd      }t               }g }t        d	|d
   dddd      }|j                  t        d|             |j                  t        dd             t        d|d   ddd      }	|j                  t        d|	             |j                  t        dd             |j                  t        d|j                  j                   |d                |j                  j                  r5|j                  t        d|j                  j                   |d                |j                  t        d|j                  j                   xs d |d                |j                  t        dd             |j                  t        d|	             |j                  t        dd             t#        |j$                  d      D ]V  \  }
}|j                  t        d|
 d|j&                   d|d                |j                  t        d |j(                   |d                |j                  t        d!|j*                   |d                |j                  t        d"|j,                   |d                |j                  t        d#|j.                   |d                |j                  t        d$|j0                   |d                |j                  t        d%|j2                  xs d& |d                |j                  t        dd'             Y |j                  t        d(|	             |j                  t        dd             |j                  t        d)|j4                  j6                   d|d                |j                  t        d*|j4                  j8                   |d                |j                  t        d+|j4                  j:                   |d                |j                  t        d,|j4                  j<                   |d                |j                  t        d$|j4                  j0                   |d                |j4                  j>                  r5|j                  t        d-|j4                  j>                   |d                |j                  t        d.|j4                  j@                   |d                |j                  t        d/|j4                  jB                   |d                |j4                  jD                  r5|j                  t        d0|j4                  jD                   |d                |j                  t        dd'             |j                  t        d1|jF                  j6                   d|d                |j                  t        d*|jF                  j8                   |d                |j                  t        d+|jF                  j:                   |d                |j                  t        d,|jF                  j<                   |d                |j                  t        d$|jF                  j0                   |d                |jF                  j>                  r5|j                  t        d-|jF                  j>                   |d                |j                  t        d.|jF                  j@                   |d                |j                  t        d/|jF                  jB                   |d                |jF                  jD                  r5|j                  t        d0|jF                  jD                   |d                |j                  t        dd             |j                  t        d2|	             |j                  t        dd             |j                  t        d3|d                |jH                  }t        d4|d         t        d5|jJ                  d6|d         gt        d7|d         t        d5|jL                  d6|d         gt        d8|d         t        d5|jN                  d6|d         gt        d9|d         t        d5|jP                  d6|d         gt        d:|d         t        d5|jR                  d6|d         gt        d;|d         t        d5|jT                  d6|d         gt        d<|d         t        d5|jV                  d6|d         gt        d=|d         t        d5|jX                  d6|d         gt        d>|d         t        d5|jZ                  d6|d         gt        d?|d         t        d5|j\                  d6|d         gt        d@|d         t        dA|j^                  d6d|d         gg}ta        |dBtb        z  dCtb        z  gD      }|je                  tg        dEdFdGdHdIth        jj                  fdJdKdIdLth        jl                  fdMdNdOdPdQg	             |j                  |       |j                  t        dd'             |j                  t        dR|d                |jn                  }t        d4|d         t        d5|jJ                  d6|d         gt        d7|d         t        d5|jL                  d6|d         gt        d8|d         t        d5|jN                  d6|d         gt        d9|d         t        d5|jP                  d6|d         gt        d:|d         t        d5|jR                  d6|d         gt        d;|d         t        d5|jT                  d6|d         gt        d<|d         t        d5|jV                  d6|d         gt        d=|d         t        d5|jX                  d6|d         gt        d>|d         t        d5|jZ                  d6|d         gt        d?|d         t        d5|j\                  d6|d         gt        dS|d         t        dA|j^                  d6d|d         gg}ta        |dBtb        z  dCtb        z  gD      }|je                  tg        dEdFdGdHdIth        jj                  fdJdKdIdLth        jl                  fdMdNdOdPdQg	             |j                  |       |j                  t        dd             |j                  t        dT|	             |j                  t        dd             t        dT|d         t        |jp                  jr                  |d         gt        dU|d         t        tu        |jp                  jv                        |d         gg}ta        |dBtb        z  dCtb        z  gD      }|je                  tg        dEdFdJdKdIdLth        jl                  fdMdNdOdPdQg             |j                  |       |jy                  |       |j{                  d       |S )Vz4Generate PDF report for Module 1 in specified formatr   r   r   r   r   r   2   pagesize
leftMarginrightMargin	topMarginbottomMarginCustomTitleHeading1      r0   Helvetica-Bold)parentfontSize
spaceAfter	alignmentfontNamez5Module 1: All about your Brand, Customers and Stores!SectionHeaderHeading2   r   )r   r   r   r  zBranding & Store Detailsz<b>Name of the Store:</b> Normalz<b>Logo of the store:</b> z<b>Rationale:</b> rs   z#Consumer Segments & Catchment Sizesz<b>Segment : z</b>z<b>ISEC Segmentation:</b> u+   • <b>Chief Wage Earner's Occupation:</b> u9   • <b>Education of the highest educated male adult:</b> u;   • <b>Education of the highest educated female adult:</b> u   • <b>Location:</b> u   • <b>Catchment Size:</b> Not specified   zStore Format Detailsz<b>Store Format A: u$   • <b>Store Size (in sq. ft.):</b> u   • <b>Merchandise:</b> u   • <b>Pricing Strategy:</b> u+   • <b>Additional Location Parameters:</b> u   • <b>Service Parameters:</b> u    • <b>Technology Adoption:</b> u   • <b>Other Parameters:</b> z<b>Store Format B: zCapital Expensesz<b>Store Format A</b>z
Civil WorkRs. ,.2fzRacking and Display UnitszCarpentry and FurniturezElectrical and CablingzCommercial EquipmentzSignage and Display BoardszInformation TechnologyzVisual MerchandisingPlumbingOthersz<b>Total</b>z<b>Rs.    r   	colWidthsALIGNr   r   r  LEFTVALIGNr  r  TOP
BACKGROUNDr   r  r  GRIDr        ?WORDWRAPr  r  TLEFTPADDINGr  r     RIGHTPADDINGr  r  r"  
TOPPADDINGr  r  r"  BOTTOMPADDINGr  r  r"  z<b>Store Format B</b>z<b>Total Investments</b>zDepreciation MethodzDepreciation Years (in Years))>r   r   rf   r`   r   r   r   r
   r   r   r   r   r   r   rt   rv   ru   	enumerater   r}   r~   r   r   r   r   r   r   r   r   r   pricing_strategyr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   setStyler   r   	lightgreyblackr   r   r   strr   buildseek)rm   rX   r   report_databufferdocstylesstorytitle_stylesection_styleir   capex_acapex_a_datacapex_a_tablecapex_bcapex_b_datacapex_b_tabler   depreciation_tables                       re   generate_pdf_reportz(Module1ReportService.generate_pdf_report&  s~   ) !4773C)H:Mc8dee228<PR^`oqr$& %*%%
 	YVXcdeVAr]# '*%%
 	Y9=IJVAr]# 	Y!;K<U<U<`<`;abdjksdtuv$$//LL%?@Y@Y@d@d?e#fhnowhxyzY!3K4M4M4W4W4i[i3jkmst|m}~VAr]# 	YDmTUVAr]##K$A$A1EJAwLL[2gll^4#H&QYJZ[\LL%?@T@T?U#VX^_gXhijLL%PQXQuQuPv#wy  AI  zJ  K  LLL%^_f_|_|^}#~  AG  HP  AQ  R  SLL%`ah  bA  bA  aB  $C  EK  LT  EU  V  WLL%:7;K;K:L#MvV^O_`aLL%@AYAYAl]l@m#npvw  qA  B  CLL2' F 	Y5}EFVAr]# 	Y!4[5O5O5Z5Z4[[_`bhiqbrstY!EkF`F`FkFkElmouv~o  A  	BY!9+:T:T:`:`9abdjksdtuvY!>{?Y?Y?j?j>klntu}n~  	AY!6{7Q7Q7Z7Z6[\^dem^nop%%DDLL%PQ\QkQk  RK  RK  QL  $M  OU  V^  O_  `  aY!@A[A[AnAn@oprx  zB  sC  D  	EY!A+B\B\BpBpAqrtz  |D  uE  F  	G%%66LL%B;C]C]CnCnBo#prx  zB  sC  D  EVAr]# 	Y!4[5O5O5Z5Z4[[_`bhiqbrstY!EkF`F`FkFkElmouv~o  A  	BY!9+:T:T:`:`9abdjksdtuvY!>{?Y?Y?j?j>klntu}n~  	AY!6{7Q7Q7Z7Z6[\^dem^nop%%DDLL%PQ\QkQk  RK  RK  QL  $M  OU  V^  O_  `  aY!@A[A[AnAn@oprx  zB  sC  D  	EY!A+B\B\BpBpAqrtz  |D  uE  F  	G%%66LL%B;C]C]CnCnBo#prx  zB  sC  D  EVAr]# 	Y1=ABVAr]# 	Y6x8HIJ77|VH%56	DI[I[\`HaBbdjksdt8uv2F84DEySWX_XuXuvzW{Q|  E  FN  O  HP  Q0&2BCYQUV]VqVqrvUwOx  {A  BJ  {K  FL  M/1ABIPTU\UoUoptTuNvx~  @H  yI  EJ  K-vh/?@)dSZSoSoptRuLvx~  @H  yI  CJ  K3VH5EF	TXY`YwYwx|X}R~  AG  HP  AQ  IR  S/1ABIPTU\UsUstxTyNz  }C  DL  }M  EN  O-vh/?@)dSZSoSoptRuLvx~  @H  yI  CJ  Kz6(#34i$wGWGWX\F]@^`fgo`p6qrx!12IW^^TXDY>Z\bck\l4mn~vh'78)ggmm\`MaaeDfhnowhx:yz
 lqvqv6FGz//7Hf.>.>?VXsFLL9001/2
+
 
  
	 	]#VAr]# 	Y6x8HIJ77|VH%56	DI[I[\`HaBbdjksdt8uv2F84DEySWX_XuXuvzW{Q|  E  FN  O  HP  Q0&2BCYQUV]VqVqrvUwOx  {A  BJ  {K  FL  M/1ABIPTU\UoUoptTuNvx~  @H  yI  EJ  K-vh/?@)dSZSoSoptRuLvx~  @H  yI  CJ  K3VH5EF	TXY`YwYwx|X}R~  AG  HP  AQ  IR  S/1ABIPTU\UsUstxTyNz  }C  DL  }M  EN  O-vh/?@)dSZSoSoptRuLvx~  @H  yI  CJ  Kz6(#34i$wGWGWX\F]@^`fgo`p6qrx!12IW^^TXDY>Z\bck\l4mn16(3CDiRYZaZgZghlYmmqPrtz  |D  uE  GF  G
 lqvqv6FGz//7Hf.>.>?VXsFLL9001/2
+
 
  
	 	]#VAr]# 	Y4mDEVAr]# ,fX.>?;KcKcKwKwy  AI  zJ  BK  L6x8HI9UXYdYqYq  ZE  ZE  VF  HN  OW  HX  LY  Z

 ##444@PQ##J//VXsFLL9001/2	0
 	% 		 	'(		%Arp   c                     ddl m} t        || j                        s |dd| d      	 d }| j	                  |      }| j                  |      }| j                  |      \  }}| j                  |d      }| j                  |d	      }	| j                  |      }
t        d
|j                   d|j                         t        d ||j                         d       t        |      dkD  r|d   nd}t        |      dkD  r|d   nd}g }|j                  d       |j                  d       |j                  d       |j                  d       |j                  d       |j                  d       |j                  d       |j                  d       |j                  d       |j                  d       |j                  d       |j                  d       |j                  d       |j                  d       |j                  d       |j                  d       |j                  d        |j                  d!       |j                  d"       |j                  d#       |j                  d$       |j                  d%       |j                  d&       |j                  d'       |j                  d(       |j                  d)       |j                  d*       d+j                  |      }|S # t        $ r}t        d,t        |             d}~ww xY w)-z<Generate HTML report for Module 1 matching exact user formatr   r   r   r   r   r   c                     | yt        |       }g d}|D ]  }|j                  |d      } |j                         }	 t        |      }|dS #  |r|cY S dcY S xY w)Nz0.00)   ■   ▪   •   ♦   ●   ○u   ◦   ‣   ⁃rC  rD  rE  rF  rG  rH  u   ▫rI  rJ   .2f)r.  r   stripfloat)val	clean_strsymbols_to_removesymbolnums        re   clean_valuez>Module1ReportService.generate_html_report.<locals>.clean_value  ss    ;!H	 %~!/F ) 1 1&" =I 0 &OO-	>	*C!#Y'>(19=v=s   A AAr   r   zDEBUG civil_work: 'z' hex: zDEBUG cleaned: ''Nr0   z<!DOCTYPE html>z<html>z<head>z<meta charset="UTF-8">z)<title>Reporting Processes Report</title>z</head>z<body>z!<p><i>Reporting Processes</i></p>z?<p>The following report will be generated from this module.<br>z@<b>Module 1: All about your Brand, Customers and Stores!</b></p>z<p><b>Capital Expenses</b></p>z<p><b>Store Format A</b></p>zF<table border="1" cellspacing="0" cellpadding="3" style="width:100%;">z)<tr><td>Civil Work</td><td>0.00</td></tr>z8<tr><td>Racking and Display Units</td><td>0.00</td></tr>z6<tr><td>Carpentry and Furniture</td><td>0.00</td></tr>z5<tr><td>Electrical and Cabling</td><td>0.00</td></tr>z3<tr><td>Commercial Equipment</td><td>0.00</td></tr>z9<tr><td>Signage and Display Boards</td><td>0.00</td></tr>z5<tr><td>Information Technology</td><td>0.00</td></tr>z3<tr><td>Visual Merchandising</td><td>0.00</td></tr>z'<tr><td>Plumbing</td><td>0.00</td></tr>z%<tr><td>Others</td><td>0.00</td></tr>z+<tr><td><b>Total</b></td><td>0.00</td></tr>z</table>z</body>z</html>
zError generating HTML report: )r   r   rf   r`   r{   r   r   r   r   printr   lenr   joinr_   r.  )rm   rX   r   rT  r   r   r   r   r   r   r   segment1segment2
html_partshtml_contentes                   re   generate_html_reportz)Module1ReportService.generate_html_report  s   ) !4773C)H:Mc8deeF	G>& ,,X6J 228<M!%!<!<X!FHh!%!@!@K[!\!%!@!@K[!\ $ : :8 D '(:(E(E'FgN`NkNkMnop$[1C1N1N%O$PPQRS ,/}+=+A}Q'tH+.}+=+A}Q'tH J/0h'h'67IJi(h'AB_``a>?<=fgIJXYVWUVSTYZUVSTGHEFKLj)i(i(99Z0L 	G<SVHEFF	Gs   J;K( (	L1LLN)__name__
__module____qualname__r   rn   intr2   r{   r   r7   r   tupler8   r   r.  r9   r   r:   r   r;   r   r   r@  r_   rp   re   rh   rh   G   s    7 

s 

 

# $7H2I &-"s -"u=RTi=i7j -"^\3 \3 \Sk \|
c 
6L 
 
 
8M 
<wC wG wrNGS NGS NGrp   rh   c                       e Zd ZdefdZdedee   fdZdedee	   fdZ
dedefdZdedefdZdedefd	Zdedee   fd
ZdededefdZdededefdZdededefdZdedefdZdedefdZdedefdZy)Module2ReportServicer`   c                     || _         y rj   rk   rl   s     re   rn   zModule2ReportService.__init__1  ro   rp   rX   rY   c                    | j                   j                  t              j                  t        j                  |k(        j                         }g }|D ]  }t        |dd      xs d}t        |dd      xs d}||z  }|j                  t        t        |j                        t        |dd      xs dt        |dd      xs dt        |dd      xs d|j                  xs d|j                  xs d|||		              |S )
z2Get customer segment estimates from segments tableshopping_frequency_per_monthr   household_consumption_per_monthsample_sizeaverage_ager   income_levelsr  )	r~   rl  rm  rn  occupation_modeeducation_level_moderj  rk  total_household_consumption)r`   rb   r   rw   rX   r   r   r   r<   r.  r   r   r   )rm   rX   r   r   r   shopping_freqhousehold_consumptiontotal_consumptions           re   get_customer_segments_dataz/Module2ReportService.get_customer_segments_data4  s    77==,33J4G4G84STXXZG#G-KQOTSTM$+G5VXY$Z$_^_! -0E E 7 !5!56#G]A>C!#G]C@GC%gPcTc ' D D W%,%B%B%Uo-:0E,=
! 
  $ rp   c                    | j                   j                  t              j                  t        j                  |k(        j                         }g }|D ]u  }|j                  t        t        |j                        |j                  xs d|j                  xs d|j                  xs dt        |dd      t        |dd                   w |S )zGet catchment potential datar   r   assumptionsNsources)r~   number_of_householdspercentage_of_segmentpotential_householdsrw  rx  )r`   rb   r$   rw   rX   r   r   r=   r.  r   ry  rz  potential_number_of_householdsr   )rm   rX   catchment_datapotential_datar   s        re   get_catchment_potential_dataz1Module2ReportService.get_catchment_potential_dataM  s    '<=DDEZEcEcgoEopttv"D!!"8 !2!23%)%>%>%C!&*&@&@&GC%)%H%H%MA#D->i6#  # rp   c                     | j                   j                  t              j                  t        j                  |k(        j                         }|r|j                  S dS )zGet estimated market sharer   )r`   rb   r*   rw   rX   rx   market_share_estimate)rm   rX   market_shares      re   get_market_share_dataz*Module2ReportService.get_market_share_data^  sI    ww}}%<=DDE\EeEeiqEqrxxz5A|11JsJrp   c                     | j                   j                  t              j                  t        j                  |k(        j                         }|r|j                  S dS )zGet competition intensityrr   )r`   rb   r%   rw   rX   rx   total_square_footage)rm   rX   competitions      re   get_competition_intensityz.Module2ReportService.get_competition_intensityc  sI    ggmm$:;BBCYCbCbfnCnouuw3>{//MIMrp   c                     | j                   j                  t              j                  t        j                  |k(        j                         }|r|j                  S dS )zGet spillage factorrr   )r`   rb   r)   rw   rX   rx   estimated_spillage_factor)rm   rX   spillages      re   get_spillage_factorz(Module2ReportService.get_spillage_factorh  sI    77==!:;BBC\CeCeiqCqrxxz5=x11L9Lrp   c                    | j                   j                  t              j                  t        j                  |k(        j                         }g }|D ]l  }|j                  t        |j                  xs d|j                  xs d|j                  xs dt        |j                  xs d      |j                               n |S )z Get competitor benchmarking datar  r   )reference_competitornumber_of_bills_per_monthnumber_of_items_per_billaverage_price_per_itemother_remarks)r`   rb   r+   rw   rX   r   r   r>   r  bills_per_monthitems_pre_billrN  	avg_priceother_remark)rm   rX   competitorsbenchmark_data
competitors        re    get_competitor_benchmarking_dataz5Module2ReportService.get_competitor_benchmarking_datam  s    ggmm$=>EEF_FhFhltFtuyy{%J!!"9%/%D%D%W*4*D*D*I)3)B)B)Ga',Z-A-A-FQ'G(55#  & rp   r   c                    | j                   j                  t              j                  t        j                  |k(  t        j
                  |k(        j                         }|st        ddddddd      S |j                  xs d}t        t        |j                  xs d      |j                  xs dd|v d|v d	|v t        |j                  xr |j                  j                  d
            t        |dd      xs d|j                        S )z.Get location details for specific store formatr   r  F)trading_radiusadjacenciescorner_propertyhigh_streetmallparking_spaceconversion_factorrK  r   zCorner Property
HighstreetMallr  r  )r  r  r  r  r  r  r  additional_details)r`   rb   r&   rw   rX   r   rx   r?   location_characteristicsrN  r  r  booldetailsgetr   )rm   rX   r   r   characteristicss        re   get_location_details_dataz.Module2ReportService.get_location_details_data}  s   77==!34;;''8300L@
 %' 	
 *"+ %!#"%  #;;Ar& !8!8!=A> ,,?-@$7?*x//YH4D4D4H4H4YZ%h0CSIPS'//	
 		
rp   c                    | j                   j                  t              j                  t        j                  |k(  t        j
                  |k(        j                         }d}d}d}d}d}|D ]  }	|	j                  dk(  rt        |	j                  xs d      }nh|	j                  dk(  r|	j                  xs d}nH|	j                  dk(  r|	j                  xs d}n(|	j                  dk(  rt        |	j                  xs d      }|	j                  s||	j                   d|	j                   d	z  } ||z  |z  }
|
d
z  }t        |||||
||r|j                  d	            S d      S )z1Get sales estimate data for specific store formatr   r   rK  zGross Margin % EstimatezNumber of Bills per MonthzNumber of Items per Billz"Average Price per item (in Rupees)r  z; 333333?N)cogs_percentager  r  r  sales_valuesales_potentialremarks)r`   rb   r'   rw   rX   r   r   	parameterrN  valueremarkr@   rM  )rm   rX   r   
sales_datar  r  items_per_billavg_price_per_itemr  r   r  r  s               re   get_sales_estimate_dataz,Module2ReportService.get_sales_estimate_data  sd   WW]]#34;;%%1//<?
 #% 	   D~~!::"'

a"8#>>"&**/#==!%q#GG%*4::?%;"{{dnn-R}B??  &69KK &+ +&5%3#5#++2GMM$'
 	
 9=
 	
rp   c           	         | j                   j                  t              j                  t        j                  |k(  t        j
                  |k(        j                         }|st        dddd      S t        t        |j                  xs d      t        |j                  xs d      |j                  xs dt        |j                  xs d      |j                        S )z/Get rent expense data for specific store formatr   r   )store_size_sqftrental_advance_amountrental_advance_periodrent_per_month)r  r  r  r  ru   )r`   rb   r(   rw   rX   r   rx   rA   rN  r   r  r  r  rational_for_rental_expenses)rm   rX   r   	rent_datas       re   get_rent_expense_dataz*Module2ReportService.get_rent_expense_data  s    GGMM/299$$0--=
 %' 	
 " #&)&'"	  !)"6"6";!<"'	(G(G(L1"M"+"A"A"FQ !9!9!>Q?<<
 	
rp   c                 z   ddl m} t        || j                        s |dd| d      | j	                  |      }| j                  |      }| j                  |      }| j                  |      }| j                  |      }| j                  |      }| j                  |d      }	| j                  |d      }
| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }t        |D cg c]  }|j                   c}      }t        ||||||||	|
||||	      S c c}w )
z3Generate complete Module 2 Location Analysis reportr   r   r   r   r   r   r   r   )customer_segmentsrq  catchment_potentialestimated_market_sharecompetition_intensityspillage_factorcompetitor_benchmarkinglocation_details_format_alocation_details_format_bsales_estimate_format_asales_estimate_format_brent_details_format_arent_details_format_b)r   r   rf   r`   ru  r  r  r  r  r  r  r  r  r   rq  rB   )rm   rX   r   r  r  r  r  r  r  location_details_alocation_details_bsales_estimate_asales_estimate_brent_details_arent_details_bsegrq  s                    re   generate_module2_reportz,Module2ReportService.generate_module2_report  sg   ) !4773C)H:Mc8dee !;;HE"??I11(; $ > >x H228<"&"G"G"Q!;;HFVW!;;HFVW77BRS77BRS33H>NO33H>NO '*Vg*hVgs3+J+JVg*h&i#$/(C 3#/"7+$;&8&8$4$4"0"0
 	
 +is   D8c                    ddl m} t        || j                        s |dd| d      | j	                  |      }d}|j
                  D ]1  }|d|j                   d	|j                  d
d|j                  ddz  }3 |d|j                  d
dz  }d}d}d| d| d|j                  j                   d| d|j                  j                   d|j                  j                  dd|j                  j                  dd| d| d}|S )z0Generate HTML report using exact format providedr   r   r   r   r   r   rK  
    <tr>
        <td></td>
        <td>.1f%</td>
        <td>,</td>
    </tr>z>
    <tr>
        <td>Estimated Market Share</td>
        <td>z"%</td>
        <td></td>
    </tr>r   r   u  <!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Location Analysis Report</title>
</head>
<body style="font-family: Times New Roman, Times, serif; font-size:16px;">

<!-- Module Header -->
<table style="width:100%; border:1px solid #999; border-collapse:collapse;">
    <tr>
        <td style="padding:6px;"><b>Module 2: Location Analysis</b></td>
    </tr>
    <tr>
        <td style="height:25px;"></td>
    </tr>
</table>
<br>

<!-- Understanding Shoppers -->
<i>Understanding Shoppers</i>
<ul>
    <li>• Shopping Frequency per Month</li>
    <li>• Household Consumption per Month</li>
    <li>• Total Household Consumption per Month</li>
</ul>
<hr>
<br>

<!-- Catchment Potential Table -->
<i>Catchment Potential</i>
<table border="1" cellspacing="0" cellpadding="4" style="width:120%; border-collapse:collapse; margin-bottom:10px;">
    <tr>
        <td><b>ISEC Category</b></td>
        <td><b>Percentage of Segment</b></td>
        <td><b>Number of Potential Households</b></td>
    </tr>uf  
</table>
<br>

<!-- Competition Intensity -->
<i>Competition Intensity</i>
<ul>
    <li>• Total Square foot of the competition</li>
</ul>
<hr>
<br>

<!-- Quality of Location -->
<i>Quality of Location</i>
<ul>
    <li>• Spillage Factor</li>
</ul>
<hr>
<br>

<!-- Location Definition: Store Format A -->
<i>Location Definition</i>
<b><br>Store Format A: uE   </b>
<ul>
    <li>• Trading Radius <span style="margin-left:50px;">u   </span></li>
    <li>• Adjacencies</li>
    <li>• Corner Property</li>
    <li>• Highstreet</li>
    <li>• Mall</li>
    <li>• Parking Space</li>
</ul>
<!-- Location Definition: Store Format B -->
<b>Store Format B: u  </span></li>
    <li>• Adjacencies</li>
    <li>• Corner Property</li>
    <li>• Highstreet</li>
    <li>• Mall</li>
    <li>• Parking Space</li>
</ul>
<hr>
<br>

<!-- Estimated Sales Table -->
<i>Estimated Sales:</i>
<table border="1" cellspacing="0" cellpadding="4" style="width:100%; border-collapse:collapse;">
    <tr>
        <td><b>Estimated Sales</b></td>
        <td><b>Store A</b></td>
        <td><b>Store B</b></td>
    </tr>
    <tr>
        <td></td>
        <td>₹ r  u   </td>
        <td>₹ zi</td>
    </tr>
</table>
<br>

<!-- Rent Details Format A -->
<i>Rent Details</i>
<b><br>Store Format A: u   </b>
<ul>
    <li>• Rental Advance Amount (in Rupees)</li>
    <li>• Rental Advance Period (in Months)</li>
    <li>• Rent per Month (in Rupees)</li>
</ul>
<!-- Rent Details Format B -->
<b>Store Format B: u   </b>
<ul>
    <li>• Rental Advance Amount (in Rupees)</li>
    <li>• Rental Advance Period (in Months)</li>
    <li>• Rent per Month (in Rupees)</li>
</ul>
<hr>

</body>
</html>)r   r   rf   r`   r  r  r~   rz  r{  r  r  r  r  r  r  r  )	rm   rX   r   r1  catchment_rowscpformat_a_nameformat_b_namer]  s	            re   r_  z)Module2ReportService.generate_html_report  s   ) !4773C)H:Mc8dee228< 11B #__ %%c* +$$Q' (
	 N 2 	  //4 5
 	 )($
H 	 , & '<<G<a<a<p<p;q r "? #<<G<a<a<p<p;q r( 44@@F G44@@F G & ' "? 	#Srh rp   c                    ddl m} t        || j                        s |dd| d      | j	                  |      }t               }t        |t        dddd      }t               }g }|j                  t        d	|d
                |j                  t        dd             |j                  t        d|d
                |j                  t        d|d
                |j                  t        d|d
                |j                  t        d|d
                |j                  t        dd             |j                  t        d|d
                t        d|d
         t        d|d
         t        d|d
         gg}|j                  D ]a  }	|j                  t        |	j                  |d
         t        |	j                  dd|d
         t        |	j                  d|d
         g       c |j                  t        d|d
         t        |j                   dd|d
         t        d|d
         g       t#        |dt$        z  dt$        z  dt$        z  g      }
|
j'                  t)        dddd d!dt*        j,                  fd"d#d$d%d&d'g	             |j                  |
       |j                  t        dd             |j                  t        d(|d
                |j                  t        d)|d
                |j                  t        dd             |j                  t        d*|d
                |j                  t        d+|d
                |j                  t        dd             |j                  t        d,|d
                |j                  t        d-|d
                |j                  t        d.|j.                  j0                   |d
                |j                  t        d/|d
                |j                  t        d0|d
                |j                  t        d1|d
                |j                  t        d2|d
                |j                  t        d3|d
                |j                  t        d4|d
                |j                  t        d.|j2                  j0                   |d
                |j                  t        d/|d
                |j                  t        d0|d
                |j                  t        d1|d
                |j                  t        d2|d
                |j                  t        d3|d
                |j                  t        dd             |j                  t        d5|d
                t        d6|d
         t        d7|d
         t        d8|d
         gt        d|d
         t        d9|j4                  j6                  d:|d
         t        d9|j8                  j6                  d:|d
         gg}t#        |dt$        z  dt$        z  dt$        z  g      }|j'                  t)        dddd d!dt*        j,                  fd"d#d$d%d&d'g	             |j                  |       |j                  t        dd             |j                  t        d;|d
                |j                  t        d-|d
                |j                  t        d<|d
                |j                  t        d=|d
                |j                  t        d>|d
                |j                  t        d4|d
                |j                  t        d<|d
                |j                  t        d=|d
                |j                  t        d>|d
                |j;                  |       |j=                  d       |S )?z@Generate PDF report using ReportLab with proper table formattingr   r   r   r   r   r   r   r   z"<b>Module 2: Location Analysis</b>r  r0      z<i>Understanding Shoppers</i>u    • Shopping Frequency per Monthu#   • Household Consumption per Monthu)   • Total Household Consumption per Monthz<i>Catchment Potential</i>zISEC CategoryzPercentage of SegmentzNumber of Potential Householdsr  %r  zEstimated Market SharerK  r         @r  r  FONTNAMEr  r  r   r   r  r  r  r  r  r   r#  r%  r'  z<i>Competition Intensity</i>u(   • Total Square foot of the competitionz<i>Quality of Location</i>u   • Spillage Factorz<i>Location Definition</i>z%<b>Store Format A: Store Format A</b>u   • Trading Radius: u   • Adjacenciesu   • Corner Propertyu   • Highstreetu   • Mallu   • Parking Spacez%<b>Store Format B: Store Format B</b>z<i>Estimated Sales:</i>zEstimated SaleszStore AzStore Br
  r  z<i>Rent Details</i>u%   • Rental Advance Amount (in Rupees)u%   • Rental Advance Period (in Months)u   • Rent per Month (in Rupees))r   r   rf   r`   r  r   r   r
   r   r   r   r   r  r~   rz  r{  r  r   r   r+  r   r   r-  r  r  r  r  r  r  r/  r0  )rm   rX   r   r1  r2  r3  r4  r5  r}  r  catchment_tabler  sales_tables                re   r@  z(Module2ReportService.generate_pdf_report  s-   ) !4773C)H:Mc8dee228<PR^`oqr$& 	YCVHEUVWVAr]# 	Y>x@PQRYA6(CSTUYDfXFVWXYJFS[L\]^VAr]# 	Y;VH=MNO$_fX6FGSjlrs{l|I}  @I  Jj  lr  s{  l|  @}  ~  11B!!9R__fX>N#OQZ^`^v^vwz]{{|[}  @F  GO  @P  RQ  S\  `b  `w  `w  xy  _z  }C  DL  }M  SN  #O  P 2y)A6(CSTV_cn  dF  dF  GJ  cK  KL  aM  OU  V^  O_  W`  bk  ln  pv  w  p@  bA  B  	C1T61T63t8:TU  /;VXq&,,7/001/2
-
 
" 
	 	_%VAr]# 	Y=vh?OPQYI6RZK[\]VAr]# 	Y;VH=MNOY4fX6FGHVAr]# 	Y;VH=MNOYFxHXYZY!5k6[6[6j6j5klntu}n~  	AY0&2BCDY4fX6FGHY/1ABCYz6(+;<=Y2F84DEFYFxHXYZY!5k6[6[6j6j5klntu}n~  	AY0&2BCDY4fX6FGHY/1ABCYz6(+;<=Y2F84DEFVAr]# 	Y8&:JKL(&*:;YyRXYaRb=cenox  {A  BJ  {K  fL  Mr6(+,i${?b?b?n?nos>t8uw}  G  xH  /I  KT  W[  \g  \  \  \K  \K  LP  [Q  UR  TZ  [c  Td  Ke  f


 J1T61T61T62JKZ/;VXq&,,7/001/2
)
 
 
	 	[!VAr]# 	Y4fX6FGHYFxHXYZYFxHXYZYFxHXYZY?AQRSYFxHXYZYFxHXYZYFxHXYZY?AQRS		%Arp   N)r`  ra  rb  r   rn   rc  r   r<   ru  r=   r  rN  r  r.  r  r  r>   r  r?   r  r@   r  rA   r  rB   r  r_  r   r@  re  rp   re   rg  rg  /  s/   7 3 4@W;X 2S TBX=Y "Kc Ke K
N# N# N
MC MC M
 F]A^  
# 
S 
Md 
@+
 +
3 +
K\ +
Z
c 
 
 
.*
 *
8M *
XTS TS TlqC qG qrp   rg  c                   <    e Zd ZdZdefdZdeddfdZdedefdZ	y	)
Module3ReportServicez?Service class for generating Module 3: Network Planning reportsr`   c                     || _         y rj   rk   rl   s     re   rn   zModule3ReportService.__init__  ro   rp   rX   rY   r3   c                    ddl m} t        || j                        s |dd| d      ddlm}m}m}m}m	}m
} 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g}	|	dd|dz  z    }
g }|
D ]5  }|j                   ||d    |d!   |d"z  z   |d#   |d$z  z   |d%   &             7 t        |      d'z  |z   }d(|d)z  z   }d|d*z  z   }d+|d,z  z   }d-|d.z  z   }d-|d/z  z   }d0|d1z  z   }d2|d3z  z   }d4|d,z  z   } |||||||z   ||z   ||||d5|d6z  z   d7|d8z  z   ||z   |z   |z   d$z   |d6z  z   ||z   |z   |z   d9z   |d8z  z   :      } ||g d;|dz     |g  |d<d<=       |d>d>d5|d6z  z   d7|d8z  z   ?      |@      S )Az.Generate Module 3 Network Planning report datar   r   r   r   r   r   r0   )r3   LocationSelectionDataNetworkPlanningDataTradingMonthsDataPreOperatingExpenseDataStoreInvestmentSummaryDataChennaig     z@i%& z2Major metropolitan city with high retail potential)r}   area
populationru   
Coimbatoreg     n@iO z)Industrial hub with growing consumer baseMaduraig     `b@i@B z&Cultural center with stable populationTiruchirappallig     d@iP z'Educational hub with young demographicsSalemg      _@iq z,Emerging retail market with growth potentialNr  r}   r  r   r  iP  ru   )location_name	area_sqkmhousehold_populationru   r   i` 順 i8 i@ i N  iI i:  i'  i( i@  i ia  iHY g     j@i  g     @i  i@  )!capital_expenses_excl_it_format_a!capital_expenses_excl_it_format_bit_capital_expenses_format_ait_capital_expenses_format_b%total_store_capital_expenses_format_a%total_store_capital_expenses_format_brental_advance_format_arental_advance_format_bpre_operating_expenses_format_apre_operating_expenses_format_bmarketing_expenses_format_amarketing_expenses_format_b total_store_investments_format_a total_store_investments_format_b)UrbanSuburbanRuralr  )store_format_a_monthsstore_format_b_months       @)r  r  r  r  )target_storesgeography_selectionlocation_selectionsnetwork_planningtrading_monthspre_operating_expensesstore_investment_summary)r   r   rf   r`   schemasr3   r  r  r  r  r  r   rX  )rm   rX   r   r3   r  r  r  r  r  	locationsselected_locationsr  locr  base_capex_abase_capex_b	base_it_a	base_it_bbase_rental_abase_rental_bbase_preop_abase_preop_br  s                          re   generate_module3_reportz,Module3ReportService.generate_module3_report  s   ) !4773C)H:Mc8dee	
 	
 W  TH  I!5  WB  CWS{|&V  [D  Ee6P~
	 '':X\(:; %C&&'<!&kf+B7%(%6(U:J%Kk*	(  & /014x? (V"34(U"23h./	h./	(U"23(T/2E!12E!12#=.:.:)2)22>2J2>2J$1$1,8,8(/8d?(C(/8d?(C-9I-E-UXd-dgl-lpx{p  .A-9I-E-UXd-dgl-lpx{p  .A$
 " %' >x!| L 3,2]_`#:&),3x$,G,3x$,G$
 &>
 	
rp   c                 	   ddl m} t        || j                        s |dd| d      | j	                  |      }t               }t        |t        dddd      }t               }g }|j                  t        d	|d
                |j                  t        dd             |j                  t        d|d                |j                  t        dd             g dg}|j                  D ]}  }	|j                  t        |	j                  |d         t        |	j                  dd|d         t        |	j                  d|d         t        |	j                   xs d|d         g        t#        |dt$        z  dt$        z  dt$        z  dt$        z  g      }
|
j'                  t)        ddddddt*        j,                  fdd d!d"d#d$d%g
             |j                  |
       |j                  t        dd             |j                  t        d&|d                d't/        |j0                  j2                        gd(t/        |j0                  j4                        gg}t#        |d)t$        z  d*t$        z  g      }|j'                  t)        dd+ddddt*        j,                  fdd,g             |j                  |       |j                  t        dd             |j                  t        d-|d                |j                  t        dd             g d.d/d0|j6                  j8                  d1d0|j6                  j:                  d1d2gd3d0|j6                  j<                  d1d0|j6                  j>                  d1d2gd4d0|j6                  j@                  d1d0|j6                  jB                  d1d5gd6d0|j6                  jD                  d1d0|j6                  jF                  d1d7gd8d0|j6                  jH                  d1d0|j6                  jJ                  d1d9gg}t#        |d*t$        z  d:t$        z  d:t$        z  dt$        z  g      }|j'                  t)        ddd;d<dd=t*        jL                  fd<d>dt*        jL                  fddddt*        j,                  fdd?g             |j                  |       |jO                  |       |jQ                  d       |S )@z Generate PDF report for Module 3r   r   r   r   r   r   r   r   z!<b>Module 3: Network Planning</b>r   r0   r	  z<b>Location Selection</b>r     )LocationArea
Population	Rationaler  r  z sq kmr  zStrategic location      ?皙?皙	@r  r  r  r  r  r  r  FONTSIZEr  r  r&  r  r!  r  r     r$  r  r  r1  r&  r  r  r1  r(  r  r  r1  z<b>Trading Months</b>zStore Format A Trading MonthszStore Format B Trading Months      @r  r  r  r  r   r/  r  r  r   z<b>Store Investment Summary</b>)zInvestment ComponentzFormat AzFormat BSourcezCapital Expenses (Excl. IT)rC  ,.0fzModule 1zIT Capital ExpenseszRental AdvancezModule 2zPre-operating ExpenseszModule 3zTotal Store InvestmentsTotal      ?r  r  r  r   r  r  r  r/  r  r  	   ))r   r   rf   r`   r$  r   r   r
   r   r   r   r   r  r  r  r  ru   r   r   r+  r   r   r-  r.  r  r  r  r  r  r  r  r   r  r  r  r  r	  r
  r,  r/  r0  )rm   rX   r   r1  r2  r3  r4  r5  location_datar   location_tabletrading_datatrading_tableinvestment_datainvestment_tables                  re   r@  z(Module3ReportService.generate_pdf_reporti  s   ) !4773C)H:Mc8dee228<PR^`oqr$& 	YBF:DVWXVAr]# 	Y:F:<NOPVAq\"HI#77H  (00&2BCX//4F;VH=MNX::1=x@PQ(,,D0DfXFVW	"  8 }T3t8SQUXWZ[_W_8`a
/;VXq&,,7/-001/2,
 ! 	 	^$VAr]# 	Y6z8JKL,c+2L2L2b2b.cd,c+2L2L2b2b.cd

 ls4xT6JKz/;VXq&,,7/.+
   	 	]#VAr]# 	Y@&BTUVVAq\" G*c+2V2V2x2xy}1~,  DG  HS  Hl  Hl  HN  HN  OS  GT  BU  Wa  b"c+*N*N*k*klp)q$rvy  {F  {_  {_  {|  {|  }A  zB  uC  EO  P[%I%I%a%abf$ghlop{  qU  qU  qm  qm  nr  ps  kt  v@  A%[-Q-Q-q-qrv,w'x|  AL  Ae  Ae  AE  AE  FJ  @K  {L  NX  Y&#k.R.R.s.stx-y(z  B  CN  Cg  Cg  CH  CH  IM  BN  }O  QX  Y
 !SXs4xQTUYQY[^_c[c<de!!*/;=67F,<,<=7Hf.>.>?VXq&,,7/-	.
 	# 		 	%&		%Arp   N)
r`  ra  rb  __doc__r   rn   rc  r$  r   r@  re  rp   re   r  r    s?    I7 K
 K
8O K
Z^C ^G ^rp   r  c                       e Zd ZdZdefdZdeddfdZdedefdZ	dede
fd	Zdedefd
ZdedefdZdede
fdZdedefdZdede
fdZdeddfdZdede
fdZy)Module4ReportServicezBService class for generating Module 4: Category Management reportsr`   c                     || _         y rj   rk   rl   s     re   rn   zModule4ReportService.__init__  ro   rp   rX   rY   r4   c           	         ddl m} t        || j                        s |dd| d      ddlm}m}m}m}m	}m
} 	 dd	lm}	 | j                  j                  |	      j                  |	j                  |k(        j!                         }
 ||
r|
j&                  nd|
r|
j(                  nd|
r|
j*                  nd|
r|
j,                  r|
j,                  nd      }	 ddlm} | j                  j                  |      j                  |j                  |k(        j!                         } ||r|j2                  r|j2                  nd|r|j4                  r|j4                  nd      }	 ddlm} | j                  j                  |      j                  |j                  |k(        j!                         } |d|r|j:                  ndd|r|j<                  nd      }	 ddlm } | j                  j                  |      j                  |j                  |k(        jC                         }|r1|dd D cg c]"  } ||jD                  jF                  d d!d"#      $ c}n" |d$d d%d!#       |d&d'd(d)#       |d*d+d!d%#      g}	 dd,l$m%} | j                  j                  |      j                  |j                  |k(        jC                         }g }d.}|ro|D ]i  } |d/|jL                   |jN                  |jP                  |jN                  |jP                  z  d0z  1      }|jS                  |       ||jT                  z  }k n^d$d%d2d3d&d(d!d3d*d!d4d3d5d(d"d3g}|D ]C  } ||d6   |d7   |d8   |d7   |d8   z  d0z  1      }|jS                  |       ||jT                  z  }E  |||||||9      S # t"        $ r}t%        d
|        d}
Y d}~<d}~ww xY w# t"        $ r}t%        d|        d}Y d}~d}~ww xY w# t"        $ r}t%        d|        d}Y d}~dd}~ww xY w# t"        $ r}t%        d|        g }Y d}~d}~ww xY wc c}w # t"        $ r}t%        d-|        g }Y d}~d}~ww xY w):z1Generate Module 4 Category Management report datar   r   r   r   r   r   r0   )r4   CompetitorResearchDataCustomerResearchDataCategoryLevelDataCategoryRoleDataGrossMarginContributionData)TblCompetitorCategoryAnalyseszError loading competitor data: NzSample Competitorr	  z Groceries, Electronics, Clothingz1Well-organized category layout with clear signage)r  number_of_categories_stockedkey_categories_stockedstocking_observations)TblConsumerPreferencesResearchzError loading customer data: z2Survey of 100 customers, focus groups, observationz@Customers prefer one-stop shopping with variety in each category)research_methodologyshopping_behavior)TblPreSelectedCategoryz!Error loading pre-selected data: Mediumr  High   )store_format_a_levelstore_format_a_categoriesstore_format_b_levelstore_format_b_categories)TblCategoryzError loading categories: r  Destination      9@g      >@)category_namecategory_rolesales_contributionmargin_contribution	Groceriesg     A@ElectronicszCash Machine      4@g      D@ClothingFlagship)TblGrossMarginContributionz!Error loading gross margin data: r   z	Category d   )ra  contribution_to_salesgross_marginsgross_margin_contribution      .@)r}   salesmarging     F@zHome & Gardenr}   rp  rq  )competitor_researchcustomer_researchcategory_levelscategory_rolesgross_margin_contributions#total_weighted_average_gross_margin)+r   r   rf   r`   r  r4   rJ  rK  rL  rM  rN  ,app.models.main.competitor_category_analysesrO  rb   rw   rX   rx   r_   rW  r  rP  rQ  rR  -app.models.main.consumer_preferences_researchrS  rT  rU  %app.models.main.pre_selected_caregoryrV  medium_value
high_valueapp.models.main.categoryr^  r   choose_categoryr  *app.models.main.gross_margin_contributionsrj  gross_idcontribution_to_total_salescontribution_to_gross_marginr   rn  )rm   rX   r   r4   rJ  rK  rL  rM  rN  rO  competitor_datar^  rr  rS  customer_datars  rV  pre_selected_datart  r^  
categoriescatru  rj  gross_margin_datarv  total_weighted_margingmcontributionsample_contributionsr   s                                  re   generate_module4_reportz,Module4ReportService.generate_module4_report  s   ) !4773C)H:Mc8dee	
 	
	#b"ggmm,IJQQ-66(Beg  5IX!E!E^qYh)U)UnpM\?#I#I  cEKZ_n  `E  `E/"G"G  K~	
	!d GGMM*HIPP.778Ceg  1GTYfY{Y{!C!C  BvANS`SrSrm==  y{

	%T $.D E L L&//8;!eg  ,!)HY&7&D&D_a!'FW&7&B&B]_	
	<{3::$$0ce   $BQ
 (# !1177+#'$(	
 (
 )+#'$(	 +,#'$(	 ((#'$(	
 	8	#] $.H I P P*33x?!ce  &(" #':$-bkk]";*,*H*H"$"A"A.0.L.LrOnOn.nqt.t	  +11,?%)O)OO% ( %ttD&F#ddC(44H	$  -:"&v,*.w-"&x..27md8n.Ls.R	  +11,?%)O)OO% - % 3/+)'A0E
 	
q  	#3A378"O	#   	!1!56 M	!  	%5aS9: $	%   	.qc23J	

B  	#5aS9: "	#s   AN$ AO "AO2 AP *'Q 8AQ $	O-OO	O/O**O/2	P;PP	P="P88P=	Q)Q$$Q)c                    ddl m} t        || j                        s |dd| d      | j	                  |      }d}|j
                  D ]>  }|d|j                   d	|j                   d	|j                  d
d|j                  d
d	z  }@ d}|j                  D ]?  }|d|j                   d	|j                  d
d|j                  d
d|j                  dd	z  }A d|j                  j                   d|j                  j                    d|j                  j"                   d|j                  j$                   d|j&                  j(                   d|j&                  j*                   d|j,                  j.                   d|j,                  j0                   d|j,                  j2                   d|j,                  j4                   d| d| d|j6                  dd}|S )z!Generate HTML report for Module 4r   r   r   r   r   r   rK  z&
            <tr>
                <td>z</td>
                <td>r  z%</td>
                <td>z%%</td>
            </tr>
            rL  a3  <!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Module 4: Category Management</title>
</head>
<body style="font-family: 'Times New Roman', serif; font-size:15px;">

<table style="width:100%; border:1px solid #999; border-collapse:collapse;">
    <tr>
        <td><b>Module 4: Category Management</b></td>
    </tr>
</table>
<br>

<b>Primary Research</b><br>
<b>Competition Research:</b>
<table border="1" cellspacing="0" cellpadding="5" style="width:100%; border-collapse:collapse;">
    <tr>
        <td>Reference Competitor</td>
        <td>zS</td>
    </tr>
    <tr>
        <td>Number of Categories Stocked</td>
        <td>zM</td>
    </tr>
    <tr>
        <td>Key Categories Stocked</td>
        <td>z</td>
    </tr>
    <tr>
        <td>What are some key observations around stocking and categories in the store?</td>
        <td>a  </td>
    </tr>
</table>

<b>Customer Research:</b>
<br><br>
<table border="1" cellspacing="0" cellpadding="5" style="width:100%; border-collapse:collapse; table-layout:fixed;">
    <tr>
        <td style="width:50%; word-wrap:break-word; white-space:normal; overflow-wrap:break-word; vertical-align:top;">Define Research Methodology (Sample Size, Probes, and Methods)</td>
        <td style="width:50%; word-wrap:break-word; white-space:normal; overflow-wrap:break-word; vertical-align:top;">ac  </td>
    </tr>
    <tr>
        <td style="width:50%; word-wrap:break-word; white-space:normal; overflow-wrap:break-word; vertical-align:top;">What are some key observations around shopping behaviors around category by customers?</td>
        <td style="width:50%; word-wrap:break-word; white-space:normal; overflow-wrap:break-word; vertical-align:top;">ae  </td>
    </tr>
</table>
<br>

<b>Category Management</b>
<table border="1" cellspacing="0" cellpadding="5" style="width:100%; border-collapse:collapse;">
    <tr>
        <td></td>
        <td><b>Level of Category or Merchandise</b></td>
        <td><b>Number of Categories Available</b></td>
    </tr>
    <tr>
        <td>Store Format A</td>
        <td>r  zE</td>
    </tr>
    <tr>
        <td>Store Format B</td>
        <td>ab  </td>
    </tr>
</table>
<br>

<p style="margin-bottom:6px;"><i><b>Category Role Management</b></i></p>
<table border="1" cellspacing="0" cellpadding="5" style="width:100%; border-collapse:collapse;">
    <tr>
        <th>Category Name</th>
        <th>Category Role</th>
        <th>Sales Contribution</th>
        <th>Margin Contribution</th>
    </tr>a^  
</table>
<br>

<p style="margin-bottom:6px;"><i><b>Gross Margin Contributions</b></i></p>
<table border="1" cellspacing="0" cellpadding="5" style="width:100%; border-collapse:collapse;">
    <tr>
        <th>Category Name</th>
        <th>Contribution to Sales</th>
        <th>Gross Margins</th>
        <th>Gross Margin Contribution</th>
    </tr>z
    <tr>
        <td colspan="2" style="font-weight:bold;">Total Weighted Average Gross Margin</td>
        <td colspan="2" style="font-style:italic;">z*%</td>
    </tr>
</table>

</body>
</html>)r   r   rf   r`   r  ru  ra  rb  rc  rd  rv  rl  rm  rn  rr  r  rP  rQ  rR  rs  rT  rU  rt  rZ  r[  r\  r]  rw  )	rm   rX   r   r1  category_role_rowsrolegross_margin_rowsr  r]  s	            re   r_  z)Module4ReportService.generate_html_reportc  s   ) !4773C)H:Mc8dee228<  ..D '''( )''( ),,S1 2--c2 3#  / 88B &%%& '--c2 3%%c* +11#6 7"  9( ,,AAB C ,,IIJ K ,,CCD E ,,BBC 	Dx yD  yV  yV  yk  yk  xl lx yD  yV  yV  yh  yh  xi i ((==> ?((BBC D ((==> ?((BBC D
 	 
 	 4 5@4c4cdg3h iw`D rp   c                    ddl m} t        || j                        s |dd| d      ddlm} ddlm}m}m	}m
}m} dd	lm}	 dd
lm}
 ddlm} ddlm} | j)                  |      } |       } |||dddd      } |	       }g }|j+                   |d|d                |j+                   |dd             |j+                   |d|d                |j+                   |dd             |j+                   |d|d                d|j,                  j.                  gdt1        |j,                  j2                        gd|j,                  j4                  gd|j,                  j6                  gg} ||d|
z  d|
z  g      }|j9                   |ddd d!d|j:                  fd"d#d$g             |j+                  |       |j+                   |dd%             |j+                   |dd&             |j+                   |d'|d                d(|j<                  j>                  gd)|j<                  j@                  gg} ||d*|
z  d+|
z  g      }|j9                   |ddd d!d|j:                  fd"d#d$g             |j+                  |       |j+                   |dd%             |j+                   |dd&             |j+                   |d,|d                g d-d.|jB                  jD                  t1        |jB                  jF                        gd/|jB                  jH                  t1        |jB                  jJ                        gg} ||d0|
z  d1|
z  d2|
z  g      }|j9                   |dd3dd d!d|j:                  fd4d#d$g             |j+                  |       |j+                   |dd%             |j+                   |dd&             |j+                   |d5|d                g d6g}|jL                  D ]G  }|j+                  |jN                  |jP                  |jR                  d7d8|jT                  d7d8g       I  ||d9|
z  d:|
z  d0|
z  d0|
z  g      }|j9                   |dd3dd d!d|j:                  fd4d;g             |j+                  |       |j+                   |dd%             |j+                   |dd&             |j+                   |d<|d                g d=g}|jV                  D ]K  }|j+                  |jN                  |jX                  d7d8|jZ                  d7d8|j\                  d>d8g       M |j+                  d?d@d@|j^                  d>d8g        ||d9|
z  d:|
z  d:|
z  d9|
z  g      }|j9                   |dd3dAdd d!d|j:                  fd4d#d$g             |j+                  |       |ja                  |       |jc                  d       |S )Bz#Generate PDF report using ReportLabr   r   r   r   r   r   r	   r   r   r   r   r   r   r   z$<b>Module 4: Category Management</b>r   r0   r	  z<b>Primary Research</b>r  r&  z<b>Competition Research:</b>r  Reference CompetitorzNumber of Categories StockedzKey Categories Stockedz=Key observations around
stocking and categories
in the store?r5  r  r  r  r  r  r  r.  r  r  r   z<b>Customer Research:</b>z>Define Research
Methodology
(Sample Size, Probes,
and Methods)zHKey observations
around shopping
behaviors around
category by customers?r   r1  z<b>Category Management</b>)rK  z Level of Category
or MerchandisezNumber of Categories
Availabler   r   r;  皙@gffffff@r  )r  r  r  MIDDLEz&<i><b>Category Role Management</b></i>)Category NamezCategory RolezSales ContributionzMargin Contributionr  r  ?r  r=  z(<i><b>Gross Margin Contributions</b></i>)r  zContribution
to SaleszGross
MarginszGross Margin
ContributionrL  z#Total Weighted
Average Gross MarginrK  r<  )2r   r   rf   r`   reportlab.lib.pagesizesr
   reportlab.platypusr   r   r   r   r   reportlab.lib.stylesr   reportlab.lib.unitsr   reportlab.libr   ior   r  r   rr  r  r.  rP  rQ  rR  r+  r-  rs  rT  rU  rt  rZ  r[  r\  r]  ru  ra  rb  rc  rd  rv  rl  rm  rn  rw  r/  r0  )rm   rX   r   r
   r   r   r   r   r   r   r   r   r   r1  r2  r3  r4  r5  	comp_data
comp_table	cust_data
cust_tablecat_data	cat_table	role_datar  
role_tablemargin_datar  margin_tables                                 re   r@  z(Module4ReportService.generate_pdf_report  s   ) !4773C)H:Mc8dee.^^<,(228<PR^`oqr$& 	YEvjGYZ[VAr]# 	Y8&:LMNVAq\"Y=vh?OPQ $[%D%D%Y%YZ+S1P1P1m1m-no%{'F'F']']^NP[PoPo  QF  QF  G	
	 9T3t80DE
J/VXq&,,7/-0(
  	 	Z VAr]# 	VAr]#Y:F8<LMN QR]RoRo  SE  SE  FZ\g\y\y  ]L  ]L  M
	
 9440@A
J/VXq&,,7/-0(
  	 	Z VAr]# 	VAr]#Y;VJ=OPQ Y{::OOQTU`UpUp  VK  VK  RL  M{::OOQTU`UpUp  VK  VK  RL  M
 (s4xT3t8.LM	:/;VXq&,,72-0'
  	 	YVAr]# 	VAr]#YGPXIYZ[de	..Dd00$2D2DI`I`adHeefFglp  mE  mE  FI  lJ  JK  jL  M  N / 9T3t8SXsSWx0XY
J/;VXq&,,72-(
  	 	Z VAr]# 	VAr]#YI6RZK[\]rs88B 0 0R5M5Mc4RRS2TY[YiYijmXnnoVpuw  vR  vR  SV  uW  WX  sY   Z  [ 9BB{O~O~  @C  OD  DE  MF  G  	H[SXs4xTSVW[S[4\]j/;=VXq&,,72-0*
  	 	\"		%Arp   c                    ddl m} t        || j                        s |dd| d      	 ddlm} | j                  j                  |      j                  |j                  |k(        j                         }|rU|D cg c]I  }t        |j                  xs d|j                  xs d	|j                  xs d
|j                  xs d      K }}n*g d}|dk  r||dz     nd| d}t        d|dd|       g}t        dddd      t        dddd      t        dddd      t        ddd d!      t        d"ddd#      t        d$d%d d&      t        d'ddd(      t        d)d%dd*      g}	t!        d+d,d-.      t!        d/d0d1.      t!        d2d,d3.      g}
t#        d+d0d14      t#        d/d,d54      t#        d2d0d14      g}t%        ||	|
|d6d78      S c c}w #  g d}|dk  r||dz     nd| d}t        d|dd|       g}Y 	xY w)9zGenerate Module 5 report datar   r   r   r   r   r   )TblVendorMetricsPriorityListr0   Unknownr  
No remarks)priorityr  metricsr  )zPrice FocuszQuality FocuszOrganic Focusr  zGroup z	 PriorityzGroup-specific metricszPriority for group zMargin %r`  rX  15)metric	weightage
importancebatnazCredit Periodro  rW  30zExpected Stock Holdingrg  zPromo Support      $@Low5zNew SKU Introduction Charges500zDisplay Incomeg      @z10 unit in 5 storeszFrequency Of Supply2z	Lead Time7re  Yesz?High margin potential and customer loyalty building opportunity)ra  private_labelru   zPersonal CareNorK  zHousehold Itemsz.Cost advantage and better control over quality)ra  category_captainshipru   z>Leading brand expertise can help optimize category performancez=Vendor management strategy focuses on quality and reliabilityzRStrategic partnerships with key vendors while maintaining competitive alternatives)vendor_priority_matrixvendor_scorecardprivate_labellingr  additional_remarkskey_takeaways)r   r   rf   r`   ,app.models.main.vendor_metrics_priority_listr  rb   rw   rX   r   rC   r  r  r  r  rD   rE   rF   rG   )rm   rX   r   r  vendor_datar   r  areasr  r  r  r  s               re   generate_module5_reportz,Module4ReportService.generate_module5_reportq  s   ) !4773C)H:Mc8dee&	a''--(DELL,55Ace   #.* #.$ -!%!3!!YY3) $ ? $ <	
 #. ' * J.6!muX\*6(S\A],!"! 8"5hZ @	*&,  zTf\`a$S[cgh'?4\bjno$SX`cd'EQUbjrwx'73SX`uv'<Yailm{cf\_`	
 !)#[
 !-"
 !/#J
& $)%)
 $-%*Z
 $/%) 
$ %#9-/!5^n
 	
a*(	EE*2a-5A&vhZy=YD(41(<	&"s   AG =AG-G G ,Hc                    ddl m} t        || j                        s |dd| d      | j	                  |      }d}|j
                  D ]<  }|d|j                   d	|j                   d	|j                   d	|j                   d
	z  }> d}|j                  D ]<  }|d|j                   d	|j                   d|j                   d	|j                   d
	z  }> d}|j                  D ]B  }|j                   dk(  r|j"                  nd}|d|j$                   d	|j                    d	| d
z  }D d}	|j&                  D ]B  }|j&                  dk(  r|j"                  nd}|	d|j$                   d	|j&                   d	| d
z  }	D d| d| d| d|	 d	}
|
S )z!Generate HTML report for Module 5r   r   r   r   r   r   rK  r  r  r  r  r  a{  <!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Module 5: Vendor Management, Category Captainship, Private Labelling</title>
    <style>
        body { font-family: 'Times New Roman', serif; font-size:15px; }
        table { border-collapse: collapse; width: 100%; }
        th, td { border:1px solid #888; padding:6px; }
        th { background: #f8f8f8; }
        input[type="text"], textarea, select { width: 100%; box-sizing: border-box; font-size:14px; }
        textarea { resize:vertical; height:35px; }
    </style>
</head>
<body>

<p><i>Reporting Processes</i></p>
<p>The following report will be generated from this module.</p>

<table style="width:100%">
    <tr>
        <td colspan="4" style="font-size:17px"><b>Module 5: Vendor Management, Category Captainship, Private Labelling</b></td>
    </tr>
</table>

<table style="width:100%">
    <tr>
        <td colspan="4"><b>Vendor Management Priority Matrix</b></td>
    </tr>
    <tr>
        <th style="width:17%">Priority</th>
        <th style="width:30%">Area</th>
        <th style="width:33%">Metrics</th>
        <th style="width:20%">Remarks</th>
    </tr>a  
</table>
<br>

<table style="width:100%">
    <tr>
        <td><b>Vendor Management Scorecard</b></td>
    </tr>
</table>
<br>

<table style="width:100%">
    <tr>
        <th style="width:17%">Metric</th>
        <th style="width:11%">Weightage</th>
        <th style="width:11%">Importance</th>
        <th style="width:61%">Best Alternative To A Negotiated Agreement (BATNA)</th>
    </tr>a)  
</table>
<br>

<table style="width:100%">
    <tr>
        <td colspan="4" style="font-weight: bold;">Private Labelling</td>
    </tr>
    <tr>
        <th style="width:28%">Category Name</th>
        <th style="width:18%">Private Label</th>
        <th style="width:54%">Rationale</th>
    </tr>a3  
</table>
<br>

<table style="width:100%">
    <tr>
        <td colspan="4" style="font-weight: bold;">Category Captainship</td>
    </tr>
    <tr>
        <th style="width:28%">Category Name</th>
        <th style="width:18%">Category Captainship</th>
        <th style="width:54%">Rationale</th>
    </tr>z
</table>

</body>
</html>)r   r   rf   r`   r  r  r  r  r  r  r  r  r  r  r  r  r  ru   ra  r  )rm   rX   r   r1  priority_matrix_rowsr   scorecard_rowsprivate_label_rowsru   captainship_rowsr]  s              re   generate_module5_html_reportz1Module4ReportService.generate_module5_html_report  s5   ) !4773C)H:Mc8dee228<  "66D  )]]O YYK \\N \\N 
%   7 00D #[[M ^^ __ ZZL 
 N 1  11D*.*<*<*E2I '  !  !K 
	#  2 44D*.*C*Cu*LRTI %  !&&' (K 
	!  5"
D 	  
" 	 
 	 
 	 WOb rp   c                 Z	   ddl m} t        || j                        s |dd| d      ddlm} ddlm}m}m	}m
}m} dd	lm}	 dd
lm}
 ddlm} ddlm} | j)                  |      } |       } |||dddd      } |	       }g }|j+                   |d|d                |j+                   |dd             |j+                   |d|d                |j+                   |dd             g dg}|j,                  D ]H  }|j+                  t/        |j0                        |j2                  |j4                  |j6                  g       J  ||d|
z  d|
z  d|
z  d|
z  g      }|j9                   |ddddd d|j:                  fd!d"d#g             |j+                  |       |j+                   |dd             |j+                   |d$|d                |j+                   |dd             g d%g}|j<                  D ]B  }|j+                  |j>                  |j@                   d&|jB                  |jD                  g       D  ||d'|
z  d(|
z  d(|
z  d)|
z  g      }|j9                   |ddddd d|j:                  fd!d"d#g             |j+                  |       |j+                   |dd             |j+                   |d*|d                |j+                   |dd             g d+g}|jF                  D ]G  }|jH                  d,k(  r|jJ                  nd-}|j+                  |jL                  |jH                  |g       I  ||d|
z  d.|
z  d/|
z  g      }|j9                   |ddddd d|j:                  fd!d"d#g             |j+                  |       |j+                   |dd             |j+                   |d0|d                |j+                   |dd             g d1g}|jN                  D ]G  }|jN                  d,k(  r|jJ                  nd-}|j+                  |jL                  |jN                  |g       I  ||d2|
z  d|
z  d3|
z  g      }|j9                   |ddddd d|j:                  fd!d4d#g             |j+                  |       |jQ                  |       |jS                  d       |S )5z0Generate PDF report for Module 5 using ReportLabr   r   r   r   r   r   r	   r   r  r   r   r   r   r   zK<b>Module 5: Vendor Management, Category Captainship, Private Labelling</b>r   r0   r	  z(<b>Vendor Management Priority Matrix</b>r  r&  )Priorityr(  MetricsRemarks333333?gffffff?r  r  r  r  r  r  r  r  r  r.  r  z"<b>Vendor Management Scorecard</b>)Metric	Weightage
ImportanceBATNAr  r;  r,  g333333@z<b>Private Labelling</b>)r  zPrivate Labelr*  r  rK  r+  r-  z<b>Category Captainship</b>)r  zCategory Captainshipr*  ?gffffff
@r/  r  r     )*r   r   rf   r`   r  r
   r  r   r   r   r   r   r  r   r  r   r  r   r  r   r  r   r  r.  r  r  r  r  r+  r-  r  r  r  r  r  r  r  ru   ra  r  r/  r0  )rm   rX   r   r
   r   r   r   r   r   r   r   r   r   r1  r2  r3  r4  r5  priority_datar   priority_tablescorecard_datascorecard_tableprivate_dataru   private_tablecaptainship_datacaptainship_tables                               re   generate_module5_pdf_reportz0Module4ReportService.generate_module5_pdf_reportc  s   ) !4773C)H:Mc8dee.^^<,(228<PR^`oqr$& 	Ylntu  oA  B  	CVAr]# 	YI6R\K]^_VAq\"CD66D  #dmm"4diit||!\] 7 }T3t8SQUXWZ[_W_8`a
/;VXq&,,7/-0,
 ! 	 	^$VAr]# 	YCVJEWXYVAq\"HI00D!!4;;4>>2B!0DdooW[WaWa"bc 1  3t8SXsSWxY\]aYa:bc  /;VXq&,,7/-0-
 " 	 	_%VAr]# 	Y96*;MNOVAq\"GH11D*.*<*<*E2I!3!3T5G5G ST 2 ls4xT3t86TUz/;VXq&,,7/-0+
   	 	]#VAr]# 	Y<fZ>PQRVAq\"RS44D*.*C*Cu*LRTI##T%7%79R9RT]$^_ 5 ""2s4xTSVW[S[>\]"":/;VXq&,,7/-0/
 $ 	 	&'		%Arp   c                    ddl m} t        || j                        s |dd| d      	 ddlm} | j                  j                  |      j                  |j                  |k(        j                         }|r|j                  xs d}ng d	}||t        |      z     }t        t        |d
ddd      t        ddd      t        ddd      gt        ddd      t        ddd      gt!        ddddd       t#        d!dd"d#d$d%&      t#        d'dd(d)d*d+&      gt%        dd,d-d.d/d01      t'        d,d2d3d4d5d6d78      d9d:;	      S #  g d	}||t        |      z     }Y xY w)<z!Generate report data for Module 6r   r   r   r   r   r   )TblCompetitorPricingAnalysiszUnknown Competitor)zLocal StorezReliance FreshzNature Basket
Big Bazaarz)High-Low Pricing with frequent promotionszGroceries and FMCG productsz?Heavy discounting on weekends, premium pricing on fresh producez?Strong focus on private label products with competitive pricing)r  r*  highest_income_categorykey_observationsr  r   zEveryday Low PricezMTargeting price-sensitive customers in urban areas with consistent low prices)r   r*  ru   r   zHigh-LowzCPremium location strategy with periodic promotions to drive trafficre  zGEssential category requiring competitive pricing for customer retention)categoryr*  ru   rf  z@High-margin category suitable for promotional pricing strategiesr  z4Buy 2 Get 1 Free, Weekend discounts, Festival offersz9Weekend discounts drive highest footfall and sales volumezEHeavy promotional calendar with seasonal and festival-based campaignsz;Strong digital promotion integration with mobile app offers)r  ongoing_promotionsmost_effective_promotionr  r  JanuaryzNew Year Salez20% increase in footfallz0Clear winter inventory and attract new customersz.Focus on essential items with 15-25% discounts)monthr  promotion_typesuccess_metric	objectiver  FebruaryzValentine Specialz15% revenue growthzTarget couples and gift buyersz.Bundle offers on mobile phones and accessoriesTz=Points-based system with tiered benefits and cashback rewardsz6Strong mobile app integration with personalized offerszBEffective in driving repeat purchases and customer data collectionz<Multi-brand partnership providing diverse redemption options)r  has_loyalty_programloyalty_program_typer  usefulness_assessmentr  zGTiered membership with points, cashback, and exclusive member discountsr  zHIncreased customer retention, valuable shopping data, higher basket sizezRHigh operational costs, potential margin pressure, customer expectation managementz;Focus on experiential rewards and community building eventsz5Integration with social media for enhanced engagement)has_programprogram_descriptionbudget_percentagebenefitsperilsdifferentiationother_noteszLComprehensive pricing and promotion strategy aligned with market positioningzaBalanced approach combining competitive pricing with strategic promotions and loyalty initiatives)	competitor_pricingstore_format_pricingcategory_pricingcompetitor_promotionsyearly_promotionscompetitor_loyaltyloyalty_programr  r  )r   r   rf   r`   +app.models.main.competitor_pricing_analysisr  rb   rw   rX   rx   r  rX  rH   rI   rJ   rK   rL   rM   rN   rO   )rm   rX   r   r  r  r  r  s          re   generate_module6_reportz,Module4ReportService.generate_module6_report  s   ) !4773C)H:Mc8dee	L`"ggmm,HIPP,55Aeg  '6'K'K'cOc$ _'28c+>N3N'O$
 !8%9!L(E!b_  #!1%9m
 #!1%/c"  (%9g
  *%/` #?%1#Y)d!h[#  #(#2#=PL  $*#6#7>L$  9%1$(%d!Y&j\  + $m"%ck ]S  n}WL
 L	
		LZK#.x#k:J/J#K s   A3E Ec                 V   ddl m} t        || j                        s |dd| d      ddlm} ddlm}m}m	}m
}m} dd	lm}	 dd
lm}
 ddlm} ddlm} | j)                  |      } |       } |||dddd      } |	       }g }|j+                   |d|d                |j+                   |dd             |j+                   |d|d                |j+                   |dd             d|j,                  j.                  gd ||j,                  j0                  |d         gd ||j,                  j2                  |d         gd ||j,                  j4                  |d         gd ||j,                  j6                  |d         gg} ||d|
z  d|
z  g      }|j9                   |dd d!d"d#d|j:                  fd$d%d&g             |j+                  |       |j+                   |dd             |j+                   |d'|d                |j+                   |dd             g d(g}|j<                  D ]>  }|j+                  |j>                  |j0                   ||j@                  |d         g       @  ||d)|
z  d*|
z  d+|
z  gd,|
z  gtC        |      z  -      }|j9                   |dd.d!d"d#d|j:                  fd$d/d&d0d1d2d3g
             |j+                  |       |j+                   |dd             |j+                   |d4|d                |j+                   |dd             g d5g}|jD                  D ]>  }|j+                  |jF                  |j0                   ||j@                  |d         g       @  ||d)|
z  d*|
z  d+|
z  gd,|
z  gtC        |      z  -      }|j9                   |dd.d!d"d#d|j:                  fd$d/d&d0d1d2d3g
             |j+                  |       |j+                   |dd             |j+                   |d6|d                |j+                   |dd             g d7g}|jH                  D ]}  }|j+                  |jJ                  |jF                   ||jL                  |d          ||jN                  |d          ||jP                  |d          ||jR                  |d         g         ||d8|
z  d9|
z  d:|
z  d:|
z  d)|
z  d;|
z  gd<|
z  gtC        |      z  -      }|j9                   |dd.d!d"d#d|j:                  fd$d=d&d>d?d@dAg
             |j+                  |       |j+                   |dd             |j+                   |dB|d                |j+                   |dd             dC|jT                  jV                  rdDndEgdF ||jT                  jX                  |d         gdG|jT                  jZ                   dHgdI ||jT                  j\                  |d         gdJ ||jT                  j^                  |d         gdK ||jT                  j`                  |d         gg} ||d;|
z  dL|
z  g      }|j9                   |dd d!d"d#d|j:                  fd$d/d&g             |j+                  |       |jc                  |       |je                  d       |S )Mz0Generate PDF report for Module 6 using ReportLabr   r   r   r   r   r   r	   r   r  r   r   r   r   r   z0<b>Module 6: Pricing, Promotions and Loyalty</b>r   r0   r	  z.<b>Competitor Analysis on Pricing Strategy</b>r  r&  r  Pricing Strategyr  zHighest Income CategoryzKey ObservationszOther Remarksr        @r  r  r6  r  r  r  r  r=  r  z'<b>Pricing Strategy by Store Format</b>)zStore Formatr  r*  r  r  g      @g?)r  
rowHeightsr  r.  )r!  r  r  r  )r$  r  r  r  )r&  r  r  r  )r(  r  r  r  z%<b>Category-wise Pricing Strategy</b>)Categoryr  r*  z<b>Yearly Promotion List</b>)Monthr  zPromotion
TypezSuccess
Metric	Objectiver  r  r  r+  r;  g?r  r0  r2  r3  r4  z<b>Loyalty Program Details</b>zHas Programr  r  DescriptionzBudget (% of sales)r  BenefitszPotential PerilsDifferentiationg      @)3r   r   rf   r`   r  r
   r  r   r   r   r   r   r  r   r  r   r  r   r  r   r  r   r  r  r*  r  r  r  r+  r-  r  r   ru   rX  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r/  r0  )rm   rX   r   r
   r   r   r   r   r   r   r   r   r   r1  r2  r3  r4  r5  pricing_datapricing_tableformat_datar   format_tablecategory_datacategory_tablepromotion_datapromotion_tableloyalty_dataloyalty_tables                                re   generate_module6_pdf_reportz0Module4ReportService.generate_module6_pdf_report<  s>   ) !4773C)H:Mc8dee.^^<,(228<PR^`oqr$& 	YQSYZdSefgVAr]# 	YOQWXbQcdeVAq\" $[%C%C%X%XY;+I+I+Z+Z\bck\l!mn&	+2P2P2h2hjpqyjz({|;+I+I+Z+Z\bck\l!mni(F(F(T(TV\]eVfgh
 ls4xT6JKz/;VXq&,,7/-0+
   	 	]#VAr]# 	YH&Q[J\]^VAq\"HI44D 1 143H3H)TXTbTbdjksdtJuvw 5 [SXs4xT4R`cdh`h_ijmnyjz_z{j/;VXq&,,7/-001/2*
  	 	\"VAr]# 	YFzHZ[\VAq\"FG00D  $--1F1F	RVR`R`bhiqbrHs!tu 1 }T3t8SQUX8Vdghldlcmnqr  oA  dA  B
/;VXq&,,7/-001/2,
 ! 	 	^$VAr]# 	Y=vj?QRSVAq\"mn11D!!4::t}}iH[H[]cdl]m>n!*4+>+>x@P!Q!*4>>6(;K!L!*4<<9I!J#L M 2  3t8SXsSWxY\]aYacfgkckmpqumu:v  EH  IM  EM  DN  OR  Sa  Ob  Db  c  /;VXq&,,7/-001/2-
 " 	 	_%VAr]# 	Y?
ASTUVAq\" [%@%@%L%LERVWIk&A&A&U&UW]^fWghi"{'B'B'T'T&UUV$WX;#>#>#G#GPXIYZ[;+F+F+M+MvV^O_!`a	+*E*E*U*UW]^fWg hi
 ls4xT6JKz/;VXq&,,7/-0+
   	 	]#		%Arp   r5   c                 L  	
 ddl m} t        || j                        s |dd| d      ddlm} ddlm
m} | G d	 d
             | G d d             | G d d             | G d d             | G d d             | G d d             | G d d             	| G 	
fdd             } |di ddd dd       dd        d!d"       d#d       d$d"       d%d&       d'd        d(d      gd)d*d+ dd,d-.       dd/d0.       d!d1d2.       d#d3d4.      gd5d6d7d8|d9z  z   d:d;d<d=d> d?d@dAdBdCdDdEF       dGdHdIdJdKdLdMF       dNdOdPdQdRdSdTF       dUdVdWdXdCdYdZF       d[dOd\d]d^dSd_F       d`dOdadbdcdSddF      gde dfdgdhi      dj dkl       dml       dnl      gdo dpl       dql       drl      gdsdtdu 	dvw       	dxw       	dyw       	dzw       	d{w      gd|d}d~dddS )z9Generate Module 7: Marketing & Communications report datar   r   r   r   r   r   )	dataclass)r   Optionalc                   "    e Zd ZU eed<   eed<   y)DModule4ReportService.generate_module7_report.<locals>.BrandAttributer}   customer_ratingNr`  ra  rb  r.  __annotations__re  rp   re   BrandAttributer    s    I  rp   r!  c                   ,    e Zd ZU eed<   eed<   eed<   y)JModule4ReportService.generate_module7_report.<locals>.CompetitorComparison	attributereference_retailer	own_brandNr  re  rp   re   CompetitorComparisonr#    s    N ##Nrp   r'  c                   T    e Zd ZU eed<   eed<   eed<   eed<   eed<   eed<   eed<   y)	GModule4ReportService.generate_module7_report.<locals>.MarketingActivityactivity_namebudget_allocatedr  measurement_metrictarget_shopper_journeyestimated_budgetr  Nr`  ra  rb  r.  r   rN  re  rp   re   MarketingActivityr)    s*    ##N ##$''##Lrp   r0  c                   ,    e Zd ZU eed<   eed<   eed<   y)HModule4ReportService.generate_module7_report.<locals>.CompetitorAnalysisr%  marketing_activity_briefr  Nr  re  rp   re   CompetitorAnalysisr2    s     ##&))  rp   r4  c                       e Zd ZU eed<   y)CModule4ReportService.generate_module7_report.<locals>.SpaceResourcedescriptionNr  re  rp   re   SpaceResourcer6        rp   r8  c                       e Zd ZU eed<   y)FModule4ReportService.generate_module7_report.<locals>.NonSpaceResourcer7  Nr  re  rp   re   NonSpaceResourcer;    r9  rp   r<  c                       e Zd ZU eed<   y)JModule4ReportService.generate_module7_report.<locals>.ConsumerJourneyStagestageNr  re  rp   re   ConsumerJourneyStager>  	  s    Jrp   r@  c                       e Zd ZU eed<   W W     ed<   eed<   W W    ed<   eed<   eed<   eed<   eed<   W W    ed	<   W ed
<   W W    ed<   W W    ed<   eed<   W W    ed<   eed<   eed<   eed<   y)CModule4ReportService.generate_module7_report.<locals>.Module7ReportrT  brand_attributesr  competitor_comparisonsbrand_positioning_statementmarketing_budget_percentagebudget_rationaletotal_marketing_budgetmarketing_activitiescompetitor_analysisspace_resourcesnon_space_resourcesincome_percentageconsumer_journey_predictionsstrategy_evolutionr  r  Nr/  )r!  r4  r'  r@  r   r0  r<  r8  s   re   Module7ReportrB  	  s    "%%">22$()=$>>),,)..!!$))"&'8"99!33!-00!%&6!77$$*./C*DD ## ##rp   rP  rT  zConducted primary research with 150 customers using structured interviews and surveys to understand brand perception and key attributes associated with retail stores in our category.rC  zQuality ProductszHigh importance)r}   r  zCompetitive PricingzVery importantzStore Accessibility	ImportantzCustomer ServicezProduct VarietyzStore AmbiancezModerate importancezBrand TrustConveniencer  zResearch revealed strong preference for value-for-money proposition combined with quality assurance and convenient shopping experience.rD  zPremium positioningzQuality at affordable prices)r$  r%  r&  zHigher price pointzValue-focused pricingzLimited locationszStrategic locationszStandard servicezPersonalized servicerE  zWe position ourselves as the trusted neighborhood retailer offering quality products at competitive prices with exceptional customer service, making everyday shopping convenient and affordable for families.rF  r5  r  rG  zAllocated 4.5% of sales for marketing to establish strong brand presence, drive customer acquisition, and maintain competitive positioning in the market.rH  g    @wArI  zDigital Marketing Campaignr`  z(Brand awareness and customer acquisitionz"Reach, engagement, conversion ratezAwareness stageg    @w@z1Focus on social media and search engine marketing)r*  r+  r  r,  r-  r.  r  zIn-store Promotionsrg  z"Drive sales and customer retentionzSales uplift, footfall increasezPurchase and retentiong     @z.Seasonal offers and loyalty program promotionszPrint Advertisingro  zLocal market penetrationzBrand recall, store visitszAwareness and considerationg    z@z(Local newspapers and community magazineszRadio Sponsorshipr  zBrand visibility and recallzBrand mentions, audience reach     @z Local radio station partnershipszCommunity Eventsz Community engagement and loyaltyz!Event attendance, brand sentimentzEngagement and loyaltyz)Local festivals and community initiativeszInfluencer PartnershipszTargeted audience reachzEngagement rate, conversionszConsideration and trialz&Local lifestyle and family influencersrJ  r  zComprehensive omnichannel approach with heavy emphasis on festival-based promotions, celebrity endorsements, and aggressive pricing campaigns across TV, digital, and print media.zOur approach focuses on community-centric marketing with personalized customer engagement, local partnerships, and sustainable practices rather than mass market celebrity-driven campaigns.)r%  r3  r  rK  zAATM installation generating rental income and increasing footfall)r7  uQ   Café corner providing additional revenue stream and extended customer dwell timezJProduct demonstration kiosks for brand partnerships and promotional incomerL  zDCustomer data monetization through targeted advertising partnershipsz=Private label product development and licensing opportunitiesz9Loyalty program partnerships with other service providersrM  r-  rN  z@Increased digital touchpoints integration with physical shopping)r?  z<Demand for personalized and sustainable shopping experiencesz5Community-driven brand engagement and social commercez6Omnichannel loyalty programs with experiential rewardsz:AI-powered product recommendations and shopping assistancerO  a  Post year three, our marketing strategy will pivot towards hyper-personalization using customer data analytics, increased focus on sustainability messaging, and community-building initiatives that position us as a lifestyle partner rather than just a retailer.r  zThe marketing strategy emphasizes building long-term customer relationships through authentic community engagement and value-driven communications.r  zSuccessful retail marketing requires balancing mass awareness with personalized engagement, leveraging both digital and traditional channels while maintaining authentic community connections and sustainable business practices.re  )	r   r   rf   r`   dataclassesr  typingr   r  )rm   rX   r   r  r  rP  r!  r4  r'  r@  r   r0  r<  r8  s         @@@@@@@@re   generate_module7_reportz,Module4ReportService.generate_module7_report  s   ) !4773C)H:Mc8dee))		! 	! 
	! 
	 	 
	
 
	 	 
	 
	! 	! 
	!
 
	 	 
	 
	 	 
	 
	 	 
	 
	 	 	 
	(  i
 "Zi
 $6HYZ$9K[\$9;W$6HYZ$5{S$4F[\MCSTMCTU	i
 di
 %/AVk  xV  W$/DYm  zQ  R$/DYl  yN  O$/AVh  uK  L	$i
& )y'i
( ),x#~(>)i
* y+i
, $,-i
0 "">%)H'K+<%-O ""7%)B'H+C%,L ""5%)8'C+H%,F ""5%);'G+<%,> ""4%)@'J+C%,G "";%)7'E+D%,D]7"/i
^ !3#/ *^ !_!_i
j *mn*}~*vwii
t !-st -lm -hi!si
| "}i
@ %+mn$+ij$+bc$+cd$+gh*i
L  fMi
N  uOi
P Qi
 i	
rp   c                 j   ddl m} t        || j                        s |dd| d      ddlm} ddlm}m}m	}m
}m}m}	 dd	lm}
 dd
lm} ddlm} ddlm} | j+                  |      } |       } |||dddd      } |
       }g }|j-                   |d|d                |j-                   |dd             |j-                   |d|d                |j-                   |dd             |j-                   |d|d                |j-                   ||j.                  |d                |j-                   |dd             |j-                   |d|d                |j-                   |dd             ddgg}|j0                  D ])  }|j-                  |j2                  |j4                  g       +  ||d|z  d|z  g      }|j7                   |d d!d"d#d$d|j8                  fd%d&g             |j-                  |       |j-                   |dd             |j-                   |d'|j:                   |d                |j-                   |dd             |j-                   |d(|d                |j-                   |dd             g d)g}|j<                  D ]4  }|j-                  |j>                  |j@                  |jB                  g       6  ||d*|z  d*|z  d*|z  g      }|j7                   |d d!d"d#d$d|j8                  fd%d+g             |j-                  |       |j-                   |dd             |j-                   |d,|d                |j-                   ||jD                  |d                |j-                   |dd             |j-                   |d-|d                |j-                   |dd             |j-                   |d.|d                d/|jF                   d0gd1d2|jH                  d3gd4 ||jJ                  |d         gg} ||d*|z  d5|z  g      }|j7                   |d d6d"d#d$d|j8                  fd%d&g             |j-                  |       |j-                   |dd             |j-                   |d7|d                |j-                   |dd             g d8g}|jL                  D ]  }|j-                   ||jN                  |d         |jP                   d9 ||jR                  |d          ||jT                  |d          ||jV                  |d         d2|jX                  d3g         ||d:|z  d;|z  d:|z  d<|z  d<|z  d<|z  g      }|j7                   |d d!d"d#d$d|j8                  fd%d=d>g             |j-                  |       |j-                   |dd             |j-                   |d?|d                d@|jZ                  j@                  gdA ||jZ                  j\                  |d         gdB ||jZ                  j^                  |d         gg} ||d*|z  d5|z  g      }|j7                   |d d6d"d#d$d|j8                  fd%d&g             |j-                  |       |j-                   |	              |j-                   |dC|d                |j-                   |dd             |j-                   |dD|d                ta        |jb                  d      D ]/  \  } }!|j-                   ||  dE|!jd                   |d                1 |j-                   |dd             |j-                   |dF|d                ta        |jf                  d      D ]/  \  } }!|j-                   ||  dE|!jd                   |d                1 |j-                   |dd             |j-                   |dG|jh                   d0|d                |j-                   |dd             |j-                   |dH|d                ta        |jj                  d      D ]/  \  } }"|j-                   ||  dE|"jl                   |d                1 |j-                   |dd             |j-                   |dI|d                |j-                   ||jn                  |d                |j-                   |dd             |j-                   |dJ|d                |j-                   |dd             dK ||jp                  |d         gdL ||jr                  |d         gg}# ||#d*|z  d5|z  g      }$|$j7                   |d d6d"d#d$d|j8                  fd%d&g             |j-                  |$       |ju                  |       |jw                  d       |S )MzLGenerate PDF report for Module 7: Marketing & Communications using ReportLabr   r   r   r   r   r   r	   )r   r   r   r   r   	PageBreakr  r   r   r   r   r   z/<b>Module 7: Marketing &amp; Communications</b>r   r0   r	  z$<b>Section 1: Branding &amp; USP</b>r  r&  z<b>Research Methodology:</b>Heading3r  r   z<b>Key Brand Attributes:</b>   	AttributezCustomer Ratingr5  r  r  r  r  r  r  r  r=  z<b>Other Remarks:</b> z-<b>Multi-Attribute Competitor Comparison:</b>)r[  Reference Retailerz	Own Brandr  r.  z#<b>Brand Positioning Statement:</b>z <b>Section 2: Marketing Plan</b>z<b>Marketing Budget:</b>zBudget Percentagez
% of saleszTotal Budget (Y1)r
  r9  r*  r  r6  z'<b>Integrated Marketing Activities:</b>)ActivityzBudget %r
  r  zJourney Stageu   Amount (₹)r  r  r  r+  r  r  z%<b>Competitor Marketing Analysis:</b>r\  zMarketing Activity BriefzOur Differentiationz)<b>Section 3: Brand Journey (Year 3+)</b>z"<b>Space Resource Utilization:</b>. z&<b>Non-Space Resource Utilization:</b>z$<b>Estimated Additional Income:</b> z.<b>Consumer Journey Evolution Predictions:</b>z$<b>Marketing Strategy Evolution:</b>z<b>Section 4: Summary</b>Additional RemarksKey Takeaways)<r   r   rf   r`   r  r
   r  r   r   r   r   r   rX  r  r   r  r   r  r   r  r   rV  r   rT  rC  r}   r  r+  r-  r  rD  r$  r%  r&  rE  rF  rH  rG  rI  r*  r+  r  r,  r-  r.  rJ  r3  r  r)  rK  r7  rL  rM  rN  r?  rO  r  r  r/  r0  )%rm   rX   r   r
   r   r   r   r   r   rX  r   r   r   r   r1  r2  r3  r4  r5  	attr_dataattr
attr_tabler  compr  budget_infobudget_tableactivity_dataactivityactivity_tablecomp_analysis_datacomp_analysis_tabler8  resourcer?  summary_datasummary_tables%                                        re   generate_module7_pdf_reportz0Module4ReportService.generate_module7_pdf_report	  s	   ) !4773C)H:Mc8dee.ii<,(228<PR^`oqr$& 	YPRXYcRdefVAr]# 	YEvjGYZ[VAq\" 	Y=vj?QRSY{??AQRSVAr]# 	Y=vj?QRSVAq\"!#456	00Ddii)=)=>? 1 9T3t80DE
J/;VXq&,,7/-(
  	 	Z VAr]#Y!78Q8Q7RSU[\dUefgVAr]# 	YNPVWaPbcdVAq\"EF	66Ddnnd.E.Et~~VW 7 9T3t8SX0NO
J/;VXq&,,7/-(
  	 	Z VAr]# 	YDfZFXYZY{FFxHXYZVAr]# 	YA6*CUVWVAq\" 	Y96*;MNO [%L%L$MZ"XY D)K)KD(Q"RS)K$@$@&BRST
 [SXs4x4HIj/;VXq&,,7/-*
  	 	\"VAr]# 	YH&Q[J\]^VAq\"ij#88H  (00&2BC,,-Q/(,,fX.>?(55vh7GH(996(;KLx0067"  9 }T3t8SQUXWZ[_W_adeiaiknosks8tu
/;VXq&,,7/-0,
 ! 	 	^$VAr]# 	YFzHZ[\!;#B#B#U#UV';3R3R3k3kmst|m})~"Ik.M.M.].]_efn_o$pq
 $$63t8SQUXBVW$$Z/;VXq&,,7/-1
 & 	 	()Y[! 	YJFS]L^_`VAq\" 	YCVJEWXY$[%@%@!DKAxLLaS8+?+?*@#A6(CSTU EVAr]# 	YGPZI[\]$[%D%DaHKAxLLaS8+?+?*@#A6(CSTU IVAr]#Y!EkFcFcEddnoqw  yA  rB  C  	DVAr]# 	YOQWXbQcde!+"J"JANHAuLLaS5;;-#8&:JKL OVAr]# 	YEvjGYZ[Y{==vh?OPQVAr]# 	Y:F:<NOPVAq\" "9[-K-KVT\M]#^_i(A(A6(CSTU

 ls4xT6JKz/;VXq&,,7/-+
   	 	]#		%Arp   N)r`  ra  rb  rE  r   rn   rc  r  r.  r_  r   r@  rG   r  r  r  rH   r  r  rV  ro  re  rp   re   rG  rG    s    L7 R
 R
8O R
hDS DS DLEC EG EPg
 g
8M g
RGS GS GRmC mG m`e
 e
8I e
RWC WG Wrp
 p
8O p
dIC IG Irp   rG  c                       e Zd ZdZdefdZdedee   fdZ	dedee
   fdZdedee   fdZdedefd	Zded
edefdZded
edee   fdZdedefdZdedefdZdedefdZy)Module8ReportServicezCService class for generating Module 8: Services & Utilities reportsr`   c                     || _         y rj   rk   rl   s     re   rn   zModule8ReportService.__init__U
  ro   rp   rX   rY   c                 
   	 | j                   j                  t              j                  t        j                  |k(        j                         }g }|D ]  }|j                  sd|j                  j                         v sd|j                  j                         v sI|j                  t        |j                  |j                  xs d|j                  xs d|j                  xs d|j                  xs d|j                   xs d|j"                  xs d              |s=g d}||t%        |      z     }t        |d	|d
z  z   d|z   d|z   d|z   d|z   d|z         g}|S # t        $ r}t        d|        g }Y d}~.d}~ww xY w)zGet corporate office roles datazError loading corporate data: Nseniorsupportr   r   role_categorycost_to_companyy1_county2_county3_county4_county5_count)zStore ManagerArea ManagerzRegional ManagerzSenior Leadership     j(Ar  r0   r   r  r1  rZ  )r`   rb   r,   rw   rX   r   r_   rW  rw  lowerr   rP   rx  y1y2y3y4y5rX  )rm   rX   corporate_datar^  corporate_rolesr  role_categoriesrw  s           re   get_corporate_office_dataz.Module8ReportService.get_corporate_office_dataX
  sx   	 !WW]]+DELL)22h>ce  "D!!x43E3E3K3K3M'MQZ^b^p^p^v^v^xQx&&'>"&"4"4$($8$8$?C!WW\!WW\!WW\!WW\!WW\(  # hO+Hs?7K,KLM ("/$,60A$B\AL1x<\AL	O A  	 21#67N	 s   AE 	F'E==Fc                    	 | j                   j                  t              j                  t        j                  |k(        j                         }g }|D ]  }|j                  sd|j                  j                         v sd|j                  j                         v sI|j                  t        |j                  |j                  xs d|j                  xs d|j                  xs d|j                  xs d|j                   xs d|j"                  xs d              |s$t        dd	d
dddd      t        ddddddd      g}|S # t        $ r}t        d|        g }Y d}~d}~ww xY w)zGet concept office roles datazError loading concept data: Nr  unitr   r   rv  r~  r  r0   r   r  r1  rZ  zUnit Managerg    Ar"  r&  r   )r`   rb   r,   rw   rX   r   r_   rW  rw  r  r   rQ   rx  r  r  r  r  r  )rm   rX   concept_datar^  concept_rolesr  s         re   get_concept_office_dataz,Module8ReportService.get_concept_office_data
  sX   	77==)BCJJ)22h>ce   D!!v1C1C1I1I1K'KvY]YkYkYqYqYsOs$$%:"&"4"4$($8$8$?C!WW\!WW\!WW\!WW\!WW\&  ! %"0$,QQ
 &"0$,QRM C  	045L	s   AE 	E)E$$E)c           
         	 | j                   j                  t              j                  t        j                  |k(        j                         }i }|D ]y  }|j                  xs d}||vr|j                  xs dddd||<   |j                  dk(  r|j                  xs d||   d<   T|j                  d	k(  sd|j                  xs d||   d
<   { g }|j                         D ],  \  }}|j                  t        ||d   |d   |d
                . |s,t        dddd      t        dddd      t        dddd      g}|S # t        $ r}t        d|        g }Y d}~d}~ww xY w)zGet store level staff datazError loading staff data: Nr  r   r   )average_salaryformat_a_countformat_b_countr   r  r   r  r  )designationr  r  r  zManager / Assistant ManagerrS  r   r  
Supervisorg     j@r1  zFront End Staffg     @r&  r  )r`   rb   r-   rw   rX   r   r_   rW  r  r  r   rd   itemsr   rR   )	rm   rX   
staff_datar^  staff_by_designationstaffr  
staff_listr   s	            re   get_store_level_staff_dataz/Module8ReportService.get_store_level_staff_data
  s   	'>?FF'00H<ce   "E++8yK"66&+&:&:&Ac&'&'5$[1 ''+;;FKkkFVUV$[12BC))-==FKkkFVUV$[12BC   
!5!;!;!=K1'#$45#$45#$45	  "> # =#*#$Q
 $ ,#*#$Q
 $ 1#*#$RJ$ c  	.qc23J	s   AE   	E$	EE$c                     t        ddd      S )zGet HR policy analysis datazReliance RetailzComprehensive employee training programs, performance-based incentives, flexible working hours, and career development opportunities with focus on customer service excellence.zOur HR policies emphasize work-life balance, continuous learning through digital platforms, and community engagement initiatives that differentiate us from traditional retail HR practices.)r%  hr_activity_briefpolicy_differentiation)rS   )rm   rX   s     re   get_hr_policy_analysisz+Module8ReportService.get_hr_policy_analysis
  s      0 P $b
 	
rp   r   c                    	 | j                   j                  t              j                  t        j                  |k(  t        j
                  |k(        j                         }t        dddd      }t        dd	d
d      }t        dddd      }g }d}	|D ]  }
t        |
j                  xs d|
j                  xs d|
j                  xs d|
j                  xs d      }d|
j                  j                         v r|}id|
j                  j                         v r|}d|
j                  j                         v sd|
j                  j                         v r|}|j                  |       |	|j                  z  }	 |j                  |j                  z   |j                  z   }	|D ]  }|	|j                  z  }	 t!        |||||	      S # t        $ r}t        d|        g }Y d}~d}~ww xY w)z,Get utilities data for specific store formatzError loading utilities data: NElectricityg     L@z*Lighting, HVAC, refrigeration, POS systemsz?Peak usage during business hours, energy-efficient LED lighting)utility_namecost_per_monthkey_usage_parametersr  Waterg     p@z+Cleaning, restrooms, food preparation areasz/Municipal water supply with backup storage tankzFuel Generationg     @@z2Backup power during outages, generator maintenancez+Diesel generator for emergency power backupg     d@r  r   r  r  electricitywaterfuel	generator)r  r  fuel_generationadditional_utilitiestotal_utility_cost)r`   rb   r.   rw   rX   r   r   r_   rW  rT   r  r  r  r  r  r   rU   )rm   rX   r   	utilitiesr^  r  r  r  r  
total_costutilityutility_datautils                re   get_utilities_dataz'Module8ReportService.get_utilities_data
  s   	j188##x/,,< ce  "&"!MU	
  !!NE	
 &*!!UA	
  "
 !G&$11>Y&55<%,%A%A%T_6,	L  4 4 : : <<*G006688$7//5577;'J^J^JdJdJf;f".$++L9l999
# !( !//%2F2FFIgIgg
(D$---J ) ##+!5)
 	
m  	21#67I	s   AG 	G)G$$G)c           	         	 | j                   j                  t              j                  t        j                  |k(  t        j
                  |k(        j                         }g }|D ]I  }|j                  t        |j                  xs d|j                  xs d|j                  xs d             K |st        ddd	      t        d
dd      g}|S # t        $ r}t        d|        g }Y d}~d}~ww xY w)z5Get operating expenses data for specific store formatzError loading expenses data: Nr  r   r  expense_typepercentage_of_salesr  zMaintenance and Repairsr  zDRegular maintenance of equipment, fixtures, and store infrastructurezAdmin Overheadsr  zSAdministrative costs including stationery, bank charges, and miscellaneous expenses)r`   rb   r/   rw   rX   r   r   r_   rW  r   rV   operating_expenses_typepercentage_of_sales_per_yearr  )rm   rX   r   r   r^  expense_listexpenses          re   get_operating_expenses_dataz0Module8ReportService.get_operating_expenses_data1  s    	ww}}%9:AA$--9$77<G ce  G 4$<<I	$+$H$H$OC6,!    $!:(+b
 %!2(+qL 7  	1!56H	s   AC 	C4C//C4c                    ddl m} t        || j                        s |dd| d      | j	                  |      }| j                  |      }| j                  |      }| j                  |      }| j                  |d      }| j                  |d      }| j                  |d      }	| j                  |d      }
t        |||||||	|
d	d

      S )z6Generate complete Module 8 Services & Utilities reportr   r   r   r   r   r   zStore Formate AzStore Formate Bz[Services and utilities strategy focuses on operational efficiency and employee satisfactionzxBalanced approach to human resource management with cost-effective utility solutions and sustainable operating practices)
corporate_office_rolesconcept_office_rolesstore_level_staffhr_policy_analysisutilities_format_autilities_format_boperating_expenses_format_aoperating_expenses_format_br  r  )r   r   rf   r`   r  r  r  r  r  r  rW   )rm   rX   r   r  r  r  r  r  r  r  r  s              re   generate_module8_reportz,Module8ReportService.generate_module8_reportU  s    ) !4773C)H:Mc8dee "&!?!?!I#;;HE ;;HE!88B!44X?PQ!44X?PQ&*&F&FxQb&c#&*&F&FxQb&c#$#9!5/111(C(C| U
 	
rp   c                 v   ddl m} t        || j                        s |dd| d      | j	                  |      }d}|j
                  D ]d  }|d|j                   d	|j                  d
d|j                   d|j                   d|j                   d|j                   d|j                   dz  }f d}|j                  D ]d  }|d|j                   d	|j                  d
d|j                   d|j                   d|j                   d|j                   d|j                   dz  }f d}|j                  D ]=  }|d|j                   d	|j                   d
d|j"                   d|j$                   d	z  }? d }	 |	|j&                        }
 |	|j(                        }d } ||j*                        } ||j,                        }d| d| d| d|j.                  j0                   d|j.                  j2                   d|j.                  j4                   d|
 d| d| d| d|j6                   d|j8                   d}|S )z!Generate HTML report for Module 8r   r   r   r   r   r   rK  r     </td>
        <td>₹r9  r  r  c                    d| j                   j                   d| j                   j                  dd| j                   j                   d| j                   j                   d| j
                  j                   d| j
                  j                  dd| j
                  j                   d| j
                  j                   d| j                  j                   d| j                  j                  dd| j                  j                   d| j                  j                   d}| j                  D ]=  }|d|j                   d|j                  dd|j                   d|j                   d	z  }? |d| j                  ddz  }|S )	Nr  r  r9  r  z%</td>
    </tr>
    <tr>
        <td>r  uk   
    <tr style="font-weight: bold; background-color: #f0f0f0;">
        <td>Total Cost</td>
        <td>₹z-</td>
        <td colspan="2"></td>
    </tr>)	r  r  r  r  r  r  r  r  r  )utilities_datarowsr  s      re   generate_utility_rowszHModule8ReportService.generate_html_report.<locals>.generate_utility_rows  s   ''445 6**99$? @''<<= >''//0 1 !!../ 0$$33D9 :!!667 8!!))* + ++889 :..==dC D++@@A B++334 5
#D( ';;   ##D) *&&' (\\N 
  <   11$7 8
 D Krp   c           	      r    d}| D ]/  }|d|j                    d|j                   d|j                   dz  }1 |S )NrK  r  r  r  r  r  )r   r  r  s      re   generate_expense_rowszHModule8ReportService.generate_html_report.<locals>.generate_expense_rows  s]    D# !!" #(() *__ 
	  $ Krp   a  <!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Module 8: Services & Utilities</title>
    <style>
        body { font-family: 'Times New Roman', serif; font-size: 14px; }
        table { border-collapse: collapse; width: 100%; margin-bottom: 20px; }
        th, td { border: 1px solid #888; padding: 8px; text-align: left; }
        th { background-color: #f8f8f8; font-weight: bold; }
        .section-header { font-size: 16px; font-weight: bold; margin: 20px 0 10px 0; }
        .subsection-header { font-size: 14px; font-weight: bold; margin: 15px 0 8px 0; }
    </style>
</head>
<body>

<div class="section-header">Module 8: Services & Utilities</div>

<div class="subsection-header">Corporate & Concept Office</div>

<p><strong>Corporate Office</strong></p>
<table>
    <tr>
        <th>Role Category</th>
        <th>Cost to Company (Y1) per Head</th>
        <th>Year 1</th>
        <th>Year 2</th>
        <th>Year 3</th>
        <th>Year 4</th>
        <th>Year 5</th>
    </tr>a  
</table>

<p><strong>Concept Office</strong></p>
<table>
    <tr>
        <th>Role Category</th>
        <th>Cost to Company (Y1) per Head</th>
        <th>Year 1</th>
        <th>Year 2</th>
        <th>Year 3</th>
        <th>Year 4</th>
        <th>Year 5</th>
    </tr>z
</table>

<div class="subsection-header">Store Level Services</div>

<table>
    <tr>
        <th>Designation</th>
        <th>Average Salary</th>
        <th>Format A Count</th>
        <th>Format B Count</th>
    </tr>z
</table>

<div class="subsection-header">Training & Talent Management</div>

<table>
    <tr>
        <th>Reference Retailer</th>
        <td>zH</td>
    </tr>
    <tr>
        <th>HR Activity Brief</th>
        <td>zM</td>
    </tr>
    <tr>
        <th>Policy Differentiation</th>
        <td>a  </td>
    </tr>
</table>

<div class="subsection-header">Utilities</div>

<p><strong>Store Format A Utilities</strong></p>
<table>
    <tr>
        <th>Utility Type</th>
        <th>Cost per Month</th>
        <th>Key Usage Parameters</th>
        <th>Remarks</th>
    </tr>z
</table>

<p><strong>Store Format B Utilities</strong></p>
<table>
    <tr>
        <th>Utility Type</th>
        <th>Cost per Month</th>
        <th>Key Usage Parameters</th>
        <th>Remarks</th>
    </tr>a  
</table>

<div class="subsection-header">Other Operating Expenses</div>

<p><strong>Store Format A Operating Expenses</strong></p>
<table>
    <tr>
        <th>Expense Type</th>
        <th>Percentage of Sales per Year</th>
        <th>Remarks</th>
    </tr>z
</table>

<p><strong>Store Format B Operating Expenses</strong></p>
<table>
    <tr>
        <th>Expense Type</th>
        <th>Percentage of Sales per Year</th>
        <th>Remarks</th>
    </tr>zz
</table>

<div class="subsection-header">Summary</div>

<table>
    <tr>
        <th>Additional Remarks</th>
        <td>D</td>
    </tr>
    <tr>
        <th>Key Takeaways</th>
        <td>)</td>
    </tr>
</table>

</body>
</html>)r   r   rf   r`   r  r  rw  rx  ry  rz  r{  r|  r}  r  r  r  r  r  r  r  r  r  r  r  r%  r  r  r  r  )rm   rX   r   r1  corporate_rowsr  concept_rows
staff_rowsr  r  utilities_a_rowsutilities_b_rowsr  expenses_a_rowsexpenses_b_rowsr]  s                   re   r_  z)Module8ReportService.generate_html_reportv  s   ) !4773C)H:Mc8dee228< 66D #  !$$T* +]]O ]]O ]]O ]]O ]]O 
	 	N 7 44D !  !$$T* +]]O ]]O ]]O ]]O ]]O 
	 	L 5 
 22E   $$T* +!!" #!!" #
 J 3$	L 11O1OP01O1OP		 00W0WX/0W0WX
< 	 
  
   ++>>? @ ++==> ? ++BBC D
 	 

 	 
 	 	
 	  ++, - &&' ({BH rp   c                 "   ddl m} t        || j                        s |dd| d      | j	                  |      }t               }t        |t        dddd      }t               }g }|j                  t        d	|d
                |j                  t        dd             |j                  t        d|d                |j                  t        dd             |j                  t        d|d                t        d|d         t        d|d         dddddgg}|j                  D ]  }	|j                  |	j                  d|	j                  dt        |	j                         t        |	j"                        t        |	j$                        t        |	j&                        t        |	j(                        g        t+        |dt,        z  dt,        z  dt,        z  dt,        z  dt,        z  dt,        z  dt,        z  g      }
|
j/                  t1        d d!d"d#d$dt2        j4                  fd%d&d'g             |j                  |
       |j                  t        dd(             |j                  t        d)|d                t        d|d         t        d|d         dddddgg}|j6                  D ]  }	|j                  |	j                  d|	j                  dt        |	j                         t        |	j"                        t        |	j$                        t        |	j&                        t        |	j(                        g        t+        |dt,        z  dt,        z  dt,        z  dt,        z  dt,        z  dt,        z  dt,        z  g      }|j/                  t1        d d!d"d#d$dt2        j4                  fd%d&d'g             |j                  |       |j                  t        dd             |j                  t        d*|d                |j                  t        dd             t        d+|d         t        d,|d         t        d-|d         t        d.|d         gg}|j8                  D ]U  }|j                  |j:                  d|j<                  dt        |j>                        t        |j@                        g       W t+        |d/t,        z  dt,        z  d0t,        z  d0t,        z  g      }|j/                  t1        d d!d"d#d$dt2        j4                  fd%d1d'g             |j                  |       |j                  t        dd             |j                  t        d2|d                |j                  t        dd             d3|jB                  jD                  gd4t        |jB                  jF                  |d         gd5t        |jB                  jH                  |d         gg}t+        |d/t,        z  d6t,        z  g      }|j/                  t1        d d7d"d#d$dt2        j4                  fd%d1g             |j                  |       |j                  t        dd             |j                  t        d8|d                |j                  t        dd             |j                  t        d9|d                t        d:|d         t        d;|d         t        d<|d         t        d=|d         gg}|jK                  |jL                  jN                  jP                  d|jL                  jN                  jR                  dt        |jL                  jN                  jT                  |d         t        |jL                  jN                  jV                  |d         g|jL                  jX                  jP                  d|jL                  jX                  jR                  dt        |jL                  jX                  jT                  |d         t        |jL                  jX                  jV                  |d         g|jL                  jZ                  jP                  d|jL                  jZ                  jR                  dt        |jL                  jZ                  jT                  |d         t        |jL                  jZ                  jV                  |d         gg       |jL                  j\                  D ]]  }|j                  |jP                  d|jR                  dt        |jT                  |d         t        |jV                  |d         g       _ |j                  d>d|jL                  j^                  dd?d?g       t+        |dt,        z  d0t,        z  d/t,        z  d@t,        z  g      }|j/                  t1        d d!dAdBdCd$t2        j`                  fd"d#d$dt2        j4                  fd%d&d'g             |j                  |       |j                  t        dd(             |j                  t        dD|d                t        d:|d         t        d;|d         t        d<|d         t        d=|d         gg}|jK                  |jb                  jN                  jP                  d|jb                  jN                  jR                  dt        |jb                  jN                  jT                  |d         t        |jb                  jN                  jV                  |d         g|jb                  jX                  jP                  d|jb                  jX                  jR                  dt        |jb                  jX                  jT                  |d         t        |jb                  jX                  jV                  |d         g|jb                  jZ                  jP                  d|jb                  jZ                  jR                  dt        |jb                  jZ                  jT                  |d         t        |jb                  jZ                  jV                  |d         gg       |jb                  j\                  D ]]  }|j                  |jP                  d|jR                  dt        |jT                  |d         t        |jV                  |d         g       _ |j                  d>d|jb                  j^                  dd?d?g       t+        |dt,        z  d0t,        z  d/t,        z  d@t,        z  g      }|j/                  t1        d d!dAdBdCd$t2        j`                  fd"d#d$dt2        j4                  fd%d&d'g             |j                  |       |j                  t        dd             |j                  t        dE|d                |j                  t        dd             |j                  t        dF|d                t        dG|d         t        dH|d         t        d=|d         gg}|jd                  D ]D  }|j                  |jf                  |jh                   dIt        |jV                  |d         g       F t+        |d/t,        z  dt,        z  dJt,        z  g      }|j/                  t1        d d!d"d#d$dt2        j4                  fd%d1d'g             |j                  |       |j                  t        dd(             |j                  t        dK|d                t        dG|d         t        dH|d         t        d=|d         gg}|jj                  D ]D  }|j                  |jf                  |jh                   dIt        |jV                  |d         g       F t+        |d/t,        z  dt,        z  dJt,        z  g      }|j/                  t1        d d!d"d#d$dt2        j4                  fd%d1d'g             |j                  |       |j                  t        dd             |j                  t        dL|d                |j                  t        dd             dMt        |jl                  |d         gdNt        |jn                  |d         gg}t+        |d/t,        z  d6t,        z  g      }|j/                  t1        d d7d"d#d$dt2        j4                  fd%d1g             |j                  |       |jq                  |       |js                  d       |S )Oz0Generate PDF report for Module 8 using ReportLabr   r   r   r   r   r   r   r   z)<b>Module 8: Services &amp; Utilities</b>r   r0   r	  z%<b>Corporate &amp; Concept Office</b>r  r&  z<b>Corporate Office</b>rY  zRole Categoryr  zCost to Company (Y1) per HeadY1Y2Y3Y4Y5r
  r9  r;  r  r  r  r  r  r  r  r  r  r.  r  r  z<b>Concept Office</b>z<b>Store Level Services</b>DesignationzAverage SalaryzFormat A CountzFormat B Countr  r+  r=  z'<b>Training &amp; Talent Management</b>r\  zHR Activity BriefzPolicy Differentiationr  r6  z<b>Utilities</b>z<b>Store Format A Utilities</b>zUtility TypezCost per MonthzKey Usage Parametersr  z
Total CostrK  r  r<  r  r  z<b>Store Format B Utilities</b>z<b>Other Operating Expenses</b>z(<b>Store Format A Operating Expenses</b>zExpense TypezPercentage of Sales per Yearr  r  z(<b>Store Format B Operating Expenses</b>z<b>Summary</b>r_  r`  ):r   r   rf   r`   r  r   r   r
   r   r   r   r   r  rw  rx  r.  ry  rz  r{  r|  r}  r   r   r+  r   r   r-  r  r  r  r  r  r  r  r%  r  r  extendr  r  r  r  r  r  r  r  r  r  r,  r  r  r  r  r  r  r  r/  r0  )rm   rX   r   r1  r2  r3  r4  r5  r  r  corporate_tabler  concept_tabler  r  staff_tablehr_datahr_tableutilities_a_datar  utilities_a_tableutilities_b_datautilities_b_tableexpenses_a_datar  expenses_a_tableexpenses_b_dataexpenses_b_tablerm  rn  s                                 re   r@  z(Module8ReportService.generate_pdf_reportf  sR   ) !4773C)H:Mc8dee228<PR^`oqr$& 	YJFS]L^_`VAr]# 	YFzHZ[\VAq\" 	Y8&:LMN$_fX6FGSrtz  |D  uE  JF  HL  NR  TX  Z^  `d  e  f66D!!""t++D12DMM"DMM"DMM"DMM"DMM"#  7  3t8SXsSWxY\]aYacfgkckmpqumuwz{w  ;A  B  /;VXq&,,7/-0-
 " 	 	_%VAr]# 	Y6z8JKL"?F84DEyQprx  zB  sC  HD  FJ  LP  RV  X\  ^b  c  d44D""t++D12DMM"DMM"DMM"DMM"DMM"!  5 ls4xT3t8UXY]U]_bcg_gilmqiqsvw{s{6|}z/;VXq&,,7/-0+
   	 	]#VAr]# 	Y<fZ>PQRVAq\" x0@A9M]_efn_oCpr{  }M  OU  V^  O_  s`  bk  l|  ~D  EM  ~N  bO  P  Q
 22E!!u++D12E(()E(()	  3 J3t8SXs4xQTUYQY2Z[Z/;VXq&,,7/-0)
  	 	[!VAr]# 	YH&Q[J\]^VAq\" ";#A#A#T#TU )K,J,J,\,\^dem^n"op%y1O1O1f1fhnowhx'yz
 SXs4x,@A*/;VXq&,,7/-&
  	 	XVAr]# 	Y16*3EFGVAq\" 	Y@&BTUV&~vh7GH)TdflmufvJw  zC  DZ  \b  ck  \l  zm  ox  yB  DJ  KS  DT  oU  V  W 	++77DDK22>>MMdST{55AAVVX^_gXhi{55AAII6RZK[\^ ++11>>K2288GGMN{55;;PPRXYaRbc{55;;CCVHEUVX ++;;HHK22BBQQRVWX{55EEZZ\bck\lm{55EEMMvV^O_`b!
 	   22GGD##!!t**401$33VH5EF$,,x(89	%  H 	;11DDTJK!
 	 ""2s4xTSVW[S[]`ae]e>fg"":/;=7Hf.>.>?VXq&,,7/-0	/
 	$ 		 	&'VAr]# 	Y@&BTUV&~vh7GH)TdflmufvJw  zC  DZ  \b  ck  \l  zm  ox  yB  DJ  KS  DT  oU  V  W++77DDK22>>MMdST{55AAVVX^_gXhi{55AAII6RZK[\^ ++11>>K2288GGMN{55;;PPRXYaRbc{55;;CCVHEUVX ++;;HHK22BBQQRVWX{55EEZZ\bck\lm{55EEMMvV^O_`b!
 	  22GGD##!!t**401$33VH5EF$,,x(89	%  H 	;11DDTJK!
 	 ""2s4xTSVW[S[]`ae]e>fg"":/;=7Hf.>.>?VXq&,,7/-0	/
 	$ 		 	&'VAr]# 	Y@&BTUVVAq\" 	YI6R\K]^_%nfX6FGSqsy  {C  tD  JE  GP  QZ  \b  ck  \l  Gm  n  o">>G""$$../q1'//6(+;<$  ? !SXs4xQTUYQY<Z[!!*/;VXq&,,7/-0.
 # 	 	%&VAr]# 	YI6R\K]^_%nfX6FGSqsy  {C  tD  JE  GP  QZ  \b  ck  \l  Gm  n  o">>G""$$../q1'//6(+;<$  ? !SXs4xQTUYQY<Z[!!*/;VXq&,,7/-0.
 # 	 	%&VAr]# 	Y/
1CDEVAq\" "9[-K-KVT\M]#^_i(A(A6(CSTU

 ls4xT6JKz/;VXq&,,7/-+
   	 	]#		%Arp   N)r`  ra  rb  rE  r   rn   rc  r   rP   r  rQ   r  rR   r  rS   r  r.  rU   r  rV   r  rW   r  r_  r   r@  re  rp   re   rq  rq  R
  s    M7 &# &$?V:W &P' '=R8S 'R73 74@S;T 7r
s 
| 
C
3 C
c C
FY C
J"C "s "tThOi "H
 
8M 
BnS nS n`cC cG crp   rq  c                   b    e Zd ZdZdefdZdeded   fdZdeddfd	Z	dede
fd
ZdedefdZy)Module9ReportServicezEService class for generating Module 9: Backend & Supply Chain reportsr`   c                     || _         y rj   rk   rl   s     re   rn   zModule9ReportService.__init__  ro   rp   rX   rY   r1   c                 N   ddl m} ddl}	 ddlm} | j
                  j                  |      j                  |j                  |k(        j                         }g }|D ]  }|j                  }	t        |	t              r	 |j                  |	      }	nt        |	t               sg }	|j#                   ||j$                  |	|j&                  xs d|j(                  xs d|j*                  xs d	              |S # t        $ r}t        d|        g }Y d}~d}~ww xY w#  |	r|	gng }	Y xY w)
z,Get adapting supply chain data for the groupr0   )r1   r   N)TblAdaptingSupplyChainz!Error loading supply chain data: rK  r  )adapting_idwhat_are_some_categoriesremarks_about_these_categoriesdo_you_think_you_needat_which_point_and_why)r  r1   json%app.models.main.adapting_supply_chainr  r`   rb   rw   rX   r   r_   rW  r  
isinstancer.  loadslistr   r  r  r  r  )
rm   rX   r1   r  r  supply_chain_entriesr^  adapting_dataentryr  s
             re   get_adapting_supply_chain_dataz3Module9ReportService.get_adapting_supply_chain_data  s    4	&T#'77==1G#H#O#O&//8;$ce ! )E77J*c*D!%J!7J  
D1
  !8!--)3/4/S/S/YWY&+&A&A&IT','C'C'Ir"  *& 1  	&5aS9:#% 	&D1;*Js$   AC3 ;D3	D<DD	D$r6   c           	         ddl m} t        || j                        s |dd| d      ddlm} | j                  |      }t        |      }|dk(  r
|d	z  }|}|}nt        d
 |D              }||z
  }g }|D ];  }	|	j                  j                         dk(  s!|j                  |	j                         = g }
|D ]  }||
vs|
j                  |         ||||
||dd      S )z8Generate complete Module 9 Backend & Supply Chain reportr   r   r   r   r   r   r0   )r6   r   c              3   \   K   | ]$  }|j                   j                         d k(  s!d & yw)yesr0   N)r  r  )r   r  s     re   r   z?Module9ReportService.generate_module9_report.<locals>.<genexpr>  s*     )z9IUMhMhMnMnMptyMy!9Is   ",,r   z\Supply chain adaptation analysis completed based on category requirements and business needszoStrategic supply chain decisions should align with category performance and operational efficiency requirements)adapting_supply_chain_entriestotal_entriescategories_requiring_adaptationadaptation_needed_countadaptation_not_needed_countr  r  )r   r   rf   r`   r  r6   r  rX  r   r  r  r  r  r   )rm   rX   r   r6   adapting_entriesr  r  r  r  r  unique_categoriesr  s               re   generate_module9_reportz,Module9ReportService.generate_module9_report  s   ) !4773C)H:Mc8dee2  >>xH ,-A$qLM&.#*2'&))z9I)z&z#*7:Q*Q' +-'%E**002e;/66u7U7UV &
 2C++!((- 3 %*:',=$;(C} L
 	
rp   c                 >   ddl m} t        || j                        s |dd| d      | j	                  |      }d}|j
                  D ]Z  }dj                  |j                        }|d	|j                   d
| d
|j                   d
|j                   d
|j                   dz  }\ d}t        |j                  d      D ]  \  }}	|d| d|	 dz  } d| d|j                   d|j                   d|j                    d| d|j"                   d|j$                   d}
|
S )z!Generate HTML report for Module 9r   r   r   r   r   r   rK  , r  r  r  r0   z<li>r^  z</li>a  <!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Module 9: Backend & Supply Chain</title>
    <style>
        body { font-family: 'Times New Roman', serif; font-size: 14px; }
        table { border-collapse: collapse; width: 100%; margin-bottom: 20px; }
        th, td { border: 1px solid #888; padding: 8px; text-align: left; }
        th { background-color: #f8f8f8; font-weight: bold; }
        .section-header { font-size: 16px; font-weight: bold; margin: 20px 0 10px 0; }
        .subsection-header { font-size: 14px; font-weight: bold; margin: 15px 0 8px 0; }
        .summary-box { background-color: #f0f8ff; padding: 15px; border: 1px solid #ccc; margin: 15px 0; }
    </style>
</head>
<body>

<div class="section-header">Module 9: Backend & Supply Chain</div>

<p><i>Reporting Processes</i></p>
<p>The following report will be generated from this module.</p>

<div class="subsection-header">Adapting Supply Chain Analysis</div>

<table>
    <tr>
        <th>Entry ID</th>
        <th>Categories</th>
        <th>Remarks About Categories</th>
        <th>Adaptation Needed</th>
        <th>Point and Rationale</th>
    </tr>z
</table>

<div class="summary-box">
    <div class="subsection-header">Summary Statistics</div>
    <p><strong>Total Entries:</strong> z></p>
    <p><strong>Categories Requiring Adaptation:</strong> zB</p>
    <p><strong>Categories Not Requiring Adaptation:</strong> zc</p>
</div>

<div class="subsection-header">Categories Requiring Supply Chain Adaptation</div>
<ul>z</ul>

<div class="subsection-header">Analysis Summary</div>

<table>
    <tr>
        <th>Additional Remarks</th>
        <td>r  r  )r   r   rf   r`   r  r  rY  r  r  r  r  r  r)  r  r  r  r  r  r  )rm   rX   r   r1  supply_chain_rowsr  categories_strcategories_listr8  r  r]  s              re   r_  z)Module9ReportService.generate_html_report  s   ) !4773C)H:Mc8dee228<  >>E!YYu'E'EFN &   112 3(() *))* +
"  ? $[%P%PRSTKAxaS8*E::O U
> 	 (
 )4(A(A'B C::E:]:]9^ _>>I>e>e=f g   ++, - &&' (k:x rp   c                 J   ddl m} t        || j                        s |dd| d      | j	                  |      }t               }t        |t        dddd      }t               }g }|j                  t        d	|d
                |j                  t        dd             |j                  t        d|d                |j                  t        dd             |j                  t        d|d                |j                  t        dd             t        d|d         t        d|d         t        d|d         t        d|d         t        d|d         gg}|j                  D ]  }	dj                  |	j                        }
|j                  t        t        |	j                         |d         t        |
|d         t        |	j"                  |d         t        |	j$                  |d         t        |	j&                  |d         g        t)        |dt*        z  dt*        z  dt*        z  dt*        z  dt*        z  g      }|j-                  t/        dd d!d"d#dt0        j2                  fd$d%d&d'd(d)d*g
             |j                  |       |j                  t        dd             |j                  t        d+|d                |j                  t        dd             t        d,|d         t        t        |j4                        |d         gt        d-|d         t        t        |j6                        |d         gt        d.|d         t        t        |j8                        |d         gg}t)        |d/t*        z  d0t*        z  g      }|j-                  t/        dd1d!d"d#dt0        j2                  fd$d2d&d3d4d5d6g
             |j                  |       |j                  t        dd             |j:                  r|j                  t        d7|d                |j                  t        dd             t=        |j:                  d      D ](  \  }}|j                  t        | d8| |d                * |j                  t        dd             |j                  t        d9|d                |j                  t        dd             t        d:|d         t        |j>                  |d         gt        d;|d         t        |j@                  |d         gg}t)        |d0t*        z  d<t*        z  g      }|j-                  t/        dd1d!d"d#dt0        j2                  fd$d=d&d3d4d5d6g
             |j                  |       |jC                  |       |jE                  d       |S )>z0Generate PDF report for Module 9 using ReportLabr   r   r   r   r   r   r   r   z+<b>Module 9: Backend &amp; Supply Chain</b>r   r0   r	  z%<i>Adapting Supply Chain Analysis</i>r  r   z&<b>Supply Chain Adaptation Entries</b>r  r&  zEntry ID
Categoriesr  zAdaptation NeededzPoint & Rationaler
  r  r;  r  r,  r  r  r  r  r  r  r  r  r.  r  r0  r2  r3  r4  z<b>Summary Statistics</b>zTotal EntrieszCategories Requiring Adaptationz#Categories Not Requiring Adaptationr5  r  r6  r7  r   r#  r%  r'  z3<b>Categories Requiring Supply Chain Adaptation</b>r^  z<b>Analysis Summary</b>r_  r`  r  r=  )#r   r   rf   r`   r  r   r   r
   r   r   r   r   r  rY  r  r.  r  r  r  r  r   r   r+  r   r   r-  r  r  r  r  r)  r  r  r/  r0  )rm   rX   r   r1  r2  r3  r4  r5  supply_datar  r  supply_tablerm  rn  r8  r  analysis_dataanalysis_tables                     re   r@  z(Module9ReportService.generate_pdf_report=  s   ) !4773C)H:Mc8dee228<PR^`oqr$& 	YLfU_N`abVAr]# 	YFxHXYZVAr]# 	YGPZI[\]VAq\"!*fX.>?<Y_`hYiAjluv  BH  IQ  BR  mS  U^  _r  tz  {C  tD  UE  GP  Qd  fl  mu  fv  Gw  x  y >>E!YYu'E'EFN#e//0&2BC.&*:;%>>x@PQ%55vh7GH%66x8HI   ? [SXs4xTSVW[S[]`ae]e4fgj/;VXq&,,7/-001/2*
  	 	\"VAr]# 	Y:F:<NOPVAq\" x(899SIbIbEceklteu;vw8&:JKYWZ[f[~[~W  BH  IQ  BR  NS  T<fX>NOQZ[^_j  `G  `G  \H  JP  QY  JZ  R[  \
 ls4xT6JKz/;VXq&,,7/.001/2+
   	 	]#VAr]# 66LL#XZ`akZlmnLL1&()T)TVWX8Y!Bxj'96(;KLM  YLL2' 	Y8&:LMNVAq\" +VH-=>	+JhJhjpqyjz@{|x(899[E^E^`fgo`p;qr

 }T3t88LM
/;VXq&,,7/-001/2,
 ! 	 	^$		%Arp   N)r`  ra  rb  rE  r   rn   rc  r   r  r  r.  r_  r   r@  re  rp   re   r  r    sm    O7 "s "tD]?^ "H,
 ,
8O ,
\XS XS XtsC sG srp   r  N)zsqlalchemy.ormr   rU  r   r   r   r  r   r  r
   r  r   r   r   r   r   r  r   r   r  r   r  r   app.models.main.brandr   app.models.main.segmentr   app.models.main.store_formater   app.models.main.civilr   $app.models.main.display_racking_unitr   app.models.main.carpentryr   "app.models.main.electrical_cablingr   $app.models.main.commercial_equipmentr   app.models.main.display_boardr   app.models.main.info_techr    -app.models.main.visual_merchendising_elementsr!   app.models.main.Plumbingr"   app.models.main.depreciationr#   #app.models.main.catchment_potentialr$   $app.models.main.competitor_intensityr%    app.models.main.location_detailsr&   app.models.main.sales_estimater'   app.models.main.rent_expensesr(   1app.models.main.location_spillage_factor_analysisr)   &app.models.main.projected_market_sharer*   'app.models.main.competitor_benchmarkingr+   (app.models.main.corporate_concept_officer,   'app.models.main.store_level_staff_needsr-   app.models.main.utilityr.   "app.models.main.operating_expensesr/   r  r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rc  r  rf   rh   rg  r  rG  rq  r  re  rp   re   <module>r.     s   " " "  & V V D $   * . 8 * F 2 C G 9 1 P 0 8 E G ? ; 9 W J M N K . C           D ,fG fGPe eNq qfG GR,w wre erp   