bug#11600
dev: julio qua: git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@85272 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
2e41a3e0f6
commit
9a05693f16
|
@ -21,9 +21,9 @@ import org.springframework.stereotype.Repository;
|
|||
import com.rjconsultores.ventaboletos.dao.BpeDAO;
|
||||
import com.rjconsultores.ventaboletos.entidad.Estado;
|
||||
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
|
||||
import com.rjconsultores.ventaboletos.utilerias.UtiliteriasFiscal;
|
||||
import com.rjconsultores.ventaboletos.utilerias.exportacao.bpe.ExportacaoBPEBase;
|
||||
import com.rjconsultores.ventaboletos.utilerias.exportacao.bpe.ExportacaoBPEVo;
|
||||
import com.rjconsultores.ventaboletos.utilerias.exportacao.bpe.ExportacaoBPEVo.TipoComp;
|
||||
import com.rjconsultores.ventaboletos.utilerias.fiscal.vo.DetalhadoFiscal;
|
||||
import com.rjconsultores.ventaboletos.utilerias.fiscal.vo.FiscalRdi;
|
||||
import com.rjconsultores.ventaboletos.utilerias.fiscal.vo.RdiValidacion;
|
||||
|
@ -373,87 +373,106 @@ public class BpeHibernateDAO extends HibernateDaoSupport implements BpeDAO {
|
|||
|
||||
List<FiscalRdi> rdis = new ArrayList<FiscalRdi>();
|
||||
|
||||
BigDecimal aliquotaAnt = null;
|
||||
|
||||
for (DetalhadoFiscal det : list) {
|
||||
|
||||
String xml = det.getXml();
|
||||
|
||||
BigDecimal tarifa = BigDecimal.ZERO;
|
||||
BigDecimal taxaEmbarque = BigDecimal.ZERO;
|
||||
BigDecimal pedagio = BigDecimal.ZERO;
|
||||
BigDecimal seguro = BigDecimal.ZERO;
|
||||
BigDecimal passagem = BigDecimal.ZERO;
|
||||
BigDecimal isentos = BigDecimal.ZERO;
|
||||
BigDecimal outros = BigDecimal.ZERO;
|
||||
BigDecimal rbc = BigDecimal.ZERO;
|
||||
BigDecimal baseCalculo = BigDecimal.ZERO;
|
||||
BigDecimal aliquota = BigDecimal.ZERO;
|
||||
BigDecimal icms = BigDecimal.ZERO;
|
||||
BigDecimal cp = BigDecimal.ZERO;
|
||||
BigDecimal credPres = BigDecimal.ZERO;
|
||||
BigDecimal icmsRec = BigDecimal.ZERO;
|
||||
|
||||
if (det.getIsenta()) {
|
||||
isentos = valorPassagem(det, isReceitaTerceiros);
|
||||
} else {
|
||||
passagem = valorPassagem(det, isReceitaTerceiros);
|
||||
boolean isEstadual = det.isInterEstadual();
|
||||
String tipoViagem = isEstadual ? "IE" : "IM";
|
||||
|
||||
if (det.isInterEstadual()) {
|
||||
aliquota = det.getTributacaoImportacao() != null ? det.getTributacaoImportacao() : det.getIcmsInterestadual();
|
||||
} else {
|
||||
aliquota = det.getTributacaoImportacao() != null ? det.getTributacaoImportacao() : det.getIcmsIntermunicipal();
|
||||
ExportacaoBPEVo exportacaoBPEVo = new ExportacaoBPEVo();
|
||||
TBPe tbpe = null;
|
||||
if (StringUtils.isNotBlank(xml))
|
||||
tbpe = exportacaoBPEVo.convertXmlToBpe(xml);
|
||||
|
||||
String vBC = null;
|
||||
String pICMS = null;
|
||||
String vICMS = null;
|
||||
String pRedBC = null;
|
||||
String cst = null;
|
||||
|
||||
if (StringUtils.isNotBlank(xml)) {
|
||||
if (tbpe.getInfBPe().getImp().getICMS().getICMS00() != null) {
|
||||
vBC = tbpe.getInfBPe().getImp().getICMS().getICMS00().getVBC();
|
||||
pICMS = tbpe.getInfBPe().getImp().getICMS().getICMS00().getPICMS();
|
||||
vICMS = tbpe.getInfBPe().getImp().getICMS().getICMS00().getVICMS();
|
||||
} else if (tbpe.getInfBPe().getImp().getICMS().getICMS20() != null) {
|
||||
vBC = tbpe.getInfBPe().getImp().getICMS().getICMS20().getVBC();
|
||||
pICMS = tbpe.getInfBPe().getImp().getICMS().getICMS20().getPICMS();
|
||||
vICMS = tbpe.getInfBPe().getImp().getICMS().getICMS20().getVICMS();
|
||||
pRedBC = tbpe.getInfBPe().getImp().getICMS().getICMS20().getPRedBC();
|
||||
cst = tbpe.getInfBPe().getImp().getICMS().getICMS20().getCST();
|
||||
}
|
||||
|
||||
if (det.isInterEstadual()) {
|
||||
cp = det.getPorcRedEstadual() == null ? BigDecimal.ZERO : det.getPorcRedEstadual();
|
||||
} else {
|
||||
cp = det.getPorcRedMunicipal() == null ? BigDecimal.ZERO : det.getPorcRedMunicipal();
|
||||
if (tbpe.getInfBPe().getInfValorBPe() != null) {
|
||||
|
||||
String vPgto = tbpe.getInfBPe().getInfValorBPe().getVPgto();
|
||||
passagem = new BigDecimal(vPgto == null ? "0.0" : vPgto);
|
||||
|
||||
for (TBPe.InfBPe.InfValorBPe.Comp comp : tbpe.getInfBPe().getInfValorBPe().getComp()) {
|
||||
if (comp.getTpComp().equals(TipoComp.TARIFA)) {
|
||||
String vDesconto = tbpe.getInfBPe().getInfValorBPe().getVDesconto();
|
||||
tarifa = new BigDecimal(comp.getVComp() == null ? "0.0" : comp.getVComp());
|
||||
tarifa = tarifa.subtract(new BigDecimal(vDesconto == null ? "0.0" : vDesconto));
|
||||
}
|
||||
|
||||
if (comp.getTpComp().equals(TipoComp.PEDAGIO)) {
|
||||
isentos = isentos.add(isEstadual && !det.getIndPedagioEstdual() ? new BigDecimal(comp.getVComp() == null ? "0.0" : comp.getVComp()) : BigDecimal.ZERO);
|
||||
isentos = isentos.add(!isEstadual && !det.getIndPedagioMunicipal() ? new BigDecimal(comp.getVComp() == null ? "0.0" : comp.getVComp()) : BigDecimal.ZERO);
|
||||
|
||||
pedagio = isReceitaTerceiros ? new BigDecimal(comp.getVComp() == null ? "0.0" : comp.getVComp()) : BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
if (comp.getTpComp().equals(TipoComp.TAXA_EMBARQUE)) {
|
||||
isentos = isentos.add(isEstadual && !det.getIndTxembarqueEstadual() ? new BigDecimal(comp.getVComp() == null ? "0.0" : comp.getVComp()) : BigDecimal.ZERO);
|
||||
isentos = isentos.add(!isEstadual && !det.getIndTxembarqueMunicipal() ? new BigDecimal(comp.getVComp() == null ? "0.0" : comp.getVComp()) : BigDecimal.ZERO);
|
||||
|
||||
taxaEmbarque = isReceitaTerceiros ? new BigDecimal(comp.getVComp() == null ? "0.0" : comp.getVComp()) : BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
if (comp.getTpComp().equals(TipoComp.SEGURO)) {
|
||||
isentos = isentos.add(isEstadual && !det.getIndSeguroEstadual() ? new BigDecimal(comp.getVComp() == null ? "0.0" : comp.getVComp()) : BigDecimal.ZERO);
|
||||
isentos = isentos.add(!isEstadual && !det.getIndSeguroMunicipal() ? new BigDecimal(comp.getVComp() == null ? "0.0" : comp.getVComp()) : BigDecimal.ZERO);
|
||||
|
||||
seguro = isReceitaTerceiros ? new BigDecimal(comp.getVComp() == null ? "0.0" : comp.getVComp()) : BigDecimal.ZERO;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rbc = det.getRedBaseCalcIcms() == null ? BigDecimal.ZERO : det.getRedBaseCalcIcms().divide(UtiliteriasFiscal.CEM);
|
||||
|
||||
BigDecimal tarifa = valorBaseCalculo(det, isReceitaTerceiros);
|
||||
BigDecimal redutor = tarifa.multiply(rbc);
|
||||
baseCalculo = tarifa.subtract(redutor);
|
||||
|
||||
icms = baseCalculo.multiply(aliquota.divide(BigDecimal.TEN.multiply(BigDecimal.TEN)));
|
||||
credPres = icms.multiply(cp.divide(BigDecimal.TEN.multiply(BigDecimal.TEN)));
|
||||
icmsRec = icms.subtract(credPres);
|
||||
}
|
||||
outros = isentos.equals(BigDecimal.ZERO) ? BigDecimal.ZERO : passagem.subtract(isentos).subtract(baseCalculo);
|
||||
|
||||
String tipoViagem = det.isInterEstadual() ? "IE" : "IM";
|
||||
BigDecimal taxaEmbarque = isReceitaTerceiros && det.getTaxaEmbarque() == null ? BigDecimal.ZERO : det.getTaxaEmbarque();
|
||||
BigDecimal pedagio = isReceitaTerceiros && det.getPedagio() == null ? BigDecimal.ZERO : det.getPedagio();
|
||||
BigDecimal seguro = isReceitaTerceiros && det.getSeguro() == null ? BigDecimal.ZERO : det.getSeguro();
|
||||
BigDecimal baseCalculo = new BigDecimal(vBC == null ? "0.0" : vBC);
|
||||
BigDecimal aliquota = new BigDecimal(pICMS == null ? "0.0" : pICMS);
|
||||
aliquota = (aliquota.intValue() == 0 ? aliquotaAnt : aliquota);
|
||||
|
||||
rdis.add(new FiscalRdi(det.getEstadoOrigem(), tipoViagem, det.getTipoReceita(), det.getTarifa(),
|
||||
seguro, taxaEmbarque, pedagio, passagem, isentos, outros, det.getRedBaseCalcIcms(),
|
||||
if (aliquota != null && aliquota.intValue() > 0)
|
||||
aliquotaAnt = aliquota;
|
||||
|
||||
BigDecimal icms = new BigDecimal(vICMS == null ? "0.0" : vICMS);
|
||||
|
||||
BigDecimal outros = new BigDecimal(pRedBC == null ? "0.0" : pRedBC);
|
||||
BigDecimal cp = new BigDecimal(cst == null ? "0.0" : cst);
|
||||
BigDecimal credPres = icms.multiply(cp.divide(BigDecimal.TEN.multiply(BigDecimal.TEN)));
|
||||
BigDecimal icmsRec = icms.subtract(credPres);
|
||||
|
||||
BigDecimal vRedBC = new BigDecimal(pRedBC == null ? "0.0" : pRedBC);
|
||||
|
||||
rdis.add(new FiscalRdi(det.getEstadoOrigem(), tipoViagem, det.getTipoReceita(), tarifa,
|
||||
seguro, taxaEmbarque, pedagio, passagem, isentos, outros, vRedBC,
|
||||
baseCalculo, aliquota, icms, cp, credPres, icmsRec));
|
||||
}
|
||||
|
||||
return rdis;
|
||||
}
|
||||
|
||||
private BigDecimal valorBaseCalculo(DetalhadoFiscal det, boolean isReceitaTerceiros) {
|
||||
|
||||
BigDecimal total = BigDecimal.ZERO;
|
||||
total = total.add(det.getTarifa() == null ? BigDecimal.ZERO : det.getTarifa());
|
||||
|
||||
if (isReceitaTerceiros && (det.isInterEstadual() && det.getIndTxembarqueEstadual() || !det.isInterEstadual() && det.getIndTxembarqueMunicipal()))
|
||||
total = total.add(det.getTaxaEmbarque() == null ? BigDecimal.ZERO : det.getTaxaEmbarque());
|
||||
|
||||
if (isReceitaTerceiros && (det.isInterEstadual() && det.getIndPedagioEstdual() || !det.isInterEstadual() && det.getIndPedagioMunicipal()))
|
||||
total = total.add(det.getPedagio() == null ? BigDecimal.ZERO : det.getPedagio());
|
||||
|
||||
if (isReceitaTerceiros && (det.isInterEstadual() && det.getIndSeguroEstadual() || !det.isInterEstadual() && det.getIndSeguroMunicipal()))
|
||||
total = total.add(det.getSeguro() == null ? BigDecimal.ZERO : det.getSeguro());
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
private BigDecimal valorPassagem(DetalhadoFiscal det, boolean isReceitaTerceiros) {
|
||||
BigDecimal total = BigDecimal.ZERO;
|
||||
total = total.add(det.getTarifa() == null ? BigDecimal.ZERO : det.getTarifa());
|
||||
total = total.add(det.getTaxaEmbarque() == null ? BigDecimal.ZERO : det.getTaxaEmbarque());
|
||||
total = total.add(det.getPedagio() == null ? BigDecimal.ZERO : det.getPedagio());
|
||||
total = total.add(det.getSeguro() == null ? BigDecimal.ZERO : det.getSeguro());
|
||||
return total;
|
||||
}
|
||||
|
||||
private List<DetalhadoFiscal> montaRelatorioRDI(Connection connection, Date inicio, Date fim, Integer empresaId, String ufs) {
|
||||
|
||||
List<DetalhadoFiscal> list = new ArrayList<DetalhadoFiscal>();
|
||||
|
@ -735,9 +754,10 @@ public class BpeHibernateDAO extends HibernateDaoSupport implements BpeDAO {
|
|||
sql.append(" inner join estado est_bpe on bpe.uf = est_bpe.codibge ");
|
||||
|
||||
// sql.append(" left join boleto b on b.boleto_id = coalesce(bori.boletoanterior_id, bori.boletooriginal_id) ");
|
||||
sql.append(" left join boleto b on b.boleto_id = bori.boletooriginal_id ");
|
||||
sql.append(" left join bpe bpeori on b.boleto_id = bpeori.boleto_id ");
|
||||
// sql.append(" left join boleto b on b.boleto_id = bori.boletooriginal_id ");
|
||||
sql.append(" left join boleto b on b.boleto_id = (case when bori.motivocancelacion_id = 99 then bori.boletoanterior_id else bori.boletooriginal_id end) ");
|
||||
|
||||
sql.append(" left join bpe bpeori on b.boleto_id = bpeori.boleto_id ");
|
||||
sql.append(" inner join punto_venta ptv on ptv.puntoventa_id = bori.puntoventa_id ");
|
||||
sql.append(" inner join parada ori on (b.origen_id = ori.parada_id ) ");
|
||||
sql.append(" inner join parada des on (b.destino_id = des.parada_id ) ");
|
||||
|
|
|
@ -259,7 +259,7 @@ public class FiscalRdi implements Comparable<FiscalRdi> {
|
|||
public int compareTo(FiscalRdi o) {
|
||||
int result = this.estado.compareToIgnoreCase(o.estado);
|
||||
if (result == 0) {
|
||||
result = this.tipoViagem.compareToIgnoreCase(o.tipoViagem);
|
||||
result = o.tipoViagem.compareToIgnoreCase(this.tipoViagem);
|
||||
}
|
||||
if (result == 0) {
|
||||
return o.tipoReceita.compareToIgnoreCase(this.tipoReceita);
|
||||
|
|
Loading…
Reference in New Issue