Created
September 3, 2019 00:22
-
-
Save FredAzevedo/5ef88f04f6f284289433550135eefdbd to your computer and use it in GitHub Desktop.
DashboardFinanceiroView.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class DashboardFinanceiroView extends TPage | |
{ | |
public function __construct($param) | |
{ | |
parent::__construct(); | |
//TPage::include_css('app/resources/catalog.css'); | |
$this->html = new THtmlRenderer('app/view/financeiro/dashboardFinanceiro.html'); | |
try | |
{ | |
if(isset($param['filtro_inicio'])){ | |
$filtro_inicio = $param['filtro_inicio']; | |
} | |
if(isset($param['filtro_fim'])){ | |
$filtro_fim = $param['filtro_fim']; | |
} | |
$unit_id = TSession::getValue('userunitid'); | |
TTransaction::open('sample'); | |
$conexao = TTransaction::get(); | |
$replaces = []; | |
$replaces['contadorDia'] = $this->getNumeroContasReceberHoje($conexao); | |
$replaces['valorDia'] = number_format($this->getValorContasReceberHoje($conexao), 2, ',','.'); | |
$replaces['contadorMes'] = $this->getNumeroContasReceberEsseMes($conexao); | |
$replaces['valorMes'] = number_format($this->getValorContasReceberEsseMes($conexao), 2, ',','.'); | |
$replaces['contadorInadiplencia'] = $this->getNumeroContasInadiplentes($conexao); | |
$replaces['valorInadiplencia'] = number_format($this->getValorContasInadiplentes($conexao), 2, ',','.'); | |
$replaces['contadorCPmes'] = $this->getNumeroContasAPagarMes($filtro_inicio, $filtro_fim, $unit_id, $conexao); | |
$replaces['valorCPmes'] = number_format($this->getValorContasAPagarMes($filtro_inicio, $filtro_fim, $unit_id, $conexao), 2, ',','.'); | |
$replaces['contadorCPdia'] = $this->getNumeroContasPagarHoje($conexao); | |
$replaces['valorCPdia'] = number_format($this->getValorContasPagarHoje($conexao), 2, ',','.'); | |
$replaces['valorCPAtrasadas'] = number_format($this->getValorDespesasAtraso($conexao), 2, ',','.'); | |
$replaces['contadorCPAtrasadas'] = $this->getNumeroDespesasAtraso($conexao); | |
$conect = TTransaction::get(); | |
$query = $conect->prepare("SELECT b.nome_banco, SUM(sb.valor) as valor from saldos_bancarios sb | |
inner join conta_bancaria cb ON (cb.id = sb.conta_bancaria_id) | |
inner join banco b ON (b.id = cb.banco_id) | |
where sb.unit_id = ? group by 1"); | |
$query->execute(array(TSession::getValue('userunitid'))); | |
$result = $query->fetchAll(); | |
$count = '0.00'; | |
foreach($result as $row){ | |
$banco = $row['nome_banco']; | |
$valor = $row['valor']; | |
$count = $count + $valor; | |
$value = number_format($valor,2,',','.'); | |
$arrayDeContas[] = ['banco'=>$banco, 'value'=>$value ]; | |
} | |
if(!empty($arrayDeContas)) | |
{ | |
$replaces['SALDOS'] = $arrayDeContas; | |
} | |
$countSaldototais = $count; | |
$replaces['countSaldototais'] = number_format($countSaldototais,2,',','.'); | |
$this->html->enableSection('main',$replaces); | |
TTransaction::close(); | |
} | |
catch (Exception $e) | |
{ | |
new TMessage('error', $e->getMessage()); | |
} | |
$vbox = new TVBox; | |
$vbox->style = 'width: 100%'; | |
$vbox->add(new TXMLBreadCrumb('menu.xml','DashboardFinanceiroView')); | |
$vbox->add($this->html); | |
parent::add($vbox); | |
} | |
public function getNumeroContasAPagarMes($filtro_inicio, $filtro_fim, $unit_id, $conexao){ | |
$resultado = $conexao->query("SELECT COUNT(valor) as despesa_mes FROM conta_pagar WHERE data_vencimento between ". "'".$filtro_inicio."'"." and "."'".$filtro_fim."'"." AND baixa='N' AND unit_id = ".$unit_id.";"); | |
foreach ($resultado as $row) | |
return $row['despesa_mes']; | |
} | |
public function getValorContasAPagarMes($filtro_inicio, $filtro_fim, $unit_id, $conexao){ | |
$resultado = $conexao->query("SELECT SUM(valor) as despesa_mes FROM conta_pagar WHERE data_vencimento between ". "'".$filtro_inicio."'"." and "."'".$filtro_fim."'"." AND baixa='N' AND unit_id = ".$unit_id.";"); | |
foreach ($resultado as $row) | |
return $row['despesa_mes']; | |
} | |
public function getNumeroContasReceberHoje($conexao){ | |
$sthContDia = $conexao->prepare("SELECT COUNT(valor) as valor_dia FROM conta_receber WHERE data_vencimento = CURDATE( ) AND baixa = 'N' AND unit_id = ? "); | |
$sthContDia->execute([TSession::getValue('userunitid')]); | |
$result4 = $sthContDia->fetchAll(); | |
foreach ($result4 as $row4) | |
return $contadorDia = $row4['valor_dia']; | |
} | |
public function getValorContasReceberHoje($conexao){ | |
$sthContDia = $conexao->prepare("SELECT SUM(valor) as valor_dia FROM conta_receber WHERE data_vencimento = CURDATE( ) AND baixa = 'N' AND unit_id = ? "); | |
$sthContDia->execute([TSession::getValue('userunitid')]); | |
$result4 = $sthContDia->fetchAll(); | |
foreach ($result4 as $row4) | |
return $contadorDia = $row4['valor_dia']; | |
} | |
public function getNumeroContasReceberEsseMes($conexao){ | |
$sthContMes = $conexao->prepare("SELECT COUNT(valor) as valor_mes FROM conta_receber WHERE MONTH(data_vencimento) = MONTH(NOW()) AND baixa = 'N' AND unit_id = ? "); | |
$sthContMes->execute([TSession::getValue('userunitid')]); | |
$result2 = $sthContMes->fetchAll(); | |
foreach ($result2 as $row2) | |
return $contadorMes = $row2['valor_mes']; | |
} | |
public function getValorContasReceberEsseMes($conexao){ | |
$sthVM = $conexao->prepare("SELECT SUM(valor) as valor_mes FROM conta_receber WHERE MONTH(data_vencimento) = MONTH(NOW()) AND baixa = 'N' AND unit_id = ? "); | |
$sthVM->execute([TSession::getValue('userunitid')]); | |
$result1 = $sthVM->fetchAll(); | |
foreach ($result1 as $row1) | |
return $valorMes = $row1['valor_mes']; | |
} | |
public function getNumeroContasInadiplentes($conexao){ | |
$unit_id = TSession::getValue('userunitid'); | |
$resultado = $conexao->query("SELECT COUNT(valor) as valor FROM conta_receber WHERE data_vencimento < NOW() AND baixa='N' AND unit_id = ".$unit_id.";"); | |
foreach ($resultado as $row) | |
return $row['valor']; | |
} | |
public function getValorContasInadiplentes($conexao){ | |
$unit_id = TSession::getValue('userunitid'); | |
$resultado = $conexao->query("SELECT SUM(valor) as valor FROM conta_receber WHERE data_vencimento < NOW() AND baixa='N' AND unit_id = ".$unit_id.";"); | |
foreach ($resultado as $row) | |
return $row['valor']; | |
} | |
public function getNumeroContasPagarHoje($conexao){ | |
$sthContDia = $conexao->prepare("SELECT COUNT(valor) as valor_dia FROM conta_pagar WHERE data_vencimento = CURDATE( ) AND baixa = 'N' AND unit_id = ? "); | |
$sthContDia->execute([TSession::getValue('userunitid')]); | |
$result4 = $sthContDia->fetchAll(); | |
foreach ($result4 as $row4) | |
return $contadorDia = $row4['valor_dia']; | |
} | |
public function getValorContasPagarHoje($conexao){ | |
$sthContDia = $conexao->prepare("SELECT SUM(valor) as valor_dia FROM conta_pagar WHERE data_vencimento = CURDATE( ) AND baixa = 'N' AND unit_id = ? "); | |
$sthContDia->execute([TSession::getValue('userunitid')]); | |
$result4 = $sthContDia->fetchAll(); | |
foreach ($result4 as $row4) | |
return $contadorDia = $row4['valor_dia']; | |
} | |
public function getNumeroDespesasAtraso($conexao){ | |
//Select em conta a pagar para trazer QTD de valores atrasados | |
$sthContCPAtrasadas = $conexao->prepare("SELECT COUNT(valor) as valor FROM conta_pagar WHERE data_vencimento < CURDATE( ) AND baixa = 'N' AND unit_id = ? "); | |
$sthContCPAtrasadas->execute([TSession::getValue('userunitid')]); | |
$resultCP6 = $sthContCPAtrasadas->fetchAll(); | |
foreach ($resultCP6 as $rowD6) | |
return $contadorCPAtrasadas = $rowD6['valor']; | |
} | |
public function getValorDespesasAtraso($conexao){ | |
//Select em conta a pagar para trazer QTD de valores atrasados | |
$sthContCPAtrasadas = $conexao->prepare("SELECT SUM(valor) as valor FROM conta_pagar WHERE data_vencimento < CURDATE( ) AND baixa = 'N' AND unit_id = ? "); | |
$sthContCPAtrasadas->execute([TSession::getValue('userunitid')]); | |
$resultCP6 = $sthContCPAtrasadas->fetchAll(); | |
foreach ($resultCP6 as $rowD6) | |
return $contadorCPAtrasadas = $rowD6['valor']; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment