<!---
This file is Copyright � 1998-2009 by Home Care Business Services. This work may not be reproduced, in whole or in part, 
using any medium, including, but not limited to, electronic transmission, CD-ROM or published in print, without the express 
permission of Home Care Business Services.

$Revision: 1.1 $
$Id: timeauthorization.cfm,v 1.1 2010/03/11 16:41:01 arlen Exp $
$Date: 2010/03/11 16:41:01 $
--->
<cfinclude template="../__Security-Block.cfm">

<cfparam name="attributes.aid" default="0">
<cfparam name="attributes.atid" default="0">
<cfparam name="attributes.rid" default="0">
<cfparam name="attributes.date" default=#now()#>


<cfset approvedhours=0>
<cfset usedhours=0>
<cfset scheduledhours=0>

<cfquery  name="GetTime" datasource="#Application.DataSrc#">
	SELECT at.*,si.visit_date,sum(si.Total_units) as total,si.rev_code,si.rev_codeid
	FROM #Request.prefix_db_lookup#.Assessment_TimeAuthorizations at
	left outer join #Request.prefix_db_agency#.ScheduleItems si on at.assessment_tracker_id = si.assessment_tracker_id
	where at.Assessment_Tracker_ID = #attributes.atid# and at.Assessment_ID = #attributes.aid#
	and at.revcode_id = #attributes.rid#
	and at.revcode_id = si.rev_codeid
	and si.visit_date > #CreateODBCDate(attributes.date)#
	group by si.rev_code 
	order by si.rev_code
</cfquery>

<cfif gettime.recordcount>
	<cfset approvedhours=gettime.approvedhours>
	<cfset scheduledhours=gettime.total>
</cfif>

<cfquery  name="GetTimePast" datasource="#Application.DataSrc#">
	SELECT at.*,si.visit_date,sum(si.Total_units) as total,si.rev_code,si.rev_codeid
	FROM #Request.prefix_db_lookup#.Assessment_TimeAuthorizations at
	left outer join #Request.prefix_db_agency#.ScheduleItems si on at.assessment_tracker_id = si.assessment_tracker_id
	where at.Assessment_Tracker_ID = #attributes.atid# and at.Assessment_ID = #attributes.aid#
	and at.revcode_id = #attributes.rid#
	and at.revcode_id = si.rev_codeid
	and si.visit_date <= #CreateODBCDate(attributes.date)#
	group by rev_code 
	order by si.rev_code
</cfquery>

<cfif gettimepast.recordcount>
	<cfset approvedhours=gettimepast.approvedhours>
	<cfset usedhours=gettimepast.total>
</cfif>

<cfoutput>
	<span style="font-size:7pt;">
	Hours:<br>
	&nbsp;&nbsp;Approved: #approvedhours#<br>
	<cfset avl=#approvedhours#-#usedhours#-#scheduledhours#>
	&nbsp;&nbsp;Avail: <cfif avl lt 0><font color=red>#avl#</font><cfelse>#avl#</cfif><br>
	&nbsp;&nbsp;Used: #usedhours#<br>
	&nbsp;&nbsp;Sched: #scheduledhours#<br>
	</span>
</cfoutput>
