fixes bug#14580

dev:JULIO
qua:juliana

git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Web/trunk/ventaboletos@95415 d1611594-4594-4d17-8e1d-87c2c4800839
master
aristides 2019-07-04 17:45:57 +00:00
parent c32201c7e7
commit 6e49982eb7
2 changed files with 174 additions and 84 deletions

View File

@ -6,6 +6,7 @@ public class RelatorioEmbarqueLocalidadeBean {
private String horario;
private String linha;
private String classe;
private String prefixo;;
private Long embarques;
private Integer indexColun;
private Integer indexLinha;
@ -66,6 +67,16 @@ public class RelatorioEmbarqueLocalidadeBean {
this.classe = classe;
}
public String getPrefixo() {
return prefixo;
}
public void setPrefixo(String prefixo) {
this.prefixo = prefixo;
}
@Override
public int hashCode() {
final int prime = 31;

View File

@ -106,8 +106,9 @@ public class RelatorioEmbarqueLocalidadeController extends MyGenericForwardCompo
private static final int NUM_LINHA_TITULO = 0;
private static final int NUM_LINHA_PERIODO = 1;
private static final int NUM_FAIXA_HORARIA = 2;
private static final int NUM_LINHA_DATA_EMPRESA = 3;
private static final int NUM_LINHA_INICIO = 5;
private static final int NUM_LINHA_INICIO = 4;
private Empresa empresa;
private Ruta ruta;
@ -205,42 +206,53 @@ public class RelatorioEmbarqueLocalidadeController extends MyGenericForwardCompo
try {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFCellStyle estiloVerticalMerge = wb.createCellStyle();
estiloVerticalMerge.setVerticalAlignment(CellStyle.ALIGN_CENTER);
HSSFSheet sheet1 = null;
String dataAtual = DateUtil.getStringDate(new Date(),"dd-MM-yy");
sheet1 = wb.createSheet(dataAtual);
geraCabecalho(sheet1, dataAtual, wb);
HSSFFont font = wb.createFont();
HSSFCellStyle style = wb.createCellStyle();
font.setFontName(HSSFFont.FONT_ARIAL);
font.setFontHeightInPoints((short) 10);
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
font.setColor(HSSFColor.RED.index);
style.setFont(font);
HSSFSheet sheet1 = null;
HSSFFont fonteTotal = wb.createFont();
fonteTotal.setColor(HSSFColor.RED.index);
HSSFCellStyle styleTotal = wb.createCellStyle();
styleTotal.setAlignment(HSSFCellStyle.ALIGN_CENTER);
styleTotal.setFont(fonteTotal);
int linha = NUM_LINHA_INICIO;
HSSFRow row = null;
String dataAtual = DateUtil.getStringDate(new Date(),"dd-MM-yy");
sheet1 = wb.createSheet(dataAtual);
geraCabecalho(sheet1, dataAtual, wb);
Map<String, Integer> linhas = new HashMap<String, Integer>();
int totalGeral = 0;
int linhaTotalizador = 6;
HSSFCell cellTotal = null;
HSSFCellStyle estiloVerticalMerge = wb.createCellStyle();
estiloVerticalMerge.setAlignment(CellStyle.ALIGN_CENTER);
estiloVerticalMerge.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
for (RelatorioEmbarqueLocalidadeBean bean : ls) {
int indexColun = mapAux.get(bean.getHorario());
if (!linhas.containsKey(bean.getLinha())) {
linhas.put(bean.getLinha(), linha);
if (!linhas.containsKey(bean.getPrefixo()+bean.getLinha())) {
linhas.put(bean.getPrefixo()+bean.getLinha(), linha);
row = sheet1.createRow(linha);
linhaTotalizador = linha;
linha++;
} else {
row = sheet1.getRow(linhas.get(bean.getLinha()));
linhaTotalizador = sheet1.getRow(linhas.get(bean.getLinha())).getRowNum();
row = sheet1.getRow(linhas.get(bean.getPrefixo()+bean.getLinha()));
linhaTotalizador = sheet1.getRow(linhas.get(bean.getPrefixo()+bean.getLinha())).getRowNum();
}
HSSFCell cellHorario = row.createCell(0);
@ -249,39 +261,56 @@ public class RelatorioEmbarqueLocalidadeController extends MyGenericForwardCompo
cellTotal = row.createCell(mapAux.size() + 3);
row.createCell(indexColun).setCellValue(bean.getEmbarques());
row.createCell(0).setCellValue(bean.getLinha());
row.createCell(0).setCellValue(bean.getPrefixo());
row.createCell(1).setCellValue(bean.getClasse());
cellTotal.setCellStyle(estiloVerticalMerge);
row.createCell(2).setCellValue(bean.getLinha());
cellTotal.setCellStyle(styleTotal);
String colluna;
String celTotal;
colluna = CellReference.convertNumToColString(mapAux.size() + 2);
celTotal = "SUM(D" + (linhaTotalizador + 1) + ":" + colluna + (linhaTotalizador + 1) + ")";
row.createCell(mapAux.size() + 3).setCellValue(celTotal);
cellTotal.setCellFormula(celTotal);
cellTotal.setCellStyle(style);
totalGeral += bean.getEmbarques();
}
row = sheet1.createRow(linha);
int qtdLinhas = linhas.size() + 5;
row = sheet1.createRow(linha+3);
int qtdLinhas = linhas.size() + 4;
int somatorioColuna = 3;
for (int i = 3; i < mapAux.size() + 3; i++) {
String colluna = CellReference.convertNumToColString(i);
cellTotal = row.createCell(somatorioColuna);
cellTotal.setCellFormula("SUM(" + colluna + 6 + ":" + colluna + (qtdLinhas) + ")");
cellTotal.setCellStyle(style);
cellTotal.setCellFormula("SUM(" + colluna + 5 + ":" + colluna + (qtdLinhas) + ")");
cellTotal.setCellStyle(styleTotal);
somatorioColuna++;
}
sheet1.addMergedRegion(new CellRangeAddress(
linha+3, // first row (0-based)
linha+3 , // last row (0-based)
0, // first column (0-based)
2 // last column (0-based)
));
HSSFCell cellTotalPorFaixaEtaria = row.createCell(0);
cellTotalPorFaixaEtaria.setCellValue("TOTAL POR FAIXA HORÁRIA");
cellTotalPorFaixaEtaria.setCellStyle(styleTotal);
HSSFCell cellTotalValue = row.createCell(total);
cellTotalValue = row.createCell(mapAux.size() + 3);
cellTotalValue.setCellValue(totalGeral);
cellTotalValue.setCellStyle(style);
cellTotalValue.setCellStyle(styleTotal);
linha = NUM_LINHA_INICIO;
@ -331,25 +360,35 @@ public class RelatorioEmbarqueLocalidadeController extends MyGenericForwardCompo
}
}
private void geraCabecalhoTitulo(HSSFSheet sheet1, HSSFWorkbook wb) {
private void geraCabecalhoTitulo(HSSFSheet sheet1, HSSFWorkbook wb,Integer somaColuna, String nomeEmpresa) {
HSSFRow titulo = sheet1.createRow(NUM_LINHA_TITULO);
sheet1.addMergedRegion(new CellRangeAddress(
NUM_LINHA_TITULO, // first row (0-based)
NUM_LINHA_TITULO, // last row (0-based)
0, // first column (0-based)
7 // last column (0-based)
somaColuna // last column (0-based)
));
HSSFFont fonte = wb.createFont();
fonte.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
HSSFCellStyle estilo = wb.createCellStyle();
estilo.setFont(fonte);
titulo.createCell(0).setCellValue("EMBARQUE POR LOCALIDADE");
HSSFFont fonteTitulo = wb.createFont();
fonteTitulo.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
fonteTitulo.setColor(HSSFColor.RED.index);
// fonteTitulo.setFontHeight((short) 12);
HSSFCellStyle estilo = wb.createCellStyle();
HSSFCell cell = titulo.createCell(0);
cell.setCellValue(nomeEmpresa);
HSSFCellStyle styleTitulo = wb.createCellStyle();
styleTitulo.setAlignment(HSSFCellStyle.ALIGN_CENTER);
styleTitulo.setFont(fonteTitulo);
cell.setCellStyle(styleTitulo);
titulo.setRowStyle(estilo);
}
private void geraCabecalhoPeriodo(HSSFSheet sheet1) {
private void geraCabecalhoPeriodo(HSSFSheet sheet1,HSSFWorkbook wb,Integer somaColuna) {
HSSFRow periodo = sheet1.createRow(NUM_LINHA_PERIODO);
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
@ -357,45 +396,23 @@ public class RelatorioEmbarqueLocalidadeController extends MyGenericForwardCompo
NUM_LINHA_PERIODO, // first row (0-based)
NUM_LINHA_PERIODO, // last row (0-based)
0, // first column (0-based)
7 // last column (0-based)
somaColuna // last column (0-based)
));
periodo.createCell(0).setCellValue("Período: " + sdf.format(this.datInicial.getValue()) + " a " + sdf.format(this.datFinal.getValue()));
HSSFCell cell = periodo.createCell(0);
cell.setCellValue("PASSAGEIRO TRANSPORTADO/Período: " + sdf.format(this.datInicial.getValue()) + " a " + sdf.format(this.datFinal.getValue()));
HSSFFont fontePeriodo= wb.createFont();
fontePeriodo.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
fontePeriodo.setFontHeight((short) 11);
HSSFCellStyle stylePeriodo = wb.createCellStyle();
stylePeriodo.setAlignment(HSSFCellStyle.ALIGN_CENTER);
cell.setCellStyle(stylePeriodo);
}
private void geraCabecalho(HSSFSheet sheet1, String dataAtual, HSSFWorkbook wb) {
geraCabecalhoTitulo(sheet1, wb);
geraCabecalhoPeriodo(sheet1);
sheet1.addMergedRegion(new CellRangeAddress(
NUM_LINHA_DATA_EMPRESA, // first row (0-based)
NUM_LINHA_DATA_EMPRESA, // last row (0-based)
1, // first column (0-based)
7 // last column (0-based)
));
HSSFFont font = wb.createFont();
HSSFCellStyle style = wb.createCellStyle();
font.setFontName(HSSFFont.FONT_ARIAL);
font.setFontHeightInPoints((short) 10);
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
style.setFont(font);
// Montando o Cabeçalho
HSSFRow r0 = sheet1.createRow(NUM_LINHA_DATA_EMPRESA);
if (empresa != null) {
r0.createCell(1).setCellValue("EMPRESA: " + empresa.getNombempresa());
r0.getCell(1).setCellStyle(style);
r0.createCell(1).setCellValue("EMPRESA: " + empresa.getNombempresa());
r0.getCell(1).setCellStyle(style);
font.setColor(HSSFColor.RED.index);
style.setFont(font);
} else {
}
HSSFRow r1 = sheet1.createRow(NUM_LINHA_DATA_EMPRESA + 1);
HSSFRow r1 = sheet1.createRow(NUM_LINHA_DATA_EMPRESA);
List<RelatorioEmbarqueLocalidadeBean> lsAux = new ArrayList<RelatorioEmbarqueLocalidadeBean>();
mapAux = new HashMap<String, Integer>();
@ -415,22 +432,83 @@ public class RelatorioEmbarqueLocalidadeController extends MyGenericForwardCompo
}
lsAux.add(bean);
}
String valorEmpresa= empresa==null? "EMPRESA: TODOS" :"EMPRESA: " + empresa.getNombempresa();
geraCabecalhoTitulo(sheet1, wb, i, valorEmpresa);
geraCabecalhoPeriodo(sheet1, wb,i );
sheet1.addMergedRegion(new CellRangeAddress(
NUM_FAIXA_HORARIA, // first row (0-based)
NUM_FAIXA_HORARIA+1 , // last row (0-based)
0, // first column (0-based)
2 // last column (0-based)
));
HSSFFont fontCodigoNomeLinha = wb.createFont();
fontCodigoNomeLinha.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
HSSFCellStyle estiloCellCodigoNomeLinha = wb.createCellStyle();
estiloCellCodigoNomeLinha.setAlignment(HSSFCellStyle.ALIGN_CENTER);
estiloCellCodigoNomeLinha.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
estiloCellCodigoNomeLinha.setFont(fontCodigoNomeLinha);
HSSFRow periodo = sheet1.createRow(NUM_FAIXA_HORARIA);
HSSFCell cell = periodo.createCell(0);
cell.setCellValue("CÓDIGO- NOME DA LINHA");
cell.setCellStyle(estiloCellCodigoNomeLinha);
sheet1.addMergedRegion(new CellRangeAddress(
NUM_FAIXA_HORARIA, // first row (0-based)
NUM_FAIXA_HORARIA , // last row (0-based)
3, // first column (0-based)
i==3?3:i-1 // last column (0-based)
));
sheet1.addMergedRegion(new CellRangeAddress(
NUM_FAIXA_HORARIA, // first row (0-based)
NUM_FAIXA_HORARIA+1 , // last row (0-based)
i, // first column (0-based)
i // last column (0-based)
));
HSSFCell cell1 = periodo.createCell(3);
cell1.setCellValue("FAIXA HORÁRIA");
cell1.setCellStyle(estiloCellCodigoNomeLinha);
i = 3;
mapAux = new TreeMap<String, Integer>(map);
HSSFFont fontHorario = wb.createFont();
HSSFCellStyle styleHorario = wb.createCellStyle();
fontHorario.setColor(HSSFColor.BLACK.index);
fontHorario.setBoldweight(Font.BOLDWEIGHT_BOLD);
styleHorario.setFont(fontHorario);
styleHorario.setAlignment(HSSFCellStyle.ALIGN_CENTER);
styleHorario.setVerticalAlignment(HSSFCellStyle.ALIGN_CENTER);
for (Entry<String, Integer> bean : mapAux.entrySet()) {
r1.createCell(bean.getValue()).setCellValue(bean.getKey());
r1.getCell(bean.getValue()).setCellStyle(styleHorario);
i++;
}
r1.createCell(i++).setCellValue("TOTAL");
r1.setRowStyle(styleHorario);
HSSFCellStyle styleTituloTotal = wb.createCellStyle();
HSSFCell cellTituloTotal = periodo.createCell(i++);
cellTituloTotal.setCellValue("TOTAL");
styleTituloTotal.setAlignment(HSSFCellStyle.ALIGN_CENTER);
styleTituloTotal.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
HSSFFont fontTituloTotal = wb.createFont();
fontTituloTotal.setBoldweight(Font.BOLDWEIGHT_BOLD);
fontTituloTotal.setFontHeightInPoints((short) 10);
fontTituloTotal.setColor(HSSFColor.RED.index);
styleTituloTotal.setFont(fontTituloTotal);
cellTituloTotal.setCellStyle(styleTituloTotal);
total = i;
}
@ -483,8 +561,8 @@ public class RelatorioEmbarqueLocalidadeController extends MyGenericForwardCompo
sql.append("select ");
sql.append(" concat(concat(concat(TO_CHAR(b.fechorviaje,'HH24'), ':00'), ' a '),concat(TO_CHAR(b.fechorviaje,'HH24'), ':59')), ");
sql.append(" concat(concat(r.prefixo, ' '), r.descruta), cla.descclase, ");
sql.append(" count(b.boleto_id) ");
sql.append(" r.descruta, cla.descclase, ");
sql.append(" count(b.boleto_id), r.prefixo ");
sql.append("from ");
sql.append(" boleto b ");
sql.append(" inner join ruta r on r.ruta_id = b.ruta_id ");
@ -511,7 +589,7 @@ public class RelatorioEmbarqueLocalidadeController extends MyGenericForwardCompo
sql.append("group by ");
sql.append(" concat(concat(concat(TO_CHAR(b.fechorviaje,'HH24'), ':00'), ' a '),concat(TO_CHAR(b.fechorviaje,'HH24'), ':59')), ");
sql.append(" concat(concat(r.prefixo, ' '), r.descruta), cla.descclase ");
sql.append(" r.descruta, cla.descclase,r.prefixo ");
sql.append("order by ");
sql.append(" 1 ");
@ -529,6 +607,7 @@ public class RelatorioEmbarqueLocalidadeController extends MyGenericForwardCompo
bean.setLinha(rset.getString(2));
bean.setClasse(rset.getString(3));
bean.setEmbarques(rset.getLong(4));
bean.setPrefixo(rset.getString(5));
ls.add(bean);
}