<html>
<head>
<title>Persona Homes Project Management System</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href="style.css">
<script language="JavaScript" type="text/javascript" src="../js/print.js"></script>
</head>
<body>
<!-- #include file="includes/top.asp" -->
<table align="center" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td height="400" bgcolor="#FFFFFF" valign="top"><table border="0" cellpadding="0" cellspacing="0">
			<tr>
				<td width="10"></td>
				<td><div id="areaToPrint"><table border="0" cellpadding="0" cellspacing="0">
<%            
On Error Resume Next
Response.Expires = 0
Dim objConn, objRS, strQuery
Dim strConnection
Dim tKPI, tSupervisor, tOutFrom

if Session("Admin") <> -1 then
	Response.Write "<tr><td width=""780"" height=""80""></td></tr>"
  	Response.Write "<tr><td width=""780"" height=""25"" align=""center"" class=""h2"">You are not authorized to view this page.</td></tr>"
    Response.Write "<tr><td width=""780"" height=""20""></td></tr>"
    Response.Write "<tr><td width=""780"" height=""25"" align=""center""><input TYPE=""button"" NAME=""close"" value=""Close"" class=""submit"" ONCLICK=""JavaScript:window.close();""></td></tr>"
else
%>
    				<tr>
      					<td width="780" height="25" align="center" class="head">Hi <%= Session("Login") %>!</td>
					</tr>
    				<tr>
                    	<td><table width="100%" border="0" cellpadding="0" cellspacing="0">
                        	<tr height="25">
                            	<td class="h2"><%= Date & " " & Time%></td>
                                <td align="right"><table border="0" cellpadding="0" cellspacing="0">
                                    <tr>
                                        <td height="25"><a href="javascript:printPage('areaToPrint');" class="h2">Print</a></td>
                                        <td width="20" height="25"></td>
                                        <td height="25"><a href="home.asp" class="h2">Back to Home</a></td>
                                        <td width="20" height="25"></td>
                                        <td height="25"><a href="logout.asp" class="h2">Logout</a></td>
                                    </tr>
                                </table></td>
                            </tr>
                        </table></td>
					</tr>
    				<tr>
      					<td width="780" height="10"></td>
					</tr>
    				<tr>
      					<td width="780" height="25" align="center" class="h1">Payment Received Report</td>
					</tr>
    				<tr>
      					<td width="780" height="10"></td>
					</tr>
<%					
    Set objConn = Server.CreateObject("ADODB.Connection")
    strConnection = "DSN=personahomes;Database=WebDB.mdb;"
  
    objConn.Open strConnection
	
	tKPI = Request.Form("KPI")
	tSupervisor = Request.Form("supervisor")
	tOutFrom = Request.Form("outFrom")
	tOutTo = Request.Form("outTo")

	if InStr(tSupervisor,"'") > 0 then
		tRSupervisor = Replace(tSupervisor,"'","''")
	else
		tRSupervisor = tSupervisor
	end if

	tCriteria = ""

	strQuery = "SELECT ProgressPayment.* FROM ProgressPayment, Project WHERE ProgressPayment.DateOut IS NOT NULL AND ProgressPayment.Amount > 0 AND ProgressPayment.ProjectID = Project.ID"

	if not tKPI = "" then
		
		strQuery = strQuery & " AND ProgressID = " & tKPI
		KstrQuery = "SELECT * FROM Progress WHERE ID = " & tKPI
		Set KobjRS = objConn.Execute(KstrQuery)
		tCriteria = tCriteria & "<tr height=""20""><td align=""right"" class=""p"">Stage:</td><td width=""10""></td><td class=""p"">" & KobjRS("Name") & "</td></tr>"
		
	end if

	if not tSupervisor = "" then
		strQuery = strQuery & " AND Project.Supervisor = '" & tRSupervisor & "'"
		tCriteria = tCriteria & "<tr height=""20""><td align=""right"" class=""p"">Building Supervisor:</td><td width=""10""></td><td class=""p"">" & tSupervisor & "</td></tr>"
	end if

	if not tOutFrom = "" then
		strQuery = strQuery & " AND DateOut >= #" & Month(tOutFrom) & "/" & Day(tOutFrom) & "/" & Year(tOutFrom) & "#"
		tCriteria = tCriteria & "<tr height=""20""><td align=""right"" class=""p"">Out From:</td><td width=""10""></td><td class=""p"">" & tOutFrom & "</td></tr>"
	end if

	if not tOutTo = "" then
		strQuery = strQuery & " AND DateOut <= #" & Month(tOutTo) & "/" & Day(tOutTo) & "/" & Year(tOutTo) & "#"
		tCriteria = tCriteria & "<tr height=""20""><td align=""right"" class=""p"">Out To:</td><td width=""10""></td><td class=""p"">" & tOutTo & "</td></tr>"
	end if

	strQuery = strQuery & " ORDER BY DateOut"

    Set objRS = objConn.Execute(strQuery)

    if objRS.EOF then
  	  Response.Write "<tr><td width=""780"" height=""25"" align=""center"" class=""h2"">There is currently no payment based on the search criteria.</td></tr>"
	else
