﻿<?xml version="1.0" encoding="utf-8"?>
<inherited BaseReport="..\..\Reports\Base.frx" ScriptLanguage="CSharp" DoublePass="true" StartReportEvent="_StartReport" ReportInfo.Created="05/15/2013 14:45:40" ReportInfo.Modified="06/08/2015 11:53:42" ReportInfo.CreatorVersion="1.6.57.0">
  <ScriptText>using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;
using System.Data;
using FastReport;
using FastReport.Data;
using FastReport.Dialog;
using FastReport.Barcode;
using FastReport.Table;
using FastReport.Utils;

namespace FastReport
{
  public class ReportScript
  {

    int decimalValue = 0;
    string orderBy = String.Empty;
    string selection = String.Empty;
    string showItems = String.Empty;
    
    private void _StartReport(object sender, EventArgs e)
    {
      
      
      
    }
    
    private void Form1_Shown(object sender, EventArgs e)
    {
      decimalValue = Convert.ToInt32(Report.GetColumnValue(&quot;programs_config.QtyDecimalValue&quot;));
      //MessageBox.Show(showItems);
      
      cboSelection.Text = &quot;All&quot;;
      cboOrderBy.Text = &quot;Description&quot;;
      if (string.Compare(Report.GetColumnValue(&quot;programs_config.StockTake_VarianceShow&quot;).ToString(), &quot;Show all items&quot;, true) == 0)
        optShowAllItems.Checked = true;
      else 
        optShowOnlyVariances.Checked = true;
      if (string.Compare(Report.GetColumnValue(&quot;programs_config.StockTake_VarianceOrderBy&quot;).ToString(), &quot;Description&quot;, true) == 0)
        cboOrderBy.Text = &quot;Description&quot;;
      else
        cboOrderBy.Text = &quot;Item code&quot;;
    }
    
    
    private void btnOk_Click(object sender, EventArgs e)
    {
      //Report.SetParameterValue(&quot;OrderBy&quot;, cboOrderBy.Text); DOES NOT WORK ?????
      TableDataSource tProducts = Report.GetDataSource(&quot;products&quot;) as TableDataSource;
      
      
       
      
      if (cboOrderBy.Text == &quot;Item code&quot;)
        orderBy = &quot;ProductCode&quot;;      
      else if (cboOrderBy.Text == &quot;Description&quot;)      
        orderBy = &quot;Description&quot;;      
      
      
      if (optShowOnlyVariances.Checked) 
        showItems = &quot; AND QtyCounted - QtyAvailable &lt;&gt; 0&quot;;
      
      if (cboSelection.Text == &quot;All&quot;)
      {
        txtSelectionFeedback.Text = &quot;Selection: All&quot;;
        selection = &quot;ID &gt; 0&quot;;
      }
      else if (cboSelection.Text == &quot;Location =&quot;)
      {
        txtSelectionFeedback.Text = &quot;Location = &quot; + cboLocation.Text;
        selection = &quot;Location = '&quot; + cboLocation.Text + &quot;'&quot;;
      }
      else if (cboSelection.Text == &quot;Sub-Location =&quot;)
      {
        txtSelectionFeedback.Text = &quot;Sub-Location = &quot; + cboSubLocation.Text;
        selection = &quot;SubLocation = '&quot; + cboSubLocation.Text + &quot;'&quot;; 
      }
      else if (cboSelection.Text == &quot;Category =&quot;)
      {
        txtSelectionFeedback.Text = &quot;Category = &quot; + cboCategory.Text;
        selection = &quot;Category = '&quot; + cboCategory.Text + &quot;'&quot;;
      }
      else if (cboSelection.Text == &quot;Sub-Category =&quot;)
      {
        txtSelectionFeedback.Text = &quot;Sub-Category = &quot; + cboSubCategory.Text;
        selection = &quot;SubCategory = '&quot; + cboSubCategory.Text + &quot;'&quot;; 
      }
      
      tProducts.SelectCommand = tProducts.SelectCommand.ToString().Replace(&quot;@Selection&quot;, selection + showItems);
      tProducts.SelectCommand = tProducts.SelectCommand.ToString().Replace(&quot;@OrderBy&quot;, orderBy);
    }
   
    

