<%@ Page Title="Detail Stock Report" Language="C#" MasterPageFile="~/SunMaster.Master" AutoEventWireup="true" CodeBehind="DetailStkReport.aspx.cs" Inherits="SUNWEB.DetailStkReport" %>
<%@ Register Assembly="AjaxControlToolkit" TagPrefix="asp" Namespace="AjaxControlToolkit" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
    <link type="text/css" rel="Stylesheet" href="css/NestedDG.css" />
    <style type="text/css">
    th {
       background: white!important;
       color:	#596365!important;
       position: sticky!important;
       top: 0;
       box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.4);
   }
   th, td {
       padding: 0.25rem;
   }

   
   </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;
            }
        }
    </style>
    



     <script type="text/javascript">
         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";
             }
         }

         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;
                     }
                 }
             }
         }


     </script>


    <%--Grid Pager CSS :--%>
    <style>
        .GridPager a,
        .GridPager span {
            display: inline-block;
            padding: 0px 9px;
            margin-right: 4px;
            border-radius: 3px;
            border: solid 1px #c0c0c0;
            background: #e9e9e9;
            box-shadow: inset 0px 1px 0px rgba(255,255,255, .8), 0px 1px 3px rgba(0,0,0, .1);
            font-size:12PX;
            font-weight: bold;
            text-decoration: none;
            color: #717171;
            text-shadow: 0px 1px 0px rgba(255,255,255, 1);
        }

        .GridPager a {
            background-color: #f5f5f5;
            color: #969696;
            border: 1px solid #969696;
        }

        .GridPager span {

            background: #616161;
            box-shadow: inset 0px 0px 8px rgba(0,0,0, .5), 0px 1px 0px rgba(255,255,255, .8);
            color: #f0f0f0;
            text-shadow: 0px 0px 3px rgba(0,0,0, .5);
            border: 1px solid #3AC0F2;
        }

    </style>

         <%-- Loading  CSS :--%>
    <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;
    }
</style>




