rendered paste body<?
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";
?>
<div id="header">
<table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td> <ul>
<img src="logo.jpg" />
</ul> </td>
<td>
<ul>
<li><a href="index.php" title="Página Principal">Página Principal</a></li>
</ul> </td>
<? if(isSuperAdmin() || (isAdmin() && hasPermission())) { ?>
<td>
<ul>
<li><a href="insert.php" title="Inserir Entidade">Inserir Entidade</a></li>
</ul> </td>
<td>
<ul>
<li><a href="insert_data.php" title="Inserir Movimento">Inserir Movimento</a></li>
</ul> </td>
<? } ?>
<? if(isSuperAdmin()) { ?>
<td>
<ul>
<li><a href="users.php" title="Editar Utilizadores">Editar Utilizadores</a></li>
</ul> </td>
<? } ?>
<td>
<ul>
<li><a href="<?=$site_url?>/users/edit.php" title="Editar Info">Editar Info</a></li>
</ul> </td>
</tr>
</table>
</div>
<br />
<div align="center">
<div id="box">
<table style="width: 100%; height: 28px; background-color: #ffffff">
<tr>
<td style="padding: 0 10px 0 10px"><strong>Pesquisa de movimento:</strong>
<form style="display: inline" action="detail.php" method="GET"><input style="height: 18px; border: 1px solid #999; font-size: 13px;" type="text" name="cid" size="6" maxlength="6" value="" />
<input style="height: 22px; font-size: 11px;" type="submit" value="Procurar" />
</form></td>
</tr>
</table>
</table>
<form method="GET" action="index.php">
<table width="589" border="0" align="center">
<tr>
<td width="211"><p align="left"><strong>Empresa:</strong> <? echo $licenciado; ?></p>
<p align="left"><strong>Versão:</strong></strong> <? echo $version; ?> [<? echo $last_update; ?>]</p>
<p align="left"><a href="ajuda.php"><strong>Ver informação detalhada</strong></a></p>
<td width="35"> </td>
<td width="329"><div align="center"><strong>Ver entidades:</strong>
<select name="type">
<option value="all">Todos</option>
<?
for($i=0; $i<count($types); $i++) {
if(isSuperAdmin() || hasPermissionForType($i)) {
?>
<option value="<?=$i?>">
<?=$types[$i]?>
</option>
<?
}
}
?>
</select>
<input type="submit" value="OK" />
</div></td>
</tr>
</table>
</form>
</div>
<?
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;
}
?>
<form action="index.php" method="GET">
<input type="hidden" name="type" value="<?=$type?>">
<div align="center">
<select name="mdiff">
<option value="1">1 mês</option>
<option value="2" selected>3 meses</option>
<option value="3">5 meses</option>
</select>
<select name="cmonth">
<? for($m=1; $m<=12; $m++) { ?>
<option value="<?=$m?>" <?=($cmonth==$m)?"selected":"";?>><?=$months[$m]?></option>
<? } ?>
</select>
<select name="cyear">
<? for($m=2007; $m>=2005; $m--) { ?>
<option value="<?=$m?>" <?=($cyear==$m)?"selected":"";?>><?=$m?></option>
<? } ?>
</select>
<input type="submit" value="ok" />
</div>
</form>
<?
$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<count($entidades); $j++) {
//$query = "SELECT month, SUM(value) AS total, COUNT(*) as count FROM conta WHERE eid = ".$entidades[$j][id]." GROUP BY month ORDER BY month";
$querymais = "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";
$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;
?>
<br />
<h3><u><?=$types[$i]?></u></h3>
<table cellpadding="2" cellspacing="0" border="1">
<tr>
<th width="130">Nome</th>
<?
$ms = 1; $me = 12;
if($limitmonth != "") {
$ms = $cmonth - $mdiff;
$me = $cmonth + $mdiff;
if($ms < 1) $ms = 1;
if($me > 12) $me = 12;
}
for($m=$ms; $m<=$me; $m++) { ?>
<th width="200" colspan="2"><?=$months[$m]?></th>
<? } ?>
<th width="80" bgcolor="#999999">Total</th>
<th width="90"><div align="center">Responsabilidade</div></th>
<th width="90">C.C.</th>
</tr>
<?
for($j=0; $j<count($tabela[$i]); $j++) {
$ent = $tabela[$i][$j];
?>
<tr>
<td><a href="insert.php?eid=<?=$ent[id]?>"><?=$ent[name]?></a></td>
<?
$total = 0;
$total_c = false;
$linkmais_c = false;
$linkmenos_c = false;
for($k=$ms; $k<=$me; $k++) {
if($ent['mais']['count'][$k] > 0) {
$total_c = true;
$total_absoluto_c = true;
$linkmais_c = true;
}
if($ent['menos']['count'][$k] > 0) {
$total_c = true;
$total_absoluto_c = true;
$linkmenos_c = true;
}
$total_meses[$k]['mais'] += $ent['mais']['mes'][$k];
$total_meses[$k]['maiscount'] += $ent['mais']['count'][$k];
$total_meses[$k]['count'] += $ent['mais']['count'][$k];
$total_meses[$k]['menos'] += $ent['menos']['mes'][$k];
$total_meses[$k]['menoscount'] += $ent['menos']['count'][$k];
$total_meses[$k]['count'] += $ent['menos']['count'][$k];
$total += $ent['mais']['mes'][$k] + $ent['menos']['mes'][$k];
?>
<td style="width: 100px" align="right">
<? if($ent['mais']['count'][$k] > 0) { ?>
<a href="detail.php?type=<?=$i?>&eid=<?=$ent[id]?>&mes=<?=$k?>&show=mais">
<? } ?>
<?=formatar($ent['mais']['mes'][$k])?>
<? if($ent['mais']['count'][$k] > 0) { ?>
</a>
<? } ?>
</td>
<td width="100" align="right">
<? if($ent['menos']['count'][$k] > 0) { ?>
<a href="detail.php?type=<?=$i?>&eid=<?=$ent[id]?>&mes=<?=$k?>&show=menos">
<? } ?>
<?=formatar($ent['menos']['mes'][$k])?>
<? if($ent['menos']['count'][$k] > 0) { ?>
</a>
<? } ?>
</td>
<?
}
$total_info2 += $ent['mais']['mes'][13] + $ent['menos']['mes'][13];
$total_info2_c[$k] = true;
if($contas[$z][count] > 0) {
$total_absoluto_c = true;
}
?>
<td align="right" bgcolor="#999999">
<? if($total_c) { ?>
<a href="detail.php?type=<?=$i?>&eid=<?=$ent[id]?><?=$limitmonthurl?>">
<? } ?>
<?=formatar($total)?>
<? if($total_c) { ?>
</a>
<? } ?>
</td>
<td align="right">
<? if($ent['mais']['count']['13'] > 0) { ?>
<a href="detail_info.php?type=<?=$i?>&eid=<?=$ent[id]?>">
<? } ?>
<?=formatar($ent['mais']['mes'][13] + $ent['menos']['mes'][13])?>
<? if($ent['mais']['count']['13'] > 0) { ?>
</a>
<? } ?>
</td>
<td align="center"> <?=$ent[info1]?></td>
<?
}
$total_absoluto = 0;
?>
</tr>
<tr>
<td>Total discrim.</td>
<?
for($z=$ms; $z<=$me; $z++) {
$total_absoluto += $total_meses[$z]['mais'] + $total_meses[$z]['menos'];
?>
<td align="right">
<? if($total_meses[$z]['maiscount'] != 0) { ?><a href="detail.php?type=<?=$i?>&mes=<?=$z?>&show=mais"><? } ?>
<?=formatar($total_meses[$z]['mais'])?>
<? if($total_meses[$z]['maiscount'] != 0) { ?></a><? } ?>
</td>
<td align="right">
<? if($total_meses[$z]['menoscount'] != 0) { ?><a href="detail.php?type=<?=$i?>&mes=<?=$z?>&show=menos"><? } ?>
<?=formatar($total_meses[$z]['menos'])?>
<? if($total_meses[$z]['menoscount'] != 0) { ?></a><? } ?>
</td>
<? } ?>
<td align="right" bgcolor="#999999">
<? if($total_absoluto_c) { ?><a href="detail.php?type=<?=$i?><?=$limitmonthurl?>"><? } ?>
<?=formatar($total_absoluto)?>
<? if($total_absoluto_c) { ?></a><? } ?> </td>
<td align="right">
<? if($total_info2_c[$j]) { ?>
<a href="detail_info.php?type=<?=$i?>">
<? } ?>
<?=formatar($total_info2)?>
<? if($total_info2_c[$j]) { ?>
</a>
<? } ?>
</td>
<td align="center"></td>
</tr>
<tr>
<td>Total</td>
<?
for($z=$ms; $z<=$me; $z++) {
?>
<td align="right" colspan="2">
<? if($total_meses[$z]['count'] != 0) { ?><a href="detail.php?type=<?=$i?>&mes=<?=$z?>"><? } ?>
<?=formatar($total_meses[$z]['mais']+$total_meses[$z]['menos'])?>
<? if($total_meses[$z]['count'] != 0) { ?></a><? } ?>
</td>
<? } ?>
<td align="right" bgcolor="#999999">
<? if($total_absoluto_c) { ?><a href="detail.php?type=<?=$i?>"><? } ?>
<?=formatar($total_absoluto)?>
<? if($total_absoluto_c) { ?></a><? } ?> </td>
<td align="right">
<? if($total_info2_c[$j]) { ?>
<a href="detail_info.php?type=<?=$i?>">
<? } ?>
<?=formatar($total_info2)?>
<? if($total_info2_c[$j]) { ?>
</a>
<? } ?>
</td>
<td align="center"></td>
</tr>
</table>
<?
}
}
}
?>
<div align="center" id="footer">
<strong><a href="index.php" title="Página Principal">Página Principal</a></strong> |
<strong><a href="contactos.php" title="Ajuda">Contactos</a></strong> | <strong><a href="ajuda.php">Ajuda</a></strong></a></strong> | <strong><a href="<?=$site_url?>/users/logout.php" title="Terminar Sessão">Terminar Sessão</a></strong></div>
<br />
<?
include "$site_dir/lib/bottom.inc.php";
?>