Subversion Repositories Integrator Subversion

Rev

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