Subversion Repositories Integrator Subversion

Rev

Details | Last modification | View Log | RSS feed

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