%>
			<tr>
  				<td align="center"><table border="0" cellpadding="0" cellspacing="0">
<%
Response.Write tCriteria
%>						
				</table></td>
			</tr>
			<tr>
				<td HEIGHT="10"></td>
			</tr>
			<tr>
				<td align="center"><table border="2" bordercolor="CCCCCC" cellpadding="0" cellspacing="0">
			   		<tr height="25">
						<td width="90" class="h2">Reference No.</td>
						<td width="120" class="h2">Customer</td>
						<td width="40" class="h2">Type</td>
						<td class="h2">Address</td>
        				<td width="70" class="h2">Supervisor</td>
						<td width="100" class="h2">Stage</td>
        				<td width="60" class="h2">Date In</td>
						<td width="60" class="h2">Date Out</td>
						<td width="80" class="h2">Amount</td>
      				</tr>
<%
		tTotal = 0
		
        Do While not objRS.EOF
		
			PstrQuery = "SELECT * FROM Project WHERE ID = " & objRS("ProjectID")
			Set PobjRS = objConn.Execute(PstrQuery)

			TstrQuery = "SELECT * FROM Type WHERE ID = " & PobjRS("TypeID")
			Set TobjRS = objConn.Execute(TstrQuery)
		
			SstrQuery = "SELECT * FROM Progress WHERE ID = " & objRS("ProgressID")
			Set SobjRS = objConn.Execute(SstrQuery)
		
			Response.Write "<tr height=""25"">"
			Response.Write "<td class=""p""><a href=""projectStatusEdit.asp?id=" & PobjRS("ID") & """ class=""p"">" & PobjRS("ID") & "</a></td>"
			Response.Write "<td class=""p"">" & PobjRS("FirstName") & " " & PobjRS("LastName") & "</td>"
			Response.Write "<td class=""p"">" & TobjRS("Name") & "</td>"
			Response.Write "<td class=""p"">" & PobjRS("Lot") & " " & PobjRS("SAddress1") & " " & PobjRS("SStreetType") & " " & PobjRS("SSuburb") & " " & PobjRS("SState") & " " & PobjRS("SPostcode") & "</td>"
			Response.Write "<td class=""p"">" & PobjRS("Supervisor") & "</td>"
			Response.Write "<td class=""p"">" & SobjRS("Name") & "</td>"
			Response.Write "<td class=""p"">" & objRS("DateIn") & "</td>"
			Response.Write "<td class=""p"">" & objRS("DateOut") & "</td>"
			Response.Write "<td align=""right"" class=""p"">" & FormatCurrency(objRS("Amount"),2) & "</td>"
			Response.Write "</tr>"
			
			tTotal = tTotal + objRS("Amount")

          	objRS.MoveNext
        Loop
%>
				</table></td>
            </tr>
            <tr>
            	<td height="20"></td>
            </tr>
            <tr>
            	<td height="20" align="center" class="p4">Total Inc GST: <%= FormatCurrency(tTotal,2) %></td>
            </tr>
            <tr>
            	<td height="20" align="center" class="p4">Total Exc GST: <%= FormatCurrency(tTotal/1.1,2) %></td>
            </tr>
<%
    end if
%>
            <tr>
            	<td height="20"></td>
            </tr>
            <tr>
            	<td align="center"><input type="button" name="export" value="Export" class="submit" onClick="javascript:window.location='reportProjectPaymentReceivedExcel.asp?KPI=<%= tKPI %>&Supervisor=<%= tSupervisor %>&OutFrom=<%= tOutFrom %>&OutTo=<%= tOutTo %>'"> &nbsp;&nbsp; <input type="button" name="close" value="Close" class="submit" onClick="javascript:window.close()" /></td>
            </tr>
<%	
	objRS.close
    objConn.close
    Set objRS = Nothing
    Set objConn = Nothing
end if  
%>
				</table></div></td>
				<td width="10"></td>
			</tr>
		</table></td>
	</tr>
<!-- #include file="includes/bottom.asp" -->
</table>
</body>
</html>