Subversion Repositories Integrator Subversion

Rev

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