<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Admin.Master" CodeBehind="Planning.aspx.vb" Inherits="RGBC_Forecast.Planning" EnableEventValidation="false" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

  <script type="text/javascript">
  
    function confirmSave() {
      if (confirm("Are you sure you want to install this Forecast Plan? This process may take up to an hour to complete...")) {
        jsShowLoading(1);
        return true;
      }
      else
        return false;
    }

    function jsQFTargetBlur(obj) {
    //alert('arr')
      obj = removeAlpha(obj);
      var percBGForecast;
      var ldblSalesProjected;
      percBGForecast = d('ctl00_ContentPlaceHolder1_percBGForecast')
      ldblSalesProjected = d('ctl00_ContentPlaceHolder1_ldblSalesProjected')
      dblProjected = removeAlpha(ldblSalesProjected).value

      dblProjected = obj.value / dblProjected - 1;
      if (dblProjected > 0) {
        percBGForecast.innerHTML = '+' + Math.round(dblProjected * 100, 2) + '%';
      } else {
        percBGForecast.innerHTML = Math.round(dblProjected * 100, 2) + '%';
      }

      jsQFBlur(ldblSalesProjected);
      jsQFBlur(obj);
    }
    
  </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
  <div id="divHelp" style="position:absolute; left:900px; top:25px;">
    <asp:HyperLink ID="aHelp" runat="server" NavigateUrl="~/HelpPlanning.aspx" Target="_blank" ToolTip="Help" >
      <asp:Image ID="imhHelp" runat="server" Width="51px" ToolTip="Help" ImageUrl="content/128139-simple-red-square-icon-alphanumeric-information2-ps.png" /></asp:HyperLink>
  </div>
<fieldset>
  <legend>Planning</legend>
    <table style="width:1000px;" class="" border="0">
      <tr>
        
        <td align="left" valign="top" width="20%">
          <table style="width:100%;" class="" border="0" cellpadding="2">
            <tr>
              <td width=""></td>
            </tr>
            <tr>
              <td></td>
            </tr>
          </table>          
        </td comment=col1>
        
        <td align="left" valign="top" width="30%">
          <table style="width:100%;" class="" border="0" cellpadding="2">
            <tr>
              <td align="right" width="50%"></td>
              <td width=""></td>
              <td width=""></td>
            </tr>
            <tr>
              <td align="right">Financial Year: </td>
              <td nowrap="nowrap">
                <asp:DropDownList ID="ddlFinYear" runat="server" AppendDataBoundItems="True" 
                  DataSourceID="sdsFinYear" DataTextField="DataTextField" 
                  DataValueField="DataValueField" CausesValidation="False" ValidationGroup="Load">
                  <asp:ListItem Value="0">- Select -</asp:ListItem>
                </asp:DropDownList> <b>*</b></td>
              <td>
                
              </td>
            </tr>
            <tr>
              <td colspan=2 align="right">
                <asp:RequiredFieldValidator  ID="valFinYear" runat="server" 
                  ErrorMessage="Please select a Financial Year. " CssClass="textError boxError" 
                  ControlToValidate="ddlFinYear" SetFocusOnError="True" Display="Dynamic" 
                  ForeColor="" Type="Integer" InitialValue="0" BorderColor="#7F0206" 
                  BorderStyle="Solid" BorderWidth="1px" ValidationGroup="Load"></asp:RequiredFieldValidator >
              </td>
            </tr>
          </table comment="col2">
        </td comment="col2">
        
        <td align="left" valign="top" width="40%">
          <table style="width:100%;" class="" border="0" cellpadding="2">
            <tr>
              <td align="right" width="40%"></td>
              <td width=""></td>
              <td width=""></td>
            </tr>            
            <tr>
              <td align="right">Brand: </td>
              <td nowrap="nowrap">
                <asp:DropDownList ID="ddlBrand" runat="server" AppendDataBoundItems="True" 
                  DataSourceID="sdsBrand" DataTextField="DataTextField" 
                  DataValueField="DataValueField" CssClass="select1" ValidationGroup="Load">
                  <asp:ListItem Value="0">- Select -</asp:ListItem>
                </asp:DropDownList> <b>*</b></td>
              <td ><div style="position: absolute; margin: 1px; padding: 1px;">
                <asp:RequiredFieldValidator  ID="valBrand" runat="server" 
                  ErrorMessage="Please select a Brand. " CssClass="textError boxError" 
                  ControlToValidate="ddlBrand" SetFocusOnError="True" Display="Dynamic" 
                  ForeColor="" Type="Integer" InitialValue="0" BorderColor="#7F0206" 
                  BorderStyle="Solid" BorderWidth="1px" ValidationGroup="Load"></asp:RequiredFieldValidator ></div></td>
            </tr>            
              <tr>
              <td align="right">Copy Brand Sales Rhythm: </td>
              <td nowrap="nowrap"><asp:DropDownList ID="ddlBrandCopy" runat="server" AppendDataBoundItems="True" 
                  DataSourceID="sdsBrand" DataTextField="DataTextField" DataValueField="DataValueField" CssClass="select1" ValidationGroup="Copy">
                  <asp:ListItem Value="0">- None -</asp:ListItem>
                  </asp:DropDownList></td>
              <td ><div style="position: absolute">                
                <asp:RequiredFieldValidator  ID="valBrandCopy2" runat="server" ErrorMessage="Please select another Brand to Copy. " 
                  CssClass="textError boxError" ControlToValidate="ddlBrandCopy" SetFocusOnError="True" Display="Dynamic" ForeColor="" Type="Integer" 
                  BorderColor="#7F0206" BorderStyle="Solid" BorderWidth="1px" ValidationGroup="Load"></asp:RequiredFieldValidator >
                  </div></td>
            </tr>            
          </table comment="col3">
        </td comment="col3">
      </tr>     
      <tr>
        <td></td>
        <td align="right">
          &nbsp; 
          </td>
        <td><asp:Button ID="btnLoad" runat="server" OnClientClick="jsShowLoading(1);" ValidationGroup="Load" Text="Load"/>&nbsp;</td>
      </tr>
    </table>
    <div style="position:absolute; left:995px; top:110px;"><img src="content/073874-red-white-pearl-icon-alphanumeric-number-1.png" width="84" alt="Step 1: Load Brand." title="Step 1: Load Brand."/></div>
