Subversion Repositories Integrator Subversion

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
200 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
 
12
import br.com.ec.core.generic.GenericService;
13
import br.com.ec.core.util.DataUtils;
14
import br.com.ec.core.util.VerificadorUtil;
15
import br.com.ec.domain.dto.LojaDTO;
16
import br.com.ec.domain.model.AberturaLoja;
17
import br.com.ec.domain.model.Loja;
18
import br.com.ec.domain.model.Pessoa;
19
import br.com.ec.domain.model.Venda;
20
import br.com.ec.domain.model.VendaVivo;
21
import br.com.ec.domain.model.tipos.TipoEmitirNotaFiscal;
22
import br.com.ec.domain.service.aberturaloja.AberturaLojaService;
23
import br.com.ec.domain.service.loja.LojaService;
24
import br.com.ec.domain.service.produto.ProdutoService;
25
import br.com.ec.domain.service.transferencia.TransferenciaService;
26
import br.com.ec.domain.service.venda.VendaService;
27
import br.com.ec.domain.service.vendavivo.VendaVivoService;
28
import br.com.ec.domain.shared.ConstantesSEC;
29
import br.com.ec.web.exception.VerificadorLancamentoException;
30
import br.com.ec.web.exception.VerificadorLancamentoException.CommandBean;
31
import br.com.ec.web.generic.AbstractBean;
32
import br.com.ec.web.message.LancadorMensagem;
33
 
