<?php

$id = $link->hrefquery ();

if ($id != '') {
	
	$getid = $id ['1'];
	if ($getid != '') {
		$query = $db->delete ( 'payment', array ('id' => $getid ) );
		if ($query) {
			?>
<div class='hide1'>
	<div id='gritter-notice-wrapper'>
		<div id='gritter-item-2' class='gritter-item-wrapper gritter-warning'
			style=''>
			<div class='gritter-top'></div>
			<div class='gritter-item'>
				<div class='gritter-close' id='gritterremove'
					style='display: inline;'></div>
				<h5>Cheers, Your Record IS Deleted...</h5>
				<div style='clear: both'></div>
			</div>
			<div class='gritter-bottom'></div>
		</div>
	</div>
</div>

<?php }else{?>
<div class='hide1'>
	<div id='gritter-notice-wrapper'>
		<div id='gritter-item-2' class='gritter-item-wrapper gritter-warning'
			style=''>
			<div class='gritter-top'></div>
			<div class='gritter-item'>
				<div class='gritter-close' id='gritterremove'
					style='display: inline;'></div>
				<h5>Oops, Record Are Not Deleted...</h5>
				<div style='clear: both'></div>
			</div>
			<div class='gritter-bottom'></div>
		</div>
	</div>
</div>
<?php
		
		}
	}
} else {

}
?>
<?php

if (isset ( $_POST ['submit'] ) && $_POST ['check'] == 'date') {
	
	$date = '';
	$paymentdate = $_POST ['date'];
	$paymentdate ['final'];
	$final = explode ( '-', $paymentdate ['final'] );
	
	$paymentdate ['date1'] = $final [0];
	$paymentdate ['date2'] = $final [1];
	
	$paymentdate1 = strtotime ( $paymentdate ['date1'] );
	
	$paymentdate2 = strtotime ( $paymentdate ['date2'] );
	
	$userid = $db->get_col ( 'users', array ('email' => $uemail ), 'id' );
	$time = $db->get_all ( 'payment' );
	
	foreach ( $time as $row ) {
		$dtime = $row ['time'];
		$paymentdatenew = date ( "d-m-Y", strtotime ( $dtime ) );
		$db_time = strtotime ( $paymentdatenew );
		
		if ($paymentdate1 <= $db_time && $paymentdate2 >= $db_time) {
			
			$select [] = $row;
		
		} else {
			$warning = "<div class='hide1'>
				  <div id='gritter-notice-wrapper'>
					<div id='gritter-item-2' class='gritter-item-wrapper gritter-warning' style=''>
						<div class='gritter-top'></div>
						<div class='gritter-item'>
							<div class='gritter-close' id='gritterremove' style='display: inline;'></div>
								<h5>
									Oops! There Is No Data For Required Date...
								</h5>
							 <div style='clear:both'></div>
						</div>
						<div class='gritter-bottom'></div>
					</div>
				  </div>
			    </div>";
		}
	}
	if ($select == '') {
		echo $warning;
		$query = $db->get_all ( 'payment', array ('user_id' => '' ) );
	} else {
		$query = $select;
		
		$blank = '';
		$null = '';
		foreach ( $query as $find ) {
			
			if ($find ['payment'] == 'expense') {
				$t_exp = $blank + $find ['amount'];
				$blank = $t_exp;
			}
			if ($find ['payment'] == 'income') {
				$t_inc = $null + $find ['amount'];
				$null = $t_inc;
			
			}
		}
	
	}
} 

else {
	// $userid = $db->get_col ( 'users', array ('email' => $uemail ), 'id' );
	
	$query = $db->get_all ( 'payment' );
	
	$expense = $db->get_col ( 'payment', array ('payment' => 'expense' ), 'amount' );
	
	$blank = '';
	foreach ( $expense as $find ) {
		
		$t_exp = $blank + $find;
		$blank = $t_exp;
	}
	
	$null = '';
	$income = $db->get_col ( 'payment', array ('payment' => 'income' ), 'amount' );
	foreach ( $income as $find ) {
		$t_inc = $null + $find;
		$null = $t_inc;
	
	}

}
?>