</fieldset>
    
  <br />
  <asp:Label ID="lblBrand" runat="server" CssClass="labelBrand"></asp:Label>
  <asp:Label ID="lblMessage" runat="server" CssClass="boxError"></asp:Label>
  <br />
  <br />
  <asp:GridView ID="gvSalesR1" runat="server" CellPadding="2" 
  CssClass="gridviewDefault" Caption="SALES RHYTHM" EmptyDataText="0.0" 
  DataKeyNames="Region" >	
		<HeaderStyle CssClass="" HorizontalAlign="Center" Wrap="True" />
		<AlternatingRowStyle CssClass="listAlternate" />
  </asp:GridView>
  <br />
  <asp:GridView ID="gvSalesR2" runat="server" CellPadding="2"  Visible="true" 
  CssClass="gridviewDefault" DataKeyNames="Region" Caption="SALES RHYTHM" 
  EmptyDataText="0.0">	
		<HeaderStyle CssClass="" HorizontalAlign="Center" Wrap="True" />
		<AlternatingRowStyle CssClass="listAlternate" />
  </asp:GridView>
  <br />
  <asp:GridView ID="gvStats" runat="server" CellPadding="2"  Visible="true" CssClass="gridviewDefault" DataKeyNames="Region" Caption="STATS & PROJECTIONS">	
		<HeaderStyle CssClass="" HorizontalAlign="Center" Wrap="True" />
		<AlternatingRowStyle CssClass="listAlternate" />
  </asp:GridView>
  <br />
