<%
/******************************************************************************
 * Copyright (c) 2000-2005 e-Deal
 *
 * e-Deal S.A.
 * 55 rue Brillat Savarin
 * 75013 Paris
 * France
 *
 * T: +33 (0)1 53 80 80 30
 * F: +33 (0)1 73 01 69 77
 * http://www.e-deal.com
 * 
 * La diffusion de ce code source sous quelque forme que ce soit sans
 * l'autorisation de E-DEAL est interdite.
 *
 * Vous êtes autorisés à modifier ce code source uniquement pour votre usage
 * propre et sous réserve que les mentions de copyright demeurent intactes.
 *
 * Ce code est fourni en l'état. Aucune garantie d'aucune sorte, explicite ou
 * implicite n'est donnée. En aucun cas E-DEAL ne pourra être tenu pour
 * responsable des dommages pouvant résulter de l'utilisation de ce code
 * source.
 ******************************************************************************/
%>
<%@page session="true"%>
<%@ page import="com.edeal.frontline.navigation.FlRequest" %>
<%@ page import="com.edeal.frontline.FlContext" %>
<%@ page import="com.edeal.frontline.FieldNotInitializedException" %>
<%@ page import="com.edeal.frontline.Utils" %>
<%@ page import="com.edeal.frontline.DataDictionary" %>
<%@ page import="java.text.DecimalFormat" %>
<%@ page import="com.edeal.frontline.FlLocale" %>
<%@taglib uri="http://www.e-deal.com/taglib/fl" prefix="fl" %>
<jsp:useBean class="com.edeal.frontline.StageBean" id="Stage" scope="request"/>
<%
	final org.apache.commons.logging.Log logger = org.apache.commons.logging.LogFactory.getLog(getClass());
	FlRequest flRequest = new FlRequest(request);
	FlContext context = flRequest.getContext();
	
	String SfwID = flRequest.getRequestParameterOrAttribute("SfwID");
	
	DataDictionary dico = context.getDataDictionary();
	
	String id = null;
	try {
		id = Stage.getID();
	} catch (FieldNotInitializedException fnie) {
	}
	
	//intilisation
	int nbContactEst = 0;
	int nbContactReal = 0;
	int nbContactDiffN = 0;
	//récupération des attributs
	try {
		nbContactEst = Stage.getStgContactEst();
	} catch(FieldNotInitializedException e) {
		e.printStackTrace(System.err);
	}
	
	try {
		nbContactReal = Stage.getStgContactReal();
	} catch(FieldNotInitializedException e) {
	}
	
	//calcul de la différebce 
	nbContactDiffN = nbContactReal - nbContactEst;
	
	
	
	
	
	

	DecimalFormat intFormat = FlLocale.getInstance(session).getDecimalFormat("#,##0;- #,##0");
	DecimalFormat floatFormat = FlLocale.getInstance(session).getDecimalFormat("#,##0.00;- #,##0.00");
%>
<style type="text/css">
	.borderLineOne {
		border-right: 1px dashed #9EC6D0;
		border-bottom: 1px dashed #9EC6D0;
		
	}

	.borderLineTwo {
		border-right: 1px dashed #9EC6D0;
	}
</style>
<fl:bigTabs objectTitle="<%= Utils.getMessage(session, \"L3046\", \"Etape\") %>" listTitle="<%= Utils.getMessage(session, \"L65C7\", \"Fiche etape\") %>" ou="<%= \"/read_stage.fl\" + (id != null ? \"?id=\" + id : \"\") %>">
	<table class="container" cellpadding="0">
		<tr>
			<td class="titreFiche">
				<fl:getProperty name="Stage" property="StgTitle" alt="&nbsp;"/><br>
			</td>
		</tr>
		<tr class="ligne_separation"><td></td></tr>
	</table>
	<table class="container" cellpadding="0">	
		<tr>
			<td class="dataValue" style="vertical-align:top; width: 50%">
				<table class="data_column" cellpadding="0">
					<fl:fieldRead property="StgCode" />
					<fl:fieldRead property="StgCpgID" bean="true" href="true" disp="<%= flRequest.computeURL(\"/read_campaign.fl\") %>"/>
					<fl:fieldRead property="StgEvtID" bean="true"/>
				</table>
			</td>
			<td class="separation"><div class="separation"></div></td>
			<td class="dataValue" style="vertical-align: top; width: 50%">
				<table class="data_column" cellpadding="0">
					<fl:fieldRead property="StgDateBeg"/>
					<fl:fieldRead property="StgDateEnd"/>
					<tr>
					<td class="dataLabel"><fl:getMessage code="F2004" alt="Cloturée"/></td>
					<td class="dataValue"><fl:getProperty name="Stage" property="StgEnd" alt="" valueCodeIfTrue="L2005" valueCodeIfFalse="L2006"/></td>
					</tr>
				</table>
			</td>
		</tr>
		<tr class="ligne_separation"><td colspan="4"></td></tr>
	</table>
	<table class="container" cellpadding="0">
		
		<tr class="ligne_separation">
			<td></td>
		</tr>
	</table>
	<table class="container" cellpadding="0">
	<tr valign="top">
	<td class="titrePartie">
	
	
	
	<fl:notes name="StgDescr" title="<%= Utils.getMessage(session, \"L2007\", \"Description\") %>"  nbPix="30"><fl:getProperty name="Stage" property="StgDescr" alt="&nbsp;"/></fl:notes>
	</td>
	</tr>
	</table>
	<link href="<fl:webapp/>/css/smalltabs_css.jsp" rel="stylesheet" type="text/css">

	<fl:smallTabs name="SimulationTabs">
		<fl:sTab id="POP" title="<%= Utils.getMessage(session, \"F000C\", false, true, \"Population\") %>">
			<table class="container" cellpadding="0">
				<tr>
					<td class="column2">
						<table class="data_column" cellpadding="0">
							<fl:fieldRead property="StgPopID" bean="true" name="Stage" href="true" alt="" disp="<%=\"/read_populationv2.fl?SfwID=\"+ SfwID %>" />
						</table>
					</td>
					<td class="separation"><div class="separation"></div></td>
					<td class="column2"></td>
				</tr>
				<tr class="ligne_separation"></tr>	
				<tr class="ligne_separation"></tr>
			</table> 
			<table class="container" cellpadding="3" width="100%">
			<thead>
			<tr>
				<td class="headerDataGrid">&nbsp;</td>
				<td class="headerDataGrid"><fl:getMessage code="F2008" alt="Prévisionnel"/></td>
				<td class="headerDataGrid"><fl:getMessage code="F2009" alt="Réel"/></td>
				<td class="headerDataGrid"><fl:getMessage code="L200A" alt="Ecart"/></td>
			</tr>
			</thead>
			<tbody>
				<tr class="tabSimpleFdBleu">
					<td style="width:30%;text-align : left;">
						<fl:getMessage code="L311E" alt="Nb contacts"/>
					</td>
					<td style="width:20%;text-align : right; ">
						<span /><%=  intFormat.format(nbContactEst).trim()  %>&nbsp;</span>
					</td>
					<td style="width:20%;text-align : right; ">
						<span /><%= intFormat.format(nbContactReal).trim()  %>&nbsp;</span>
					</td>
						<td style="width:20%;text-align : right;">
						<span /><%= intFormat.format(nbContactDiffN).trim() %>&nbsp;</span>
					</td>				
				</tr>
				</tbody>
			</table>
		</fl:sTab>
		<fl:sTab id="STAGE1" title="<%= context.getAutoDisplayManager().getTitle(session, \"Stage\", \"Etape 1\") %>" visible="<%= context.getAutoDisplayManager().hasEntry(\"Stage\", \"Etape 1\") %>">
			<fl:autodisplay name="Stage" zone="Etape 1"/>
		</fl:sTab>
		<fl:sTab id="BUDGET" title="<%= Utils.getMessage(session, \"L2009\", false, true, \"Budget\") %>">
			<table class="container" cellpadding="0">
				<tr class="fieldline">
					<td class="headerDataGrid" style="width: 30%"></td>
					<td class="headerDataGrid" style="width: 20%;"><fl:getMessage code="F2008" alt="Prévisionnel"/></td>
					<td class="headerDataGrid" style="width: 20%;"><fl:getMessage code="F2009" alt="Réel"/></td>
					<td class="headerDataGrid" style="width: 20%;"><fl:getMessage code="L200A" alt="Ecart"/></td>
				</tr>
				<%
					float fixedCostEst = 0;
						float fixedCostReal = 0;
						float fixedCostDiffN = 0;
						double fixedCostDiffP = 0;
						try {
							fixedCostEst = Stage.getStgFixedCostEst();
						} catch(FieldNotInitializedException e) {
						}
						try {
							fixedCostReal = Stage.getStgFixedCostReal();
						} catch(FieldNotInitializedException e) {
						}
						fixedCostDiffN = fixedCostReal - fixedCostEst;
						if (fixedCostEst != 0) {
							fixedCostDiffP = ((double)fixedCostDiffN / (double)fixedCostEst) * 100;
						}
				%>
				<tr class="tabSimpleFdBleu">
					<td style="text-align : left; width: 30%"><fl:getMessage code="L3120" alt="Coûts fixes"/></td>
					<td style="text-align : right; width: 20%"><%= floatFormat.format(fixedCostEst).trim() %> &euro;&nbsp;</td>
					<td style="text-align : right; width: 20%"><%= floatFormat.format(fixedCostReal).trim() %> &euro;&nbsp;</td>
					<td style="text-align : right; width: 20%"><%= floatFormat.format(fixedCostDiffN).trim() %> &euro; : <%= floatFormat.format(fixedCostDiffP).trim() %> %&nbsp;</td>
				</tr>
				<%
					float contactCostEst = 0;
					float contactCostReal = 0;
					float contactCostDiffN = 0;
					double contactCostDiffP = 0;
					try {
						contactCostEst = Stage.getStgContactCostEst();
					} catch(FieldNotInitializedException e) {
					}
					try {
						contactCostReal = Stage.getStgContactCostReal();
					} catch(FieldNotInitializedException e) {
					}
					contactCostDiffN = contactCostReal - contactCostEst;
					if (contactCostEst != 0) {
						contactCostDiffP = ((double)contactCostDiffN / (double)contactCostEst) * 100;
					}
				%>
				<tr class="tabSimpleFdBlanc">
					<td style="width: 30%" nowrap><fl:getMessage code="L3121" alt="Coûts contact"/></td>
					<td style="width: 20%; text-align:right;" nowrap><%= floatFormat.format(contactCostEst).trim() %> &euro;&nbsp;</td>
					<td style="width: 20%; text-align:right;" nowrap><%= floatFormat.format(contactCostReal).trim() %> &euro;&nbsp;</td>
					<td style="width: 20%; text-align:right;" nowrap><%= floatFormat.format(contactCostDiffN).trim() %> &euro; : <%= floatFormat.format(contactCostDiffP).trim() %> %&nbsp;</td>
				</tr>
				<%
					float totalCostEst = fixedCostEst + (contactCostEst * nbContactEst);
					float totalCostReal = fixedCostReal + (contactCostReal * nbContactReal);
					float totalCostDiffN = totalCostReal - totalCostEst;
					double totalCostDiffP = 0;
					if (totalCostEst!=0) {
						totalCostDiffP = ((double)totalCostDiffN / (double)totalCostEst) * 100;
					}
				%>
				<tr class="tabSimpleFdBleu">
					<td style="width: 30%" nowrap><fl:getMessage code="F1058" alt="Total"/></td>
					<td style="width: 20%; text-align: right" nowrap><%= floatFormat.format(totalCostEst).trim() %> &euro;&nbsp;</td>
					<td style="width: 20%; text-align: right" nowrap><%= floatFormat.format(totalCostReal).trim() %> &euro;&nbsp;</td>
					<td style="width: 20%; text-align: right" nowrap><%= floatFormat.format(totalCostDiffN).trim() %> &euro; : <%= floatFormat.format(totalCostDiffP).trim() %> %&nbsp;</td>
				</tr>
			</table>
		</fl:sTab>
		<fl:sTab id="INDIC" title="<%= Utils.getMessage(session, \"L620C\", false, true, \"Indicateurs\") %>">
			<table class="container" cellpadding="0">
				<tr class="fieldline">
					<td class="headerDataGrid" style="width: 30%;"></td>
					<td class="headerDataGrid" style="width: 20%;"><fl:getMessage code="F2008" alt="Prévisionnel"/></td>
					<td class="headerDataGrid" style="width: 20%;"><fl:getMessage code="F2009" alt="Réel"/></td>
					<td class="headerDataGrid" style="width: 20%;"><fl:getMessage code="L200A" alt="Ecart"/></td>
				</tr>
				<%
					float est = 0;
					float reel = 0;
					float diffN = 0;
					double diffP = 0;
					try {
						est = Stage.getStgIndicEst1();
					} catch(FieldNotInitializedException e) {
					}
					try {
						reel = Stage.getStgIndicReal1();
					} catch(FieldNotInitializedException e) {
					}
					diffN = reel - est;
					if (est != 0) {
						diffP = ((double)diffN / (double)est) * 100;
					}
					String unit1 = "";
					try {
						String tmpUnit = (String)dico.getRefDisp(session, "StgIndicUnit1", Stage.getStgIndicUnit1());
						if (tmpUnit != null) {
							unit1 = "&nbsp;" + tmpUnit;
						} else {
							logger.error("StgIndicUnit1 is not specified");
						}
					} catch (FieldNotInitializedException e) {
					}
				%>
				<tr class="tabSimpleFdBleu">
					<td style="width: 30%; text-align : left"><fl:getProperty name="Stage" property="StgIndicLabel1" alt="" edit="false"/></td>
					<td style="width: 20%; text-align : right"><%= floatFormat.format(est).trim() %><%= unit1 %>&nbsp;</td>
					<td style="width: 20%; text-align : right"><%= floatFormat.format(reel).trim() %><%= unit1 %>&nbsp;</td>
					<td style="width: 20%; text-align : right"><%= floatFormat.format(diffN).trim() %><%= unit1 %> : <%= floatFormat.format(diffP).trim() %>%&nbsp;</td>
				</tr>
				<%
					est = 0;
					reel = 0;
					diffN = 0;
					diffP = 0;
					try {
						est = Stage.getStgIndicEst2();
					} catch(FieldNotInitializedException e) {
					}
					try {
						reel = Stage.getStgIndicReal2();
					} catch(FieldNotInitializedException e) {
					}
					diffN = reel - est;
					if (est != 0) {
						diffP = ((double)diffN / (double)est) * 100;
					}
					String unit2 = "";
					try {
						String tmpUnit = (String)dico.getRefDisp(session, "StgIndicUnit2", Stage.getStgIndicUnit2());
						if (tmpUnit != null) {
							unit2 = "&nbsp;" + tmpUnit;
						} else {
							logger.error("StgIndicUnit2 is not specified");
						}
					} catch (FieldNotInitializedException e) {
					}
				%>
				<tr class="tabSimpleFdBlanc">
					<td style="width: 30%;" nowrap><fl:getProperty name="Stage" property="StgIndicLabel2" alt="" edit="false"/></td>
					<td style="width: 20%; text-align:right;" nowrap><%= floatFormat.format(est).trim() %><%= unit2 %>&nbsp;</td>
					<td style="width: 20%; text-align:right;" nowrap><%= floatFormat.format(reel).trim() %><%= unit2 %>&nbsp;</td>
					<td style="width: 20%; text-align:right;" nowrap><%= floatFormat.format(diffN).trim() %><%= unit2 %> : <%= floatFormat.format(diffP).trim() %>%&nbsp;</td>
				</tr>
				<%
					est = 0;
					reel = 0;
					diffN = 0;
					diffP = 0;
					try {
						est = Stage.getStgIndicEst3();
					} catch(FieldNotInitializedException e) {
					}
					try {
						reel = Stage.getStgIndicReal3();
					} catch(FieldNotInitializedException e) {
					}
					diffN = reel - est;
					if (est != 0) {
						diffP = ((double)diffN / (double)est) * 100;
					}
					String unit3 = "";
					try {
						String tmpUnit = (String)dico.getRefDisp(session, "StgIndicUnit3", Stage.getStgIndicUnit3());
						if (tmpUnit != null) {
							unit3 = "&nbsp;" + tmpUnit;
						} else {
							logger.error("StgIndicUnit3 is not specified");
						}
					} catch (FieldNotInitializedException e) {
					}
				%>
				<tr class="tabSimpleFdBleu">
					<td style="width: 30%;" nowrap><fl:getProperty name="Stage" property="StgIndicLabel3" alt="" edit="false"/></td>
					<td style="width: 20%; text-align:right;" nowrap><%= floatFormat.format(est).trim() %><%= unit3 %>&nbsp;</td>
					<td style="width: 20%; text-align:right;" nowrap><%= floatFormat.format(reel).trim() %><%= unit3 %>&nbsp;</td>
					<td style="width: 20%; text-align:right;" nowrap><%= floatFormat.format(diffN).trim() %><%= unit3 %> : <%= floatFormat.format(diffP).trim() %>%&nbsp;</td>
				</tr>
				<%
					est = 0;
					reel = 0;
					diffN = 0;
					diffP = 0;
					try {
						est = Stage.getStgIndicEst4();
					} catch(FieldNotInitializedException e) {
					}
					try {
						reel = Stage.getStgIndicReal4();
					} catch(FieldNotInitializedException e) {
					}
					diffN = reel - est;
					if (est != 0) {
						diffP = ((double)diffN / (double)est) * 100;
					}
					String unit4 = "";
					try {
						String tmpUnit = (String)dico.getRefDisp(session, "StgIndicUnit4", Stage.getStgIndicUnit4());
						if (tmpUnit != null) {
							unit4 = "&nbsp;" + tmpUnit;
						} else {
							logger.error("StgIndicUnit4 is not specified");
						}
					} catch (FieldNotInitializedException e) {
					}
				%>
				<tr class="tabSimpleFdBlanc">
					<td style="width: 30%;" nowrap><fl:getProperty name="Stage" property="StgIndicLabel4" alt="" edit="false"/></td>
					<td style="width: 20%; text-align:right;" nowrap><%= floatFormat.format(est).trim() %><%= unit4 %>&nbsp;</td>
					<td style="width: 20%; text-align:right;" nowrap><%= floatFormat.format(reel).trim() %><%= unit4 %>&nbsp;</td>
					<td style="width: 20%; text-align:right;" nowrap><%= floatFormat.format(diffN).trim() %><%= unit4 %> : <%= floatFormat.format(diffP).trim() %>%&nbsp;</td>
				</tr>
				<%
					est = 0;
					reel = 0;
					diffN = 0;
					diffP = 0;
					try {
						est = Stage.getStgIndicEst5();
					} catch(FieldNotInitializedException e) {
					}
					try {
						reel = Stage.getStgIndicReal5();
					} catch(FieldNotInitializedException e) {
					}
					diffN = reel - est;
					if (est != 0) {
						diffP = ((double)diffN / (double)est) * 100;
					}
					String unit5 = "";
					try {
						String tmpUnit = (String)dico.getRefDisp(session, "StgIndicUnit5", Stage.getStgIndicUnit5());
						if (tmpUnit != null) {
							unit5 = "&nbsp;" + tmpUnit;
						} else {
							logger.error("StgIndicUnit5 is not specified");
						}
					} catch (FieldNotInitializedException e) {
					}
				%>
				<tr class="tabSimpleFdBleu">
					<td style="width: 30%;" nowrap><fl:getProperty name="Stage" property="StgIndicLabel5" alt="" edit="false"/></td>
					<td style="width: 20%; text-align:right;" nowrap><%= floatFormat.format(est).trim() %><%= unit5 %>&nbsp;</td>
					<td style="width: 20%; text-align:right;" nowrap><%= floatFormat.format(reel).trim() %><%= unit5 %>&nbsp;</td>
					<td style="width: 20%; text-align:right;" nowrap><%= floatFormat.format(diffN).trim() %><%= unit5 %> : <%= floatFormat.format(diffP).trim() %>%&nbsp;</td>
				</tr>
			</table>
		</fl:sTab>
		<fl:sTab id="ATTACHMENT" title="<%= Utils.getMessage(session, \"L201C\", false, true, \"Documents joints\") %>">
			<fl:attach name="Stage" colID="StgAttID" edit="false"/>
		</fl:sTab>
	</fl:smallTabs>
</fl:bigTabs>
