<%@ Page Title="TopSale Report" Language="C#" MasterPageFile="~/SunMaster.Master"
    AutoEventWireup="true" CodeBehind="TopsaleNew.aspx.cs" Inherits="SUNWEB.TopsaleNew" %>

<%@ Register Assembly="AjaxControlToolkit" TagPrefix="asp" Namespace="AjaxControlToolkit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <%--    <script type="text/javascript">
        google.load('visualization', '1', { packages: ['corechart'] });
    </script>

     <script type="text/javascript">
      google.load('visualization', '1', { packages: ['corechart'] });
    </script>--%>
    <style type="text/css">
        
    </style>
    <style type="text/css">
        @media only screen and (max-width: 600px)
        {
            table, th, td
            {
                font-size: 10px;
                font-weight: bold;
            }
        
            .Labels
            {
                font-size: 10px;
            }
            .alnright
            {
                text-align: right;
            }
        
        
            div
            {
                text-align: left;
            }
            .Labels
            {
                font-size: 10px;
            }
        
            .LoadingImgCss
            {
                height: 10px;
                width: 10px;
            }
                       
        }
    </style>
    <style type="text/css">
        .overlay
        {
            position: fixed;
            top: 0px;
            left: 0px;
            z-index: 0;
            height: 100%;
            width: 100%;
            top: 0;
            background-color: White;
            filter: alpha(opacity=60);
            opacity: 0.9;
            -moz-opacity:1;
        }
        
        .LoadingDivCss
        {
            margin: 0;
            position: absolute;
            top: 50%;
            left: 50%;
            margin-right: -50%;
            transform: translate(-50%, -50%);
        }
        
        .LoadingImgCss
        {
            height: 100px;
            width: 100px;
        }
        
        .ExportTxtCss
        {
            text-align:center;
        }
    </style>
    <script type="text/javascript">
        function showProgress() {
            var updateProgress = $get("<%= UpdateProgress.ClientID %>");
            updateProgress.style.display = "block";
        }
    
    </script>
    <script type="text/javascript">
        function CheckOne(obj) {
            var grid = obj.parentNode.parentNode.parentNode;
            var inputs = grid.getElementsByTagName("input");
            for (var i = 0; i < inputs.length; i++) {
                if (inputs[i].type == "checkbox") {
                    if (obj.checked && inputs[i] != obj && inputs[i].checked) {
                        inputs[i].checked = false;
                    }
                }
            }
        }



        function switchViews(obj, row) {
            var div = document.getElementById(obj);
            var img = document.getElementById('img' + obj);

            if (div.style.display == "none") {
                div.style.display = "inline";
                img.src = "IMG/minus.gif";
            } else {
                div.style.display = "none";
                img.src = "IMG/plus.gif";
            }
        }



    </script>
    <%--    <script type="text/javascript">
        $("[src*=plus]").live("click", function () {
            $(this).closest("tr").after("<tr><td></td><td colspan = '999'>" + $(this).next().html() + "</td></tr>")
            $(this).attr("src", "IMG/minus.gif");
        });
        $("[src*=minus]").live("click", function () {
            $(this).attr("src", "IMG/plus.gif");
            $(this).closest("tr").next().remove();
        });
    </script>--%>
    <%-- <script type="text/javascript" language="javascript">
             window.onbeforeunload = function () {
                 var msg = "Are you sure you want to close windows";
                 return msg;
             }
          </script>--%>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
   <div class="row">
    <div class="container-fluid ps-3">
    <div class="d-flex align-items-center gap-3">
        <!--  Export Button - Excel1 -->
          <asp:Button ID="btnExcel" runat="server" CssClass="btn btn-success" Visible="true"
            OnClick="btnExcelHeader_Click" Text="Excel 1"  ToolTip="Export Top Sales Report" />
        <!--  Export Button - Excel1 -->
       <asp:Button ID="btnExcel2" runat="server" Text="Excel 2" CssClass="btn btn-success"
         Visible="true"  OnClick="btnExcelDetails_Click" ToolTip="Export Detailed Top Sales Report" />

    </div>
 </div>