34
@Named
35
@Scope("view")
36
public class LojaBean extends AbstractBean<Loja> implements Serializable {
37
 
38
        private static final long serialVersionUID = 1L;
39
 
40
        private LojaService lojaService;
41
        private VendaService vendaService;
42
        private VendaVivoService vendaVivoService;
43
        private ProdutoService produtoService;
44
        private AberturaLojaService aberturaLojaService;
45
        private TransferenciaService transferenciaService;
46
 
47
        private Loja lojaSelecionada;
48
        private String senhaUsuarioParaAbertura;
49
        private List<Loja> centrosDeCustos;
50
        private List<Loja> listaLojasAtivas;
51
        private List<Loja> listaLojasAtivasEspacoCase;
52
        private List<Loja> listaLojas;
53
        private List<Loja> listaLojasComDetalhes;
54
        private List<LojaDTO> listaLojasDTOAtivas;
55
 
56
        private Integer quantidadeNotificacoes;
57
        private Integer quantidadeNotificacoesContagem;
58
        private Integer quantidadeNotificacoesRetirarDoSite;
59
        private Integer quantidadeTransferenciasParaReceberAbertas;
60
 
61
        private Integer quantidadeVendas;
62
 
63
        private Boolean consultarComCasaDasCapas = false;
64
 
65
        @Inject
66
        public LojaBean(LojaService lojaService, VendaService vendaService, VendaVivoService vendaVivoService,
67
                        ProdutoService produtoService, AberturaLojaService aberturaLojaService, TransferenciaService transferenciaService) {
68
                this.lojaService = lojaService;
69
                this.vendaService = vendaService;
70
                this.vendaVivoService = vendaVivoService;
71
                this.produtoService = produtoService;
72
                this.aberturaLojaService = aberturaLojaService;
73
                this.transferenciaService = transferenciaService;
74
        }
75
 
76
        @Override
77
        public void limparEntidade() {
78
                setEntidade(new Loja());
79
        }
80
 
81
        @Override
82
        public GenericService<Loja> getService() {
83
                return lojaService;
84
        }
85
 
86
        @Override
87
        public Loja getEntidade() {
88
                return entidade;
89
        }
90
 
91
        @Override
92
        public Loja getId() {
93
                return getEntidade();
94
        }
95
 
96
        public Loja getLojaSelecionada() {
97
                if (VerificadorUtil.estaNulo(lojaSelecionada)) {
98
                        if (VerificadorUtil.naoEstaNulo(getParametro("sequencialLoja"))) {
99
                                Loja loja = new Loja();
100
                                loja.setSequencial(new Long(getParametro("sequencialLoja").toString()));
101
                                lojaSelecionada = lojaService.consultarPorId(loja);
102
                        }
103
                }
104
                return lojaSelecionada;
105
        }
106
        public void setLojaSelecionada(Loja lojaSelecionada) {
107
                this.lojaSelecionada = lojaSelecionada;
108
        }
109
 
110
        public String getSenhaUsuarioParaAbertura() {
111
                return senhaUsuarioParaAbertura;
112
        }
113
        public void setSenhaUsuarioParaAbertura(String senhaUsuarioParaAbertura) {
114
                this.senhaUsuarioParaAbertura = senhaUsuarioParaAbertura;
115
        }
116
 
117
        public List<Loja> getCentrosDeCustos() {
118
                if (VerificadorUtil.estaNuloOuVazio(centrosDeCustos)) {
119
                        List<Loja> lojasAtivas = new ArrayList<Loja>();
120
                        lojasAtivas.add(new Loja(new Long(-1), "SEM CENTRO DE CUSTOS"));
121
                        lojasAtivas.addAll(getListaLojasAtivas());
122
                        setCentrosDeCustos(lojasAtivas);
123
                }
124
                return centrosDeCustos;
125
        }
126
        public void setCentrosDeCustos(List<Loja> centrosDeCustos) {
127
                this.centrosDeCustos = centrosDeCustos;
128
        }
129
 
130
        public List<Loja> getListaLojasAtivas() {
131
                if (VerificadorUtil.estaNulo(listaLojasAtivas)) {
132
                        setListaLojasAtivas(lojaService.listarLojasAtivas());
133
                }
134
                return listaLojasAtivas;
135
        }
136
        public void setListaLojasAtivas(List<Loja> listaLojasAtivas) {
137
                this.listaLojasAtivas = listaLojasAtivas;
138
        }
139
 
140
        public List<Loja> getListaLojasAtivasEspacoCase() {
141
                if (VerificadorUtil.estaNulo(listaLojasAtivasEspacoCase)) {
142
                        setListaLojasAtivasEspacoCase(lojaService.listarLojasAtivasEspacoCase());
143
                }
144
                return listaLojasAtivasEspacoCase;
145
        }
146
        public void setListaLojasAtivasEspacoCase(List<Loja> listaLojasAtivasEspacoCase) {
147
                this.listaLojasAtivasEspacoCase = listaLojasAtivasEspacoCase;
148
        }
149
        public List<Loja> listaLojasAtivasEspacoCase(Boolean comCasaDasCapas) {
150
                Loja lojaCasaDasCapas = new Loja(ConstantesSEC.SEQUENCIAL_CASA_DAS_CAPAS_17);
151
                if (comCasaDasCapas) {
152
                        if (!getListaLojasAtivasEspacoCase().contains(lojaCasaDasCapas)) {
153
                                setListaLojasAtivasEspacoCase(lojaService.listarLojasAtivasEspacoCaseEeCasaDasCapas());
154
                        }
155
                } else {
156
                        getListaLojasAtivasEspacoCase().remove(lojaCasaDasCapas);
157
                }
158
                return getListaLojasAtivasEspacoCase();
159
        }
160
 
161
        public List<Loja> getListaLojas() {
162
                if (VerificadorUtil.estaNulo(listaLojas)) {
163
                        setListaLojas(lojaService.consultarTodos(new Loja()));
164
                }
165
                return listaLojas;
166
        }
167
        public void setListaLojas(List<Loja> listaLojas) {
168
                this.listaLojas = listaLojas;
169
        }
170
 
171
        public List<Loja> getListaLojasComDetalhes() {
172
                if (VerificadorUtil.estaNulo(listaLojasComDetalhes)) {
173
                        setListaLojasComDetalhes(lojaService.listarLojasComDetalhe());
174
                }
175
                return listaLojasComDetalhes;
176
        }
177
        public void setListaLojasComDetalhes(List<Loja> listaLojasComDetalhes) {
178
                this.listaLojasComDetalhes = listaLojasComDetalhes;
179
        }
180
 
181
        public List<LojaDTO> getListaLojasDTOAtivas() {
182
                if (VerificadorUtil.estaNulo(listaLojasDTOAtivas)) {
183
                        setListaLojasDTOAtivas(lojaService.listarLojasDTOAtivas());
184
                }
185
                return listaLojasDTOAtivas;
186
        }
187
        public void setListaLojasDTOAtivas(List<LojaDTO> listaLojasDTOAtivas) {
188
                this.listaLojasDTOAtivas = listaLojasDTOAtivas;
189
        }
190
 
191
        public Integer getQuantidadeNotificacoes() {
192
                if (VerificadorUtil.naoEstaNulo(getLojaSelecionada())) {
193
                        if (VerificadorUtil.estaNulo(quantidadeNotificacoes)) {
194
                                setQuantidadeNotificacoes(quantidadeNotificacoes());
195
                        }
196
                }
197
                return quantidadeNotificacoes;
198
        }
199
        public void setQuantidadeNotificacoes(Integer quantidadeNotificacoes) {
200
                this.quantidadeNotificacoes = quantidadeNotificacoes;
201
        }
202
 
203
        public Integer getQuantidadeNotificacoesContagem() {
204
                if (VerificadorUtil.naoEstaNulo(getLojaSelecionada())) {
205
                        if (VerificadorUtil.estaNulo(quantidadeNotificacoesContagem)) {
206
                                setQuantidadeNotificacoesContagem(quantidadeNotificacoesContagem(getLojaSelecionada()));
207
                        }
208
                }
209
                return quantidadeNotificacoesContagem;
210
        }
211
        public void setQuantidadeNotificacoesContagem(Integer quantidadeNotificacoesContagem) {
212
                this.quantidadeNotificacoesContagem = quantidadeNotificacoesContagem;
213
        }
214
 
215
        public Integer getQuantidadeNotificacoesRetirarDoSite() {
216
                if (VerificadorUtil.naoEstaNulo(getLojaSelecionada())) {
217
                        if (VerificadorUtil.estaNulo(quantidadeNotificacoesRetirarDoSite)) {
218
                                setQuantidadeNotificacoesRetirarDoSite(quantidadeNotificacoesRetirarDoSite(getLojaSelecionada()));
219
                        }
220
                }
221
                return quantidadeNotificacoesRetirarDoSite;
222
        }
223
        public void setQuantidadeNotificacoesRetirarDoSite(Integer quantidadeNotificacoesRetirarDoSite) {
224
                this.quantidadeNotificacoesRetirarDoSite = quantidadeNotificacoesRetirarDoSite;
225
        }
226
 
227
        public Integer getQuantidadeTransferenciasParaReceberAbertas() {
228
                if (VerificadorUtil.naoEstaNulo(getLojaSelecionada())) {
229
                        if (VerificadorUtil.estaNulo(quantidadeTransferenciasParaReceberAbertas)) {
230
                                setQuantidadeTransferenciasParaReceberAbertas(quantidadeTransferenciasAbertasParaReceber(getLojaSelecionada()));
231
                        }
232
                }
233
                return quantidadeTransferenciasParaReceberAbertas;
234
        }
235
        public void setQuantidadeTransferenciasParaReceberAbertas(Integer quantidadeTransferenciasParaReceberAbertas) {
236
                this.quantidadeTransferenciasParaReceberAbertas = quantidadeTransferenciasParaReceberAbertas;
237
        }
238
 
239
        /***************************************************************/
240
 
241
        public TipoEmitirNotaFiscal[] getTiposEmitirNotaFiscal() {
242
                return TipoEmitirNotaFiscal.values();
243
        }
244
 
245
        public boolean lojaEstaAberta(Loja loja) {
246
                return VerificadorUtil.naoEstaNulo(aberturaLojaService.consultarAberturaLoja(DataUtils.getDataAtual(), loja));
247
        }
248
 
249
        public AberturaLoja consultarAberturaLoja(Long sequencialLoja) {
250
                return aberturaLojaService.consultarAberturaLoja(DataUtils.getDataAtual(), new Loja(sequencialLoja));
251
        }
252
 
253
        public void abrirLoja() {
254
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
255
                        public void execute() {
256
                                aberturaLojaService.abrirLoja(getSenhaUsuarioParaAbertura(), getLojaSelecionada());
257
                                LancadorMensagem.lancarSucessoRedirecionandoTela("ABERTURA DE LOJA REALIZADA COM SUCESSO!", "/sistema/loja.xhtml?sequencialLoja=" + getLojaSelecionada().getSequencial());
258
                        }
259
                });
260
        }
261
 
262
        public Integer getQuantidadeVendas() {
263
                return quantidadeVendas;
264
        }
265
        public void setQuantidadeVendas(Integer quantidadeVendas) {
266
                this.quantidadeVendas = quantidadeVendas;
267
        }
268
        public Integer quantidadeVendas(Loja loja) {
269
                if (VerificadorUtil.estaNulo(getQuantidadeVendas())) {
270
                        Venda venda = new Venda();
271
                        venda.setLoja(loja);
272
                        setQuantidadeVendas(vendaService.obterQuantidadeDeVendasPorLojaEePeriodo(venda, DataUtils.getDataAtual(), DataUtils.getDataAtual()));
273
                }
274
                return getQuantidadeVendas();
275
        }
276
 
277
        public Boolean getConsultarComCasaDasCapas() {
278
                return consultarComCasaDasCapas;
279
        }
280
        public void setConsultarComCasaDasCapas(Boolean consultarComCasaDasCapas) {
281
                this.consultarComCasaDasCapas = consultarComCasaDasCapas;
282
        }
283
 
284
        public Integer quantidadeVendasVivo(Loja loja) {
285
                VendaVivo venda = new VendaVivo();
286
                venda.setLoja(loja);
287
                return vendaVivoService.obterQuantidadeDeVendasPorLojaEePeriodo(venda, DataUtils.getDataAtual(), DataUtils.getDataAtual());
288
        }
