fixes bug#23027
dev: VALDEVIR qua: Juliane git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Web/trunk/ventaboletos@108790 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
bc09334aa8
commit
a534b447e7
|
@ -5,21 +5,20 @@ import java.sql.ResultSet;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.rjconsultores.ventaboletos.enums.EnumTipoVenda;
|
||||
import com.rjconsultores.ventaboletos.relatorios.utilitarios.ArrayDataSource;
|
||||
import com.rjconsultores.ventaboletos.relatorios.utilitarios.Relatorio;
|
||||
import com.rjconsultores.ventaboletos.web.utilerias.NamedParameterStatement;
|
||||
|
||||
public class RelatorioEstoque extends Relatorio {
|
||||
|
||||
public RelatorioEstoque(Map<String, Object> parametros, Connection conexao) throws Exception
|
||||
{
|
||||
public RelatorioEstoque(Map<String, Object> parametros, Connection conexao) throws Exception {
|
||||
super(parametros, conexao);
|
||||
|
||||
this.setCustomDataSource(new ArrayDataSource(this) {
|
||||
|
||||
public void initDados() throws Exception {
|
||||
Connection conexao = this.relatorio.getConexao();
|
||||
Map<String, Object> parametros = this.relatorio.getParametros();
|
||||
String sql = getSql();
|
||||
|
||||
NamedParameterStatement stmt = new NamedParameterStatement(conexao, sql);
|
||||
|
@ -28,12 +27,15 @@ public class RelatorioEstoque extends Relatorio {
|
|||
|
||||
while (rset.next()) {
|
||||
Map<String, Object> dataResult = new HashMap<String, Object>();
|
||||
|
||||
String formInicio = rset.getString("tipoVenta").equals(EnumTipoVenda.TPV_MANUAL.getId().toString()) ? rset.getString("ultimoFolioCaja") : rset.getString("forminicial");
|
||||
|
||||
dataResult.put("aidf", rset.getString("aidf"));
|
||||
dataResult.put("empresa", rset.getString("nombempresa"));
|
||||
dataResult.put("estacao", rset.getString("estacao"));
|
||||
dataResult.put("agencia", rset.getString("nombpuntoventa"));
|
||||
dataResult.put("serie", rset.getString("serie"));
|
||||
dataResult.put("forminicio", rset.getString("forminicial"));
|
||||
dataResult.put("forminicio", formInicio);
|
||||
dataResult.put("formfinal", rset.getString("formfinal"));
|
||||
dataResult.put("estado", rset.getString("nombestado"));
|
||||
dataResult.put("tipo", rset.getString("tipo"));
|
||||
|
@ -51,33 +53,62 @@ public class RelatorioEstoque extends Relatorio {
|
|||
|
||||
private String getSql() {
|
||||
StringBuilder sql = new StringBuilder();
|
||||
sql.append(" select dab.aidf_id as aidf, e.nombempresa, p.nombpuntoventa, dab.NUMSERIEPREIMPRESA as serie, es.descestacion as estacao, tp.desctipo as tipo, ");
|
||||
sql.append(" case when dab.STATUSOPERACION = 0 then dab.NUMFOLIOINICIAL else coalesce(fp.FOLIOPREIMPRESO,dab.NUMFOLIOINICIAL) end as forminicial, dab.NUMFOLIOFINAL as formfinal, ");
|
||||
sql.append(" est.nombestado, ar.descarticulo ");
|
||||
sql.append(" from abasto_boleto ab ");
|
||||
sql.append(" inner join empresa e on e.empresa_id = ab.empresa_id and ab.ACTIVO = 1 ");
|
||||
sql.append(" inner join det_abasto_boleto dab on dab.abastoboleto_id = ab.abastoboleto_id and dab.ACTIVO = 1 ");
|
||||
sql.append(" inner join punto_venta p on p.puntoventa_id = ab.puntoventa_id and p.ACTIVO = 1 ");
|
||||
sql.append(" left join TIPO_PTOVTA tp on tp.TIPOPTOVTA_ID = p.TIPOPTOVTA_ID and tp.ACTIVO = 1 ");
|
||||
sql.append(" inner join estacion es on es.ESTACION_ID = ab.ESTACION_ID ");
|
||||
sql.append(" inner join ARTICULO ar on ar.ARTICULO_ID = ab.ARTICULO_ID ");
|
||||
sql.append(" left join FOLIO_PREIMPRESO fp on fp.AIDF_ID = dab.AIDF_ID and fp.EMPRESA_ID = e.EMPRESA_ID and fp.ESTACION_ID = ab.ESTACION_ID and fp.activo = 1 ");
|
||||
sql.append(" inner join aidf ai on ai.aidf_id =dab.aidf_id ");
|
||||
sql.append(" inner join estado est on est.estado_id = ai.ESTADO_ID ");
|
||||
sql.append("SELECT dab.aidf_id AS aidf, ");
|
||||
sql.append(" e.nombempresa, ");
|
||||
sql.append(" p.nombpuntoventa, ");
|
||||
sql.append(" dab.NUMSERIEPREIMPRESA AS serie, ");
|
||||
sql.append(" es.descestacion AS estacao, ");
|
||||
sql.append(" tp.desctipo AS tipo, ");
|
||||
|
||||
sql.append(" where ");
|
||||
sql.append(" dab.statusoperacion in (0,1) and dab.activo = 1 and ab.activo = 1 ");
|
||||
if(parametros.get("EMPRESA_ID") != null){
|
||||
sql.append(" and e.empresa_id = ").append(parametros.get("EMPRESA_ID"));
|
||||
sql.append(" ( case ");
|
||||
sql.append(" when ");
|
||||
sql.append(" dab.STATUSOPERACION = 0 ");
|
||||
sql.append(" then ");
|
||||
sql.append(" dab.NUMFOLIOINICIAL");
|
||||
sql.append(" else ");
|
||||
sql.append(" coalesce(fp.FOLIOPREIMPRESO,dab.NUMFOLIOINICIAL) ");
|
||||
sql.append(" end ) AS forminicial,");
|
||||
sql.append(" dab.NUMFOLIOFINAL AS formfinal, ");
|
||||
|
||||
sql.append(" ( SELECT ");
|
||||
sql.append(" MAX(to_number(c.numfoliopreimpreso)) + 1 AS numfoliopreimpreso");
|
||||
sql.append(" FROM Caja c");
|
||||
sql.append(" WHERE ( ( c.numseriepreimpresa = dab.numseriepreimpresa ");
|
||||
sql.append(" AND c.aidf_id = dab.aidf_id ) ");
|
||||
sql.append(" OR ( c.numseriepreimpresa IS NULL ");
|
||||
sql.append(" AND dab.numseriepreimpresa IS NULL ) ) ");
|
||||
sql.append(" AND to_number(c.numfoliopreimpreso) BETWEEN dab.numfolioinicial AND dab.numfoliofinal ");
|
||||
sql.append(" AND ( c.indreimpresion = 0 ");
|
||||
sql.append(" OR ( c.indreimpresion = 1 AND c.indstatusboleto = 'E' ) ) ");
|
||||
sql.append(" AND c.marca_id = ab.empresa_id ");
|
||||
sql.append(" ) AS ultimoFolioCaja, ");
|
||||
|
||||
sql.append(" ar.articulo_id AS tipoventa,");
|
||||
sql.append(" ar.descarticulo, ");
|
||||
sql.append(" est.nombestado ");
|
||||
sql.append(" FROM abasto_boleto ab ");
|
||||
sql.append(" INNER JOIN empresa e ON ( e.empresa_id = ab.empresa_id and ab.ACTIVO = 1 )");
|
||||
sql.append(" INNER JOIN det_abasto_boleto dab ON ( dab.abastoboleto_id = ab.abastoboleto_id and dab.ACTIVO = 1 )");
|
||||
sql.append(" INNER JOIN punto_venta p ON ( p.puntoventa_id = ab.puntoventa_id and p.ACTIVO = 1 )");
|
||||
sql.append(" LEFT JOIN TIPO_PTOVTA tp ON ( tp.TIPOPTOVTA_ID = p.TIPOPTOVTA_ID and tp.ACTIVO = 1 )");
|
||||
sql.append(" INNER JOIN estacion es ON ( es.ESTACION_ID = ab.ESTACION_ID )");
|
||||
sql.append(" INNER JOIN ARTICULO ar ON ( ar.ARTICULO_ID = ab.ARTICULO_ID )");
|
||||
sql.append(" LEFT JOIN FOLIO_PREIMPRESO fp ON ( fp.AIDF_ID = dab.AIDF_ID and fp.EMPRESA_ID = e.EMPRESA_ID and fp.ESTACION_ID = ab.ESTACION_ID and fp.activo = 1 )");
|
||||
sql.append(" INNER JOIN aidf ai ON ( ai.aidf_id =dab.aidf_id )");
|
||||
sql.append(" INNER JOIN estado est ON ( est.estado_id = ai.ESTADO_ID ) ");
|
||||
|
||||
sql.append(" WHERE ");
|
||||
sql.append(" dab.statusoperacion in (0,1) and dab.activo = 1 and ab.activo = 1 ");
|
||||
if (parametros.get("EMPRESA_ID") != null) {
|
||||
sql.append(" AND e.empresa_id = ").append(parametros.get("EMPRESA_ID"));
|
||||
}
|
||||
if(parametros.get("NUMPUNTOVENTA") != null){
|
||||
sql.append(" and ab.puntoventa_id in(").append(parametros.get("NUMPUNTOVENTA")).append(") ");
|
||||
if (parametros.get("NUMPUNTOVENTA") != null) {
|
||||
sql.append(" AND ab.puntoventa_id in(").append(parametros.get("NUMPUNTOVENTA")).append(") ");
|
||||
}
|
||||
sql.append(" order by e.nombempresa, p.nombpuntoventa,es.descestacion, ar.descarticulo, forminicial");
|
||||
sql.append(" ORDER BY e.nombempresa, p.nombpuntoventa,es.descestacion, ar.descarticulo, forminicial");
|
||||
|
||||
return sql.toString();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue