<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="DriverMaster.master" CodeBehind="Dashboard.aspx.vb" Inherits="Web.Dashboard" %>
<%@ MasterType VirtualPath="DriverMaster.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="phContent" runat="server">

    <article>

        <asp:Repeater ID="repCurrent" runat="server" DataSourceID="dsCurrent">
            <HeaderTemplate>
                <section>
                    <h2>Current Applications</h2>
            </HeaderTemplate>
            <ItemTemplate>
                <div class="card">
                    <h1><%# Eval("companyName") %></h1>
                    <p><%# Eval("timeDisplay") %></p>
                    <p>Status: <%# Eval("status") %></p>
                    <a class="default" href="<%# Eval("linkUrl") %>"><%# Eval("linkText") %></a>
                </div>
            </ItemTemplate>
            <FooterTemplate>
                </section>
            </FooterTemplate>
        </asp:Repeater>
        <asp:SqlDataSource ID="dsCurrent" runat="server"
            SelectCommand="
                SELECT cust1.Name companyName,
	                'Started: ' + FORMAT(xfer.transferStartDate, 'M/d/yyyy h:mm:ss tt') timeDisplay,
	                'pending transfer' status,
	                'transfer/?xferId=' + CONVERT(VARCHAR,xfer.id) linkUrl,
	                'Transfer to ' + cust2.Name + '...' linkText,
	                0 sortField1, xfer.transferStartDate sortField2
                FROM web_DriverMoveApplication xfer
                LEFT JOIN ServiceContract sc1 ON sc1.ID = xfer.previousContractId
                LEFT JOIN Customer cust1 ON cust1.ID = sc1.CustomerId
                LEFT JOIN web_DriverApplication app ON app.id = xfer.appId
                LEFT JOIN ServiceContract sc2 ON sc2.ID = app.clientId
                LEFT JOIN Customer cust2 ON cust2.ID = sc2.CustomerID
                WHERE xfer.transferCompleteDate IS NULL AND app.driverAccountId=@accountId
                UNION ALL
                SELECT cust.Name companyName,
	                'Updated: ' + FORMAT(app.dateUpdated, 'M/d/yyyy h:mm:ss tt') timeDisplay,
	                app.status,
	                'application/?appId=' + CONVERT(VARCHAR,app.id) linkUrl,
	                'Continue with application...' linkText,
	                1 sortField1, app.dateUpdated sortField2
                FROM web_DriverApplication app
                LEFT JOIN ServiceContract sc ON sc.ID = app.ClientId
                LEFT JOIN Customer cust ON cust.ID = SC.CustomerId
                WHERE canDriverEdit=1 AND driverAccountId=@accountId
                ORDER BY sortField1, sortField2 DESC">
            <SelectParameters>
                <asp:Parameter Name="accountId" />
            </SelectParameters>
        </asp:SqlDataSource>

        <asp:Repeater ID="repHistory" runat="server" DataSourceID="dsHistory">
            <HeaderTemplate>
                <section>
                    <h2>Past Applications</h2>
                    <table>
                        <tr>
                            <th>Submitted</th>
                            <th>Company</th>
                        </tr>
            </HeaderTemplate>
            <ItemTemplate>
                <tr>
                    <td><%# Eval("dateSubmitted") %></td>
                    <td><%# Eval("companyName") %></td>
                </tr>
            </ItemTemplate>
            <FooterTemplate>
                    </table>
                </section>
            </FooterTemplate>
        </asp:Repeater>
        <asp:SqlDataSource ID="dsHistory" runat="server"
            SelectCommand="
                SELECT app.dateSubmitted, Customer.Name AS companyName
                FROM web_DriverApplication app
                LEFT JOIN ServiceContract SC ON SC.ID = app.ClientId
                LEFT JOIN Customer ON Customer.ID = SC.CustomerId
                WHERE canDriverEdit=0 AND driverAccountId=@accountId
                ORDER BY app.dateSubmitted DESC"
            >
            <SelectParameters>
                <asp:Parameter Name="accountId" />
            </SelectParameters>
        </asp:SqlDataSource>
    <asp:PlaceHolder id="phMessage" runat="server" Visible="false">
        <div class="container">
		<h5 style="padding-bottom: 5px">
            APPLICANT INSTRUCTIONS: If you do not see the online application link on this page after signing in, the application link may have been broken. Please ensure that you are signed in.  Then go to the original application link that was provided and click on it again to reconnect.
        </h5>
            </div>
    </asp:PlaceHolder>

    </article>
</asp:Content>