289
 
290
        public Integer quantidadeNotificacoes(Loja loja) {
291
                Integer notificacoes = 0;
292
                if (VerificadorUtil.naoEstaNulo(loja)) {
293
                        if (quantidadeNotificacoesContagem(loja) > 0) {notificacoes++;}
294
                }
295
                return notificacoes;
296
        }
297
 
298
        public Integer quantidadeNotificacoes(Integer quantidadeNotificacoesContagem) {
299
                Integer notificacoes = 0;
300
                if (VerificadorUtil.naoEstaNulo(quantidadeNotificacoesContagem)) {
301
                        if (quantidadeNotificacoesContagem > 0) {notificacoes++;}
302
                }
303
                return notificacoes;
304
        }
305
 
306
        public Integer quantidadeNotificacoes() {
307
                Integer notificacoes = 0;
308
                if (VerificadorUtil.naoEstaNulo(getQuantidadeNotificacoesContagem())) {
309
                        if (getQuantidadeNotificacoesContagem() > 0) {notificacoes++;}
310
                }
311
                return notificacoes;
312
        }
313
 
314
        public Integer quantidadeNotificacoesContagem(Loja loja) {
315
                return produtoService.quantidadeParaContagem(loja);
316
        }
317
 
318
        public Integer quantidadeNotificacoesRetirarDoSite(Loja loja) {
319
                return produtoService.quantidadeProdutosParaRetirarDoOnline(loja);
320
        }
321
 
322
        public Integer quantidadeTransferenciasAbertasParaReceber(Loja loja) {
323
                return transferenciaService.obterQuantidadeDeTransferenciasParaReceberAbertas(loja, null, null);
324
        }
325
 
326
        public void selecionarPessoaJuridica(final Pessoa pessoa) {
327
                new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() {
328
                        public void execute() {
329
                                getEntidade().setPessoaJuridica(pessoa);
330
                                adicionandoParametroArgsConfirmandoAcao(true);
331
                        }
332
                });
333
        }
334
 
335
        public void retirarPessoaJuridica() {
336
                getEntidade().setPessoaJuridica(null);
337
        }
338
 
339
        /***************************************************************/
340
 
341
        public Long getSequencialQuiosqueExtra() {
342
                return ConstantesSEC.SEQUENCIAL_QUIOSQUE_EXTRA_2;
343
        }
344
 
345
        public Long getSequencialLojaVivo() {
346
                return ConstantesSEC.SEQUENCIAL_LOJA_VIVO_4;
347
        }
348
 
349
        public Long getSequencialMatrizEstoque() {
350
                return ConstantesSEC.SEQUENCIAL_MATRIZ_ESTOQUE_9;
351
        }
352
 
353
        public Long getSequencialLojaFarmacia() {
354
                return ConstantesSEC.SEQUENCIAL_LOJA_FARMACIA_7;
355
        }
356
 
357
        public Long getSequencialRestaurante() {
358
                return ConstantesSEC.SEQUENCIAL_RESTAURANTE_16;
359
        }
360
 
361
        public Long getSequencialCasaDasCapas() {
362
                return ConstantesSEC.SEQUENCIAL_CASA_DAS_CAPAS_17;
363
        }
364
 
365
}