Ejemplo n.º 1
0
 private Object[] loadReceber2(
     Integer codempvd, Integer codfilialvd, String tipovenda, Integer codvenda)
     throws SQLException {
   Object[] result = null;
   StringBuilder sql = new StringBuilder();
   sql.append("select codemp, codfilial, codrec");
   sql.append(", (select first 1 ir.dtvencitrec ");
   sql.append(" from fnitreceber ir ");
   sql.append(
       " where ir.codemp=rc.codemp and ir.codfilial=rc.codfilial and ir.codrec=rc.codrec and ir.statusitrec = 'R1' ");
   sql.append(" order by ir.dtvencitrec) ");
   sql.append(" emaberto ");
   sql.append(", (select first 1 ir.dtvencitrec - ir.dtliqitrec ");
   sql.append(" from fnitreceber ir ");
   sql.append(
       " where ir.codemp=rc.codemp and ir.codfilial=rc.codfilial and ir.codrec=rc.codrec and ir.statusitrec = 'RP' ");
   sql.append(" order by ir.dtvencitrec) ");
   sql.append(" pago ");
   sql.append(
       ", (select max( case when ir.dtvencitrec<coalesce(ir.dtliqitrec, cast('now' as date)) ");
   sql.append(" then coalesce(ir.dtliqitrec, cast('now' as date)) - ir.dtvencitrec else 0 end ) ");
   sql.append(" from fnitreceber ir ");
   sql.append(" where ir.codemp=rc.codemp and ir.codfilial=rc.codfilial and ir.codrec=rc.codrec ");
   sql.append(" ) ");
   sql.append(" atraso ");
   sql.append("from fnreceber rc ");
   sql.append("where rc.codempva=? and rc.codfilialva=? and rc.tipovenda=? and rc.codvenda=?");
   PreparedStatement ps = getConn().prepareStatement(sql.toString());
   int param = 1;
   ps.setInt(param++, codempvd);
   ps.setInt(param++, codfilialvd);
   ps.setString(param++, tipovenda);
   ps.setInt(param++, codvenda);
   ResultSet rs = ps.executeQuery();
   if (rs.next()) {
     result = new Object[RESULT_RECEBER2.values().length];
     result[RESULT_RECEBER2.EMABERTO.ordinal()] = rs.getDate(RESULT_RECEBER2.EMABERTO.name());
     result[RESULT_RECEBER2.PAGO.ordinal()] = new Integer(rs.getInt(RESULT_RECEBER2.PAGO.name()));
     result[RESULT_RECEBER2.ATRASO.ordinal()] =
         new Integer(rs.getInt(RESULT_RECEBER2.ATRASO.name()));
   }
   return result;
 }