Rev 195 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 106 | espaco | 1 | package br.com.ec.controller.managedbean; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 4 | import java.util.ArrayList; |
||
| 5 | import java.util.List; |
||
| 6 | |||
| 7 | import javax.inject.Inject; |
||
| 8 | import javax.inject.Named; |
||
| 9 | |||
| 10 | import org.springframework.context.annotation.Scope; |
||
| 11 | |||
| 195 | espaco | 12 | import br.com.ec.core.generic.GenericService; |
| 13 | import br.com.ec.core.util.DataUtils; |
||
| 14 | import br.com.ec.core.util.VerificadorUtil; |
||
| 106 | espaco | 15 | import br.com.ec.domain.dto.DreDTO; |
| 16 | import br.com.ec.domain.dto.DreVigenciaDTO; |
||
| 17 | import br.com.ec.domain.dto.ParametrosConsultaLancamentosDTO; |
||
| 18 | import br.com.ec.domain.dto.ParametrosConsultaVendasDTO; |
||
| 19 | import br.com.ec.domain.model.IndicadorDRE; |
||
| 159 | espaco | 20 | import br.com.ec.domain.model.Loja; |
| 106 | espaco | 21 | import br.com.ec.domain.model.Vigencia; |
| 22 | import br.com.ec.domain.service.dre.IndicadorDREService; |
||
| 23 | import br.com.ec.domain.service.parcela.ParcelaService; |
||
| 24 | import br.com.ec.domain.service.venda.VendaService; |
||
| 25 | import br.com.ec.domain.shared.ConstantesSEC; |
||
| 195 | espaco | 26 | import br.com.ec.web.generic.AbstractBean; |
| 106 | espaco | 27 | |
| 28 | @Named |
||
| 29 | @Scope("view") |
||
| 30 | public class DreBean extends AbstractBean<DreDTO> implements Serializable { |
||
| 31 | |||
| 32 | private static final long serialVersionUID = 1L; |
||
| 33 | |||
| 34 | private List<Vigencia> vigencias; |
||
| 35 | private Vigencia vigencia; |
||
| 36 | private List<DreVigenciaDTO> dreVigencias; |
||
| 159 | espaco | 37 | private Loja centroDeCustosSelecionado; |
| 106 | espaco | 38 | private List<IndicadorDRE> indicadoresDRE; |
| 39 | private List<IndicadorDRE> indicadores; |
||
| 40 | |||
| 41 | private IndicadorDREService indicadorDREService; |
||
| 42 | private ParcelaService parcelaService; |
||
| 43 | private VendaService vendaService; |
||
| 44 | |||
| 45 | @Inject |
||
| 159 | espaco | 46 | public DreBean(IndicadorDREService indicadorDREService, ParcelaService parcelaService, VendaService vendaService) { |
| 106 | espaco | 47 | this.indicadorDREService = indicadorDREService; |
| 48 | this.parcelaService = parcelaService; |
||
| 49 | this.vendaService = vendaService; |
||
| 50 | } |
||
| 51 | |||
| 52 | @Override |
||
| 53 | public void preCarregamento() { |
||
| 54 | setEntidade(new DreDTO(DataUtils.getPrimeiroDiaDoAnoAtual(), DataUtils.getUltimoDiaDoAnoAtual())); |
||
| 55 | } |
||
| 56 | |||
| 57 | @Override |
||
| 58 | public void limparEntidade() { |
||
| 59 | setEntidade(new DreDTO()); |
||
| 60 | } |
||
| 61 | |||
| 62 | @Override |
||
| 63 | public GenericService<DreDTO> getService() { |
||
| 64 | return null; |
||
| 65 | } |
||
| 66 | |||
| 67 | @Override |
||
| 68 | public DreDTO getEntidade() { |
||
| 69 | return entidade; |
||
| 70 | } |
||
| 71 | |||
| 72 | @Override |
||
| 73 | public DreDTO getId() { |
||
| 74 | return getEntidade(); |
||
| 75 | } |
||
| 76 | |||
| 77 | /********************************************************************/ |
||
| 78 | |||
| 79 | public List<Vigencia> getVigencias() { |
||
| 80 | return vigencias; |
||
| 81 | } |
||
| 82 | public void setVigencias(List<Vigencia> vigencias) { |
||
| 83 | this.vigencias = vigencias; |
||
| 84 | } |
||
| 85 | |||
| 86 | public Vigencia getVigencia() { |
||
| 87 | return vigencia; |
||
| 88 | } |
||
| 89 | public void setVigencia(Vigencia vigencia) { |
||
| 90 | this.vigencia = vigencia; |
||
| 91 | } |
||
| 92 | |||
| 93 | public List<IndicadorDRE> getIndicadoresDRE() { |
||
| 94 | if (VerificadorUtil.estaNulo(indicadoresDRE)) { |
||
| 95 | setIndicadoresDRE(indicadorDREService.consultarIndicadores()); |
||
| 96 | } |
||
| 97 | return indicadoresDRE; |
||
| 98 | } |
||
| 99 | public void setIndicadoresDRE(List<IndicadorDRE> indicadoresDRE) { |
||
| 100 | this.indicadoresDRE = indicadoresDRE; |
||
| 101 | } |
||
| 102 | |||
| 103 | public List<IndicadorDRE> getIndicadores() { |
||
| 104 | return indicadores; |
||
| 105 | } |
||
| 106 | public void setIndicadores(List<IndicadorDRE> indicadores) { |
||
| 107 | this.indicadores = indicadores; |
||
| 108 | } |
||
| 109 | |||
| 110 | public List<DreVigenciaDTO> getDreVigencias() { |
||
| 111 | return dreVigencias; |
||
| 112 | } |
||
| 113 | public void setDreVigencias(List<DreVigenciaDTO> dreVigencias) { |
||
| 114 | this.dreVigencias = dreVigencias; |
||
| 115 | } |
||
| 116 | |||
| 159 | espaco | 117 | public Loja getCentroDeCustosSelecionado() { |
| 118 | return centroDeCustosSelecionado; |
||
| 119 | } |
||
| 120 | public void setCentroDeCustosSelecionado(Loja centroDeCustosSelecionado) { |
||
| 121 | this.centroDeCustosSelecionado = centroDeCustosSelecionado; |
||
| 122 | } |
||
| 123 | |||
| 106 | espaco | 124 | public void consultarDRE() { |
| 125 | List<DreVigenciaDTO> dreVigencias = new ArrayList<DreVigenciaDTO>(); |
||
| 126 | for (Vigencia vigenciaSelecionada : getVigencias()) { |
||
| 127 | DreVigenciaDTO dre = new DreVigenciaDTO(); |
||
| 128 | dre.setVigencia(vigenciaSelecionada); |
||
| 129 | |||
| 130 | List<IndicadorDRE> indicadores = new ArrayList<IndicadorDRE>(); |
||
| 131 | Double valorReceitaBruta = 0.0; |
||
| 132 | Double valorResultante = 0.0; |
||
| 133 | for (IndicadorDRE indicadorDRE : getIndicadoresDRE()) { |
||
| 134 | IndicadorDRE indicador = null; |
||
| 135 | try { |
||
| 136 | indicador = indicadorDRE.clone(); |
||
| 137 | } catch (CloneNotSupportedException e) {e.printStackTrace();} |
||
| 138 | |||
| 139 | ParametrosConsultaLancamentosDTO parametros = new ParametrosConsultaLancamentosDTO(); |
||
| 140 | parametros.setVigencia(vigenciaSelecionada); |
||
| 141 | parametros.setIndicadorDRE(indicador); |
||
| 159 | espaco | 142 | parametros.setCentroDeCustos(getCentroDeCustosSelecionado()); |
| 106 | espaco | 143 | Double valorTotal = parcelaService.obterValorPassandoParametrosConsulta(parametros); |
| 144 | if (VerificadorUtil.estaNulo(valorTotal)) { |
||
| 145 | valorTotal = 0.0; |
||
| 146 | } |
||
| 147 | ParametrosConsultaVendasDTO parametrosConsultaVendas = new ParametrosConsultaVendasDTO(); |
||
| 148 | parametrosConsultaVendas.setDataInicial(vigenciaSelecionada.getDataInicio()); |
||
| 149 | parametrosConsultaVendas.setDataFinal(vigenciaSelecionada.getDataFim()); |
||
| 159 | espaco | 150 | parametrosConsultaVendas.setLoja(getCentroDeCustosSelecionado()); |
| 106 | espaco | 151 | if (indicador.getCodigo().equals(ConstantesSEC.DRE.RECEITA_OPERACIONAL_BRUTA_1)) { |
| 152 | indicador.setObservacao(ConstantesSEC.DRE.RECEITA_OPERACIONAL_BRUTA_1_INFO); |
||
| 153 | valorTotal = valorTotal + vendaService.obterValorTotalBrutoDeVendasPorLojaEePeriodo(parametrosConsultaVendas); |
||
| 154 | valorResultante = valorResultante + valorTotal; |
||
| 155 | valorReceitaBruta = valorTotal; |
||
| 156 | } |
||
| 157 | if (indicador.getCodigo().equals(ConstantesSEC.DRE.DEDUCOES_ABATIMENTOS_2)) { |
||
| 158 | indicador.setObservacao(ConstantesSEC.DRE.DEDUCOES_ABATIMENTOS_2_INFO); |
||
| 159 | Double valorBruto = vendaService.obterValorTotalBrutoDeVendasPorLojaEePeriodo(parametrosConsultaVendas); |
||
| 160 | valorTotal = valorTotal + (valorBruto - vendaService.obterValorTotalLiquidoDeVendasPorLojaEePeriodo(parametrosConsultaVendas)); |
||
| 161 | } |
||
| 162 | if (indicador.getCodigo().equals(ConstantesSEC.DRE.CUSTO_PRODUTOS_VENDIDOS_SERVICOS_PRESTADOS_3)) { |
||
| 163 | indicador.setObservacao(ConstantesSEC.DRE.CUSTO_PRODUTOS_VENDIDOS_SERVICOS_PRESTADOS_3_INFO); |
||
| 164 | valorTotal = valorTotal + vendaService.obterValorProdutosUtilizadosEmVendasPorLojaEePeriodo(parametrosConsultaVendas); |
||
| 165 | } |
||
| 166 | |||
| 167 | if (indicador.getCodigo().equals(ConstantesSEC.DRE.DESPESAS_OPERACIONAIS_VENDAS_VARIAVEIS_4)) { |
||
| 168 | indicador.setObservacao(ConstantesSEC.DRE.DESPESAS_OPERACIONAIS_VENDAS_VARIAVEIS_4_INFO); |
||
| 169 | } |
||
| 170 | |||
| 171 | if (indicador.getCodigo().equals(ConstantesSEC.DRE.DESPESAS_GERAIS_ADMINISTRATIVAS_5)) { |
||
| 172 | indicador.setObservacao(ConstantesSEC.DRE.DESPESAS_GERAIS_ADMINISTRATIVAS_5_INFO); |
||
| 173 | } |
||
| 174 | |||
| 175 | if (indicador.getCodigo().equals(ConstantesSEC.DRE.DESPESAS_FINANCEIRAS_6)) { |
||
| 176 | indicador.setObservacao(ConstantesSEC.DRE.DESPESAS_FINANCEIRAS_6_INFO); |
||
| 177 | } |
||
| 178 | |||
| 179 | if (indicador.getCodigo().equals(ConstantesSEC.DRE.DESPESAS_DEPRECIACAO_7)) { |
||
| 180 | indicador.setObservacao(ConstantesSEC.DRE.DESPESAS_DEPRECIACAO_7_INFO); |
||
| 181 | } |
||
| 182 | |||
| 183 | if (indicador.getCodigo().equals(ConstantesSEC.DRE.IMPOSTO_RENDA_JURIDICA_8)) { |
||
| 184 | indicador.setObservacao(ConstantesSEC.DRE.IMPOSTO_RENDA_JURIDICA_8_INFO); |
||
| 185 | } |
||
| 186 | |||
| 187 | if (indicador.getCodigo().equals(ConstantesSEC.DRE.CONTRIBUICAO_SOCIAL_LUCRO_CSLL_9)) { |
||
| 188 | indicador.setObservacao(ConstantesSEC.DRE.CONTRIBUICAO_SOCIAL_LUCRO_CSLL_9_INFO); |
||
| 189 | } |
||
| 190 | |||
| 191 | if (indicador.getCodigo().equals(ConstantesSEC.DRE.PRO_LABORE_10)) { |
||
| 192 | indicador.setObservacao(ConstantesSEC.DRE.PRO_LABORE_10_INFO); |
||
| 193 | } |
||
| 194 | |||
| 195 | if (indicador.getCodigo().equals(ConstantesSEC.DRE.PARTICIPACAO_NOS_LUCROS_11)) { |
||
| 196 | indicador.setObservacao(ConstantesSEC.DRE.PARTICIPACAO_NOS_LUCROS_11_INFO); |
||
| 197 | } |
||
| 198 | |||
| 199 | indicador.setValorTotal(valorTotal); |
||
| 200 | indicador.setMargem(indicador.getValorTotal()/valorReceitaBruta); |
||
| 201 | indicadores.add(indicador); |
||
| 202 | |||
| 203 | if (!indicador.getCodigo().equals(ConstantesSEC.DRE.RECEITA_OPERACIONAL_BRUTA_1)) { |
||
| 204 | valorResultante = valorResultante - valorTotal; |
||
| 205 | } |
||
| 206 | |||
| 207 | IndicadorDRE ind = new IndicadorDRE(); |
||
| 208 | ind.setValorTotal(valorResultante); |
||
| 209 | ind.setMargem(ind.getValorTotal()/valorReceitaBruta); |
||
| 210 | |||
| 211 | if (indicador.getCodigo().equals(ConstantesSEC.DRE.DEDUCOES_ABATIMENTOS_2)) { |
||
| 212 | ind.setDescricao(ConstantesSEC.DRE.RECEITA_OPERACIONAL_LIQUIDA); |
||
| 213 | ind.setObservacao(ConstantesSEC.DRE.RECEITA_OPERACIONAL_LIQUIDA_INFO); |
||
| 214 | } |
||
| 215 | |||
| 216 | if (indicador.getCodigo().equals(ConstantesSEC.DRE.CUSTO_PRODUTOS_VENDIDOS_SERVICOS_PRESTADOS_3)) { |
||
| 217 | ind.setDescricao(ConstantesSEC.DRE.RESULTADO_OPERACIONAL_BRUTO_LUCRO_BRUTO); |
||
| 218 | ind.setObservacao(ConstantesSEC.DRE.RESULTADO_OPERACIONAL_BRUTO_LUCRO_BRUTO_INFO); |
||
| 219 | } |
||
| 220 | |||
| 221 | if (indicador.getCodigo().equals(ConstantesSEC.DRE.DESPESAS_OPERACIONAIS_VENDAS_VARIAVEIS_4)) { |
||
| 222 | ind.setDescricao(ConstantesSEC.DRE.MARGEM_CONTRIBUICAO); |
||
| 223 | ind.setObservacao(ConstantesSEC.DRE.MARGEM_CONTRIBUICAO_INFO); |
||
| 224 | } |
||
| 225 | |||
| 226 | if (indicador.getCodigo().equals(ConstantesSEC.DRE.DESPESAS_GERAIS_ADMINISTRATIVAS_5)) { |
||
| 227 | ind.setDescricao(ConstantesSEC.DRE.EBITDA); |
||
| 228 | ind.setObservacao(ConstantesSEC.DRE.EBITDA_INFO); |
||
| 229 | } |
||
| 230 | |||
| 231 | if (indicador.getCodigo().equals(ConstantesSEC.DRE.DESPESAS_DEPRECIACAO_7)) { |
||
| 232 | ind.setDescricao(ConstantesSEC.DRE.RESULTADO_OPERACIONAL_LIQUIDO_ANTES_IRPJ_CSLL); |
||
| 233 | ind.setObservacao(ConstantesSEC.DRE.RESULTADO_OPERACIONAL_LIQUIDO_ANTES_IRPJ_CSLL_INFO); |
||
| 234 | } |
||
| 235 | |||
| 236 | if (indicador.getCodigo().equals(ConstantesSEC.DRE.CONTRIBUICAO_SOCIAL_LUCRO_CSLL_9)) { |
||
| 237 | ind.setDescricao(ConstantesSEC.DRE.LUCRO_LIQUIDO_ANTES_PARTICIPACOES); |
||
| 238 | ind.setObservacao(ConstantesSEC.DRE.LUCRO_LIQUIDO_ANTES_PARTICIPACOES_INFO); |
||
| 239 | } |
||
| 240 | |||
| 241 | if (indicador.getCodigo().equals(ConstantesSEC.DRE.PARTICIPACAO_NOS_LUCROS_11)) { |
||
| 242 | ind.setDescricao(ConstantesSEC.DRE.RESULTADO_LIQUIDO_EXERCICIO); |
||
| 243 | ind.setObservacao(ConstantesSEC.DRE.RESULTADO_LIQUIDO_EXERCICIO_INFO); |
||
| 244 | } |
||
| 245 | |||
| 246 | if (VerificadorUtil.naoEstaNuloOuVazio(ind.getDescricao()) && |
||
| 247 | (!indicador.getCodigo().equals(ConstantesSEC.DRE.DESPESAS_FINANCEIRAS_6) || |
||
| 248 | !indicador.getCodigo().equals(ConstantesSEC.DRE.IMPOSTO_RENDA_JURIDICA_8) || |
||
| 249 | !indicador.getCodigo().equals(ConstantesSEC.DRE.PRO_LABORE_10))) { |
||
| 250 | indicadores.add(ind); |
||
| 251 | } |
||
| 252 | } |
||
| 253 | dre.setIndicadores(indicadores); |
||
| 254 | dreVigencias.add(dre); |
||
| 255 | setIndicadores(indicadores); |
||
| 256 | } |
||
| 257 | DreVigenciaDTO dreVigenciaTotal = montarTotal(dreVigencias); |
||
| 258 | DreVigenciaDTO dreVigenciaMedia = montarMedias(dreVigenciaTotal, dreVigencias.size()); |
||
| 259 | dreVigencias.add(dreVigenciaMedia); |
||
| 260 | dreVigencias.add(dreVigenciaTotal); |
||
| 261 | setDreVigencias(dreVigencias); |
||
| 262 | } |
||
| 263 | |||
| 264 | private DreVigenciaDTO montarTotal(List<DreVigenciaDTO> dreVigencias) { |
||
| 265 | DreVigenciaDTO dreVigenciaTotal = new DreVigenciaDTO(); |
||
| 266 | dreVigenciaTotal.setIndicadores(new ArrayList<IndicadorDRE>()); |
||
| 267 | Vigencia vigencia = new Vigencia(); |
||
| 268 | vigencia.setDescricao("TOTAL"); |
||
| 269 | dreVigenciaTotal.setVigencia(vigencia); |
||
| 270 | for (DreVigenciaDTO dreVigencia : dreVigencias) { |
||
| 271 | for (IndicadorDRE indicador : dreVigencia.getIndicadores()) { |
||
| 272 | try { |
||
| 273 | dreVigenciaTotal.acrescentarValorIndicador(indicador.clone()); |
||
| 274 | } catch (CloneNotSupportedException e) { |
||
| 275 | e.printStackTrace(); |
||
| 276 | } |
||
| 277 | } |
||
| 278 | } |
||
| 279 | return dreVigenciaTotal; |
||
| 280 | } |
||
| 281 | |||
| 282 | private DreVigenciaDTO montarMedias(DreVigenciaDTO dreVigenciaTotal, Integer quantidadeVigencias) { |
||
| 283 | DreVigenciaDTO dreVigenciaMedias = new DreVigenciaDTO(); |
||
| 284 | dreVigenciaMedias.setIndicadores(new ArrayList<IndicadorDRE>()); |
||
| 285 | Vigencia vigencia = new Vigencia(); |
||
| 286 | vigencia.setDescricao("MÉDIA"); |
||
| 287 | dreVigenciaMedias.setVigencia(vigencia); |
||
| 304 | espaco | 288 | Double valorReceitaBruta = 0.0; |
| 106 | espaco | 289 | for (IndicadorDRE indicador : dreVigenciaTotal.getIndicadores()) { |
| 290 | try { |
||
| 291 | IndicadorDRE indicadorMedia = indicador.clone(); |
||
| 292 | indicadorMedia.setValorTotal(indicadorMedia.getValorTotal()/quantidadeVigencias); |
||
| 304 | espaco | 293 | if (VerificadorUtil.naoEstaNulo(indicador.getCodigo())) { |
| 294 | if (indicadorMedia.getCodigo().equals(new Long(ConstantesSEC.DRE.RECEITA_OPERACIONAL_BRUTA_1))) { |
||
| 295 | valorReceitaBruta = indicadorMedia.getValorTotal(); |
||
| 296 | } |
||
| 297 | } |
||
| 298 | indicadorMedia.setMargem(indicadorMedia.getValorTotal()/valorReceitaBruta); |
||
| 106 | espaco | 299 | dreVigenciaMedias.getIndicadores().add(indicadorMedia); |
| 300 | } catch (CloneNotSupportedException e) { |
||
| 301 | e.printStackTrace(); |
||
| 302 | } |
||
| 303 | } |
||
| 304 | return dreVigenciaMedias; |
||
| 305 | } |
||
| 306 | |||
| 307 | } |