Skip to content
Snippets Groups Projects
bilanz.class.php 3.24 KiB
Newer Older
Eric Laufer's avatar
Eric Laufer committed
<?php

class bilanz{
	private $db;
	
	public function __construct(){
		global $datenbank;
		$this->db = $datenbank;
	}
	
	private function TCSS($row){
		if($row < 0){
			return 'table-danger';
		}else{
			return 'table-success';
		}
	}
	
	public function ShowTable(){
		$i = 1;
		$aus = '
			<table class="table" id="BilanzTable">
				<thead>
					<tr>
						<th>#</th>
						<th>Datum</th>
						<th class="text-right">Einnahmen</th>
						<th class="text-right">Ausgaben</th>
						<th class="text-right">Bilanz</th>
						<th></th>
					</tr>
				</thead>
				<tbody>
				';
		foreach($this->db->get_results("SELECT SUM(ein) AS ges_ein, SUM(aus) AS ges_aus, datum FROM ". PREFIX . BILANZ ." GROUP BY datum ORDER BY datum DESC") AS $res){
			$bilanz = $res->ges_ein-$res->ges_aus;
			$aus .= '
					<tr class="'. $this->TCSS($bilanz) .'">
						<td>'. $i .'</td>
						<td>'. date("d.m.Y", $res->datum) .'</td>
						<td class="text-right">'. number_format($res->ges_ein,2,',','.') .'</td>
						<td class="text-right">'. number_format($res->ges_aus,2,',','.') .'</td>
						<td class="text-right">'. number_format($bilanz,2,',','.') .'</td>
						<td class="text-center"><a href="?page=/bilanzsystem&TID='. $res->datum .'" class="btn btn-info btn-sm">Details</a></td>
					</tr>
			';
			$i++;
		}
		
		$aus .= '</tbody></table>';
		return $aus;
	}
	
	private function ShowDetails($gruppe,$date){
		$aus = '
			<table class="table table-hover">
				<tr>
					<th>Typ</th>
					<th class="text-right">Einnahmen</th>
					<th class="text-right">Ausgaben</th>
				</tr>
		';
		foreach($this->db->get_results("SELECT * FROM ". PREFIX . BILANZ ." WHERE gruppe = '$gruppe' AND datum = '$date'") AS $res){
			if($res->ein < $res->aus){ $css = 'table-danger';}else{ $css = 'table-success';}
			$aus .= '
				<tr class="'. $css .'">
					<td>'. $res->name .'</td>
					<td class="text-right">'. number_format($res->ein,2,',','.') .'</td>
					<td class="text-right">'. number_format($res->aus,2,',','.') .'</td>
				</tr>
			';
		}
		
		return $aus.'</table>';
	}
	
	public function ShowDate($date){
		if((int)$date){
			$aus = array("head" => '', "body" => '');
			$i = 1;
			foreach($this->db->get_results("SELECT * FROM ". PREFIX . BILANZ ." WHERE datum = '". $date ."' GROUP BY gruppe") AS $res){
				if($i == 1){ $aktive = 'active'; $show = 'show';}else{$aktive = ''; $show = '';}
				$aus['head'] .= '
					<a class="nav-link '. $aktive .'" id="nav-'. $res->id .'-tab" data-toggle="tab" href="#nav-'. $res->id .'" role="tab" aria-controls="nav-'. $res->id .'" aria-selected="true">'. $res->gruppe .'</a>
				';
				$aus['body'] .= '
					<div class="tab-pane fade '. $show .' '. $aktive .'" id="nav-'. $res->id .'" role="tabpanel" aria-labelledby="nav-'. $res->id .'-tab">
						'. $this->ShowDetails($res->gruppe,$date) .'
					</div>
				';
				$i++;
			}
			return '
				<nav>
					<div class="nav nav-tabs" id="nav-tab" role="tablist">
						'. $aus['head'] .'
					</div>
				</nav>
				<div class="tab-content" id="nav-tabContent">
					'. $aus['body'] .'
				</div>
				<a href="'. $_SERVER['HTTP_REFERER'] .'" class="btn btn-warning">Zur&uuml;ck</a>
			';
		}else{
			return 'Falsche Zeitangabe';
		}
	}
}