    private void Data1_AfterData(object sender, EventArgs e)
    {
      //total Qty Column format      
      
      decimal qtyVal = 0; 
      if (Decimal.TryParse(txtQtyAvailable.Text, out qtyVal))
      {
        txtQtyAvailable.Text = String.Format(&quot;{0:F&quot; + decimalValue + &quot;}&quot;, qtyVal);
      }
      if (Decimal.TryParse(txtQtyCounted.Text, out qtyVal))
      {
        txtQtyCounted.Text = String.Format(&quot;{0:F&quot; + decimalValue + &quot;}&quot;, qtyVal);
      }
      if (Decimal.TryParse(txtQtyDiff.Text, out qtyVal))
      {
        txtQtyDiff.Text = String.Format(&quot;{0:F&quot; + decimalValue + &quot;}&quot;, qtyVal);
      }
    }

    private void DataFooter1_AfterData(object sender, EventArgs e)
    {
      //total Qty Column format      
      decimal qtyVal = 0; 
      if (Decimal.TryParse(txtQtyAvailableTotal.Text, out qtyVal))
      {
        txtQtyAvailableTotal.Text = String.Format(&quot;{0:F&quot; + decimalValue + &quot;}&quot;, qtyVal);
      }
      if (Decimal.TryParse(txtQtyCountedTotal.Text, out qtyVal))
      {
        txtQtyCountedTotal.Text = String.Format(&quot;{0:F&quot; + decimalValue + &quot;}&quot;, qtyVal);
      }
      if (Decimal.TryParse(txtQtyDiffTotal.Text, out qtyVal))
      {
        txtQtyDiffTotal.Text = String.Format(&quot;{0:F&quot; + decimalValue + &quot;}&quot;, qtyVal);
      }
    }

    

