public function consultarSaldoContaBancaria(ContaBancaria $obj) { $douValorTotalEntrada = 0; $douValorTotalSaida = 0; //valor inicial da conta $strSQL = "SELECT COB_SaldoInicial FROM FIN_COB_CONTAS_BANCARIAS "; $strSQL .= "WHERE COB_ID = " . $obj->getId() . " "; $arrStrDados = Db::getInstance()->select($strSQL); if ($arrStrDados != null) { if (count($arrStrDados) > 0) { if (trim($arrStrDados[0]["COB_SaldoInicial"]) != "") { $douValorTotalEntrada += $arrStrDados[0]["COB_SaldoInicial"]; } } } //entradas fluxo de caixa $strSQL = "SELECT SUM(LCA_Valor) AS LCA_ValorTotal FROM FIN_LCA_LANCAMENTOS_CAIXA WHERE COB_ID = " . $obj->getId() . " "; $strSQL .= " AND LCA_Tipo = 'E' "; $arrStrDados = Db::getInstance()->select($strSQL); if ($arrStrDados != null) { if (count($arrStrDados) > 0) { if (trim($arrStrDados[0]["LCA_ValorTotal"]) != "") { $douValorTotalEntrada += $arrStrDados[0]["LCA_ValorTotal"]; } } } // saidas fluxo de caixa $strSQL = "SELECT SUM(LCA_Valor) AS LCA_ValorTotal FROM FIN_LCA_LANCAMENTOS_CAIXA WHERE COB_ID = " . $obj->getId() . " "; $strSQL .= " AND LCA_Tipo = 'S' "; $arrStrDados = Db::getInstance()->select($strSQL); if ($arrStrDados != null) { if (count($arrStrDados) > 0) { if (trim($arrStrDados[0]["LCA_ValorTotal"]) != "") { $douValorTotalSaida += $arrStrDados[0]["LCA_ValorTotal"]; } } } // entradas contas a pagar $strSQL = "SELECT SUM(P.PCL_Valor) AS PCL_ValorTotal FROM FIN_PCL_PARCELAS AS P "; $strSQL .= "INNER JOIN FIN_CON_CONTAS AS C ON (C.CON_ID=P.CON_ID) "; $strSQL .= "INNER JOIN FIN_PLA_PLANOS_CONTAS AS PC ON (PC.PLA_ID=C.PLA_ID) "; $strSQL .= "WHERE P.COB_ID = " . $obj->getId() . " "; $strSQL .= "AND PC.PLA_Movimentacao = 'E' "; $arrStrDados = Db::getInstance()->select($strSQL); if ($arrStrDados != null) { if (count($arrStrDados) > 0) { if (trim($arrStrDados[0]["PCL_ValorTotal"]) != "") { $douValorTotalEntrada += $arrStrDados[0]["PCL_ValorTotal"]; } } } // saidas contas a pagar $strSQL = "SELECT SUM(P.PCL_Valor) AS PCL_ValorTotal FROM FIN_PCL_PARCELAS AS P "; $strSQL .= "INNER JOIN FIN_CON_CONTAS AS C ON (C.CON_ID=P.CON_ID) "; $strSQL .= "INNER JOIN FIN_PLA_PLANOS_CONTAS AS PC ON (PC.PLA_ID=C.PLA_ID) "; $strSQL .= "WHERE P.COB_ID = " . $obj->getId() . " "; $strSQL .= "AND PC.PLA_Movimentacao = 'S' "; $arrStrDados = Db::getInstance()->select($strSQL); if ($arrStrDados != null) { if (count($arrStrDados) > 0) { if (trim($arrStrDados[0]["PCL_ValorTotal"]) != "") { $douValorTotalSaida += $arrStrDados[0]["PCL_ValorTotal"]; } } } // Contribuições $strSQL = "SELECT SUM(CTB_Valor) AS CTB_ValorTotal FROM FIN_CTB_CONTRIBUICOES AS C "; $strSQL .= "INNER JOIN FIN_PLA_PLANOS_CONTAS AS PC ON (PC.PLA_ID=C.PLA_ID) "; $strSQL .= "WHERE C.COB_ID = " . $obj->getId() . " "; $strSQL .= " AND PC.PLA_Movimentacao = 'E' "; $arrStrDados = Db::getInstance()->select($strSQL); if ($arrStrDados != null) { if (count($arrStrDados) > 0) { if (trim($arrStrDados[0]["CTB_ValorTotal"]) != "") { $douValorTotalEntrada += $arrStrDados[0]["CTB_ValorTotal"]; } } } // Transferencias Entradas $strSQL = "SELECT SUM(TRC_Valor) AS TRC_ValorTotal FROM FIN_TRC_TRANSFERENCIAS_CONTAS "; $strSQL .= "WHERE COB_Para_ID = " . $obj->getId() . " "; $arrStrDados = Db::getInstance()->select($strSQL); if ($arrStrDados != null) { if (count($arrStrDados) > 0) { if (trim($arrStrDados[0]["TRC_ValorTotal"]) != "") { $douValorTotalEntrada += $arrStrDados[0]["TRC_ValorTotal"]; } } } // Transferencias Saidas $strSQL = "SELECT SUM(TRC_Valor) AS TRC_ValorTotal FROM FIN_TRC_TRANSFERENCIAS_CONTAS "; $strSQL .= "WHERE COB_De_ID = " . $obj->getId() . " "; $arrStrDados = Db::getInstance()->select($strSQL); if ($arrStrDados != null) { if (count($arrStrDados) > 0) { if (trim($arrStrDados[0]["TRC_ValorTotal"]) != "") { $douValorTotalSaida += $arrStrDados[0]["TRC_ValorTotal"]; } } } return $douValorTotalEntrada - $douValorTotalSaida; }