<fieldset>
  <legend>Settings</legend>
  <table style="width:1000px;" class="" border="0">
    <tr>
      
      <td align="left" valign="top" width="40%">
        <table style="width:100%;" class="" border="0" cellpadding="2" >
          <tr>
            <td width="35%" nowrap="nowrap">Sales LY: </td>
            <td width="" align="right" nowrap="nowrap"><asp:Literal ID="ldblSalesLY" runat="server" Text="0.0"></asp:Literal></td>
            <td width="30%"></td>
          </tr>
          <tr>
            <td nowrap="nowrap">Sales YTD: </td>
            <td align="right" nowrap="nowrap"><asp:Literal ID="ldblSalesTY" runat="server" Text="0.0"></asp:Literal></td>
          </tr>
          <tr>
            <td nowrap="nowrap">Sales Projected: </td>
            <td align="right" nowrap="nowrap"><asp:TextBox ID="ldblSalesProjected" runat="server" Text="0.0" CssClass="controlLabel controlTextbox"></asp:TextBox></td>
          </tr>
          <tr>
            <td nowrap="nowrap" >Current Fiscal % Completed: </td>
            <td nowrap="nowrap" class="columnYellow" align="right"><asp:Literal ID="lpercCompleted" runat="server" Text="0.0%"></asp:Literal></td>
          </tr>
          <tr>
            <td >Current Fiscal QF: </td>
            <td align="right" nowrap="nowrap"><asp:Literal ID="ldblQFCurrent" runat="server" Text="0.0"></asp:Literal></td>
          </tr>
        </table >
      </td>        
      <td align="left" valign="top" width="">
        <table style="width:100%;" class="" border="0" cellpadding="2" cellspacing=0>
          <tr>
            <td width="15%"></td>
            <td nowrap="nowrap">Brand Growth LY [<asp:Literal ID="lblBGLY" runat="server"></asp:Literal>]:</td>
            <td align="right"><asp:Literal ID="percBGLY" runat="server" Text="0.0%"></asp:Literal></td>
            <td align="center" rowspan="4"><img src="content/073875-red-white-pearl-icon-alphanumeric-number-2.png" width="84" alt="Step 2: Calculate Plan." title="Step 2: Calculate Plan from QF Target using Regional Contributions."/></td>
            <td align="center" rowspan="4"><img src="content/073876-red-white-pearl-icon-alphanumeric-number-3.png" width="84" alt="Step 3: Fine tune Regional Contributions." title="Step 3: Fine tune Regional Contributions using the Regional Total."/></td>
            <td align="center" rowspan="4"><img src="content/073877-red-white-pearl-icon-alphanumeric-number-4.png" width="84" alt="Step 4: Apply QF Plan." title="Step 4: Apply QF Plan to Adjustments, Qview and StockControl."/></td>
          </tr>
          <tr>
            <td></td>
            <td nowrap="nowrap">Brand Growth TY [<asp:Literal ID="lblBGTY" runat="server"></asp:Literal>]:</td>
            <td align="right"><asp:Literal ID="percBGTY" runat="server" Text="0.0%"></asp:Literal></td>
          </tr>
          <tr>
            <td></td>
            <td nowrap="nowrap">Brand Growth Projected [<asp:Literal ID="lblBGProjected" runat="server"></asp:Literal>]:</td>
            <td align="right"><asp:Literal ID="percBGProjected" runat="server" Text="0.0%"></asp:Literal></td>
          </tr>
          <tr>
            <td></td>
            <td>Brand Growth Forecast [<asp:Literal ID="lblBGForecast" runat="server"></asp:Literal>] (target/projected):</td>
            <td align="right"><asp:Label ID="percBGForecast" runat="server" Text="0.0%"></asp:Label></td>
          </tr>
          <tr>
            <td></td>
            <td><b>Brand Forecast Target</b>:</td>
            <td><asp:TextBox ID="txtQFTarget" runat="server" CssClass="textNumeric controlTextboxBig" Text="0"></asp:TextBox></td>
            <td align="center" ><asp:Button runat="server" ID="btnCalculate" Text="Calculate Plan" OnClientClick="jsShowLoading(1);"/></td>
            <td align="center" ><asp:Button runat="server" ID="btnCalculateRe" Text="Re-Calculate Plan" OnClientClick="jsShowLoading(1);"/></td>
            <td align="center" >&nbsp;<asp:Button runat="server" ID="btnSave" Text="Save" Enabled="False" OnClientClick="return confirmSave();"/>&nbsp;</td>
          </tr>
        </table>
      </td comment=col1>      
    </tr>
    </table>
  </fieldset>
  <br />
  <asp:GridView ID="gvPlanning" runat="server" CellPadding="2" 
    CssClass="gridviewDefault" Caption="Planned Forecast" 
    DataSourceID="sdsRegionBlank" AutoGenerateColumns="False" Visible="False">
      <Columns>
        <asp:BoundField DataField="#" HeaderText="#" ReadOnly="True" SortExpression="#" />
        <asp:BoundField DataField="Region" HeaderText="Region" ReadOnly="True" SortExpression="Region" />
        <asp:BoundField DataField="Jul" HeaderText="Jul" ReadOnly="True"  />
        <asp:BoundField DataField="Aug" HeaderText="Aug" ReadOnly="True"  />
        <asp:BoundField DataField="Sep" HeaderText="Sep" ReadOnly="True"  />
        <asp:BoundField DataField="Q1" HeaderText="Q1" ReadOnly="True"  />
        <asp:BoundField DataField="Oct" HeaderText="Oct" ReadOnly="True"  />
        <asp:BoundField DataField="Nov" HeaderText="Nov" ReadOnly="True"  />
        <asp:BoundField DataField="Dec" HeaderText="Dec" ReadOnly="True"  />
        <asp:BoundField DataField="Q2" HeaderText="Q2" ReadOnly="True"  />
        <asp:BoundField DataField="Jan" HeaderText="Jan" ReadOnly="True"  />
        <asp:BoundField DataField="Feb" HeaderText="Feb" ReadOnly="True"  />
        <asp:BoundField DataField="Mar" HeaderText="Mar" ReadOnly="True"  />
        <asp:BoundField DataField="Q3" HeaderText="Q3" ReadOnly="True"  />
        <asp:BoundField DataField="Apr" HeaderText="Apr" ReadOnly="True"  />
        <asp:BoundField DataField="May" HeaderText="May" ReadOnly="True"  />
        <asp:BoundField DataField="Jun" HeaderText="Jun" ReadOnly="True"  />
        <asp:BoundField DataField="Q4" HeaderText="Q4" ReadOnly="True"  />
	      <asp:TemplateField HeaderText="Total" >
          <ItemTemplate>            
            <asp:TextBox ID="Total" runat="server" CssClass="controlTextboxBig" 
              Text='<%# Bind("Total") %>'></asp:TextBox>
          </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="Average" HeaderText="Average" ReadOnly="True"  />
     </Columns>
			<HeaderStyle CssClass="" HorizontalAlign="Center" Wrap="True" />
			<AlternatingRowStyle CssClass="listAlternate" />
  </asp:GridView>
  <asp:TextBox ID="planningAnchor" runat="server" Text="" CssClass="controlLabel" ReadOnly="True"></asp:TextBox>
    <!-- 
    eof
    //-->
    <asp:SqlDataSource ID="sdsFinYear" runat="server" 
      ConnectionString="<%$ ConnectionStrings:SuperbowlConnectionString %>"
                  
    SelectCommand="SELECT DISTINCT intFiscalYear AS DataValueField, intFiscalYear AS DataTextField FROM mstPeriod WHERE intFiscalYear > 2010 ORDER BY DataTextField DESC">

    </asp:SqlDataSource>
    
    <asp:SqlDataSource ID="sdsBrand" runat="server" 
      ConnectionString="<%$ ConnectionStrings:SuperbowlConnectionString %>" 
      SelectCommand="SELECT BrandID AS DataValueField, strBrand AS DataTextField FROM mstBrand WHERE blnActive = 1 GROUP BY BrandID, strBrand ORDER BY DataTextField">
    </asp:SqlDataSource>
    
  <asp:SqlDataSource ID="sdsRegionBlank" runat="server" 
    ConnectionString="<%$ ConnectionStrings:SuperbowlConnectionString %>" 
    SelectCommand="SELECT strRegionOrder AS '#', strRegionDesc2 AS Region, 0 AS Jul, 0 AS Aug, 0 AS Sep, 0 AS Q1, 0 AS Oct, 0 AS Nov, 0 AS Dec, 0 AS Q2, 0 AS Jan, 0 AS Feb, 0 AS Mar, 0 AS Q3, 0 AS Apr, 0 AS May, 0 AS Jun, 0 AS Q4, 0 AS Total, 0 AS Average FROM dwdCustomer GROUP BY strRegionOrder, strRegionDesc2 UNION ALL SELECT 99 AS '#', 'Total' AS Region, 0 AS Jul, 0 AS Aug, 0 AS Sep, 0 AS Q1, 0 AS Oct, 0 AS Nov, 0 AS Dec, 0 AS Q2, 0 AS Jan, 0 AS Feb, 0 AS Mar, 0 AS Q3, 0 AS Apr, 0 AS May, 0 AS Jun, 0 AS Q4, 0 AS Total, 0 AS Average ORDER BY '#', Region">
  </asp:SqlDataSource>
    
</asp:Content>
