<?php
	include_once("includes/config.php");
	include_once("includes/common_functions.php");
	
	$common = new General_Functions();
	$css_class = "x-gray";
	$common->SetCssClass($css_class);
	
	$query = "Select * FROM site_employee_master WHERE emp_reportingto = '".USR."'";
	$common->sql->query($query, SQL_ALL, SQL_ASSOC);
	$rec1 = $common->sql->record;
	
	if(count($rec1) == 0)
		$pndg_rpt_visible = "hidden";
	else
		$pndg_rpt_visible = "visible";
	
	if(count($rec1) == 0)
		$pndg_rpt_visible = false;
	else
		$pndg_rpt_visible = true;
	
	$query = "Select * FROM site_employee_master WHERE emp_processingto = '".USR."'";
	$common->sql->query($query, SQL_ALL, SQL_ASSOC);
	$rec1 = $common->sql->record;
	
	if(count($rec1) == 0)
		$pndg_prcs_visible = "hidden";
	else
		$pndg_prcs_visible = "visible";
	
	if(count($rec1) == 0)
		$pndg_prcs_visible = false;
	else
		$pndg_prcs_visible = true;
	
	$query = "Select site_expense_master_dtl.* FROM site_expense_master
					INNER JOIN site_expense_master_dtl ON (site_expense_master_dtl.exp_hdr_id = site_expense_master.exp_id)
					INNER JOIN site_employee_master ON (site_employee_master.emp_id = site_expense_master.exp_emp_id)
					INNER JOIN site_location_type ON (site_location_type.location_id = site_expense_master.exp_location)
					INNER JOIN site_bussiness_expense_type ON (site_bussiness_expense_type.busns_exp_typ_id = site_expense_master.exp_type)
			WHERE exp_emp_id = '".USR."' GROUP BY site_expense_master.exp_id";
	
	$query = "Select site_expense_detail.*, site_expense_header.exp_stage AS exp_stage_rpt FROM site_expense_header
					INNER JOIN site_expense_detail ON (site_expense_detail.exp_hdr_id_fk = site_expense_header.exp_hdr_id)
					INNER JOIN site_employee_master ON (site_employee_master.emp_id = site_expense_header.exp_emp_id)
					INNER JOIN site_city_category ON (site_city_category.city_cat_id = site_expense_header.exp_location)
					INNER JOIN site_bussiness_expense_type ON (site_bussiness_expense_type.busns_exp_typ_id = site_expense_header.exp_type)
			WHERE exp_emp_id = '".USR."' GROUP BY site_expense_header.exp_hdr_id";
	$common->sql->query($query, SQL_ALL, SQL_ASSOC);
	$rec1 = $common->sql->record;
	// print_r($rec1);
	
	$tot_rpt = count($rec1);
	$tot_aprv = 0;
	$tot_sbtd = 0;
	$tot_rjct = 0;
	$tot_hold = 0;
	$tot_pndg = 0;
	
	for($i=0; $i<$tot_rpt; $i++)
	{
		if($rec1[$i]['exp_aprove_status'] == "1")
			$tot_aprv++;
		if($rec1[$i]['exp_stage_rpt'] == '1')
			$tot_sbtd++;
		if($rec1[$i]['exp_aprove_status'] == "2")
			$tot_rjct++;
		if($rec1[$i]['exp_aprove_status'] == "4")
			$tot_pndg++;
	}
	
	$query = "SELECT * FROM site_notification WHERE status= 'Y'";
	$common->sql->query($query, SQL_ALL, SQL_ASSOC);
	$notification_rec = $common->sql->record;
	
	$notification_text = '';
	for($i=0; $i<count($notification_rec); $i++)
	{
		if($notification_rec[$i]['note_desc'] == '')
			$notification_text .= $notification_rec[$i]['note_title']."<br /><br />";
		else
		{
			$notification_text .= '<a href="#notification'.$notification_rec[$i]['note_id'].'" class="defaultDOMWindow">'.$notification_rec[$i]['note_title'].'</a>
									<div id="notification'.$notification_rec[$i]['note_id'].'" style="display: none;"><p>'.$notification_rec[$i]['note_desc'].'</p></div>
									<script type="text/javascript"> 
									$(\'.defaultDOMWindow\').openDOMWindow({ 
									eventType:\'click\', 
									loader:1, 
									loaderImagePath:\'animationProcessing.gif\', 
									loaderHeight:16, 
									loaderWidth:17 
									}); 
									</script><br /><br />';
			
		}
	}
?>
<div class="content_bg">
<div class="dashboard" align="center">
	<div class="left">
    	<div class="dashboard_title">Announcements</div>
        <div class="dashboard_content">
    		<marquee height="165px" direction="up" behavior="scroll" scrollamount="3" onmouseover="this.stop();" onmouseout="this.start();">
            	<!--Your upward scrolling text goes here Your upward scrolling text goes here<br /><br />
            	Your upward scrolling text goes here<br /><br />
            	Your upward scrolling text goes here<br /><br /> -->
                <?php echo $notification_text; ?>
            </marquee>
        </div>
    </div>
	<div class="right">
    	<div class="dashboard_title">Reports Status</div>
        <div class="dashboard_content">
        	<div style="padding: 0px 5px 3px; width: 95%;">
            	<a href="?page=expense_new#tabs-2">
                    <div>Submitted Report</div>
                    <div><b><?php echo $tot_sbtd; ?> / <?php echo $tot_rpt; ?></b></div>
                </a>
            </div>
        	<div style="padding: 5px 5px 3px; width: 95%;">
            	<a href="?page=expense_new#tabs-3">
                    <div>Approved Report</div>
                    <div><b><?php echo $tot_aprv; ?> / <?php echo $tot_rpt; ?></b></div>
                </a>
            </div>
        	<div style="padding: 5px 5px 3px; width: 95%;">
            	<div>Rejected Report</div>
                <div><b><?php echo $tot_rjct; ?> / <?php echo $tot_rpt; ?></b></div>
            </div>
        </div>
    </div>
    <br /><br />
    <?php if($pndg_rpt_visible) { ?>
	<div class="left" style="visibility:<?php echo $pndg_rpt_visible; ?>">
    	<div class="dashboard_title">Pending Approval</div>
        <div class="dashboard_content">
        	<div style="width: 100%; height: 165px; overflow: auto;">
            <?php
				foreach($emp_name as $key => $val)
				{
					$emp = array_unique($emp_name[$key]);
					echo '<div style="padding: 5px 5px 3px; width: 95%;">
						<div>'.$emp[0].'</div>
						<div><b>'.array_sum($emp_pndg[$key]).'</b></div>
					</div>';
				}
			?>
			</div>
        </div>
    </div>
    <?php } ?>
    <?php if($pndg_prcs_visible) { ?>
	<div class="right" style="visibility:<?php echo $pndg_prcs_visible; ?>">
    	<div class="dashboard_title">Pending Processing</div>
        <div class="dashboard_content">
        	<div style="width: 100%; height: 165px; overflow: auto;">
            <?php
				foreach($pndng_prcs_emp_name as $key => $val)
				{
					$emp = array_unique($pndng_prcs_emp_name[$key]);
					echo '<div style="padding: 5px 5px 3px; width: 95%;">
						<div>'.$emp[0].'</div>
						<div><b>'.array_sum($pndng_prcs_emp_pndg[$key]).'</b></div>
					</div>';
				}
			?>
			</div>
        </div>
    </div>
    <?php } ?>
</div>
</div>