    private void cboSelection_SelectedIndexChanged(object sender, EventArgs e)
    {
      if (cboSelection.Text == &quot;Location =&quot;)
        cboLocation.Visible = true;
      else if (cboSelection.Text == &quot;Sub-Location =&quot;)
        cboSubLocation.Visible = true;
      else if (cboSelection.Text == &quot;Category =&quot;)
        cboCategory.Visible = true;
      else if (cboSelection.Text == &quot;Sub-Category =&quot;)
        cboSubCategory.Visible = true; 
    }
   
    

    
  }
}
</ScriptText>
  <Dictionary>
    <MySqlDataConnection Name="Connection" ConnectionString="rijcmlqomabmqtwD7y3BaVO988XrjoBefSoHBX+xGSDpo0d+ot8yrzL17EhRvx7tW87ZuxDTsXprPmiOj80ATh2Aow+2w==">
      <TableDataSource Name="companies" DataType="System.Int32" Enabled="true" TableName="companies" SelectCommand="SELECT * FROM companies WHERE ID = @CompanyID">
        <Column Name="ID" DataType="System.UInt32"/>
        <Column Name="Name" DataType="System.String"/>
        <Column Name="Email" DataType="System.String"/>
        <Column Name="Address" DataType="System.String"/>
        <Column Name="RegNo" DataType="System.String"/>
        <Column Name="VATno" DataType="System.String"/>
        <Column Name="ContactNo" DataType="System.String"/>
        <Column Name="AltNo" DataType="System.String"/>
        <Column Name="FaxNo" DataType="System.String"/>
        <Column Name="CellNo" DataType="System.String"/>
        <Column Name="LogoPath" DataType="System.String"/>
        <Column Name="InvoiceStylePath" DataType="System.String"/>
        <Column Name="InvoiceSize" DataType="System.String"/>
        <Column Name="VATrate" DataType="System.String"/>
        <Column Name="BankingDetails" DataType="System.String"/>
        <CommandParameter Name="companyID" DataType="254" Expression="[CompanyID]"/>
      </TableDataSource>
      <TableDataSource Name="Table" Alias="products" DataType="System.Int32" Enabled="true" SelectCommand="SELECT ProductCode, Description, QtyAvailable, QtyCounted, QtyCounted - QtyAvailable AS QtyDiff, &#13;&#10;CostPrice * QtyCounted AS TotalCostCounted, (QtyCounted - QtyAvailable) * CostPrice AS TotCostDiff &#13;&#10;FROM products WHERE CompanyID = @CompanyID &#13;&#10;AND @Selection &#13;&#10;ORDER BY @OrderBy&#13;&#10;">
        <Column Name="ProductCode" DataType="System.String"/>
        <Column Name="QtyAvailable" DataType="System.Decimal"/>
        <Column Name="Description" DataType="System.String"/>
        <Column Name="QtyCounted" DataType="System.Decimal"/>
        <Column Name="QtyDiff" DataType="System.Decimal"/>
        <Column Name="TotalCostCounted" DataType="System.Decimal"/>
        <Column Name="TotCostDiff" DataType="System.Decimal"/>
        <CommandParameter Name="CompanyID" DataType="254" Expression="[CompanyID]"/>
        <CommandParameter Name="orderBy" DataType="254"/>
        <CommandParameter Name="Selection" DataType="254" Expression="[Selection]"/>
      </TableDataSource>
      <TableDataSource Name="Table2" Alias="programs_config" DataType="System.Int32" Enabled="true" SelectCommand="SELECT QtyDecimalValue, StockTake_VarianceOrderBy, StockTake_VarianceShow FROM programs_config WHERE CompanyID = @CompanyID">
        <Column Name="QtyDecimalValue" DataType="System.UInt32"/>
        <Column Name="StockTake_VarianceShow" DataType="System.String"/>
        <Column Name="StockTake_VarianceOrderBy" DataType="System.String"/>
        <CommandParameter Name="CompanyID" DataType="254" Expression="[CompanyID]"/>
      </TableDataSource>
      <TableDataSource Name="Table3" Alias="Categories" DataType="System.Int32" Enabled="true" SelectCommand="SELECT DISTINCT Category FROM products  WHERE CompanyID = @CompanyID ORDER BY Category">
        <Column Name="Category" DataType="System.String"/>
        <CommandParameter Name="CompanyID" DataType="254" Expression="CompanyID"/>
      </TableDataSource>
      <TableDataSource Name="Table4" Alias="SubCategories" DataType="System.Int32" Enabled="true" SelectCommand="SELECT DISTINCT(SubCategory) FROM products WHERE CompanyID = @CompanyID ORDER BY SubCategory">
        <Column Name="SubCategory" DataType="System.String"/>
        <CommandParameter Name="CompanyID" DataType="254" Expression="[CompanyID]"/>
      </TableDataSource>
      <TableDataSource Name="Table1" Alias="Locations" DataType="System.Int32" Enabled="true" SelectCommand="SELECT DISTINCT Location FROM products  WHERE CompanyID = @CompanyID ORDER BY Location">
        <Column Name="Location" DataType="System.String"/>
        <CommandParameter Name="CompanyID" DataType="254" Expression="[CompanyID]"/>
      </TableDataSource>
      <TableDataSource Name="Table5" Alias="SubLocations" DataType="System.Int32" Enabled="true" SelectCommand="SELECT DISTINCT SubLocation FROM products  WHERE CompanyID = @CompanyID ORDER BY SubLocation">
        <Column Name="SubLocation" DataType="System.String"/>
        <CommandParameter Name="CompanyID" DataType="254" Expression="[CompanyID]"/>
      </TableDataSource>
    </MySqlDataConnection>
    <Parameter Name="CompanyID" DataType="System.Int32"/>
    <Parameter Name="OrderBy" DataType="System.String"/>
    <Parameter Name="Selection" DataType="System.String"/>
    <Total Name="Total_Cost" Expression="[products.TotalCostCounted]" Evaluator="Data1" PrintOn="DataFooter1"/>
    <Total Name="Total_Variance" Expression="[products.TotCostDiff]" Evaluator="Data1" PrintOn="DataFooter1"/>
    <Total Name="Total_QtyAvailable" Expression="[products.QtyAvailable]" Evaluator="Data1" PrintOn="DataFooter1"/>
    <Total Name="Count_Total_Items" TotalType="Count" Evaluator="Data1"/>
    <Total Name="Total_QtyCounted" Expression="[products.QtyCounted]" Evaluator="Data1" PrintOn="DataFooter1"/>
    <Total Name="Total_QtyDiff" Expression="[products.QtyDiff]" Evaluator="Data1" PrintOn="DataFooter1"/>
  </Dictionary>
  <inherited Name="Page1" RawPaperSize="9" FirstPageSource="15" OtherPagesSource="15">
    <inherited Name="PageHeader1">
      <inherited Name="_CompanyName"/>
      <ChildBand Name="Child1" ZOrder="-1" Top="41.8" Width="718.2" Height="141.75">
        <ShapeObject Name="Shape7" Top="75.6" Width="718.2" Height="56.7" Border.Color="Gainsboro" Fill.Color="WhiteSmoke" Shape="RoundRectangle"/>
        <TextObject Name="txtHeaderCost" Left="548.1" Top="85.05" Width="75.6" Height="37.8" Text="Counted Cost" HorzAlign="Center"/>
        <TextObject Name="txtHeaderSelling" Left="633.15" Top="85.05" Width="75.6" Height="37.8" Text="Variance Value" HorzAlign="Center"/>
        <TextObject Name="Text18" Left="141.75" Top="85.05" Width="179.55" Height="18.9" Text="Description"/>
        <TextObject Name="Text19" Left="9.45" Top="85.05" Width="122.85" Height="18.9" Text="Item Code"/>
        <TextObject Name="txtHeaderQtyAvail" Left="406.35" Top="85.05" Width="66.15" Height="37.8" Text="Qty Available" HorzAlign="Center"/>
        <TextObject Name="Text31" Left="37.8" Width="444.15" Height="56.7" Text="Stock-Take Variance report" Font="Segoe UI Light, 22pt" TextFill.Color="OliveDrab"/>
        <TextObject Name="txtSelectionFeedback" Left="217.35" Top="37.8" Width="472.5" Height="28.35" Text="All" HorzAlign="Right" Font="Segoe UI Light, 14pt"/>
        <TextObject Name="Text81" Left="330.75" Top="85.05" Width="66.15" Height="37.8" Text="Qty Counted" HorzAlign="Center"/>
        <TextObject Name="Text82" Left="481.95" Top="85.05" Width="56.7" Height="37.8" Text="Qty Diff." HorzAlign="Center"/>
      </ChildBand>
    </inherited>
    <DataBand Name="Data1" ZOrder="0" Top="187.55" Width="718.2" Height="18.9" AfterDataEvent="Data1_AfterData" DataSource="Table">
      <TextObject Name="Text4" Left="9.45" Width="122.85" Height="18.9" Cursor="Hand" Hyperlink.Kind="DetailPage" ClickEvent="Text4_Click" Text="[products.ProductCode]" Trimming="EllipsisCharacter"/>
      <TextObject Name="Text5" Left="141.75" Width="179.55" Height="18.9" Text="[products.Description]" WordWrap="false" Trimming="EllipsisCharacter"/>
      <TextObject Name="txtCostData" Left="548.1" Width="75.6" Height="18.9" Text="[products.TotalCostCounted]" Format="Number" Format.UseLocale="true" HorzAlign="Right" WordWrap="false" Trimming="EllipsisCharacter"/>
      <TextObject Name="txtVarianceData" Left="633.15" Width="75.6" Height="18.9" Text="[products.TotCostDiff]" Format="Number" Format.UseLocale="true" HorzAlign="Right" WordWrap="false" Trimming="EllipsisCharacter"/>
      <TextObject Name="txtQtyAvailable" Left="406.35" Width="66.15" Height="18.9" Text="[products.QtyAvailable]" HorzAlign="Right" WordWrap="false" Trimming="EllipsisCharacter"/>
      <TextObject Name="txtQtyCounted" Left="330.75" Width="66.15" Height="18.9" Text="[products.QtyCounted]" HorzAlign="Right" WordWrap="false" Trimming="EllipsisCharacter"/>
      <TextObject Name="txtQtyDiff" Left="481.95" Width="56.7" Height="18.9" Text="[products.QtyDiff]" HorzAlign="Right" WordWrap="false" Trimming="EllipsisCharacter"/>
      <DataFooterBand Name="DataFooter1" Top="210.45" Width="718.2" Height="56.7" AfterDataEvent="DataFooter1_AfterData">
        <ShapeObject Name="Shape8" Top="9.45" Width="718.2" Height="37.8" Border.Color="Gainsboro" Fill.Color="WhiteSmoke" Shape="RoundRectangle"/>
        <TextObject Name="txtTotalCost" Left="548.1" Top="18.9" Width="75.6" Height="18.9" Text="[Total_Cost]" Format="Number" Format.UseLocale="true" HorzAlign="Right"/>
        <TextObject Name="txtTotalVariance" Left="633.15" Top="18.9" Width="75.6" Height="18.9" Text="[Total_Variance]" Format="Number" Format.UseLocale="true" HorzAlign="Right"/>
        <TextObject Name="txtQtyAvailableTotal" Left="406.35" Top="18.9" Width="66.15" Height="18.9" Text="[Total_QtyAvailable]" HorzAlign="Right"/>
        <TextObject Name="Text32" Left="9.45" Top="18.9" Width="245.7" Height="18.9" Text="Totals Excl Tax:   (Units X Qty's)" TextFill.Color="DimGray"/>
        <TextObject Name="txtQtyCountedTotal" Left="330.75" Top="18.9" Width="66.15" Height="18.9" Text="[Total_QtyCounted]" HorzAlign="Right"/>
        <TextObject Name="txtQtyDiffTotal" Left="481.95" Top="18.9" Width="56.7" Height="18.9" Text="[Total_QtyDiff]" HorzAlign="Right"/>
      </DataFooterBand>
    </DataBand>
    <ReportSummaryBand Name="ReportSummary1" ZOrder="-1" Top="271.15" Width="718.2" Height="37.8">
      <TextObject Name="Text30" Left="189" Top="9.45" Width="94.5" Height="18.9" Text="[Count_Total_Items]"/>
      <TextObject Name="Text33" Top="9.45" Width="179.55" Height="18.9" Text="Item count:" HorzAlign="Right" TextFill.Color="DimGray"/>
    </ReportSummaryBand>
    <PageFooterBand Name="PageFooter1" ZOrder="-1" Top="312.95" Width="718.2" Height="37.8">
      <TextObject Name="Text36" Left="9.45" Top="9.45" Width="94.5" Height="18.9" Text="[PageNofM]" Font="Arial, 9pt" TextFill.Color="DimGray"/>
      <TextObject Name="Text79" Left="434.7" Top="9.45" Width="94.5" Height="18.9" Text="Print Date:" HorzAlign="Right" TextFill.Color="DimGray"/>
      <TextObject Name="Text78" Left="538.65" Top="9.45" Width="160.65" Height="18.9" Text="[Date]" TextFill.Color="DimGray"/>
    </PageFooterBand>
  </inherited>
  <DialogPage Name="Form1" ZOrder="1" Width="658" Height="464" AcceptButton="btnOk" CancelButton="btnCancel" ShownEvent="Form1_Shown">
    <ButtonControl Name="btnOk" Left="462" Top="373" Height="40" Anchor="Bottom, Right" Font="Segoe UI Light, 11pt" TabIndex="0" Text="OK" ClickEvent="btnOk_Click" DialogResult="OK"/>
    <ButtonControl Name="btnCancel" Left="545" Top="373" Height="40" Anchor="Bottom, Right" Font="Segoe UI Light, 11pt" TabIndex="1" Text="Cancel" DialogResult="Cancel"/>
    <LabelControl Name="Label3" Left="24" Top="24" Width="138" Height="37" Font="Segoe UI Light, 20pt" ForeColor="OliveDrab" TabIndex="6" Text="Items - List"/>
    <ComboBoxControl Name="cboOrderBy" Left="216" Top="164" Width="233" Font="Segoe UI Light, 11pt" TabIndex="7" ClickEvent="" DropDownStyle="DropDownList" DropDownWidth="233" ItemHeight="20" ItemsText="Item code&#13;&#10;Description"/>
    <LabelControl Name="Label4" Left="68" Top="168" Width="116" Height="20" Font="Segoe UI Light, 11pt" TabIndex="5" Text="Order records by"/>
    <ComboBoxControl Name="cboSelection" Left="216" Top="92" Width="233" Font="Segoe UI Light, 11pt" TabIndex="7" ClickEvent="" DropDownStyle="DropDownList" DropDownWidth="233" ItemHeight="20" ItemsText="All&#13;&#10;Location =&#13;&#10;Sub-Location =&#13;&#10;Category =&#13;&#10;Sub-Category =" SelectedIndexChangedEvent="cboSelection_SelectedIndexChanged"/>
    <LabelControl Name="Label5" Left="68" Top="96" Width="65" Height="20" Font="Segoe UI Light, 11pt" TabIndex="5" Text="Selection"/>
    <ComboBoxControl Name="cboCategory" Left="216" Top="128" Width="233" Visible="false" Font="Tahoma, 11pt" TabIndex="8" DataColumn="Categories.Category" DropDownStyle="DropDownList" DropDownWidth="233" ItemHeight="18"/>
    <ComboBoxControl Name="cboSubCategory" Left="216" Top="128" Width="233" Visible="false" Font="Tahoma, 11pt" TabIndex="8" DataColumn="SubCategories.SubCategory" DropDownStyle="DropDownList" DropDownWidth="233" ItemHeight="18"/>
    <GroupBoxControl Name="GroupBox1" Left="216" Top="216" Width="284" Height="120" Font="Segoe UI Light, 11pt" TabIndex="9" Text="Options">
      <RadioButtonControl Name="optShowAllItems" Left="72" Top="32" Width="114" Font="Segoe UI Light, 11pt" TabIndex="10" Text="Show all Items" Checked="true"/>
      <RadioButtonControl Name="optShowOnlyVariances" Left="72" Top="76" Width="155" Font="Segoe UI Light, 11pt" TabIndex="10" TabStop="false" Text="Show Only Variances"/>
    </GroupBoxControl>
    <ComboBoxControl Name="cboLocation" Left="216" Top="128" Width="233" Visible="false" Font="Tahoma, 11pt" TabIndex="8" DataColumn="Locations.Location" DropDownStyle="DropDownList" DropDownWidth="233" ItemHeight="18"/>
    <ComboBoxControl Name="cboSubLocation" Left="216" Top="128" Width="233" Visible="false" Font="Tahoma, 11pt" TabIndex="8" DataColumn="SubLocations.SubLocation" DropDownStyle="DropDownList" DropDownWidth="233" ItemHeight="18"/>
  </DialogPage>
</inherited>