</div>






    <asp:UpdatePanel ID="Upanel" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <div class="row">
            <div class="section-block">
                <h7 class="section-title">
                 &nbsp;TOP SALES REPORT
                </h7>
            </div>
            </div>
            <div class="row">
                <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
                    <div class="card">
                        <div class="card-body">
                            <div class="form-row">
                                <div class="col-xl-4 col-lg-4 col-md-12 col-sm-12 col-12 mb-2">
                                    <caption>
                                        <label for="validationCustom03">
                                            From 
                                        </label>
                                        <asp:TextBox ID="txtFromDt" class="form-control" runat="server"></asp:TextBox>
                                        <asp:CalendarExtender ID="calexdFrom" Format="yyyy-MM-dd" runat="server" TargetControlID="txtFromDt"
                                            PopupPosition="BottomLeft" FirstDayOfWeek="Sunday"></asp:CalendarExtender>
                                    </caption>
                                </div>
                                <div class="col-xl-4 col-lg-4 col-md-12 col-sm-12 col-12 mb-2">
                                    <label for="validationCustom03">
                                        To
                                    </label>
                                    <asp:TextBox ID="txtToDt" class="form-control" runat="server"></asp:TextBox>
                                    <asp:CalendarExtender ID="calexdTo" Format="yyyy-MM-dd" runat="server" TargetControlID="txtToDt"
                                        PopupPosition="BottomLeft" FirstDayOfWeek="Sunday"></asp:CalendarExtender>
                                </div>
                                <div class="col-xl-4 col-lg-4 col-md-12 col-sm-12 col-12 mb-2">
                                    <label for="validationCustom03">
                                        <asp:Label ID="lblBranchAliasName" runat="server" Text="Branch"></asp:Label></label>
                                    <asp:DropDownList ID="cmbBranches" CssClass="custom-select" runat="server" AutoPostBack="true"
                                        OnSelectedIndexChanged="cmbBranches_SelectedIndexChanged">
                                    </asp:DropDownList>
                                </div>
                                <div class="col-xl-4 col-lg-4 col-md-12 col-sm-12 col-12 mb-2">
                                    <caption>
                                        <label for="validationCustom03">
                                            Select By
                                        </label>
                                        <asp:DropDownList ID="CmbSelect" runat="server" CssClass="custom-select" AutoPostBack="true"
                                            OnSelectedIndexChanged="cmbSelect_SelectedIndexChanged">
                                            <asp:ListItem Text="All Inventory" Value="AInventory"></asp:ListItem>
                                            <asp:ListItem Text="Category" Value="Category"></asp:ListItem>
                                            <asp:ListItem Text="Group 1" Value="Group1"></asp:ListItem>
                                            <asp:ListItem Text="Group 2" Value="Group2"></asp:ListItem>
                                            <asp:ListItem Text="Group 3" Value="Group3"></asp:ListItem>
                                            <asp:ListItem Text="Group 4" Value="Group4"></asp:ListItem>
                                            <asp:ListItem Text="Group 5" Value="Group5"></asp:ListItem>
                                        </asp:DropDownList>
                                    </caption>
                                </div>
                                <div class="col-xl-4 col-lg-4 col-md-12 col-sm-12 col-12 mb-2">
                                    <caption>
                                        <label for="validationCustom03">
                                            Id
                                        </label>
                                        <asp:TextBox ID="txtID" class="form-control" runat="server" ReadOnly="true"></asp:TextBox>
                                    </caption>
                                </div>
                                <div class="col-xl-4 col-lg-4 col-md-12 col-sm-12 col-12 mb-2">
                                    <caption>
                                        <label for="validationCustom03">
                                            Name
                                        </label>
                                        <asp:TextBox ID="txtName" class="form-control" runat="server" ReadOnly="true"></asp:TextBox>
                                    </caption>
                                </div>
                                <div class="col-xl-4 col-lg-4 col-md-12 col-sm-12 col-12 mb-2">
                                    <caption>
                                        <label for="validationCustom03">
                                            Top By
                                        </label>
                                        <asp:DropDownList ID="cmbTopBy" runat="server" CssClass="custom-select" AutoPostBack="false">
                                            <asp:ListItem Text="QTY" Value="QTY"></asp:ListItem>
                                            <asp:ListItem Text="%(QTY)" Value="QTYPER"></asp:ListItem>
                                            <asp:ListItem Text="Amount" Value="Amount"></asp:ListItem>
                                            <asp:ListItem Text="%(Amount)" Value="AMTPER"></asp:ListItem>
                                        </asp:DropDownList>
                                    </caption>
                                </div>
                                <div class="col-xl-4 col-lg-4 col-md-12 col-sm-12 col-12 mb-2">
                                    <caption>
                                        <label for="validationCustom03">
                                            Top Number
                                        </label>
                                        <asp:TextBox ID="txtTopN" class="form-control" runat="server" ReadOnly="false" TextMode="Number" ></asp:TextBox>
                                    </caption>
                                </div>
                                <div class="col-xl-4 col-lg-4 col-md-12 col-sm-12 col-12 mb-2">
                                    <caption>
                                        <label for="validationCustom03">
                                            Order By 
                                        </label>
                                        <asp:DropDownList ID="cmbOrderBy" runat="server" CssClass="custom-select" AutoPostBack="false">                                            
                                            <asp:ListItem Text="Descending" Value="Desc"></asp:ListItem>
                                            <asp:ListItem Text="Ascending" Value="Asc"></asp:ListItem>
                                        </asp:DropDownList>
                                    </caption>
                                </div>
                                <div class="col-xl-4 col-lg-4 col-md-12 col-sm-12 col-12 mb-2">
                                    <asp:Button ID="btnApplySearch" runat="server" Text="Apply Search" CssClass="btn btn-primary"
                                        OnClick="btnApplySearch_Click" AutoPostBack="false" Visible="false" />
                                </div>
                                <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
                                    <div class="card">
                                        <div class="card-header" id="idSearch" runat="server" style="background-color: #4c4c4c; color: White;">
                                       
                                                <asp:Label ID="lblSearchResult" runat="server" CssClass="Labels"> </asp:Label>
                                            
                                        </div>
                                        <div class="card-body">
                                            <div class="table-responsive">
                                                <table id="example" class="table table-striped table-bordered second" style="width: 100%">
                                                    <tbody>
                                                        <caption>
                                                            <asp:Panel ID="Panel8" runat="server" BackColor="white" Height="180px" ScrollBars="Auto"
                                                                Width="1500px">
                                                                <asp:GridView ID="grv" runat="server" AutoGenerateColumns="False" EmptyDataRowStyle-CssClass="alert-dark"
                                                                    Font-Size="11px" HeaderStyle-BackColor="RoyalBlue" EmptyDataText="No Record!"
                                                                    DataKeyNames="row1" FooterStyle-BackColor="Green" FooterStyle-ForeColor="white"
                                                                    Width="920px" AllowPaging="true" PageSize="150" BackColor="White" AllowSorting="true"
                                                                    BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3">
                                                                    <Columns>
                                                                        <asp:TemplateField>
                                                                            <ItemTemplate>
                                                                                <asp:CheckBox ID="chkSelect" runat="server" onclick="CheckOne(this)" OnCheckedChanged="CheckBox_Changed"
                                                                                    AutoPostBack="true" />
                                                                            </ItemTemplate>
                                                                        </asp:TemplateField>
                                                                        <asp:TemplateField HeaderText="Number" ItemStyle-HorizontalAlign="Left" Visible="true">
                                                                            <ItemTemplate>
                                                                                <asp:Label ID="lblrow1" runat="server" Text='<%#Eval("row1") %>'></asp:Label>
                                                                            </ItemTemplate>
                                                                        </asp:TemplateField>
                                                                        <asp:TemplateField HeaderText="Name" ItemStyle-HorizontalAlign="Left">
                                                                            <ItemTemplate>
                                                                                <asp:Label ID="lblrow2" runat="server" Text='<%#Eval("row2") %>'></asp:Label>
                                                                            </ItemTemplate>
                                                                        </asp:TemplateField>
                                                                        <asp:TemplateField HeaderText="" ItemStyle-HorizontalAlign="Left">
                                                                            <ItemTemplate>
                                                                                <asp:Label ID="lblrow3" runat="server" Text='<%#Eval("row3") %>'></asp:Label>
                                                                            </ItemTemplate>
                                                                        </asp:TemplateField>
                                                                    </Columns>
                                                                    <PagerStyle CssClass="gridview"></PagerStyle>
                                                                    <FooterStyle BackColor="#006699" ForeColor="White"></FooterStyle>
                                                                    <HeaderStyle BackColor="White" Font-Bold="True" ForeColor="Black"></HeaderStyle>
                                                                    <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
                                                                    <RowStyle ForeColor="#000066" />
                                                                    <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
                                                                    <SortedAscendingCellStyle BackColor="#F1F1F1" />
                                                                    <SortedAscendingHeaderStyle BackColor="#007DBB" />
                                                                    <SortedDescendingCellStyle BackColor="#CAC9C9" />
                                                                    <SortedDescendingHeaderStyle BackColor="#00547E" />
                                                                </asp:GridView>
                                                            </asp:Panel>
                                                        </caption>
                                                    </tbody>
                                                </table>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div>
                                    <asp:Button ID="btnGetReports" runat="server" Text="Generate Report" Class="btn btn-primary"
                                        OnClick="btnGetReports_Click" />
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <br />
            <div class="row">
            <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
                <div class="card">
                    
                        <h4 class="card-header" id="idGenReport" runat="server" style="background-color: #4c4c4c; color: White;">
                            <asp:Label ID="lblMsgTotalSelection" runat="server">&nbsp;&nbsp;&nbsp; </asp:Label><asp:Label ID="Label2"
                                runat="server"></asp:Label>
                        </h4>
                    
                    <div class="card-body">
                        <div class="table-responsive">
                            <table id="Table1" class="table table-striped table-bordered second" style="width: 100%">
                                <tbody>
                                    <caption>
                                        <div align="center">
                                            <asp:GridView ID="grdTopSales" runat="server" GridLines="None" AutoGenerateColumns="False"
                                                OnSelectedIndexChanged="grdTopSales_SelectedIndexChanged" DataKeyNames="CategoryNumber" 
                                                OnPageIndexChanging = "grdTopSales_PageIndexChanging" 
                                                OnRowDataBound="grdTopSales_RowDataBound"  AllowPaging="true" PageSize="20" Width="100%" EmptyDataText="No Record!">
                                                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                                                <Columns>
                                                    <asp:TemplateField>
                                                        <ItemTemplate>
                                                            <a href="javascript:switchViews('div<%# Eval("CategoryNumber") %>', 'one');">
                                                                <img id="imgdiv<%# Eval("CategoryNumber") %>" alt="Click to show/hide Details" border="0"
                                                                    src="IMG/plus.gif" />
                                                            </a>
                                                        </ItemTemplate>
                                                        <AlternatingItemTemplate>
                                                            <a href="javascript:switchViews('div<%# Eval("CategoryNumber") %>', 'alt');">
                                                                <img id="imgdiv<%# Eval("CategoryNumber") %>" alt="Click to show/hide Details" border="0"
                                                                    src="IMG/plus.gif" />
                                                            </a>
                                                        </AlternatingItemTemplate>
                                                    </asp:TemplateField>
                                                    <asp:BoundField DataField="CategoryNumber" HeaderText="Number/Group" HeaderStyle-HorizontalAlign="Right"
                                                        HeaderStyle-CssClass="text-center" HtmlEncode="False" ItemStyle-HorizontalAlign="left"
                                                        ItemStyle-Width="8%" FooterStyle-Font-Bold="true" FooterStyle-HorizontalAlign="left" />
                                                    <asp:BoundField DataField="CategoryName" HeaderText="Name" HeaderStyle-HorizontalAlign="Right"
                                                        HeaderStyle-CssClass="text-center" HtmlEncode="False" ItemStyle-HorizontalAlign="left"
                                                        ItemStyle-Width="27%" FooterStyle-Font-Bold="true" FooterStyle-HorizontalAlign="left" />
                                                    <asp:BoundField DataField="Qty" HeaderText="QTY" HeaderStyle-HorizontalAlign="Center"
                                                        HeaderStyle-CssClass="text-center" HtmlEncode="False" ItemStyle-HorizontalAlign="Center"
                                                        ItemStyle-Width="10%" FooterStyle-Font-Bold="true" FooterStyle-HorizontalAlign="Center" />
                                                    <asp:BoundField DataField="QTYPER" HeaderText="%(QTY)" HeaderStyle-HorizontalAlign="Center"
                                                        HeaderStyle-CssClass="text-center" HtmlEncode="False" ItemStyle-HorizontalAlign="Center"
                                                        ItemStyle-Width="20%" FooterStyle-Font-Bold="true" FooterStyle-HorizontalAlign="Center" />
                                                    <asp:BoundField DataField="Total" HeaderText="Amount" HeaderStyle-HorizontalAlign="Center"
                                                        HeaderStyle-CssClass="text-center" HtmlEncode="False" ItemStyle-HorizontalAlign="Center" ItemStyle-CssClass="text-right"
                                                        ItemStyle-Width="20%" FooterStyle-Font-Bold="true" FooterStyle-HorizontalAlign="Center"
                                                        DataFormatString="{0:F2}" />
                                                    <asp:BoundField DataField="AMTPER" HeaderText="%(Amount)" HeaderStyle-HorizontalAlign="Center"
                                                        HeaderStyle-CssClass="text-center" HtmlEncode="False" ItemStyle-HorizontalAlign="Center"
                                                        ItemStyle-Width="20%" FooterStyle-Font-Bold="true" FooterStyle-HorizontalAlign="Center"
                                                        DataFormatString="{0:F2}" />
                                                    <asp:TemplateField>
                                                        <ItemTemplate>
                                                            <tr>
                                                                <td colspan="100%" style="padding-left: 25px">
                                                                    <div id="div<%# Eval("CategoryNumber") %>" style="display: none; left: 150px;">
                                                                        <asp:GridView ID="grdChildTS" runat="server" Width="100%" AutoGenerateColumns="false"
                                                                            BorderColor="Transparent" DataKeyNames="Categorynumber" EmptyDataText="No Details for this Category"
                                                                            HeaderStyle-Width="20px">
                                                                            <HeaderStyle CssClass="dataTable" />
                                                                            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                                                                            <HeaderStyle BackColor="White" ForeColor="Black" />
                                                                            <PagerStyle BackColor="White" ForeColor="Black" />
                                                                            <FooterStyle BackColor="White" ForeColor="Black" />
                                                                            <RowStyle CssClass="dataTable" />
                                                                            <Columns>
                                                                                <asp:BoundField DataField="Barcode" HeaderText="Barcode" 
                                                                                    HeaderStyle-CssClass="text-center" HtmlEncode="False" ItemStyle-HorizontalAlign="left"
                                                                                    ItemStyle-Width="10%" FooterStyle-Font-Bold="true" FooterStyle-HorizontalAlign="left" />
                                                                                <asp:BoundField DataField="Name" HeaderText="Name" 
                                                                                    HeaderStyle-CssClass="text-center" HtmlEncode="False" ItemStyle-HorizontalAlign="left"
                                                                                    ItemStyle-Width="15%" FooterStyle-Font-Bold="true" FooterStyle-HorizontalAlign="left" />
                                                                                <asp:BoundField DataField="InventoryDesc" HeaderText="Description"
                                                                                    HeaderStyle-CssClass="text-center" HtmlEncode="False" ItemStyle-HorizontalAlign="left"
                                                                                    ItemStyle-Width="15%" FooterStyle-Font-Bold="true" FooterStyle-HorizontalAlign="left" />
                                                                                <asp:BoundField DataField="QTY" HeaderText="QTY" 
                                                                                    HeaderStyle-CssClass="text-center" HtmlEncode="False" 
                                                                                    ItemStyle-Width="12%" FooterStyle-Font-Bold="true" ItemStyle-CssClass="text-center" FooterStyle-HorizontalAlign="left" />
                                                                                <asp:BoundField DataField="QTYPER" HeaderText="%(QTY)" 
                                                                                    HeaderStyle-CssClass="text-center" HtmlEncode="False" 
                                                                                    ItemStyle-Width="12%" FooterStyle-Font-Bold="true" ItemStyle-CssClass="text-center" FooterStyle-HorizontalAlign="left" />
                                                                                <asp:BoundField DataField="Amount" HeaderText="Total Amount" 
                                                                                    HeaderStyle-CssClass="text-center" HtmlEncode="False"
                                                                                    ItemStyle-Width="12%" FooterStyle-Font-Bold="true" ItemStyle-CssClass="text-right" FooterStyle-HorizontalAlign="left"
                                                                                    DataFormatString="{0:F2}" />
                                                                                <asp:BoundField DataField="AMTPER" HeaderText="%(AMOUNT)"
                                                                                    HeaderStyle-CssClass="text-center" HtmlEncode="False" 
                                                                                    ItemStyle-Width="12%" FooterStyle-Font-Bold="true" ItemStyle-CssClass="text-center" FooterStyle-HorizontalAlign="left" />
                                                                                <asp:BoundField DataField="Disc" HeaderText="TOTAL DISC" 
                                                                                    HeaderStyle-CssClass="text-center" HtmlEncode="False" 
                                                                                    ItemStyle-Width="12%" FooterStyle-Font-Bold="true" ItemStyle-CssClass="text-right" FooterStyle-HorizontalAlign="left"
                                                                                    DataFormatString="{0:F2}" />
                                                                            </Columns>
                                                                        </asp:GridView>
                                                                    </div>
                                                                </td>
                                                            </tr>   
                                                        </ItemTemplate>
                                                    </asp:TemplateField>
                                                </Columns>
                                                <EditRowStyle BackColor="#999999" />
                                                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                                 <PagerStyle CssClass="gridview"></PagerStyle>
                                                <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                                                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                                                <SortedAscendingCellStyle BackColor="#E9E7E2" />
                                                <SortedAscendingHeaderStyle BackColor="#506C8C" />
                                                <SortedDescendingCellStyle BackColor="#FFFDF8" />
                                                <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
                                            </asp:GridView>
                                        </div>
                                    </caption>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
    <asp:UpdateProgress ID="UpdateProgress" runat="server" AssociatedUpdatePanelID="Upanel">
        <ProgressTemplate>
            <div class="overlay">
                <%--  <div style="z-index: 1000; margin-left: 450px; margin-top: 0; opacity: 1; -moz-opacity: 1;">--%>
                <div class="LoadingDivCss">
                    <img alt="" src="IMG/Spinner.gif" class="LoadingImgCss" />
                </div>
            </div>
        </ProgressTemplate>
    </asp:UpdateProgress>

 <script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css?v=1.1" rel="stylesheet" />
 <!-- Bootstrap 5 -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" />
<!-- Optional Bootstrap Icons -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css" rel="stylesheet" />

</asp:Content>
