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