include "lib/config.obj.php";
if(!$db) {
include_once "$site_dir/lib/db.obj.php";
$db = new db();
}
if(!isset($_SESSION['userid'])) {
header("location: ".$site_url."/users/login.php");
exit;
}
if(isset($_GET['type']) && $_GET['type'] != "all") {
$type = $_GET['type'];
if(!isSuperAdmin() && (isAdmin() && !hasPermissionForType($type))) {
header("location: index.php");
exit;
}
}
include "$site_dir/lib/top.inc.php";
?>
if(isset($_GET['type'])) {
$type = $_GET['type'];
$tstart = $type;
$tend = $type;
$db = new db();
$limitmonth = "";
$cyear = 0;
$cmonth = 0;
$mdiff = 2;
if(isset($_GET['cyear']) && is_numeric($_GET['cyear'])) {
$cyear = $_GET['cyear'];
} else {
$cyear = date('Y');
}
if(isset($_GET['cmonth']) && is_numeric($_GET['cmonth'])) {
$cmonth = $_GET['cmonth'];
} else {
$cmonth = date('m');
}
if(isset($_GET['mdiff']) and is_numeric($_GET['mdiff'])) {
$mdiff = $_GET['mdiff']-1;
if($mdiff < 0) $mdiff = 0;
if($mdiff > 12) $mdiff = 12;
}
if(!isset($_GET['cmonth']) || $cmonth < 1 || $cmonth > 12) {
$cmonth = date('m');
} else {
$ms = $cmonth - $mdiff;
$me = $cmonth + $mdiff;
if($ms < 1) $ms = 1;
if($me > 12) $me = 12;
$limitmonth = " AND ((year = $cyear AND month >= $ms AND month <= $me) OR year = 0) ";
$limitmonthurl = "&cyear=$cyear&cmonth=$cmonth&mdiff=".($mdiff+1);
}
if($type != "") {
if($type == "all") {
$tstart = 0;
$tend = count($types) - 1;
}
?>
$tabela = array();
for($i=$tstart; $i <= $tend; $i++) {
if(!isSuperAdmin() && !hasPermissionForType($i)) continue;
$tabela[$i] = array();
$query = "SELECT * FROM entidades WHERE type = $i";
$entidades = $db->query($query);
for($j=0; $j
= 0 ORDER BY month";
$querymenos = "SELECT month, SUM(value) AS total, COUNT(*) as count FROM conta WHERE eid = ".$entidades[$j][id]." $limitmonth GROUP BY month HAVING total < 0 ORDER BY month";
$contasmais = $db->query($querymais);
$contasmenos = $db->query($querymenos);
$tabela[$i][$j] = array();
$tabela[$i][$j] = $entidades[$j];
$tabela[$i][$j]['mais'] = array();
$tabela[$i][$j]['mais']['mes'] = array(0,0,0,0,0,0,0,0,0,0,0,0,0);
$tabela[$i][$j]['mais']['count'] = array(0,0,0,0,0,0,0,0,0,0,0,0,0);
$tabela[$i][$j]['menos'] = array();
$tabela[$i][$j]['menos']['mes'] = array(0,0,0,0,0,0,0,0,0,0,0,0,0);
$tabela[$i][$j]['menos']['count'] = array(0,0,0,0,0,0,0,0,0,0,0,0,0);
for($k=1, $z = 0, $y = 0; $k<=13; $k++) {
$cmais = $contasmais[$z];
$cmenos = $contasmenos[$y];
if($k == $cmais['month']) {
if($cmais['count'] > 0) {
$tabela[$i][$j]['mais']['mes'][$k] = $cmais['total'];
$tabela[$i][$j]['mais']['count'][$k] = $cmais['count'];
}
$z++;
}
if($k == $cmenos['month']) {
if($cmenos['count'] > 0) {
$tabela[$i][$j]['menos']['mes'][$k] = $cmenos['total'];
$tabela[$i][$j]['menos']['count'][$k] = $cmenos['count'];
}
$y++;
}
}
$tabela[$i][$j]['mais']['mes'][$k] = $contasmais[$z]['total'];
$tabela[$i][$j]['mais']['count'][$k] = $contasmais[$z]['count'];
$tabela[$i][$j]['menos']['mes'][$k] = $cmenos['total'];
$tabela[$i][$j]['menos']['count'][$k] = $contasmenos[$y]['count'];
}
}
for($i=$tstart; $i <= $tend; $i++) {
if(!isSuperAdmin() && !hasPermissionForType($i)) continue;
$total_meses = array();
for($m = 0; $m <= 13; $m++) {
$total_meses[$m] = array();
$total_meses[$m]['mais'] = 0;
$total_meses[$m]['maiscount'] = 0;
$total_meses[$m]['menos'] = 0;
$total_meses[$m]['menoscount'] = 0;
$total_meses[$m]['count'] = 0;
}
$total_info2 = 0;
$total_absoluto_c = false;
?>
=$types[$i]?>
}
}
}
?>
include "$site_dir/lib/bottom.inc.php";
?>