<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BillAndPayments.aspx.cs" Inherits="TruxWebPortal.BillAndPayments" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Linq" %>
<%@ Register TagPrefix="ucHeader" TagName="truxHeader" Src="header.ascx" %>
<%@ Register TagPrefix="ucFooter" TagName="truxFooter" Src="footer.ascx" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="HeadBillPayment" runat="server">
        <title>My Invoices</title>
        <link rel="stylesheet" type="text/css" href="_style/stylesheet.css" title="TRUX7" />
        <script src="styleswitch.js" type="text/javascript"> </script>
        <script src="js/jquery/jquery-1.11.2.min.js" type="text/javascript"> </script>
        <script src="js/jqueryUI/jquery-ui.min.js" type="text/javascript"> </script>
        <link rel="Stylesheet" href="_style/css/jquery-ui-1.8.24.custom.css" />
        <script type="text/javascript">
            function generatePDF(invoiceNumber) {
                window.open("Handlers/DownloadHandler.ashx?method=generateInvoiceStream&invoiceNumber=" + invoiceNumber);
            }

            $(document).ready(function() {
                $("input.applied").blur(function () {
                    if ($(this).val().trim().length < 1 || $(this).val().trim() === "$") {
                        $(this).val('$0.00');
                    }
                });
            });
            
            function BindEvents() {

                $(document).ready(function() {
                    if ($("#CheckBox1").attr("checked") == "checked") {
                        $("#invoice_header").text("All Invoices");
                    } else {
                        $("#invoice_header").text("Outstanding Invoices");
                    }


                    $('.tooltip').tooltip({
                        content: function () {
                            return $(this).prop('title');
                        },
                    });
                });
            }

            BindEvents();
        </script>

    </head>
    <body>
        <ucHeader:truxHeader id="Hdr1" runat="server"></ucHeader:truxHeader>
    
        <div id="main_area">
            <div id="work_area">

                <form id="form1" runat="server" autocomplete="off">
                    <h1>My Invoices</h1>
                    <p><span id="Span19"><asp:Label ID="lblDesc" runat="server"></asp:Label><a href="_help/my_invoices.aspx" target="_blank"><img alt="help" style="margin-left: 5px; vertical-align: middle; width: 18px;" src="_images/help.png" /></a>                    

                       </span></p>
                    <%--Aging Backet--%>
                    <div id="account_aging">
                        <div class="title_bar_blk">Account Aging</div><!-- close Title Bar -->
                        <table>        
                            <tr class="header">
                                <td style="width: 16%" class="label"><asp:Label ID="lblAgingBucket1" runat="server" Text="0 - 30"></asp:Label></td>
                                <td style="width: 16%" class="label"><asp:Label ID="lblAgingBucket2" runat="server" Text="31 - 60"></asp:Label></td>
                                <td style="width: 16%" class="label"><asp:Label ID="lblAgingBucket3" runat="server" Text="61 - 90"></asp:Label></td>
                                <td style="width: 16%" class="label"><asp:Label ID="lblAgingBucket4" runat="server" Text="90 - 120"></asp:Label></td>
                                <td style="width: 16%" class="label"><asp:Label ID="lblAgingBucket5" runat="server" Text="Over 120"></asp:Label></td>
                                <td style="width: 20%" class="label">Account Total:</td>
                            </tr>
                            <tr  class="aging_amounts">
                                <td class="data"><span id="Span1"><asp:Label ID="lbl30" runat="server" Text=""></asp:Label></span></td>
                                <td class="data"><span id="Span2"><asp:Label ID="lbl60" runat="server" Text=""></asp:Label></span></td>
                                <td class="data"><span id="Span3"><asp:Label ID="lbl90" runat="server" Text=""></asp:Label></span></td>
                                <td class="data"><span id="Span4"><asp:Label ID="lbl120" runat="server" Text=""></asp:Label></span></td>
                                <td class="data"><span id="Span5"><asp:Label ID="lblOver120" runat="server" Text=""></asp:Label></span></td>
                                <td class="data"><span id="Span7"><asp:Label ID="lblTotal" runat="server" Text=""></asp:Label></span></td>
                            </tr>
                        </table>
                    </div>
    
                    <div id="OA_balance">Credit Balance: <asp:Label ID="lblCredit" runat="server" Text="$0.00"></asp:Label>
                        <a href="_help/my_invoices.aspx" target="_blank"><img alt="help" style="margin-left: 5px; vertical-align: middle; width: 18px;" src="_images/help.png" /></a></div>

                    <asp:ScriptManager ID="ScriptManager1" runat="server" />

                    

                    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                        <ContentTemplate>
                            <script type="text/javascript">
                                Sys.Application.add_load(BindEvents);
                            </script>
                            <div style="clear: both">
                                <asp:CheckBox ID="CheckBox1" runat="server" 
                                              oncheckedchanged="CheckBox1_CheckedChanged" AutoPostBack="true"  />
                                <p style="display: inline">Show Paid Invoices</p><asp:Label ID="lblInvoicePeriod" runat="server" Text="(* Months)"></asp:Label>
                            </div>
    
                            <%--Invoice List--%>
                            <div class="mGrid_titlebar">
                                <p id="invoice_header"></p>
                                <div class="highlighted_info">
                                    <img alt="highlight arrow" src="_images/highlight_arrow_tip.png" />
                                    <p><asp:Label ID="lblLastPayment" runat="server" Text=""></asp:Label></p>
                                </div>
                            </div>


                            <asp:GridView ID="gvInvoiceList" runat="server" AutoGenerateColumns="False"  
                                          GridLines="None" CssClass="mGrid" 
                                          AllowSortng="True" ToolTip="Invoice List" DataKeyNames="dm01_invc" EnableModelValidation="True">
                                <Columns>
                                    <asp:BoundField DataField="dm01_invc" HeaderText="Invoice" >
                                    </asp:BoundField>                
                                    <asp:BoundField DataField="dm01_date" HeaderText="Invoice Date" 
                                                    DataFormatString="{0:MM/dd/yyyy}" >
                                    </asp:BoundField>
                                    <asp:BoundField DataField="invamnt" HeaderText="Invoice Total" 
                                                    DataFormatString="{0:c2}" >
                                        <HeaderStyle CssClass="money" />
                                        <ItemStyle cssClass="money" />
                                    </asp:BoundField>
                                    <asp:BoundField DataField="paymts" HeaderText="Paid" 
                                                    DataFormatString="{0:c2}" >
                                        <HeaderStyle CssClass="money" />
                                        <ItemStyle cssClass="money" />
                                    </asp:BoundField>
                                    <asp:TemplateField>
                                        <ItemTemplate>
                                            <asp:Image Visible='<%# dtInvoicePayments.Rows.Cast<DataRow>().Any(row => string.Equals(row["DM01P_TYPE"].ToString(),"P",StringComparison.OrdinalIgnoreCase) && String.Equals(row["dm01_id"].ToString(),Eval("dm01_id").ToString(),StringComparison.OrdinalIgnoreCase)) %>' width="16px" class="tooltip" src="_images/payment.png"  runat="server"/>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:BoundField DataField="adjmts" DataFormatString="{0:c2}" 
                                                    HeaderText="Adjustment">
                                        <HeaderStyle CssClass="money" />
                                        <ItemStyle CssClass="money" />
                                    </asp:BoundField>
                                     <asp:TemplateField>
                                         <ItemTemplate>
                                             <asp:Image Visible='<%# dtInvoicePayments.Rows.Cast<DataRow>().Any(row => (string.Equals(row["DM01P_TYPE"].ToString(),"A",StringComparison.OrdinalIgnoreCase) || string.Equals(row["DM01P_TYPE"].ToString(),"DA",StringComparison.OrdinalIgnoreCase)) && String.Equals(row["dm01_id"].ToString(),Eval("dm01_id").ToString(),StringComparison.OrdinalIgnoreCase)) %>' width="16px" class="tooltip" src="_images/adjustment.png"  runat="server"/>
                                         </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:BoundField DataField="dm01_amnt" HeaderText="Invoice Balance" 
                                                    DataFormatString="{0:c2}" >
                                        <HeaderStyle CssClass="money" />
                                        <ItemStyle cssClass="money" />
                                    </asp:BoundField >  
                                    <asp:TemplateField>
                                         <ItemTemplate>
                                             <asp:Image Visible='<%# !Eval("dm01_INVC").ToString().Trim().Equals("On Account",StringComparison.OrdinalIgnoreCase)  %>' width="16px" class="pdf" src="_images/pdf.png"  runat="server"/>
                                         </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Payment Amount">
                                        <ItemTemplate>
                                            <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
                                                                            ErrorMessage="*" ControlToValidate="colApplied" 
                                                                            ValidationExpression="(^\$?)((([0-9]{1,3},((([0-9]{3},)*)([0-9]{3})))(\.([0-9]{2}))?)|([0-9]*\.[0-9]{2})|([0-9]+))"></asp:RegularExpressionValidator>
                                            <asp:TextBox ID="colApplied" runat="server" CssClass="applied"
                                                         BackColor="#FFFFCC"
                                                         style="text-align: right; z-index: 1000;" placeholder="$0.00"></asp:TextBox>
                                        </ItemTemplate>
                                        <HeaderStyle CssClass="money" />
                                        <ItemStyle cssClass="money" />
                                    </asp:TemplateField>
                                </Columns>
                                <headerstyle CssClass="col_headers"></headerstyle> 
                                <PagerStyle />
                                <AlternatingRowStyle CssClass="alt_row" />
                            </asp:GridView>

                        </ContentTemplate>
                    </asp:UpdatePanel>


                    <div style="float: right; margin-right: 4px; margin-top: 10px;">
                        <asp:Button ID="btnPay" runat="server" Text="Pay My Invoice(s)" 
                                    onclick="btnPay_Click" class="default_button" style="width: 158px;"/>
                        <span id="Span6" style="color: Red;"></span>
                    </div>
                </form>
            </div><!-- close work_area -->
        </div><!-- close main_area -->

  
        <ucfooter:truxfooter id="Ftr1" runat="server"></ucfooter:truxfooter> 
 
    
    </body>
</html>