<?php
	include('/var/www/html/uclit/protected/common/login/check.php'); 
 	include('/var/www/html/uclit/protected/common/css_login/css_head2.php');
	include('/var/www/html/uclit/protected/connections/db_arlstats.php');

	@ob_start();

	echo"<h1>Display Previous Year Adjustments (2006 - 2007) Report</h1>";
	//process 1
		
	$atLeastOnce = "false";
	$atLeastOnce2 = "false";
	$total = 0;
	$where = "";
	
	
/*-----------------------------------------------------
Purpose: tally up total records and sum of values of the selected item from previous screen
-------------------------------------------------------*/
	$db = mysql_select_db('arlstats', $arlConn) or die ("Unable to select arlstats database.");
		
	$count_add = "Select Sum(Archive_Stats.Value)
From Archive_Stats
Where ((Archive_Stats.QID = '40' OR Archive_Stats.QID = '46')  AND (Archive_Stats.CID = '1' OR Archive_Stats.CID = '2' OR Archive_Stats.CID = '3' OR Archive_Stats.CID = '4') AND (Archive_Stats.SID = '4'))";
	$add_result = @mysql_query($count_add, $arlConn) or die ("Unable to query: $count_add");
	//echo "<br />Net Adjustment: ";
	$add_total = @mysql_result($add_result,0);
	//echo $add_total;

	$count_withdraw = "Select Sum(Archive_Stats.Value)
From Archive_Stats
Where ((Archive_Stats.QID = '40' OR Archive_Stats.QID = '46')  AND (Archive_Stats.CID = '7') AND (Archive_Stats.SID = '4'))";
	$withdraw_result = @mysql_query($count_withdraw, $arlConn) or die ("Unable to query: $count_withdraw");
	//echo "<br />Net Adjustment: ";
	$add_withdrawn= @mysql_result($withdraw_result,0);




	//close cell and table
	

/*----------------------------------------------------
Purpose: querry and display in a table format for all recorded items that fit the cateria
-----------------------------------------------------*/
	$curr_status = "Select arlstats.Archive_Stats.Stat_ID AS ID, arlstats.Archive_Stats.Description AS Description, arlstats.Archive_Stats.Value AS Value, arlstats.Calendar.`Month` AS Month, arlstats.Location.Name AS Location, uclit_db.personnel.last_name AS Last_name, uclit_db.personnel.first_name AS First_name, uclit_db.personnel.middle_name AS Middle_name, arlstats.Material_Types.Name AS Mat_type, arlstats.Catalog_Types.Name AS Cat_type, arlstats.Archive_Stats.SID AS SID
From arlstats.Calendar Inner Join arlstats.Archive_Stats ON arlstats.Calendar.QID = arlstats.Archive_Stats.QID Inner Join arlstats.Location ON arlstats.Location.LID = arlstats.Archive_Stats.LID Inner Join arlstats.Material_Types ON arlstats.Material_Types.`MID` = arlstats.Archive_Stats.MID Inner Join uclit_db.personnel ON uclit_db.personnel.personnel_id = arlstats.Archive_Stats.UID Inner Join arlstats.Catalog_Types ON arlstats.Catalog_Types.CID = arlstats.Archive_Stats.CID
Where (Archive_Stats.QID = '40' OR Archive_Stats.QID = '46') AND (Archive_Stats.SID = '4') 
";
		
	$curr_result = @mysql_query($curr_status, $arlConn) or die ("Unable to query: $curr_status");
	
//	$export = "Select AdjID, AdjDesc, AdjVal, AdjPer, AdjDate, AdjYear From Current_Adjustments Where AdjYear = 2008";

	$export = "Select arlstats.Archive_Stats.Stat_ID AS ID, arlstats.Archive_Stats.SID AS SID, arlstats.Archive_Stats.Description AS Description, arlstats.Archive_Stats.Value AS Value, arlstats.Calendar.`Month` AS Month, arlstats.Location.Name AS Location, uclit_db.personnel.last_name AS Last_name, uclit_db.personnel.first_name AS First_name, uclit_db.personnel.middle_name AS Middle_name, arlstats.Material_Types.Name AS Mat_type, arlstats.Catalog_Types.Name AS Cat_type
