$totalMensal[12] = 0; $totalMensal[13] = 0; // TOTAL DA UO foreach ($uoUcs as $uoUcId) { $uc = new UnidadeConsumidora($uoUcId); $tpl->RGI = $uc->get('rgi'); $tpl->UCNOME = $uc->getNome(); $tpl->UCSTATUS = "<br>" . $uc->getAtivoText(); $tpl->UCTIPO = $uc->getTipoNome(); $tpl->UCEMPRESA = $uc->get('empresa')->getNome(); $tpl->UCCHAVE = SHA1($uc->get('id')); $tipo = $uc->get('tipo'); /********************************** MOSTRAR PAGAMENTOS MENSAIS **********************************/ $pagMensal = $uc->getExercicioMensal($anoAtual); $index = 1; $totalUc = 0; for ($i = 1; $i <= 12; $i++) { if (array_key_exists($index, $pagMensal) && $pagMensal[$index]['mes_ref'] == $i) { $val = $pagMensal[$index]['valor']; $tpl->UCMESVAL = tratarValor($val, true); $index++; } else { $val = 0; $tpl->UCMESVAL = ""; } $totalUc += $val; $totalMensal[$i] += $val; $totalMensal[13] += $val; $tpl->block('EACH_MESUC');
$id = mysql_fetch_array($queryVerif)['id']; $uc = new UnidadeConsumidora($id); /********************************* MOSTRAR INFORMAÇÕES DO RELATÓRIO *********************************/ $hasConsumo = $uc->hasConsumo(); if ($hasConsumo) { $tpl->block('SHOW_HEADER_CONS'); } $distinct_sql = "SELECT DISTINCT(ano_ref) FROM daee_notas WHERE uc = {$id} ORDER BY ano_ref ASC"; $distinct_query = mysql_query($distinct_sql); $exArray; $exArrayIndex = 0; while ($ano = mysql_fetch_array($distinct_query)) { $tpl->ANO = $ano = $ano['ano_ref']; $exercicio = $uc->getExercicioMensal($ano); $tpl->MESESPG = $meses_count = count($exercicio); $totCons = $totPago = 0; foreach ($exercicio as $mes) { if ($hasConsumo) { $totCons += $mes['consumo']; } $totPago += $mes['valor']; } if ($hasConsumo) { $exArray[$exArrayIndex]['cons'] = $totCons / $meses_count; $varCons = $exArrayIndex > 0 ? round(($exArray[$exArrayIndex]['cons'] / $exArray[$exArrayIndex - 1]['cons'] - 1) * 100) / 100 : 0; $tpl->TOTCONS = tratarValor($totCons, false); $tpl->MEDCONS = tratarValor($exArray[$exArrayIndex]['cons'], false); $tpl->VARCONS = getPorcentagem($varCons * 100, true); $tpl->block('SHOW_CONS');
$numMeses = 12 * (Date('Y') - $start) + Date('n'); $ucTipo = new UnidadeConsumidora(0, null, null, null, null, null, null, null, null, null, null, $svc); $tpl->TIPONOME = $ucTipo->getTipoNome(); $ucids = $ucTipo->getMesmoTipoPorUO($id); $tpl->UCQTD = count($ucids); $tpl->RGISINSTA = ""; /********************************* MONTAR ARRAY COM TODOS OS VALORES **********************************/ foreach ($ucids as $ucid) { $uc = new UnidadeConsumidora($ucid); $tpl->RGISINSTA .= "<br />" . $uc->getAtivoText() . " - <a href='udd_ucDetalhes.php?chave=" . sha1($uc->get('id')) . "'>"; $tpl->RGISINSTA .= $uc->get('rgi') . " - " . $uc->getNome() . "</a> "; //. $uc->getVariacaoDoMes(1, 2013) $tpl->TIPOCONS = $uc->getTipoMedida(); $exerc_atu = $uc->getExercicioMensal($start); $exerc_ant = $uc->getExercicioMensal($start - 1); $mes_atu = Date('n'); $tpl->ANO_ANT = $start - 1; $tpl->ANO = $start; $tpl->MED_LAB = 'Média ' . $start; for ($i = 1; $i <= 12; $i++) { if (array_key_exists($i, $exerc_ant)) { $ucArray[$ucid][$start - 1]['consumo'][$i] = $exerc_ant[$i]['consumo']; $ucArray[$ucid][$start - 1]['valor'][$i] = $exerc_ant[$i]['valor']; } else { $ucArray[$ucid][$start - 1]['consumo'][$i] = 0; $ucArray[$ucid][$start - 1]['valor'][$i] = 0; } if (array_key_exists($i, $exerc_atu)) { $ucArray[$ucid][$start]['consumo'][$i] = $exerc_atu[$i]['consumo'];
$tpl->GETANO = $getAno; $uo = new Unidade($uoid); $consChart = array(); if ($uo->getSigla() != "") { $ucs = $uo->getAllUcs(); $tpl->UONOME = $uo->getSigla() . " - " . $uo->getNome(); $tpl->UOFORMNOME = $uo->getSigla() . " | " . $uo->getNome(); $tpl->UOFORMID = $uoid; $tpl->block('EACHUOFORM'); $arrayUcs; foreach ($ucs as $ucid) { $uc = new UnidadeConsumidora($ucid); $arrayUcs[$uc->get('tipo')][$uc->get('id')]['rgi'] = $uc->get('rgi'); $arrayUcs[$uc->get('tipo')][$uc->get('id')]['nome'] = $uc->getNome(); $arrayUcs[$uc->get('tipo')][$uc->get('id')]['empresa'] = $uc->get('empresa')->getNome(); $arrayUcs[$uc->get('tipo')][$uc->get('id')]['mensal'] = $uc->getExercicioMensal($getAno); } $totalGeral[1] = 0; $totalGeral[2] = 0; $totalGeral[3] = 0; $totalGeral[4] = 0; $totalGeral[5] = 0; $totalGeral[6] = 0; $totalGeral[7] = 0; $totalGeral[8] = 0; $totalGeral[9] = 0; $totalGeral[10] = 0; $totalGeral[11] = 0; $totalGeral[12] = 0; foreach ($arrayUcs as $tipos => $ucs) { $temConsumo = $relatorio->temConsumo($tipos);
MOSTRAR INFORMAÇÕES DO RELATÓRIO *********************************/ $rel = new Relatorio(); $cores = $rel->cores; $tpl->UCCOLOR = $cores[$uc->get('tipo')]; $tpl->ANO = $anoAtual; $tpl->ANO_ANT = $anoAnterior; $tpl->TIPOCONS = $uc->getTipoMedida(); $tpl->RGI = $uc->get('rgi'); $tpl->NOME = $uc->getNome(); $tpl->TIPONOME = $uc->getTipoNome(); $tpl->EMPRESA = $uc->get('empresa')->getNome() . " CNPJ " . $uc->get('empresa')->transformCnpj($uc->get('empresa')->get('cnpj')); $tpl->ENDERECO = $uc->getEndereco() . " - " . $uc->getCidadeNome(); $tpl->CONTRATO = $contrato->geraNome(); $tpl->UNIDADE = $uc->get('uo')->getSigla(); $eachMes = $uc->getExercicioMensal($anoAtual); $mesConsTotal = 0; $mesPagoTotal = 0; $z = 1; $somaAnt = $somaPost = 0; foreach ($eachMes as $mes) { $mesConsTotal += $mes['consumo']; $mesPagoTotal += $mes['valor']; $tpl->MESSOMA = strtoupper(getMesNome($mes['mes_ref'])); $tpl->CONSSOMA = tratarValor($mes['consumo']); $tpl->PAGOSOMA = tratarValor($mes['valor'], true); if ($z > 1 && $z <= count($eachMes)) { $divisor = $eachMes[$z - 1]['valor'] == 0 ? 1 : $eachMes[$z - 1]['valor']; $varia = $eachMes[$z]['valor'] * 100 / $divisor - 100; $tpl->VARIASOMA = getPorcentagem($varia, true); } else {