<%@ Page Title="Sales Invoice" Language="C#" MasterPageFile="~/Master.Master" AutoEventWireup="true" CodeBehind="SalesInvoice.aspx.cs" Inherits="ZFJINV.Sales.SalesInvoice" %>

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

    <div class="row">
        <div class="col-md-12 mySpace">
            <asp:UpdatePanel runat="server">
                <ContentTemplate>
                    <div class="caption cap">
                        <span class="caption-subject font-blue sbold" style="font-size: 150%;">Sale Invoice </span>

                        <%--  <div class="pull-right">
                            <button type="button" class="btn btn-success" disabled="disabled" style="height: 28px;">saved</button>
                        </div>--%>

                        <div class="btn-group pull-right">


                            <img src="../assets/global/img/gridicons/addgrid.png" />
                            <asp:LinkButton ID="lblAdd" Text="Add" runat="server" class="imgCss" OnClick="Add"></asp:LinkButton>

                            <img src="../assets/global/img/gridicons/gridsearch.png" />
                            <asp:LinkButton ID="lblFind" Text="Find" runat="server" class="imgCss" OnClick="Find"></asp:LinkButton>

                            <%--                            <img src="../assets/global/img/gridicons/editgrid.png" />
                            <asp:LinkButton ID="lblEdit" Text="Edit" runat="server" class="imgCss" OnClick = "Edit"></asp:LinkButton>--%>

                            <img src="../assets/global/img/gridicons/first.png" />
                            <asp:LinkButton ID="lblFirst" Text="First" runat="server" class="imgCss" OnClick="First"></asp:LinkButton>

                            <img src="../assets/global/img/gridicons/next.png" />
                            <asp:LinkButton ID="lblNext" Text="Next" runat="server" class="imgCss" OnClick="Next"></asp:LinkButton>


                            <asp:LinkButton ID="lblPrevious" Text="Previous" runat="server" OnClick="Previous"></asp:LinkButton>
                            <img src="../assets/global/img/gridicons/previous.png" class="imgCss" />


                            <asp:LinkButton ID="lblLast" Text="Last" runat="server" OnClick="Last"></asp:LinkButton>
                            <img src="../assets/global/img/gridicons/last.png" class="imgCss" />
                        </div>
                    </div>

                    <div class="ui segment">
                        <div class="ui stackable form">
                            <div class="col-md-4">
                                <label class="lbStyle">Invoice ID</label>
                                <asp:TextBox ID="txtInvoiceID" AutoPostBack="true" CssClass="myInput" OnTextChanged="txtInvoiceID_TextChanged" runat="server" title="Invoice ID"></asp:TextBox>
                            </div>

                            <div class="col-md-4">

                                <label class="lbStyle">Date:</label>
                                <asp:TextBox ID="txtInvoiceDate" runat="server" class="date-picker myInput" title="Invoice Date"></asp:TextBox>
                                <%--<asp:TextBox ID="txtQuotationDate" runat="server" class="date-picker myInput" title="Quotation Date"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator1"
                                    ControlToValidate="txtInvoiceDate"
                                    ValidationGroup="formValidation"
                                    ErrorMessage="Required Field"
                                    CssClass="message" EnableClientScript="false"
                                    runat="Server">
                                </asp:RequiredFieldValidator>--%>
                            </div>

                            <div class="col-md-4">

                                <label class="lbStyle">POS:</label>
                                <asp:DropDownList ID="txtPOS" runat="server" class="myInput" OnSelectedIndexChanged="txtPOS_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator2"
                                    ControlToValidate="txtPOS"
                                    ValidationGroup="formValidation"
                                    ErrorMessage="Required Field"
                                    CssClass="message"
                                    runat="Server">
                                </asp:RequiredFieldValidator>
                            </div>

                            <div class="col-md-4">

                                <label class="lbStyle">Ref No:</label>
                                <asp:TextBox ID="txtRefNo" runat="server" class="myInput" ReadOnly="true"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator3"
                                    ControlToValidate="txtRefNo"
                                    ValidationGroup="formValidation"
                                    ErrorMessage="Required Field"
                                    CssClass="message" runat="Server">
                                </asp:RequiredFieldValidator>

                            </div>
                          
                            <div class="col-md-4">
                                <label class="lbStyle">Ref Date:</label>
                                <asp:TextBox ID="txtRefDate" runat="server" class="date-picker myInput" title="Ref Date"></asp:TextBox>
                                
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator6"
                                    ControlToValidate="txtRefDate" EnableClientScript="false"
                                    ValidationGroup="formValidation"
                                    ErrorMessage="Required Field"
                                    CssClass="message"
                                    runat="Server">
                                </asp:RequiredFieldValidator>
                            </div>

                            <div class="col-md-4">
                                <label class="lbStyle">Remarks</label>
                                <asp:TextBox ID="txtRemarks" AutoPostBack="false" CssClass="myInput" runat="server" title="Remarks"></asp:TextBox>

                                <%-- <asp:RequiredFieldValidator ID="RequiredFieldValidator7"
                                    ControlToValidate="txtRemarks"
                                    ValidationGroup="formValidation"
                                    ErrorMessage="Required Field"
                                    CssClass="message"
                                    runat="Server">
                                </asp:RequiredFieldValidator>--%>
                            </div>
                           
                           <div class="col-md-4">

                                <label class="lbStyle">Customer Name:</label>
                                <asp:TextBox ID="txtCustomer" runat="server" class="myInput" CssClass="myInput"></asp:TextBox>

                                <asp:RequiredFieldValidator ID="RequiredFieldValidator5"
                                    ControlToValidate="txtCustomer"
                                    ValidationGroup="formValidation"
                                    ErrorMessage="Required Field"
                                    CssClass="message"
                                    runat="Server">
                                </asp:RequiredFieldValidator>
                            </div>

                               <div class="col-md-4">

                                <label class="lbStyle">COA Name:</label>
                                <asp:DropDownList ID="txtCOACODE" AutoPostBack="True" OnSelectedIndexChanged="txtCOACODE_SelectedIndexChanged" runat="server" class="myInput">
                                </asp:DropDownList>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator4"
                                    ControlToValidate="txtCOACODE"
                                    ValidationGroup="formValidation"
                                    ErrorMessage="Required Field"
                                    CssClass="message" runat="Server">
                                </asp:RequiredFieldValidator>

                            </div>

                            <div class="row"></div> 
                        </div>
                    </div>

                    <div id="dvGrid1" class="clearfix">
                        <div class="rounded-corners">
                            <div style="width: 100%; overflow: auto;">

                                <asp:GridView ID="grdSalesInvoice" ShowHeaderWhenEmpty="True"
                                    GridLines="Horizontal" BorderColor="WhiteSmoke" RowStyle-Wrap="false"
                                    HeaderStyle-Wrap="false" RowStyle-BorderColor="#e8e8ec"
                                    CssClass="uimy ui table" runat="server" AutoGenerateColumns="False"
                                    ShowFooter="True"
                                    OnRowCommand="grdSalesInvoice_RowCommand"
                                    PageSize="10"
                                    PagerStyle="pagination-ys">

                                    <Columns>

                                        <asp:TemplateField HeaderText="InvoiceID" InsertVisible="False" Visible="False" SortExpression="InvoiceID">
                                            <EditItemTemplate>
                                                <asp:Label ID="Label1" runat="server" Text='<%# Eval("InvoiceID") %>'></asp:Label>
                                            </EditItemTemplate>
                                            <ItemTemplate>
                                                <asp:Label ID="Label2" runat="server" Text='<%# Bind("InvoiceID") %>'></asp:Label>
                                            </ItemTemplate>
                                            <FooterTemplate>
                                                <asp:TextBox ID="txtInvoiceID" CssClass="myInput1" runat="server"></asp:TextBox>
                                            </FooterTemplate>

                                        </asp:TemplateField>
                                        
                                        <asp:TemplateField HeaderText="Product Code" InsertVisible="False" SortExpression="ProductCode" HeaderStyle-CssClass="gridView2" ItemStyle-CssClass="gridviewBody1" FooterStyle-CssClass="FooterStyle">
                                            <EditItemTemplate>
                                                <asp:Label ID="Label3" runat="server" Text='<%# Eval("ProductCode") %>'></asp:Label>
                                            </EditItemTemplate>
                                            <ItemTemplate>
                                                <asp:Label ID="Label4" runat="server" Text='<%# Bind("ProductCode") %>'></asp:Label>
                                            </ItemTemplate>
                                            <FooterTemplate>
                                                <asp:TextBox ID="txtCode" Enabled="False" required="required" CssClass="itemCode" runat="server"></asp:TextBox>
                                            </FooterTemplate>
                                        </asp:TemplateField>

                                        <asp:TemplateField HeaderText="Warehouse" InsertVisible="False" SortExpression="WHID" HeaderStyle-CssClass="gridView2" ItemStyle-CssClass="gridviewBody1" FooterStyle-CssClass="FooterStyle2">
                                        <EditItemTemplate>
                                            <asp:DropDownList ID="txtWHID" Text='<%# Eval("WHID") %>' CssClass="select2 form-control gvModel" AutoPostBack="false" AppendDataBoundItems="true" runat="server" required="required"></asp:DropDownList>
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="lblwhid" Text='<%# Eval("WHID") %>' runat="server"></asp:Label>
                                        </ItemTemplate>
                                        <FooterTemplate>
                                            <asp:DropDownList ID="txtWHID" CssClass="select2 form-control gvModel" AutoPostBack="false" AppendDataBoundItems="true" runat="server" required="required"></asp:DropDownList>
                                       
                                        </FooterTemplate>

                                    </asp:TemplateField>

                                        <asp:TemplateField HeaderText="Brand" InsertVisible="False" SortExpression="Brand" HeaderStyle-CssClass="gridViewModel" ItemStyle-CssClass="gridviewBody1" FooterStyle-CssClass="FooterStyle">
                                            <EditItemTemplate>
                                                <asp:Label ID="txtBrand" runat="server" Text='<%# Eval("Brand") %>'></asp:Label>
                                            </EditItemTemplate>
                                            <ItemTemplate>
                                                <asp:Label ID="Label130" runat="server" Text='<%# Bind("Brand") %>'></asp:Label>
                                            </ItemTemplate>
                                            <FooterTemplate>
                                                <asp:DropDownList ID="txtBrand" CssClass="select2 form-control gvModel" runat="server" OnSelectedIndexChanged ="txtBrand_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>
                                            </FooterTemplate>
                                        </asp:TemplateField>


                                        <asp:TemplateField HeaderText="Name" InsertVisible="False" SortExpression="Name" HeaderStyle-CssClass="gridView2" ItemStyle-CssClass="gridviewBody1" FooterStyle-CssClass="FooterStyle2">
                                            <EditItemTemplate>
                                                <asp:DropDownList ID="txtName" Text='<%# Eval("Name") %>' CssClass="select2 form-control gvModel" AutoPostBack="True" required="required" AppendDataBoundItems="true" runat="server"></asp:DropDownList>
                                            </EditItemTemplate>
                                            <ItemTemplate>
                                                <asp:Label ID="Label6" Text='<%# Eval("Name") %>' runat="server"></asp:Label>
                                            </ItemTemplate>
                                            <FooterTemplate>
                                                <asp:DropDownList ID="txtName" OnSelectedIndexChanged="txtName_SelectedIndexChanged" CssClass="select2 form-control gvModel" AutoPostBack="True" AppendDataBoundItems="true" runat="server"></asp:DropDownList>

                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator13"
                                                    ControlToValidate="txtName"
                                                    ValidationGroup="gvValidation" CssClass="message1"
                                                    ErrorMessage="Required Field."
                                                    runat="Server">
                                                </asp:RequiredFieldValidator>
                                            </FooterTemplate>
                                        </asp:TemplateField>

                                        <asp:TemplateField HeaderText="Unit Price" InsertVisible="False" SortExpression="UnitPrice" HeaderStyle-CssClass="gridView2" ItemStyle-CssClass="gridviewBody1" FooterStyle-CssClass="FooterStyle">
                                            <EditItemTemplate>
                                                <asp:Label ID="Label7" runat="server" Text='<%# Eval("UnitPrice") %>'></asp:Label>
                                            </EditItemTemplate>
                                            <ItemTemplate>
                                                <asp:Label ID="Label8" runat="server" Text='<%# Bind("UnitPrice") %>'></asp:Label>
                                            </ItemTemplate>
                                            <FooterTemplate>
                                                <asp:TextBox ID="txtUnitPrice" Enabled="true" CssClass="UnitPrice" runat="server"></asp:TextBox>
                                            </FooterTemplate>

                                        </asp:TemplateField>

                                        <asp:TemplateField HeaderText="Batch No" InsertVisible="False" SortExpression="BatchNo" HeaderStyle-CssClass="gridViewModel" ItemStyle-CssClass="gridviewBody1" FooterStyle-CssClass="FooterStyle" Visible="false">
                                            <EditItemTemplate>
                                                <asp:Label ID="Label13" runat="server" Text='<%# Eval("BatchNo") %>'></asp:Label>
                                            </EditItemTemplate>
                                            <ItemTemplate>
                                                <asp:Label ID="Label14" runat="server" Text='<%# Bind("BatchNo") %>'></asp:Label>
                                            </ItemTemplate>
                                            <FooterTemplate>
                                                <asp:DropDownList ID="txtBatchNo" CssClass="Amount" runat="server" OnSelectedIndexChanged="txtBatchNo_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>
                                            </FooterTemplate>
                                        </asp:TemplateField>

                                        <asp:TemplateField HeaderText="AvailableQ TY" InsertVisible="False" SortExpression="AvailableQTY" HeaderStyle-CssClass="gridViewModel" ItemStyle-CssClass="gridviewBody1" FooterStyle-CssClass="FooterStyle">
                                            <EditItemTemplate>
                                                <asp:Label ID="Label23" runat="server" Text='<%# Eval("AvailableQTY") %>'></asp:Label>
                                            </EditItemTemplate>
                                            <ItemTemplate>
                                                <asp:Label ID="Label24" runat="server" Text='<%# Bind("AvailableQTY") %>'></asp:Label>
                                            </ItemTemplate>
                                            <FooterTemplate>
                                                <asp:TextBox ID="txtAvailableQTY" Enabled="False" CssClass="Brand" runat="server"></asp:TextBox>
                                            </FooterTemplate>
                                        </asp:TemplateField>


                                        <asp:TemplateField HeaderText="Qty" InsertVisible="False" SortExpression="Qty" HeaderStyle-CssClass="gridViewModel" ItemStyle-CssClass="gridviewBody1" FooterStyle-CssClass="FooterStyle">
                                            <EditItemTemplate>
                                                <asp:TextBox ID="txtQty" AutoPostBack="True" Text='<%# Bind("Qty") %>' TextMode="Number" CssClass="Quatntity" runat="server" required="required"></asp:TextBox>
                                            </EditItemTemplate>
                                            <ItemTemplate>
                                                <asp:Label ID="Label12" runat="server" Text='<%# Bind("Qty") %>'></asp:Label>
                                            </ItemTemplate>
                                            <FooterTemplate>
                                                <asp:TextBox ID="txtQty" AutoPostBack="True" TextMode="Number" OnTextChanged="txtQty_TextChanged" CssClass="Quatntity" runat="server"></asp:TextBox>
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator11"
                                                    ControlToValidate="txtQty"
                                                    ValidationGroup="gvValidation" CssClass="message1"
                                                    ErrorMessage="Required Field."
                                                    runat="Server">
                                                </asp:RequiredFieldValidator>
                                            </FooterTemplate>

                                        </asp:TemplateField>

                                        <asp:TemplateField HeaderText="Tax" InsertVisible="False" SortExpression="Tax" HeaderStyle-CssClass="gridView2" ItemStyle-CssClass="gridviewBody1" FooterStyle-CssClass="FooterStyle" Visible="false">
                                            <EditItemTemplate>
                                                <asp:Label ID="Label17" runat="server" Text='<%# Eval("Tax") %>'></asp:Label>
                                            </EditItemTemplate>
                                            <ItemTemplate>
                                                <asp:Label ID="Label18" runat="server" Text='<%# Bind("Tax") %>'></asp:Label>
                                            </ItemTemplate>
                                            <FooterTemplate>
                                                <asp:TextBox ID="txtTax" CssClass="Tax" Enabled="true" runat="server"></asp:TextBox>
                                            </FooterTemplate>

                                        </asp:TemplateField>


                                        <asp:TemplateField HeaderText="Discount" InsertVisible="False" SortExpression="Discount" HeaderStyle-CssClass="gridView2" ItemStyle-CssClass="gridviewBody1" FooterStyle-CssClass="FooterStyle" Visible="false">
                                            <EditItemTemplate>
                                                <asp:Label ID="Label19" runat="server" Text='<%# Eval("Discount") %>'></asp:Label>
                                            </EditItemTemplate>
                                            <ItemTemplate>
                                                <asp:Label ID="Label20" runat="server" Text='<%# Bind("Discount") %>'></asp:Label>
                                            </ItemTemplate>
                                            <FooterTemplate>
                                                <asp:TextBox ID="txtDiscount" CssClass="Discount" Enabled="true" runat="server"></asp:TextBox>
                                            </FooterTemplate>

                                        </asp:TemplateField>

                                        <asp:TemplateField HeaderText="Amount" InsertVisible="False" SortExpression="Amount" HeaderStyle-CssClass="gridView2" ItemStyle-CssClass="gridviewBody1" FooterStyle-CssClass="FooterStyle">
                                            <EditItemTemplate>
                                                <asp:Label ID="Label21" runat="server" Text='<%# Eval("Amount") %>'></asp:Label>
                                            </EditItemTemplate>
                                            <ItemTemplate>
                                                <asp:Label ID="Label22" runat="server" Text='<%# Bind("Amount") %>'></asp:Label>
                                            </ItemTemplate>
                                            <FooterTemplate>
                                                <asp:TextBox ID="txtAmount" Enabled="False" CssClass="Amount" runat="server"></asp:TextBox>
                                            </FooterTemplate>

                                        </asp:TemplateField>

                                        <asp:TemplateField HeaderText="Action" InsertVisible="False" SortExpression="Action" HeaderStyle-CssClass="gridView2" ItemStyle-CssClass="gridviewBody1" FooterStyle-CssClass="FooterStyle">
                                            <ItemTemplate>

                                                <asp:Button ID="lblDelete" CssClass="small ui button red" Text="Delete" ToolTip="Delete" CommandArgument='<%# Eval("InvoiceID") %>' formnovalidate="formnovalidate" ImageUrl="~/assets/global/img/deletee.png" runat="server" CommandName="DeleteRow" />

                                            </ItemTemplate>

                                            <EditItemTemplate>
                                            </EditItemTemplate>
                                            <FooterTemplate>
                                                <asp:Button ID="lblSave" CommandName="InsertRow" CssClass="small ui button blue" Text="Add" runat="server"
                                                    CausesValidation="true" ValidationGroup="gvValidation"></asp:Button>
                                            </FooterTemplate>

                                        </asp:TemplateField>
                                    </Columns>

                                </asp:GridView>
                            </div>
                        </div>
                    </div>
                    <div class="ui segment col-md-5" style="border-color: #AAB7B8;">
                        
                        <label style="font-size: 12px; color: #2E4053; font-weight: 700; padding-bottom: 3px;">Running Total:</label>
                        <asp:TextBox ID="txtRunningBalance" type="text" disabled="disabled" runat="server" class=" form-control" />

                        <label style="font-size: 12px; color: #2E4053; font-weight: 700; padding-bottom: 3px; padding-top: 7px;">Total Tax:</label>
                        <asp:TextBox ID="txtTotalTax" type="text" disabled="disabled" class=" form-control" runat="server" />

                        <label style="font-size: 12px; color: #2E4053; font-weight: 700; padding-bottom: 3px; padding-top: 7px;">Total Discount:</label>
                        <asp:TextBox ID="txtDiscount" type="text" disabled="disabled" class=" form-control" runat="server" />

                        <label style="font-size: 12px; color: #800000; font-weight: 700; padding-bottom: 3px; padding-top: 7px;">Grand Total:</label>
                        <asp:TextBox ID="txtGrandTotal" type="text" disabled="disabled" class=" form-control" runat="server" /><br />

                        <asp:Button ID="btnAdd" runat="server" class="ui button green" OnClick="btnAdd_Click" Text="Save"
                            CausesValidation="true" ValidationGroup="formValidation" /><tb />
                        <asp:Button ID="btnPrint" runat="server" class="ui button green" OnClick="lblShow_Click" Text="Print Preview"
                            CausesValidation="true" ValidationGroup="formValidation" /><br />
                    </div>
                      <div class="ui segment col-md-5" style="border-color: #AAB7B8;">
                        <label style="font-size: 12px; color: #2E4053; font-weight: 700; padding-bottom: 3px; padding-top: 7px;">Tax Percent:</label>
                        <asp:TextBox ID="txtTaxPercent" type="text" class=" form-control" runat="server" TextMode="Number"/>

                        <label style="font-size: 12px; color: #2E4053; font-weight: 700; padding-bottom: 3px; padding-top: 7px;">Discount Percent:</label>
                        <asp:TextBox ID="txtDiscountPercent" type="text" class=" form-control" runat="server" TextMode="Number"/>

                          <label style="font-size: 12px; color: #800000; font-weight: 700; padding-bottom: 3px; padding-top: 7px;">Total Qty:</label>
                        <asp:TextBox ID="txtTotalQty" type="text" class=" form-control" runat="server" TextMode="Number" ReadOnly="true"/>

                    </div>
                      <div class="col-md-12">
                            <div class="messagealert" id="alert_container">
                            </div>
                        </div>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="grdSalesInvoice" />
                </Triggers>
            </asp:UpdatePanel>

        </div>
    </div>
</asp:Content>