From arlstats.Calendar Inner Join arlstats.Archive_Stats ON arlstats.Calendar.QID = arlstats.Archive_Stats.QID Inner Join arlstats.Location ON arlstats.Location.LID = arlstats.Archive_Stats.LID Inner Join arlstats.Material_Types ON arlstats.Material_Types.`MID` = arlstats.Archive_Stats.MID Inner Join uclit_db.personnel ON uclit_db.personnel.personnel_id = arlstats.Archive_Stats.UID Inner Join arlstats.Catalog_Types ON arlstats.Catalog_Types.CID = arlstats.Archive_Stats.CID
Where (Archive_Stats.QID = '40' OR Archive_Stats.QID = '46') AND (Archive_Stats.SID = '4') 
";




	//display the heads of the table
?>
	 <table border = '0' width='100%' cellspacing ='10' >
            <tr>
            <?php
		
            echo"<td align = 'center' width='25%'> <br />Adjustments Added : $add_total </td><td align = 'center'></td></tr>
			
			<td align = 'center' width='25%'> <br />Adjustments Withdrawn : $add_withdrawn </td><td align = 'center'></td></tr>";
			$adjnet = $add_total - $add_withdrawn;
			$adjnet = number_format($adjnet);
			echo"
			<td align = 'center' width='25%'> <br />Adjustments Net: $adjnet </td><td align = 'center'></td></tr><br />
			
			";
            
            ?>
            <tr>
            <td align = 'center'>
            <FORM id='form2' name='form2' method='Post' ACTION='http://ul.uc.edu/uclit/protected/assocdean/collstats/export.php'>
			<INPUT name='Submit' type='submit' id='Submit' value='Export to Excel' />
            <INPUT name='saveWord' type='hidden' id='saveWord' value='2' />
			<INPUT name='current_status' type='hidden' id='current_status' value='<?php echo"$export"; ?>' />
            </FORM></td>
            </tr>
            </table>
	<form id='result' name='result' action='0' method='POST'>
		<table border='1' width='100%' class="sortable" id="maintable">
			<tr>
				<td width='20%' align='center'><strong>Desciption</strong></td>
				<td width='20%' align='center'><strong>Value</strong></td>
				<td width='20%' align='center'><strong>Cataloger</strong></td>
				<td width='20%' align='center'><strong>Format</strong></td>
				<td width='20%' align='center'><strong>Action</strong></td>
				<td width='20%' align='center'><strong>Month</strong></td>
                <td width='20%' align='center'><strong>Location</strong></td>
                <td width='20%' align='center'><strong>Delete</strong></td>
			</tr> 	
<?
	while($curr_row = @mysql_fetch_array($curr_result))
	{	
		$adjid = $curr_row['ID'];
		$adjdesc = $curr_row['Description'];
		$adjvalue = $curr_row['Value'];
		$adjmonth = $curr_row['Month'];
		$adjlocation = $curr_row['Location'];
		$adjlastname = $curr_row['Last_name'];
			$adjfirstname = $curr_row['First_name'];
			$adjmiddlename = $curr_row['Middle_name'];
				$adjmaterial = $curr_row['Mat_type'];
				$adjcatalog = $curr_row['Cat_type'];
				
		
		
		echo "<tr>";
		echo "<td width='20%' align='center'>$adjdesc</td>";
		echo "<td width='20%' align='center'>$adjvalue</td>";
		echo "<td width='20%' align='center'>$adjlastname, $adjfirstname $adjmiddlename</option>";
		echo "<td width='20%' align='center'>$adjmaterial</td>";
		echo "<td width='20%' align='center'>$adjcatalog</td>";
		echo "<td width='20%' align='center'>$adjmonth</td>";
		echo "<td width='20%' align='center'>$adjlocation</td>";
		echo "<td align='center'><a href='http://ul.uc.edu/uclit/protected/assocdean/collstats/del_arl_adj_2007.php?statid=$adjid'><img src='delete.gif' border='0'></a></td>";

		}
		echo "</tr>";
	
		
	echo "</table></BR>";
 echo"<a href='http://ul.uc.edu/uclit/protected/assocdean/collstats/arl_report_adj_2007.php'>Return to ARL 2006 - 2007 Adjustments</a>";
	require ("/var/www/html/uclit/protected/common/css_login/css_foot2.php"); 
?>