</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <div class="row">
          <div class="col-xl-4 col-lg-4 col-md-12 col-sm-12 col-12 mb-2">
          <asp:Button ID="btnExcel" runat="server" Text="Export"
           ToolTip="To Export the Report Click Here" CssClass="btn btn-success btn-xs"
          OnClick="btnExcel_Click" />
         </div>   
    </div>

           <div class="section-block">
       <h6 class="section-title">
          STOCK REPORT
       </h6>
   </div>

   
    <asp:UpdatePanel runat="server" ID="updatepanel133" UpdateMode="Conditional">
        <ContentTemplate>
            
            <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"
                                            Font-Size="Small"></asp:TextBox>
                                        <asp:CalendarExtender ID="calFirstDueDate" 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" runat="server" class="form-control"></asp:TextBox>
                                    <asp:CalendarExtender ID="CalendarExtender1" Format="yyyy-MM-dd" runat="server" TargetControlID="txtToDt"
                                        PopupPosition="BottomLeft" FirstDayOfWeek="Sunday"></asp:CalendarExtender>
                                </div>
                                <%--onselectedindexchanged="cmbBranches_SelectedIndexChanged" --%>
                                <div class="col-xl-4 col-lg-4 col-md-12 col-sm-12 col-12 mb-2">
                                    
                                    <label for="validationCustom03">
                                        Branch
                                        <asp:Label ID="lblBranchAliasName" ForeColor="Blue" runat="server"></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">
                                    <label for="validationCustom03">
                                        Category Name 
                                        <asp:Label ID="lblCategoryName" ForeColor="Blue" runat="server"></asp:Label></label>
                                    <asp:DropDownList ID="cmbCategoryname" CssClass="custom-select"
                                        runat="server" AutoPostBack="true"
                                        OnSelectedIndexChanged="cmbSearchBy_SelectedIndexChanged">
                                    </asp:DropDownList>
                                </div>

                                <div class="col-xl-4 col-lg-4 col-md-12 col-sm-12 col-12 mb-2">
                                    <label for="validationCustom03">
                                        Search By 
                                        <asp:Label ID="lblSearchBy" ForeColor="Blue" runat="server"></asp:Label></label>
                                    <asp:DropDownList ID="cmbSearchBy" CssClass="custom-select"
                                        runat="server" AutoPostBack="true" OnSelectedIndexChanged="cmbSearchBy_SelectedIndexChanged">
                                    </asp:DropDownList>
                                </div>

                                <div class="col-xl-4 col-lg-4 col-md-12 col-sm-12 col-12 mb-2">
                                    <label for="validationCustom03">
                                        (Search) Like 
                                        <asp:Label ID="lblBarcode" ForeColor="Blue" runat="server"></asp:Label></label>
                                    <asp:TextBox ID="txtBarcode" runat="server" class="form-control"></asp:TextBox>
                                </div>
                                <div class="col-xl-4 col-lg-4 col-md-12 col-sm-12 col-12 mb-2">
                                    <asp:Button ID="btnGenerate" runat="server" Text="Apply" Class="btn btn-primary"
                                        OnClick="btnGenerate_Click" />
                                </div>
                                <div class="col-2 align-content-center text-right">
                                        <asp:Label ID="lblcurrentdb" runat="server" Style="color: transparent"></asp:Label>
                                </div>
                            </div>
                        </div>

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

       
            
            <div class="card" style="display: block">
                 <h5 class="card-header" id="idGenReport" runat="server">

                    <asp:Label ID="lblMsgTotalSelection" runat="server" CssClass="Labels"> </asp:Label>
                      </h5>
             
         
              

                <div class="card-body">
                    <div class="table-responsive">
                        <div align="center">

                           
                            <table id="example4" class="table table-striped table-bordered" style="width: 100%">
                                <tbody>
                                    <caption>
                                        <div align="center">
                                           <asp:Panel ID="Panel8" runat="server" BackColor="white" Height="500px" ScrollBars="Auto"
                                             Width="1560px"> 
                                            <asp:GridView ID="GridView1"
                                                runat="server"  BorderColor="Transparent"
                                                DataKeyNames="InventoryID" AutoGenerateColumns="false" Font-Size="13px"
                                                Width="100%" OnRowDataBound="GridView1_RowDataBound"
                                                OnPageIndexChanging="GridView1_PageIndexChanging" AllowPaging="True" PageSize="20"
                                                EmptyDataText="No Record Found ! "   BorderWidth="1px" 
                                                FooterStyle-ForeColor="white" >
                                               
                                                

                                                <Columns>
                                                   <asp:TemplateField ItemStyle-Width="25px">
                                                   <ItemTemplate>
                                                   <a href="javascript:switchViews('div<%# Eval("InventoryID") %>', 'one');">
                                                   <img id="imgdiv<%# Eval("InventoryID") %>" alt="Click to show/hide Details" border="0"
                                                    src="IMG/plus.gif" width="12px" />
                                                   </a>
                                                   </ItemTemplate>
                                                   <AlternatingItemTemplate >
                                                   <a href="javascript:switchViews('div<%# Eval("InventoryID") %>', 'alt');">
                                                   <img id="imgdiv<%# Eval("InventoryID") %>" alt="Click to show/hide Details" border="0"
                                                   src="IMG/plus.gif"  width="12px"/>
                                                   </a>
                                                   </AlternatingItemTemplate>
                                                    </asp:TemplateField>


                                                    <asp:BoundField DataField="InventoryID" HeaderText="InvID" HeaderStyle-HorizontalAlign="Left" HtmlEncode="False" ItemStyle-HorizontalAlign="left" ItemStyle-Width="2%" />
                                                    <asp:BoundField DataField="Barcode" HeaderText="Barcode" HeaderStyle-HorizontalAlign="Left" HeaderStyle-CssClass="text-left" HtmlEncode="False" ItemStyle-HorizontalAlign="Left" ItemStyle-Width="11%" />
                                                    <asp:BoundField DataField="InventoryName" HeaderText="Name" HeaderStyle-HorizontalAlign="Left" HeaderStyle-CssClass="text-left" HtmlEncode="False" ItemStyle-HorizontalAlign="Left" ItemStyle-Width="18%" />
                                                    <asp:BoundField DataField="CategoryName" HeaderText="Category" HeaderStyle-HorizontalAlign="Left" HeaderStyle-CssClass="text-left" HtmlEncode="False" ItemStyle-HorizontalAlign="Left" ItemStyle-Width="14%" />
                                                    <asp:BoundField DataField="OpeningBalance" HeaderText="Op.Bal" HeaderStyle-HorizontalAlign="Right" HeaderStyle-CssClass="text-right" HtmlEncode="False" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="100px" />
                                                    <asp:BoundField DataField="StockIn" HeaderText="StockIn" HeaderStyle-HorizontalAlign="Right" HeaderStyle-CssClass="text-right" HtmlEncode="False" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="100px" />
                                                    <asp:BoundField DataField="PInvoice" HeaderText="P.Invoice" HeaderStyle-HorizontalAlign="Right" HeaderStyle-CssClass="text-right" HtmlEncode="False" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="100px" />
                                                    <asp:BoundField DataField="Receive" HeaderText="Rec.Stk" HeaderStyle-HorizontalAlign="Right" HeaderStyle-CssClass="text-right" HtmlEncode="False" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="100px" DataFormatString="{0:n2}" />
                                                    <asp:BoundField DataField="TransferRet" HeaderText="Tranfer.Ret" HeaderStyle-HorizontalAlign="Right" HeaderStyle-CssClass="text-right" HtmlEncode="False" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="100px" DataFormatString="{0:n2}" />
                                                    <asp:BoundField DataField="StockOut" HeaderText="Stk.Out" HeaderStyle-HorizontalAlign="Right" HeaderStyle-CssClass="text-right" HtmlEncode="False" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="100px" />
                                                    <asp:BoundField DataField="PReturn" HeaderText="P.Return" HeaderStyle-HorizontalAlign="Right" HeaderStyle-CssClass="text-right" HtmlEncode="False" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="100px" />
                                                    <asp:BoundField DataField="Transfer" HeaderText="S.Transfer" HeaderStyle-HorizontalAlign="Right" HeaderStyle-CssClass="text-right" HtmlEncode="False" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="100px" DataFormatString="{0:n2}" />
                                                    <asp:BoundField DataField="RetailSales" HeaderText="R.Sales" HeaderStyle-HorizontalAlign="Right" HeaderStyle-CssClass="text-right" HtmlEncode="False" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="100px" />
                                                    <asp:BoundField DataField="Wastage" HeaderText="Wastage" HeaderStyle-HorizontalAlign="Right" HeaderStyle-CssClass="text-right" HtmlEncode="False" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="100px" />
                                                    <asp:BoundField DataField="StockCheck" HeaderText="StkChk" HeaderStyle-HorizontalAlign="Right" HeaderStyle-CssClass="text-right" HtmlEncode="False" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="100px" />
                                                    <asp:BoundField DataField="ClosingBalance" HeaderText="Cl.Bal" HeaderStyle-HorizontalAlign="Right" HeaderStyle-CssClass="text-right" HtmlEncode="False" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="150px" DataFormatString="{0:n2}" />

                                                    <asp:TemplateField>
                                                    <ItemTemplate>
                                                          <tr>
                                                            <td colspan="100%" style="padding-left:80px">
                                                            <div id="div<%# Eval("InventoryID") %>" style="display: none; left: 80px;">

                                                            <asp:GridView ID="gvchild" runat="server" AutoGenerateColumns="false" Font-Size="12px"
                                                                    Width="750px" PageSize="5000000">
                                                                    <Columns>
                                                                        <asp:BoundField ItemStyle-Width="170px" DataField="Barcode" HeaderText="BARCODE" Visible="false" />
                                                                        <asp:BoundField ItemStyle-Width="250px" DataField="InventoryName" HeaderText="InventoryName" Visible="false" />
                                                                        <asp:BoundField ItemStyle-Width="250px" DataField="Description" HeaderText="DESCRIPTION" Visible="false" />
                                                                        <%--<asp:BoundField ItemStyle-Width="250px" DataField="BatchId" HeaderText="Batchid"/>--%>
                                                                        
                                                                        <asp:TemplateField HeaderText="BatchId">
                                                                        <ItemTemplate>
                                                                        <asp:Label ID="lblBatchId" Width="150px" runat="server" Text='<%#Eval("BatchId") %>'></asp:Label>
                                                                        </ItemTemplate>
                                                                        </asp:TemplateField>

                                                                        <asp:TemplateField HeaderText="REFDATE">
                                                                        <ItemTemplate>
                                                                        <asp:Label ID="lblRefDate" Width="120px" runat="server" Text='<%#Eval("RefDate") %>'></asp:Label>
                                                                        </ItemTemplate>
                                                                        
                                                                        </asp:TemplateField>
                                                                        <asp:TemplateField HeaderText="RefType">
                                                                        <ItemTemplate>
                                                                        <asp:Label ID="lblRefType" Width="200px" runat="server" Text='<%#Eval("RefType") %>'></asp:Label>
                                                                        </ItemTemplate>
                                                                        </asp:TemplateField>
                                                                        <asp:TemplateField HeaderText="RefNo">
                                                                        <ItemTemplate>
                                                                        <asp:Label ID="lblRefNo" Width="150px" runat="server" Text='<%#Eval("RefNo") %>'></asp:Label>
                                                                        </ItemTemplate>
                                                                        </asp:TemplateField>

                                                                       
                                                                       <%-- <asp:BoundField ItemStyle-Width="250px" DataField="RefNo" HeaderText="RefNo"/>--%>
                                                                        <asp:BoundField ItemStyle-Width="200px" DataField="StockInQty" HeaderText="StockInQty"/>
                                                                        <asp:BoundField ItemStyle-Width="200px" DataField="StockOutQty" HeaderText="StockOutQty"/>
                                                                        <asp:BoundField ItemStyle-Width="200px" DataField="StockCheck" HeaderText="StockCheck"/>
                                                                        
                                                                    </Columns>
                                                                   
                                                                    <PagerStyle BackColor="White" Font-Size="12px" 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>



                                                           </div>
                                                          </td>
                                                        </tr>
                                                        </ItemTemplate>
                                                    </asp:TemplateField>
                                                </Columns>
                                                <HeaderStyle BackColor="White" Font-Size="13px" Font-Bold="True" ForeColor="Black"></HeaderStyle>
                                                <PagerStyle CssClass="gridview"></PagerStyle>
                                                <PagerStyle HorizontalAlign="Left" CssClass="GridPager" />
                                                <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>
                                        </div>
                                    </caption>
                                </tbody>
                            </table>
                        </div>
                    </div>

                </div>
            </div>

            <div class="card d-none">
              <%--  <h5 class="card-header" id="idGenReport" runat="server">
                    <asp:Label ID="lblMsgTotalSelection" runat="server" CssClass="Labels"> </asp:Label>
                </h5>--%>
                <div class="container-fluid bg-white overflow-auto px-0">


                    <%--   <table id="tblinventory" class="table table-bordered">
                    <thead>
                        <tr>
                            <th class="col-2">Barcode</th>
                            <th class="col-2">Name</th>
                            <th class="col-2">Description</th>
                            <th class="col-1">Category</th>
                            <th class="col-1 text-nowrap">Openning Balance</th>
                            <th class="col-1 text-nowrap">Stock In</th>
                            <th class="col-1 text-nowrap">Stock Out</th>
                            <th class="col-1 text-nowrap">Retail Sales</th>
                            <th class="col-1 text-nowrap">Closing Balance</th>
                        </tr>
                    </thead>
                    <tbody id="tblbodyinventory" class="d-block">
                    </tbody>
                    <tbody id="tblbodyinventorydetail" class="d-none">
                    </tbody>

                </table>--%>

                    <table id="tblheader" class="table table-bordered">
                        <thead>
                            <tr>
                                <th style="width:10px;"></th>
                                <th class="col-2">Barcode</th>
                                <th class="col-2">Name</th>
                                <th class="col-2">Description</th>
                                <th class="col-1">Category</th>
                                <th class="col-1 text-nowrap">Openning Balance</th>
                                <th class="col-1 text-nowrap">Stock In</th>
                                <th class="col-1 text-nowrap">Stock Out</th>
                                <th class="col-1 text-nowrap">Retail Sales</th>
                                <th class="col-1 text-nowrap">Closing Balance</th>
                            </tr>
                        </thead>
                        <tbody id="tblbody">

                        </tbody>
                    </table>

                </div>
                <div class="container-fluid p-3 bg-white">
                    <section class="col-4 d-flex" id="inventory-list"></section>
                    <div id="paggination"></div>
                </div>
            </div>
   
  

</ContentTemplate>
</asp:UpdatePanel>

    <asp:UpdateProgress ID="UpdateProgress" runat="server" AssociatedUpdatePanelID="updatepanel133">
    <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>
