private void login1_OnLoginOk(ComponentModel.LoginEventArgs args) { IAbreCaixa caixa = null; abreCaixaNovamente: try { caixa = new AbreCaixa().PermiteAbrir(Settings.MachineName, DateTime.Now); } catch (PDVObrigatorio) { if (!PDV.Create(true).IsNullOrEmpty()) goto abreCaixaNovamente; } //tem que existir um caixa aberto para este operador. if (caixa == null) { MessageBox.Show("Não foi permitido abrir o caixa para este PDV.", "Aviso!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } IImpressora impressora = null; try { impressora = OpenPOS.ECF.ECF.Create(caixa.Caixa.PDV); } catch (Exception ex) { MessageBox.ShowError(ex, false); return; } //------------------------------------------------------------------------- // Se tem caixa aberto, impressora e o usuário for um operador de caixa ou fiscal de caixa, continua. //------------------------------------------------------------------------- if (args.Usuario.Is(new TipoUsuario((string)Settings.Setting.OperadorCaixa)) || args.Usuario.Is(new TipoUsuario((string)Settings.Setting.FiscalCaixa))) { Settings.ECF.ECFAtual = impressora; Settings.PDV.AberturaCaixa.Caixa = caixa.Caixa; if (args.Usuario.Is(new TipoUsuario((string)Settings.Setting.FiscalCaixa))) Settings.PDV.OperadorCaixaAtual = new FiscalCaixa(args.Usuario.GUID); else Settings.PDV.OperadorCaixaAtual = args.Usuario; if (Unimake.Convert.ToBoolean(Settings.Setting.EmissaoConsumidorFinalNFCe)) frmVendaCF.IniciaVendaNFCe(); else frmVendaCF.IniciaVenda(); Close(); } else { MessageBox.Show("Este usuário não é um operador de caixa"); } }
public override void Gravar() { #region Caixa Cadastro.CaixaTest caixaTest = new Cadastro.CaixaTest(); caixaTest.Gravar(); #endregion #region abrir AbreCaixa abre = new AbreCaixa(); abre.Caixa = new Caixa(caixaTest.GUID); abre.Usuario = OpenPOS.Settings.UsuarioAtual; abre.DataHoraAbertura = DateTime.Now; abre.DataHoraFechamento = DateTime.Now.AddHours(3); #endregion #region fechar FechaCaixa t = new FechaCaixa(); t.Caixa = new Caixa(caixaTest.GUID); t.Usuario = OpenPOS.Settings.UsuarioAtual; t.DataHoraAbertura = DateTime.Now; t.DataHoraFechamento = DateTime.Now.AddHours(2); #endregion //abrir o caixa antes de fechar para evitar erro abre.Save(); GUID = t.Save(); }
/// <summary> /// Faz a abertura do caixa /// </summary> /// <param name="sender">Obejto que disparou o evento</param> /// <param name="e">Argumento do evento gerado</param> private void btnOK_Click(object sender, System.EventArgs e) { dataHoraAbertura = Unimake.Convert.ToDateTime(string.Format("{0} {1}", dtpDataAbertura.Text, dtpHoraAbertura.Text)); IAbreCaixa abreCx = null; try { //sfCaixa.SelectedItem.GUID abreCx = new AbreCaixa().PermiteAbrir(Settings.MachineName, DateTime.Now); if (abreCx == null) { abreCx = new AbreCaixa(); IList<Model.IBaseModel> caixas = new Caixa().Find(new Where() { { "cad_PDV.Nome", Settings.MachineName } }); if (caixas.Count > 0) abreCx.Caixa = caixas[0] as ICaixa; else { ICaixa c = new Caixa(); c.PDV = new PDV().Find(new Where() { { "cad_PDV.Nome", Settings.MachineName } })[0] as PDV; c.Descricao = Settings.MachineName; c.Save(); abreCx.Caixa = c; } abreCx.Usuario = new Usuario(Settings.UsuarioAtual.GUID); abreCx.DataHoraAbertura = dataHoraAbertura; abreCx.Save(); Settings.PDV.AberturaCaixa = abreCx; MessageBox.ShowWarning("Caixa aberto com sucesso."); this.ClearControls(); StatusCaixa = abreCx.Status.ToString(); } else MessageBox.ShowWarning("Não é permitido abrir o caixa, pois se encontra: " + abreCx.Status.ToString()); } catch(PDVObrigatorio) { if(MessageBox.Show("Não existe PDV cadastrado para este terminal. Deseja cadastrar?", "Aviso", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { PDV pdv = new PDV(); pdv.Nome = Settings.MachineName; pdv.Observacao = Settings.MachineName; pdv.Save(); } } catch(Exception ex) { MessageBox.Show(ex.Message, "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Cria uma nova instancia de abertura ou fechamento de caixa com base no GUID informado /// </summary> /// <param name="guid">código do registro para criar a abertura ou fechamento de caixa</param> /// <returns></returns> public static AbreFechaCaixaBase Create(GUID guid) { AbreFechaCaixaBase result = null; //criar uma abertura de caixa, se o status do caixa for fechado, converter para fechamento result = new AbreCaixa(guid); //se o status for fechado, converter para um fechamento if(result.Status == Status.Fechado) result = new FechaCaixa(guid); return result; }
public void DataHoraFechamentoMenorTest() { //gravar uma abertura de caixa Gravar(); //se tentar gravar novamente AbreCaixa abre = new AbreCaixa(GUID); //forçar o erro abre.DataHoraFechamento = abre.DataHoraAbertura.AddHours(-1); //salvar abre.Save(); }
public void DataHoraAberturaObrigatorioTest() { //gravar uma abertura de caixa Gravar(); //se tentar gravar novamente AbreCaixa abre = new AbreCaixa(GUID); //forçar o erro abre.DataHoraAbertura = DateTime.MinValue; //salvar abre.Save(); }
public void CaixaObrigatorioTest() { //gravar uma abertura de caixa Gravar(); //se tentar gravar novamente AbreCaixa abre = new AbreCaixa(GUID); //forçar o erro abre.Caixa = null; //salvar abre.Save(); }
public void CaixaJaAbertoTest() { //gravar uma abertura de caixa Gravar(); //se tentar gravar novamente, tem que dar o erro AbreCaixa abre = new AbreCaixa(GUID); abre.DataHoraAbertura = abre.DataHoraFechamento; abre.DataHoraFechamento = abre.DataHoraFechamento.AddHours(2); //forçar um novo abre.GUID = GUID.Empty; //salvar abre.Save(); }
public override void Popular() { AbreCaixa t = new AbreCaixa(GUID); DumpElement(t); }
public override void Gravar() { //Cadastrar um caixa Cadastro.CaixaTest caixaTest = new Cadastro.CaixaTest(); caixaTest.Gravar(); AbreCaixa t = new AbreCaixa(); t.Caixa = new Caixa(caixaTest.GUID); t.Usuario = OpenPOS.Settings.UsuarioAtual; t.DataHoraAbertura = DateTime.Now; t.DataHoraFechamento = DateTime.Now.AddHours(2); t.Status = Enuns.FrenteCaixa.Cadastro.Caixa.Status.Aberto; GUID = t.Save(); }
public override void Editar() { AbreCaixa t = new AbreCaixa(GUID); t.DataHoraAbertura = DateTime.Now.AddHours(1); t.DataHoraFechamento = DateTime.Now.AddHours(2); t.Save(); }
public frmInicial() { InitializeComponent(); this.ResizeRedraw = true; #if !IsPAF this.mnuPrincipal.Items.Remove(mnuMenuFiscal); #endif //if(isPDV) //{ // tbtnDAV.Visible = false; // mnuLancamentoDAV.Visible = false; // mnuLancamentoPreVenda.Visible = false; // mnuLancamentoDAVOs.Visible = false; // tbtnVendas.Location = new Point(444, 384); // tbtnCaixa.Location = new Point(235, 384); //} //else //{ // mnuMenuFiscal.Visible = false; // tbtnCaixa.Visible = false; // mnuLancamentoVendaCupom.Visible = false; // optBarOutros.Controls.Remove(optBarOutros.tBtnECF); // optBarOutros.Controls.Remove(optBarOutros.touchBtnTEF); // optBarOutros.Location = new Point(848, 237); //} #if !IsPAF mnuPrincipal.Location = new Point(580, 84); #else mnuPrincipal.Location = new Point(445, 84); #endif // ResizeRedraw = true; this.LayoutMdi(MdiLayout.ArrangeIcons); #region Aplicação dos níveis de acesso // Aplica níveis de acesso aos botões foreach(Control control in this.Controls) this.AplicaNiveisDeAcessoBotoes(control.Controls); // Aplica níveis de acesso aos menus var nodeConstructor = new NodeConstructor(); var menuItens = nodeConstructor.BuildListFromMenuStrip(this.mnuPrincipal); this.AplicaNiveisDeAcessoMenus(menuItens); #endregion #region opções caixa optbCaixa.tbtnFechar.Click += new System.EventHandler((object o, EventArgs e) => { FechamentoCaixa frmFechamento = new FechamentoCaixa(); frmFechamento.ShowDialog(this); labelStatus.Text = frmFechamento.StatusCaixa; }); optbCaixa.tbtnAbrir.Click += new EventHandler((object o, EventArgs e) => { frmLogin frmLogin = new frmLogin(); frmLogin.OnLoginOk += new ComponentModel.LoginHandler((Desktop.ComponentModel.LoginEventArgs args) => { frmAberturaCaixa frmAbertura = new frmAberturaCaixa(); frmAbertura.ShowDialog(); labelStatus.Text = frmAbertura.StatusCaixa; }); frmLogin.OnLoginCancel += new ComponentModel.LoginHandler((Desktop.ComponentModel.LoginEventArgs args) => { frmLogin.Close(); }); frmLogin.ShowDialog(); }); #endregion #region opções de venda optbCaixa.tBtnVenda.Click += new EventHandler((object s, EventArgs e) => { IAbreCaixa caixa = null; try { caixa = new AbreCaixa().PermiteAbrir(Settings.MachineName, DateTime.Now); } catch(PDVObrigatorio) { if(!PDV.Create(true, false).IsNullOrEmpty()) caixa = new AbreCaixa().PermiteAbrir(Settings.MachineName, DateTime.Now); else { MessageBox.Show("Não foi possível criar um PDV para esta estação.", "Aviso!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } //tem que existir um caixa aberto para este operador. if(caixa == null) { MessageBox.Show("Não foi permitido abrir o caixa para este PDV.", "Aviso!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } IImpressora impressora = null; try { impressora = OpenPOS.ECF.ECF.Create(caixa.Caixa.PDV); } catch(Exception ex) { MessageBox.ShowError(ex, false); return; } frmLoginVendaCF f = new frmLoginVendaCF(); f.Show(this); }); optBarVenda.tBtnVendaNFe.Click += new EventHandler((object o, EventArgs e) => { new frmVendaNFe().Show(this); }); optBarVenda.tBtnVendaManual.Click += new EventHandler((object o, EventArgs e) => { new frmVendaNFManual().Show(this); }); #endregion #region opções dav optBarDAV.tBtnOrcamento.Click += new EventHandler((object o, EventArgs e) => { new frmDAV().Show(this); }); optBarDAV.tBtnOrdemServico.Click += new EventHandler((object sender, EventArgs e) => { new frmDAVOS().Show(this); }); optBarDAV.tBtnPreVenda.Click += new EventHandler((object sender, EventArgs e) => { new frmPreVenda().Show(this); }); #endregion #region opções Outros optBarOutros.tBtnECF.Click += new EventHandler((object o, EventArgs e) => { frmECF f = new frmECF(); if(!f.IsDisposed) f.ShowDialog(this); }); optBarOutros.touchBtnTEF.Click += new EventHandler((object o, EventArgs e) => { frmTEF f = new frmTEF(); if(!f.IsDisposed) f.ShowDialog(this); }); #endregion #region menu relatórios IList<Model.Reports.IRelatorio> rels = new Relatorio().Find<Model.Reports.IRelatorio>(); foreach(var rel in rels) { ToolStripMenuItem parent = GetMenuItemParent(rel.Grupo.Nome); ToolStripMenuItem item = new ToolStripMenuItem { Text = rel.Nome, Tag = rel }; item.Click += (sender, e) => { try { RdlManager.OpenViewer(((ToolStripMenuItem)sender).Tag as Model.Reports.IRelatorio); } catch(Exception ex) { MessageBox.ShowError(ex); } }; parent.DropDownItems.Add(item); mnuRelatorio.DropDownItems.Add(parent); } #endregion }
/// <summary> /// Ao carregar o formulário /// </summary> /// <param name="sender">Objeto que disparou o evento</param> /// <param name="e">Argumento do evento gerado</param> private void Inicial_Load(object sender, EventArgs e) { splash.Show(); splash.SetMessage("Verificando ECF"); if(Settings.ECF.ECFAtual != null) { ICupomFiscal cf = null; #if IsPAF IArquivoAuxiliar aux = null; #endif try { cf = new CupomFiscal(Settings.ECF.ECFAtual.ModeloACBR, Settings.ECF.ECFAtual.Porta); #if IsPAF aux = new ArquivoAuxiliar(); if(!System.IO.File.Exists(aux.ArquivoAuxiliarPath)) { aux.GrandeTotal = cf.GrandeTotal.ToString(); aux.NumeroSerie = cf.NumeroSerie; aux.Gerar(); } aux.Carregar(); #endif } catch { } #if IsPAF if((cf.Estado != EstadoECF.Livre) || !aux.PermiteFaturamento(cf.GrandeTotal)) { //TODO André: Essa parte do código só vai ser executado quando por algum motivo ocorreu a perda //acidentalmente dos dados do //arquivo auxiliar criptografado, onde será reconstituído o valor do Grande Total e Número de Série do Equipamento Emissor de Cupom Fiscal conectado //Requisito XXIV - item 8 try { using(IInformacao info = new Informacao(Settings.ECF.ECFAtual.ModeloACBR, Settings.ECF.ECFAtual.Porta)) { DadosReducaoZClass dadosReducao = info.DadosReducaoZ; if(aux.RecomporTotalizadorGeral(info.CRZ, info.CRO, dadosReducao.ValorVendaBruta, dadosReducao.DataHoraEmissao)) aux.CorrigeDados(cf.GrandeTotal); else { MessageBox.ShowWarning("Não é permitido o faturamento na impressora fiscal, pois os dados do Grande Total ou Número de série, diferem dos que estão no arquivo auxiliar criptografado!"); return; } } } catch { } } #endif splash.SetMessage("Preparando Caixa"); IVendaCF venda = new VendaCF().HasTemp(Settings.ECF.ECFAtual) as IVendaCF; if(venda != null) { if(venda.Status == Enuns.Faturamento.Lancamento.Status.ImpressoCupom) new Pagamento(cf, venda).Confirmacao(); else new Pagamento(cf, venda).CancelarTransacoesPendentes(); try { cf = new CupomFiscal(Settings.ECF.ECFAtual.ModeloACBR, Settings.ECF.ECFAtual.Porta); if(cf.Estado == EstadoECF.Pagamento) { if(cf.TotalPago > 0) { cf.CancelaCupom(); if(cf.Estado == EstadoECF.Livre) venda.Cancelar("Venda cancelada pelo Usuário"); } } else if(cf.Estado == EstadoECF.Venda) { } else if(cf.Estado == EstadoECF.Livre) { venda.Cancelar("Venda cancelada pelo Sistema"); } else if(cf.Estado == EstadoECF.Relatorio) { new OpenPOS.ECF.RelatorioGerencial(Settings.ECF.ECFAtual.ModeloACBR, Settings.ECF.ECFAtual.Porta).FechaRelatorio(Enuns.ECF.TipoOutrosDocumentos.RG, false); } else if(cf.Estado == EstadoECF.NaoInicializada) { throw new Exception(); } } catch { if(MessageBox.AskYesNo("Impressora não responde.\r\tContinuar?", "Erro") == DialogResult.No) Application.Exit(); } } splash.SetMessage("Finalizando Incialização"); } optbCaixa.Visible = optBarVenda.Visible = optbConsulta.Visible = optBarDAV.Visible = optBarOutros.Visible = false; //Configurações na barra de acordo com o terminal, ou seja PDV ou não if(isPDV) { labelOperador.Text = Settings.UsuarioAtual.NomeLogin; labelTerminal.Text = Settings.MachineName; IAbreFechaCaixa abreCx = new AbreCaixa().PermiteAbrir(Settings.MachineName, DateTime.Now); labelStatus.Text = abreCx == null ? Convert.ToString(Enuns.FrenteCaixa.Cadastro.Caixa.Status.Fechado) : Convert.ToString(abreCx.Status); } else { labelOperador.Text = Settings.UsuarioAtual.NomeLogin; labelOperador.Location = new Point(202, 540); labelTerminal.Text = ""; labelStatus.Text = ""; } splash.Close(); }
/// <summary> /// Valida se é permitido a abertura do caixa /// </summary> /// <param name="dataHora">data e hora da abertura do caixa</param> /// <param name="nomePDV">Nome do PDV associado à abertura do caixa</param> /// <returns>True se é permitido abrir</returns> public virtual IAbreCaixa PermiteAbrir(string nomePDV, DateTime dataHora) { IAbreCaixa result = null; DataReader dataReader = null; dataReader = Connection.ExecuteReader(@"SELECT cad_PDV.GUID FROM cad_PDV WHERE cad_PDV.Nome LIKE @nome", new Parameter[] { new Parameter { ParameterName = "@nome", Value = nomePDV, GenericDbType = GenericDbType.String } }); if (!dataReader.Read()) throw new PDVObrigatorio(); //validar se o caixa já está aberto. dataReader = Connection.ExecuteReader(@" SELECT cxa_AbreFechaCaixa.GUID FROM cad_PDV INNER JOIN cad_Caixa ON cad_Caixa.GUIDPDV = cad_PDV.GUID INNER JOIN cxa_AbreFechaCaixa ON cxa_AbreFechaCaixa.GUIDCaixa = cad_Caixa.GUID WHERE cad_PDV.Nome LIKE @nome AND cxa_AbreFechaCaixa.DataHoraAbertura <= @dataHora AND cxa_AbreFechaCaixa.Status = 1", new Parameter[] { new Parameter{ ParameterName = "@nome", Value = nomePDV, GenericDbType = GenericDbType.String }, new Parameter{ ParameterName = "@dataHora", Value = dataHora, GenericDbType = GenericDbType.DateTime } }); if (dataReader.Read()) result = new AbreCaixa(dataReader.GetString(0)); return result; }
/// <summary> /// Retorna o caixa aberto para este PDV /// </summary> /// <param name="nomePDV">Nome do ponto de venda ou terminal</param> /// <returns>O Caixa aberto atualmente ou o retorna null se não houver caixa aberto</returns> public IAbreFechaCaixa CaixaAberto() { IAbreCaixa result = null; //------------------------------------------------------------------------- // Aqui iremos retornar uma abertura de caixa. // Por enquanto não está validando a data de abertura e de fechamento //------------------------------------------------------------------------- DataReader dataReader = Connection.ExecuteReader(@" SELECT cxa_AbreFechaCaixa.GUID FROM cad_PDV INNER JOIN cad_Caixa ON cad_Caixa.GUIDPDV = cad_PDV.GUID INNER JOIN cxa_AbreFechaCaixa ON cxa_AbreFechaCaixa.GUIDCaixa = cad_Caixa.GUID WHERE cxa_AbreFechaCaixa.Status = @status AND cad_PDV.Nome = @nome ORDER BY datahoraabertura ASC", new Parameter[] { new Parameter{ ParameterName = "@status", Value = (int)Enuns.FrenteCaixa.Cadastro.Caixa.Status.Aberto, }, new Parameter { ParameterName = "@nome", Value = Settings.MachineName } }); if(dataReader.Read()) result = new AbreCaixa(dataReader.GetString(0)); return result; }