fixes bug#22299
dev: GLEIMAR qua: Silvania git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Web/trunk/ventaboletos@108350 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
73137d75bf
commit
756da5b697
|
@ -10,9 +10,11 @@ import java.util.Date;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.rjconsultores.ventaboletos.entidad.Empresa;
|
||||
import com.rjconsultores.ventaboletos.entidad.EsquemaCorrida;
|
||||
import com.rjconsultores.ventaboletos.relatorios.utilitarios.DataSource;
|
||||
import com.rjconsultores.ventaboletos.relatorios.utilitarios.Relatorio;
|
||||
import com.rjconsultores.ventaboletos.relatorios.utilitarios.RelatorioMensalDAERBean;
|
||||
|
@ -28,20 +30,18 @@ public class RelatorioMensalDAER extends Relatorio {
|
|||
/**
|
||||
* @param parametros
|
||||
* @param conexao
|
||||
* @param listCategoria
|
||||
*/
|
||||
public RelatorioMensalDAER(final Map<String, Object> parametros, final Connection conexao) throws Exception {
|
||||
public RelatorioMensalDAER(final Map<String, Object> parametros, final Connection conexao, final List<Integer> listCategoria) throws Exception {
|
||||
super(parametros, conexao);
|
||||
|
||||
this.setCustomDataSource(new DataSource(this) {
|
||||
@Override
|
||||
public void initDados() throws Exception {
|
||||
try {
|
||||
String agencia = parametros.get("AGENCIA") != null ? parametros.get("AGENCIA").toString() : null;
|
||||
Integer agencia = parametros.get("AGENCIA") != null ? Integer.valueOf(parametros.get("AGENCIA").toString()) : null;
|
||||
Empresa empresa = parametros.get("EMPRESA") != null ? (Empresa) (parametros.get("EMPRESA")) : null;
|
||||
String tipoVenta = parametros.get("TIPOVENTA_ID").toString();
|
||||
|
||||
// Executa query relatório e preenche objeto relatório
|
||||
lsDadosRelatorio = preencheAgrupaRelatorioBean(preparaExecutaQuery(parametros, conexao, empresa, agencia, tipoVenta));
|
||||
lsDadosRelatorio = preencheAgrupaRelatorioBean(preparaExecutaQuery(parametros, conexao, empresa, agencia, listCategoria));
|
||||
|
||||
parametros.put("RELATORIOLIST", lsDadosRelatorio);
|
||||
setLsDadosRelatorio(lsDadosRelatorio);
|
||||
|
@ -59,9 +59,11 @@ public class RelatorioMensalDAER extends Relatorio {
|
|||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
private ResultSet preparaExecutaQuery(Map<String, Object> parametros, Connection conexao, Empresa empresa, String agencia, String tipoVenta) throws SQLException {
|
||||
Boolean istipoVenta = (!tipoVenta.isEmpty());
|
||||
String sql = getSql(istipoVenta);
|
||||
private ResultSet preparaExecutaQuery(Map<String, Object> parametros, Connection conexao, Empresa empresa, Integer agencia, List<Integer> idsCorrida) throws SQLException {
|
||||
Boolean istipoVenta = (idsCorrida.size() > 0);
|
||||
StringBuilder sqlCat = new StringBuilder();
|
||||
sqlCat = getIdsCategoria(listCategoria);
|
||||
String sql = getSql(istipoVenta,sqlCat);
|
||||
NamedParameterStatement stmt = new NamedParameterStatement(conexao, sql);
|
||||
ResultSet rset = null;
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
|
||||
|
@ -76,11 +78,7 @@ public class RelatorioMensalDAER extends Relatorio {
|
|||
stmt.setString("DATA_FINAL", sdf.format(dataFinal));
|
||||
}
|
||||
stmt.setInt("EMPRESA", empresa.getEmpresaId());
|
||||
stmt.setString("AGENCIA", agencia);
|
||||
if(istipoVenta) {
|
||||
stmt.setString("TIPOVENTA_ID", tipoVenta);
|
||||
}
|
||||
|
||||
stmt.setInt("AGENCIA", agencia);
|
||||
rset = stmt.executeQuery();
|
||||
return rset;
|
||||
}
|
||||
|
@ -98,7 +96,7 @@ public class RelatorioMensalDAER extends Relatorio {
|
|||
|
||||
protected List<RelatorioMensalDAERBean> preencheAgrupaRelatorioBean(ResultSet rset) throws SQLException {
|
||||
lsDadosRelatorio = new ArrayList<RelatorioMensalDAERBean>();
|
||||
Integer qtBilhetes=null;
|
||||
Integer qtBilhetes = null;
|
||||
while (rset.next()) {
|
||||
RelatorioMensalDAERBean relatorioMensalDAER = new RelatorioMensalDAERBean(rset.getInt("corrida_id"));
|
||||
qtBilhetes = rset.getInt("qtdbilhetes");
|
||||
|
@ -109,10 +107,10 @@ public class RelatorioMensalDAER extends Relatorio {
|
|||
float comissao = comissaoDAER.floatValue();
|
||||
BigDecimal taxaFiscal = BigDecimal.valueOf(comissao * (3.0f / 100.0f));
|
||||
|
||||
relatorioMensalDAER.setFecHorSalida(retornaHora(rset.getTimestamp("partida"),true));
|
||||
relatorioMensalDAER.setFecMinSalida(retornaHora(rset.getTimestamp("partida"),false));
|
||||
relatorioMensalDAER.setFecHorInicio(retornaHora(rset.getTimestamp("inicio"),true));
|
||||
relatorioMensalDAER.setFecMinInicio(retornaHora(rset.getTimestamp("inicio"),false));
|
||||
relatorioMensalDAER.setFecHorSalida(retornaHora(rset.getTimestamp("partida"), true));
|
||||
relatorioMensalDAER.setFecMinSalida(retornaHora(rset.getTimestamp("partida"), false));
|
||||
relatorioMensalDAER.setFecHorInicio(retornaHora(rset.getTimestamp("inicio"), true));
|
||||
relatorioMensalDAER.setFecMinInicio(retornaHora(rset.getTimestamp("inicio"), false));
|
||||
relatorioMensalDAER.setFecCorrida(rset.getDate("feccorrida"));
|
||||
relatorioMensalDAER.setIndSentidoIda(sentido);
|
||||
relatorioMensalDAER.setNumRuta(rset.getString("linha"));
|
||||
|
@ -135,7 +133,7 @@ public class RelatorioMensalDAER extends Relatorio {
|
|||
|
||||
}
|
||||
|
||||
protected String getSql(Boolean existeTpVenta) {
|
||||
protected String getSql(Boolean existeTpCategoria, StringBuilder sqlCat) {
|
||||
StringBuilder sql = new StringBuilder();
|
||||
sql.append("SELECT ");
|
||||
sql.append("( case when ct.numsecuencia = 1 then null ");
|
||||
|
@ -156,18 +154,18 @@ public class RelatorioMensalDAER extends Relatorio {
|
|||
sql.append(" ( SELECT COUNT(ce.corrida_id) FROM corrida ce WHERE ce.corrida_id = co.corrida_id AND ce.tiposervicio_id = 2 ");
|
||||
sql.append(" AND ce.feccorrida BETWEEN TO_DATE(:DATA_INICIO, 'DD/MM/YYYY') AND TO_DATE(:DATA_FINAL, 'DD/MM/YYYY')) as extra, ");
|
||||
sql.append(" ( SELECT COUNT(caja_id) FROM caja WHERE corrida_id = co.corrida_id AND ruta_id = co.ruta_id ");
|
||||
if(existeTpVenta) {
|
||||
sql.append(" AND tipoventa_id in (:TIPOVENTA_ID) ");
|
||||
if (existeTpCategoria) {
|
||||
sql.append(sqlCat);
|
||||
}
|
||||
sql.append(" AND feccorrida BETWEEN TO_DATE(:DATA_INICIO, 'DD/MM/YYYY') AND TO_DATE(:DATA_FINAL, 'DD/MM/YYYY')) AS qtdbilhetes, ");
|
||||
sql.append(" ( SELECT SUM(caja.preciobase+caja.importeseguro)FROM caja WHERE corrida_id = co.corrida_id AND ruta_id = co.ruta_id ");
|
||||
if(existeTpVenta) {
|
||||
sql.append(" AND tipoventa_id in (:TIPOVENTA_ID) ");
|
||||
if (existeTpCategoria) {
|
||||
sql.append(sqlCat);
|
||||
}
|
||||
sql.append(" AND feccorrida BETWEEN TO_DATE(:DATA_INICIO, 'DD/MM/YYYY') AND TO_DATE(:DATA_FINAL, 'DD/MM/YYYY')) AS manifbilhetes, ");
|
||||
sql.append(" ( SELECT SUM(caja.importetaxaembarque)FROM caja WHERE corrida_id = co.corrida_id AND ruta_id = co.ruta_id ");
|
||||
if(existeTpVenta) {
|
||||
sql.append(" AND tipoventa_id in (:TIPOVENTA_ID) ");
|
||||
if (existeTpCategoria) {
|
||||
sql.append(sqlCat);
|
||||
}
|
||||
sql.append(" AND feccorrida BETWEEN TO_DATE(:DATA_INICIO, 'DD/MM/YYYY') AND TO_DATE(:DATA_FINAL, 'DD/MM/YYYY')) AS embarque, ");
|
||||
sql.append(" ' ' as encomendas ");
|
||||
|
@ -194,9 +192,26 @@ public class RelatorioMensalDAER extends Relatorio {
|
|||
return sql.toString();
|
||||
}
|
||||
|
||||
private StringBuilder getIdsCategoria(List<Integer> lsCategoria) {
|
||||
Integer[] idsCategoria = new Integer[lsCategoria.size()];
|
||||
StringBuilder ids = new StringBuilder();
|
||||
int i = 0;
|
||||
for (Integer ec : lsCategoria) {
|
||||
idsCategoria[i] = ec;
|
||||
i++;
|
||||
}
|
||||
|
||||
if (lsCategoria.size() >0) {
|
||||
ids.append(" AND caja.categoria_id in ( " + StringUtils.join(idsCategoria, ",") + ")");
|
||||
} else {
|
||||
ids.append("");
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
public String retornaHora(Date horaCompleta, boolean ishora) {
|
||||
String horaMin = null;
|
||||
if(horaCompleta == null) {
|
||||
if (horaCompleta == null) {
|
||||
return horaMin;
|
||||
} else if (ishora) {
|
||||
SimpleDateFormat simpleTimeFormat = new SimpleDateFormat("HH");
|
||||
|
|
|
@ -24,16 +24,16 @@ import org.zkoss.zul.Radio;
|
|||
import org.zkoss.zul.Row;
|
||||
import org.zkoss.zul.Textbox;
|
||||
|
||||
import com.rjconsultores.ventaboletos.entidad.Categoria;
|
||||
import com.rjconsultores.ventaboletos.entidad.Empresa;
|
||||
import com.rjconsultores.ventaboletos.entidad.EmpresaEmailConfig;
|
||||
import com.rjconsultores.ventaboletos.entidad.TipoVenta;
|
||||
import com.rjconsultores.ventaboletos.entidad.UsuarioUbicacion;
|
||||
import com.rjconsultores.ventaboletos.enums.MimeType;
|
||||
import com.rjconsultores.ventaboletos.relatorios.impl.RelatorioMensalDAER;
|
||||
import com.rjconsultores.ventaboletos.relatorios.utilitarios.Relatorio;
|
||||
import com.rjconsultores.ventaboletos.relatorios.utilitarios.SaidaRelatorio;
|
||||
import com.rjconsultores.ventaboletos.service.CategoriaService;
|
||||
import com.rjconsultores.ventaboletos.service.EmpresaEmailConfigService;
|
||||
import com.rjconsultores.ventaboletos.service.TipoVentaService;
|
||||
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
|
||||
import com.rjconsultores.ventaboletos.utilerias.SendMail;
|
||||
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
||||
|
@ -52,7 +52,7 @@ public class RelatorioMensalDAERController extends MyGenericForwardComposer {
|
|||
private DataSource dataSourceRead;
|
||||
|
||||
@Autowired
|
||||
private TipoVentaService tipoVentaService;
|
||||
private CategoriaService tipoVentaService;
|
||||
|
||||
@Autowired
|
||||
private EmpresaEmailConfigService empresaEmailConfigService;
|
||||
|
@ -64,9 +64,9 @@ public class RelatorioMensalDAERController extends MyGenericForwardComposer {
|
|||
private List<UsuarioUbicacion> lsAgencias;
|
||||
private String agenciasUsuario;
|
||||
private Boolean isPDF = true;
|
||||
private List<TipoVenta> lsTipoVenta;
|
||||
private List<Categoria> lsTipoVenta;
|
||||
private MyListbox selectedTipoVentaList;
|
||||
private List<TipoVenta> listSelectedTipoVenta;
|
||||
private List<Categoria> listSelectedTipoVenta;
|
||||
private MyComboboxEstandar cmbTipoVenta;
|
||||
private Radio rdTipoAnexoPDF;
|
||||
private Radio rdTipoAnexoXLS;
|
||||
|
@ -127,30 +127,23 @@ public class RelatorioMensalDAERController extends MyGenericForwardComposer {
|
|||
|
||||
StringBuilder tipVenta = new StringBuilder();
|
||||
StringBuilder tipVentaIds = new StringBuilder();
|
||||
List<Integer> listCategoria = new ArrayList<Integer>();
|
||||
String todos = "-1";
|
||||
|
||||
if (!listSelectedTipoVenta.isEmpty()) {
|
||||
for (TipoVenta venta : listSelectedTipoVenta) {
|
||||
tipVenta.append(venta.getDesctipoventa()).append(",");
|
||||
if (todos.equals(venta.getTipoventaId().toString())) {
|
||||
for (Categoria venta : listSelectedTipoVenta) {
|
||||
tipVenta.append(venta.getDesccategoria()).append(",");
|
||||
if (todos.equals(venta.getCategoriaId().toString())) {
|
||||
tipVentaIds = new StringBuilder();
|
||||
tipVentaIds.append("");
|
||||
break;
|
||||
}
|
||||
tipVentaIds.append(venta.getTipoventaId()).append(",");
|
||||
listCategoria.add(venta.getCategoriaId());
|
||||
}
|
||||
|
||||
// removendo ultima virgula
|
||||
tipVentaIds = tipVentaIds.delete(tipVentaIds.length() -1, tipVentaIds.length());
|
||||
tipVenta = tipVenta.delete(tipVenta.length() -1, tipVenta.length());
|
||||
|
||||
}
|
||||
|
||||
parametros.put("TIPOVENTA", tipVenta.append(";").toString());
|
||||
parametros.put("TIPOVENTA_ID", tipVentaIds.toString());
|
||||
|
||||
// Instancia o relatório
|
||||
Relatorio relatorio = new RelatorioMensalDAER(parametros, dataSourceRead.getConnection());
|
||||
Relatorio relatorio = new RelatorioMensalDAER(parametros, dataSourceRead.getConnection(), listCategoria);
|
||||
|
||||
if (isEnviarEmail) {
|
||||
|
||||
|
@ -191,14 +184,14 @@ public class RelatorioMensalDAERController extends MyGenericForwardComposer {
|
|||
}
|
||||
|
||||
public void onClick$btnRemoveTipoVenta(Event ev) throws InterruptedException {
|
||||
TipoVenta tVenta = (TipoVenta) selectedTipoVentaList.getSelectedItem().getValue();
|
||||
Categoria tVenta = (Categoria) selectedTipoVentaList.getSelectedItem().getValue();
|
||||
listSelectedTipoVenta.remove(tVenta);
|
||||
selectedTipoVentaList.setData(listSelectedTipoVenta);
|
||||
}
|
||||
|
||||
public void onClick$btnAddTipoVenta(Event ev) throws InterruptedException {
|
||||
if (cmbTipoVenta.getSelectedItem() != null) {
|
||||
listSelectedTipoVenta.add((TipoVenta) cmbTipoVenta.getSelectedItem().getValue());
|
||||
listSelectedTipoVenta.add((Categoria) cmbTipoVenta.getSelectedItem().getValue());
|
||||
selectedTipoVentaList.setData(listSelectedTipoVenta);
|
||||
selectedTipoVentaList.setSelectedItem(null);
|
||||
}
|
||||
|
@ -269,8 +262,9 @@ public class RelatorioMensalDAERController extends MyGenericForwardComposer {
|
|||
super.doAfterCompose(comp);
|
||||
lsEmpresas = UsuarioLogado.getUsuarioLogado().getEmpresa();
|
||||
lsAgencias = UsuarioLogado.getUsuarioLogado().getUsuarioUbicacionActivoList();
|
||||
lsTipoVenta = tipoVentaService.obtenerTodos();
|
||||
listSelectedTipoVenta = new ArrayList<TipoVenta>();
|
||||
lsTipoVenta = tipoVentaService.buscarCategoriaOrgaoConcedente("DAER");
|
||||
//lsTipoVenta = tipoVentaService.buscarCategoriaOrgaoConcedente("DAER");
|
||||
listSelectedTipoVenta = new ArrayList<Categoria>();
|
||||
StringBuilder agencias = new StringBuilder();
|
||||
|
||||
for (int i =0; i< lsAgencias.size() ; i++) {
|
||||
|
@ -324,11 +318,11 @@ public class RelatorioMensalDAERController extends MyGenericForwardComposer {
|
|||
this.selectedTipoVentaList = selectedTipoVentaList;
|
||||
}
|
||||
|
||||
public List<TipoVenta> getListSelectedTipoVenta() {
|
||||
public List<Categoria> getListSelectedTipoVenta() {
|
||||
return listSelectedTipoVenta;
|
||||
}
|
||||
|
||||
public void setListSelectedTipoVenta(List<TipoVenta> listSelectedTipoVenta) {
|
||||
public void setListSelectedTipoVenta(List<Categoria> listSelectedTipoVenta) {
|
||||
this.listSelectedTipoVenta = listSelectedTipoVenta;
|
||||
}
|
||||
|
||||
|
@ -348,11 +342,11 @@ public class RelatorioMensalDAERController extends MyGenericForwardComposer {
|
|||
this.lsAgencias = lsAgencias;
|
||||
}
|
||||
|
||||
public List<TipoVenta> getLsTipoVenta() {
|
||||
public List<Categoria> getLsTipoVenta() {
|
||||
return lsTipoVenta;
|
||||
}
|
||||
|
||||
public void setLsCategorias(List<TipoVenta> lsTipoVenta) {
|
||||
public void setLsCategorias(List<Categoria> lsTipoVenta) {
|
||||
this.lsTipoVenta = lsTipoVenta;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue