Rev 582 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 582 | blopes | 1 | package br.com.ec.domain.dto; |
| 2 | |||
| 3 | import java.util.ArrayList; |
||
| 4 | import java.util.Date; |
||
| 5 | import java.util.List; |
||
| 6 | |||
| 7 | import br.com.ec.core.util.DataUtils; |
||
| 8 | import br.com.ec.core.util.VerificadorUtil; |
||
| 9 | import br.com.ec.domain.model.Produto; |
||
| 10 | import br.com.ec.domain.model.Venda; |
||
| 11 | import br.com.ec.domain.model.tipos.TipoStatusPedidoCompra; |
||
| 12 | |||
| 13 | public class RankingProdutoDTO implements Comparable<RankingProdutoDTO> { |
||
| 14 | |||
| 15 | private Produto produto; |
||
| 16 | private Venda venda; |
||
| 17 | private Double valorTotalVendido; |
||
| 18 | private Double valorTotalComprado; |
||
| 19 | private Double valorTotalDescontos; |
||
| 20 | private Long quantidadeVendas; |
||
| 21 | private Integer quantidadeDiasVendas; |
||
| 22 | private Long quantidadeEstoque; |
||
| 23 | private Long quantidadeAuditorias; |
||
| 24 | |||
| 25 | private String statusPedidoCompra; |
||
| 26 | private Integer quantidadeParaComprarPedidoCompra; |
||
| 27 | |||
| 28 | private Double consumoMedioDiario; |
||
| 29 | private Integer tempoEstoque; |
||
| 30 | private Date dataUltimaVenda; |
||
| 31 | |||
| 32 | private List<RankingProdutoPorLojaDTO> rankingsPorLoja = new ArrayList<RankingProdutoPorLojaDTO>(); |
||
| 33 | |||
| 34 | public RankingProdutoDTO() {} |
||
| 35 | |||
| 36 | public RankingProdutoDTO(Produto produto, Long quantidadeAuditorias, Long quantidadeVendas, Long quantidadeEstoque) { |
||
| 37 | this.produto = produto; |
||
| 38 | this.quantidadeAuditorias = quantidadeAuditorias; |
||
| 39 | this.quantidadeVendas = quantidadeVendas; |
||
| 40 | this.quantidadeEstoque = quantidadeEstoque; |
||
| 41 | } |
||
| 42 | |||
| 43 | public RankingProdutoDTO(Produto produto, Double valorTotalVendido, Double valorTotalComprado, Double valorTotalDescontos, |
||
| 44 | Long quantidadeVendas, Integer quantidadeDiasVendas, Date dataUltimaVenda, Long quantidadeEstoque, String statusPedidoCompra, |
||
| 45 | Integer quantidadeParaComprarPedidoCompra) { |
||
| 46 | this.produto = produto; |
||
| 47 | this.valorTotalVendido = valorTotalVendido; |
||
| 48 | this.valorTotalComprado = valorTotalComprado; |
||
| 49 | this.valorTotalDescontos = valorTotalDescontos; |
||
| 50 | this.quantidadeVendas = quantidadeVendas; |
||
| 51 | this.quantidadeDiasVendas = quantidadeDiasVendas; |
||
| 52 | this.dataUltimaVenda = dataUltimaVenda; |
||
| 53 | this.quantidadeEstoque = quantidadeEstoque; |
||
| 54 | this.statusPedidoCompra = statusPedidoCompra; |
||
| 55 | this.quantidadeParaComprarPedidoCompra = quantidadeParaComprarPedidoCompra; |
||
| 56 | } |
||
| 57 | |||
| 58 | public RankingProdutoDTO(Produto produto, Double valorTotalVendido, Double valorTotalComprado, Double valorTotalDescontos, |
||
| 59 | Long quantidadeVendas, Date dataUltimaVenda, Long quantidadeEstoque, String statusPedidoCompra, |
||
| 60 | Integer quantidadeParaComprarPedidoCompra) { |
||
| 61 | this.produto = produto; |
||
| 62 | this.valorTotalVendido = valorTotalVendido; |
||
| 63 | this.valorTotalComprado = valorTotalComprado; |
||
| 64 | this.valorTotalDescontos = valorTotalDescontos; |
||
| 65 | this.quantidadeVendas = quantidadeVendas; |
||
| 66 | this.dataUltimaVenda = dataUltimaVenda; |
||
| 67 | this.quantidadeEstoque = quantidadeEstoque; |
||
| 68 | this.statusPedidoCompra = statusPedidoCompra; |
||
| 69 | this.quantidadeParaComprarPedidoCompra = quantidadeParaComprarPedidoCompra; |
||
| 70 | } |
||
| 71 | |||
| 72 | public RankingProdutoDTO(Produto produto, Double valorTotalVendido, Double valorTotalComprado, Double valorTotalDescontos, |
||
| 73 | Long quantidadeVendas) { |
||
| 74 | this.produto = produto; |
||
| 75 | this.valorTotalVendido = valorTotalVendido; |
||
| 76 | this.valorTotalComprado = valorTotalComprado; |
||
| 77 | this.valorTotalDescontos = valorTotalDescontos; |
||
| 78 | this.quantidadeVendas = quantidadeVendas; |
||
| 79 | } |
||
| 80 | |||
| 81 | public RankingProdutoDTO(Produto produto, Venda venda, Double valorTotalVendido, Double valorTotalDescontos, |
||
| 82 | Long quantidadeEstoque, String statusPedidoCompra, Integer quantidadeParaComprarPedidoCompra) { |
||
| 83 | this.produto = produto; |
||
| 84 | this.venda = venda; |
||
| 85 | this.valorTotalVendido = valorTotalVendido; |
||
| 86 | this.valorTotalDescontos = valorTotalDescontos; |
||
| 87 | this.quantidadeEstoque = quantidadeEstoque; |
||
| 88 | this.statusPedidoCompra = statusPedidoCompra; |
||
| 89 | this.quantidadeParaComprarPedidoCompra = quantidadeParaComprarPedidoCompra; |
||
| 90 | } |
||
| 91 | |||
| 92 | public Produto getProduto() { |
||
| 93 | return produto; |
||
| 94 | } |
||
| 95 | public void setProduto(Produto produto) { |
||
| 96 | this.produto = produto; |
||
| 97 | } |
||
| 98 | |||
| 99 | public Venda getVenda() { |
||
| 100 | return venda; |
||
| 101 | } |
||
| 102 | public void setVenda(Venda venda) { |
||
| 103 | this.venda = venda; |
||
| 104 | } |
||
| 105 | |||
| 106 | public Double getValorTotalVendido() { |
||
| 107 | return valorTotalVendido; |
||
| 108 | } |
||
| 109 | public void setValorTotalVendido(Double valorTotalVendido) { |
||
| 110 | this.valorTotalVendido = valorTotalVendido; |
||
| 111 | } |
||
| 112 | |||
| 113 | public Double getValorTotalComprado() { |
||
| 114 | return valorTotalComprado; |
||
| 115 | } |
||
| 116 | public void setValorTotalComprado(Double valorTotalComprado) { |
||
| 117 | this.valorTotalComprado = valorTotalComprado; |
||
| 118 | } |
||
| 119 | |||
| 120 | public Double getValorTotalDescontos() { |
||
| 121 | return valorTotalDescontos; |
||
| 122 | } |
||
| 123 | public void setValorTotalDescontos(Double valorTotalDescontos) { |
||
| 124 | this.valorTotalDescontos = valorTotalDescontos; |
||
| 125 | } |
||
| 126 | |||
| 127 | public Long getQuantidadeAuditorias() { |
||
| 128 | return quantidadeAuditorias; |
||
| 129 | } |
||
| 130 | public void setQuantidadeAuditorias(Long quantidadeAuditorias) { |
||
| 131 | this.quantidadeAuditorias = quantidadeAuditorias; |
||
| 132 | } |
||
| 133 | |||
| 134 | public Long getQuantidadeVendas() { |
||
| 135 | return quantidadeVendas; |
||
| 136 | } |
||
| 137 | public void setQuantidadeVendas(Long quantidadeVendas) { |
||
| 138 | this.quantidadeVendas = quantidadeVendas; |
||
| 139 | } |
||
| 140 | |||
| 141 | public Integer getQuantidadeDiasVendas() { |
||
| 142 | return quantidadeDiasVendas; |
||
| 143 | } |
||
| 144 | public void setQuantidadeDiasVendas(Integer quantidadeDiasVendas) { |
||
| 145 | this.quantidadeDiasVendas = quantidadeDiasVendas; |
||
| 146 | } |
||
| 147 | |||
| 148 | public Long getQuantidadeEstoque() { |
||
| 149 | return quantidadeEstoque; |
||
| 150 | } |
||
| 151 | public void setQuantidadeEstoque(Long quantidadeEstoque) { |
||
| 152 | this.quantidadeEstoque = quantidadeEstoque; |
||
| 153 | } |
||
| 154 | |||
| 155 | public String getStatusPedidoCompra() { |
||
| 156 | return statusPedidoCompra; |
||
| 157 | } |
||
| 158 | public void setStatusPedidoCompra(String statusPedidoCompra) { |
||
| 159 | this.statusPedidoCompra = statusPedidoCompra; |
||
| 160 | } |
||
| 161 | |||
| 162 | public Integer getQuantidadeParaComprarPedidoCompra() { |
||
| 163 | return quantidadeParaComprarPedidoCompra; |
||
| 164 | } |
||
| 165 | public void setQuantidadeParaComprarPedidoCompra(Integer quantidadeParaComprarPedidoCompra) { |
||
| 166 | this.quantidadeParaComprarPedidoCompra = quantidadeParaComprarPedidoCompra; |
||
| 167 | } |
||
| 168 | |||
| 169 | public Double getConsumoMedioDiario() { |
||
| 170 | return consumoMedioDiario; |
||
| 171 | } |
||
| 172 | public void setConsumoMedioDiario(Double consumoMedioDiario) { |
||
| 173 | this.consumoMedioDiario = consumoMedioDiario; |
||
| 174 | } |
||
| 175 | |||
| 176 | public Integer getTempoEstoque() { |
||
| 177 | return tempoEstoque; |
||
| 178 | } |
||
| 179 | public void setTempoEstoque(Integer tempoEstoque) { |
||
| 180 | this.tempoEstoque = tempoEstoque; |
||
| 181 | } |
||
| 182 | |||
| 183 | public Date getDataUltimaVenda() { |
||
| 184 | return dataUltimaVenda; |
||
| 185 | } |
||
| 186 | public void setDataUltimaVenda(Date dataUltimaVenda) { |
||
| 187 | this.dataUltimaVenda = dataUltimaVenda; |
||
| 188 | } |
||
| 189 | |||
| 190 | public Integer getQuantidadeDiasUltimaVenda() { |
||
| 191 | if (VerificadorUtil.naoEstaNulo(getDataUltimaVenda())) { |
||
| 192 | return DataUtils.calcularDiferenceEmDiasEntreDuasDatas(DataUtils.getDataAtual(), getDataUltimaVenda()); |
||
| 193 | } |
||
| 194 | return null; |
||
| 195 | } |
||
| 196 | |||
| 197 | public List<RankingProdutoPorLojaDTO> getRankingsPorLoja() { |
||
| 198 | return rankingsPorLoja; |
||
| 199 | } |
||
| 200 | public void setRankingsPorLoja(List<RankingProdutoPorLojaDTO> rankingsPorLoja) { |
||
| 201 | this.rankingsPorLoja = rankingsPorLoja; |
||
| 202 | } |
||
| 203 | |||
| 204 | public Integer quantidadeParaComprar(Integer quantidadeParaComprar, Integer quantidadeVendas, Integer quantidadeEstoque) { |
||
| 205 | return (quantidadeParaComprar * quantidadeVendas) - quantidadeEstoque; |
||
| 206 | } |
||
| 207 | |||
| 208 | public Long quantidadeEstoque(Long sequencialLoja) { |
||
| 209 | for (RankingProdutoPorLojaDTO rankingProdutoPorLojaDTO : this.getRankingsPorLoja()) { |
||
| 210 | if (rankingProdutoPorLojaDTO.getLoja().getSequencial().equals(sequencialLoja)) { |
||
| 211 | return rankingProdutoPorLojaDTO.getQuantidadeEstoque(); |
||
| 212 | } |
||
| 213 | } |
||
| 214 | return null; |
||
| 215 | } |
||
| 216 | |||
| 217 | public Long quantidadeParaTransferir(Long sequencialLoja) { |
||
| 218 | for (RankingProdutoPorLojaDTO rankingProdutoPorLojaDTO : this.getRankingsPorLoja()) { |
||
| 219 | if (rankingProdutoPorLojaDTO.getLoja().getSequencial().equals(sequencialLoja)) { |
||
| 220 | return rankingProdutoPorLojaDTO.quantidadeParaTransferir(); |
||
| 221 | } |
||
| 222 | } |
||
| 223 | return null; |
||
| 224 | } |
||
| 225 | |||
| 226 | public Long quantidadeParaTransferirSugerida(Long sequencialLoja) { |
||
| 227 | for (RankingProdutoPorLojaDTO rankingProdutoPorLojaDTO : this.getRankingsPorLoja()) { |
||
| 228 | if (rankingProdutoPorLojaDTO.getLoja().getSequencial().equals(sequencialLoja)) { |
||
| 229 | return rankingProdutoPorLojaDTO.getQuantidadeSugeridaParaTransferir(); |
||
| 230 | } |
||
| 231 | } |
||
| 232 | return null; |
||
| 233 | } |
||
| 234 | |||
| 235 | @Override |
||
| 236 | public int compareTo(RankingProdutoDTO rankingProdutoDTO) { |
||
| 237 | return rankingProdutoDTO.getValorTotalVendido().compareTo(this.valorTotalVendido); |
||
| 238 | } |
||
| 239 | |||
| 240 | public Double getPercentualLucro() { |
||
| 241 | if (VerificadorUtil.naoEstaNulo(getValorTotalVendido()) && |
||
| 242 | VerificadorUtil.naoEstaNulo(getValorTotalComprado())) { |
||
| 243 | return (((getValorTotalVendido() * 100)/getValorTotalComprado())- 100)/100; |
||
| 244 | } |
||
| 245 | return 0.0; |
||
| 246 | } |
||
| 247 | |||
| 248 | public String getCorTipoStatusSimplificado() { |
||
| 249 | if (VerificadorUtil.naoEstaNulo(getStatusPedidoCompra())) { |
||
| 250 | if (getStatusPedidoCompra().equals(TipoStatusPedidoCompra.NAO_COMPRAR.getValor())) { |
||
| 251 | return "pink-btn"; |
||
| 252 | } |
||
| 253 | if (getStatusPedidoCompra().equals(TipoStatusPedidoCompra.PENDENTE.getValor())) { |
||
| 254 | return "orange-btn"; |
||
| 255 | } |
||
| 256 | if (getStatusPedidoCompra().equals(TipoStatusPedidoCompra.SOLICITADO.getValor())) { |
||
| 257 | return "blue-btn"; |
||
| 258 | } |
||
| 259 | return "green-btn"; |
||
| 260 | } |
||
| 261 | return "black-btn"; |
||
| 262 | } |
||
| 263 | |||
| 264 | public String getCorTipoStatus() { |
||
| 265 | if (VerificadorUtil.naoEstaNulo(getStatusPedidoCompra())) { |
||
| 266 | return TipoStatusPedidoCompra.parse(getStatusPedidoCompra()).getStyleBotao(); |
||
| 267 | } |
||
| 268 | return "black-btn"; |
||
| 269 | } |
||
| 270 | |||
| 587 | blopes | 271 | public String getCorTipoStatusPedidoCompra() { |
| 272 | if (VerificadorUtil.naoEstaNulo(getStatusPedidoCompra())) { |
||
| 273 | return TipoStatusPedidoCompra.parse(getStatusPedidoCompra()).getCor(); |
||
| 274 | } |
||
| 275 | return "black"; |
||
| 276 | } |
||
| 277 | |||
| 582 | blopes | 278 | public String getQuantidadeParaComprarDoPedido() { |
| 279 | if (VerificadorUtil.naoEstaNulo(getStatusPedidoCompra())) { |
||
| 280 | if (VerificadorUtil.naoEstaNulo(getQuantidadeParaComprarPedidoCompra())) { |
||
| 281 | StringBuilder statusPedido = new StringBuilder(); |
||
| 282 | statusPedido.append(getQuantidadeParaComprarPedidoCompra()); |
||
| 283 | return statusPedido.toString(); |
||
| 284 | } |
||
| 285 | } |
||
| 286 | return "?"; |
||
| 287 | } |
||
| 288 | |||
| 289 | public String getDescricaoDoTipoStatus() { |
||
| 290 | if (VerificadorUtil.naoEstaNulo(getStatusPedidoCompra())) { |
||
| 291 | StringBuilder statusPedido = new StringBuilder(); |
||
| 292 | statusPedido.append(TipoStatusPedidoCompra.parse(getStatusPedidoCompra()).getDescricao()); |
||
| 293 | if (VerificadorUtil.naoEstaNulo(getQuantidadeParaComprarPedidoCompra())) { |
||
| 294 | statusPedido.append(" [").append(getQuantidadeParaComprarPedidoCompra()).append("]"); |
||
| 295 | } |
||
| 296 | return statusPedido.toString(); |
||
| 297 | } |
||
| 298 | return null; |
||
| 299 | } |
||
| 300 | |||
| 301 | public Double getQuantidadeConsumoMedioDiario(Date dataInicial, Date dataFinal) { |
||
| 302 | setQuantidadeDiasVendas(DataUtils.calcularDiferenceEmDiasEntreDuasDatas(dataFinal, dataInicial)); |
||
| 303 | if (VerificadorUtil.naoEstaNulo(getQuantidadeVendas())) { |
||
| 304 | return new Double(getQuantidadeVendas().floatValue()/getQuantidadeDiasVendas().floatValue()); |
||
| 305 | } |
||
| 306 | return null; |
||
| 307 | } |
||
| 308 | |||
| 309 | public void atualizarTempoEstoque(Date dataInicial, Date dataFinal) { |
||
| 310 | setConsumoMedioDiario(getQuantidadeConsumoMedioDiario(dataInicial, dataFinal)); |
||
| 311 | if (VerificadorUtil.naoEstaNulo(getConsumoMedioDiario()) |
||
| 312 | && VerificadorUtil.naoEstaNulo(getQuantidadeEstoque())) { |
||
| 313 | if (getConsumoMedioDiario() > 0 || getQuantidadeEstoque() > 0) { |
||
| 314 | Integer tempoDeEstoque = new Integer((int) (getQuantidadeEstoque().floatValue()/getConsumoMedioDiario().floatValue())); |
||
| 315 | setTempoEstoque(tempoDeEstoque > 0 ? tempoDeEstoque : 0); |
||
| 316 | } else { |
||
| 317 | setTempoEstoque(0); |
||
| 318 | } |
||
| 319 | } else { |
||
| 320 | setTempoEstoque(0); |
||
| 321 | } |
||
| 322 | } |
||
| 323 | |||
| 324 | public Integer quantidadeParaComprar(Date dataInicial, Date dataFinal) { |
||
| 325 | setConsumoMedioDiario(getQuantidadeConsumoMedioDiario(dataInicial, dataFinal)); |
||
| 326 | if (VerificadorUtil.naoEstaNulo(getConsumoMedioDiario()) |
||
| 327 | && VerificadorUtil.naoEstaNulo(getQuantidadeEstoque())) { |
||
| 328 | if (getConsumoMedioDiario() == 0 || getQuantidadeEstoque() == 0) { |
||
| 329 | return 0; |
||
| 330 | } |
||
| 331 | Integer quantidadeParaComprar = new Integer((int) ((getConsumoMedioDiario().floatValue()*getQuantidadeDiasVendas()) - getQuantidadeEstoque())); |
||
| 332 | return quantidadeParaComprar > 0 ? quantidadeParaComprar : 0; |
||
| 333 | } |
||
| 334 | return 0; |
||
| 335 | // return VerificadorUtil.naoEstaNulo(quantidadeParaComprar)? |
||
| 336 | // (quantidadeParaComprar * quantidadeVendas) - quantidadeEstoque : quantidadeParaComprar(quantidadeVendas, quantidadeEstoque); |
||
| 337 | } |
||
| 338 | |||
| 339 | public String corDoTempoEstoque(Integer quantidadeEmDias) { |
||
| 340 | if (getTempoEstoque() <= quantidadeEmDias/2) { |
||
| 341 | return "red"; |
||
| 342 | } |
||
| 343 | if (getTempoEstoque() <= quantidadeEmDias) { |
||
| 344 | return "orange"; |
||
| 345 | } |
||
| 346 | return "black"; |
||
| 347 | } |
||
| 348 | |||
| 349 | public String getCorDoTempoEstoque() { |
||
| 350 | if (getTempoEstoque() <= 10) { |
||
| 351 | return "red"; |
||
| 352 | } |
||
| 353 | if (getTempoEstoque() <= 15) { |
||
| 354 | return "orange"; |
||
| 355 | } |
||
| 356 | return "black"; |
||
| 357 | } |
||
| 358 | |||
| 359 | public Double taxaAuditoria() { |
||
| 360 | Double valor = new Double(0); |
||
| 361 | if (VerificadorUtil.naoEstaNulo(getQuantidadeAuditorias()) |
||
| 362 | && VerificadorUtil.naoEstaNulo(getQuantidadeVendas())) { |
||
| 363 | valor = new Double(getQuantidadeAuditorias()) / new Double(getQuantidadeVendas()); |
||
| 364 | } |
||
| 365 | return valor; |
||
| 366 | } |
||
| 367 | |||
| 368 | public String getCorDaTaxaAuditoria() { |
||
| 369 | if (taxaAuditoria() >= 0.15) { |
||
| 370 | return "red"; |
||
| 371 | } |
||
| 372 | if (taxaAuditoria() >= 0.1) { |
||
| 373 | return "orange"; |
||
| 374 | } |
||
| 375 | return "black"; |
||
| 376 | } |
||
| 377 | |||
| 378 | } |