private void btnConfirmar_Click_1(object sender, RoutedEventArgs e) { string nome = "Nome: " + txtNome.Text + "\n"; string cpf = "CPF: " + txtCpf.Text + "\n"; string codCliente = "Codigo do Cliente: " + txtCodCliente.Text + "\n"; string protocolo = "Protocolo: " + txtProtocolo.Text + "\n"; string plano = "Plano: " + txtPlano.Text + "\n"; string tipo; string cabos; string discador; string isolado; string onu; string poe; string rompimento; string roteador; string solucao; string endereco = "Endereço: " + txtEndereco.Text + "\n"; string telefone = "Telefone: " + txtTelefone.Text + "\n"; string referencia = "Referencia: " + txtReferencia.Text + "\n"; string periodo = "Periodo da visita: " + txtPeriodo.Text + "\n"; string descricao = "Descrição do problema: " + txtDescricao.Text + "\n"; //testes if (cbCabos.IsChecked == true) { cabos = " -Cabos Verificados" + "\n"; } else { cabos = ""; } if (cbDiscador.IsChecked == true) { discador = " -Criado Discador" + "\n"; } else { discador = ""; } if (cbIsoladoCabo.IsChecked == true) { isolado = " -Cabo Isolado" + "\n"; } else { isolado = ""; } if (cbONU.IsChecked == true) { onu = " -ONU Reiniciada" + "\n"; } else { onu = ""; } if (cbReiniciadoPoe.IsChecked == true) { poe = " -POE Reiniciado" + "\n"; } else { poe = ""; } if (cbRompimento.IsChecked == true) { rompimento = " -Possivel Rompimento" + "\n"; } else { rompimento = ""; } if (cbRoteador.IsChecked == true) { roteador = " -Roteador Reiniciado" + "\n"; } else { roteador = ""; } //tipo if (rdoRegiao.IsChecked == true) { tipo = "Existe um problema na região do cliente, por isso a falta de conexão"; } else if (rdoRadio.IsChecked == true) { tipo = "Conexão via: Radio \nTestes realizados: \n" + cabos + poe + isolado + discador; } else if (rdoFibra.IsChecked == true) { tipo = "Conexão via: Fibra \nTestes realizados: \n" + cabos + onu + rompimento + discador; } else if (rdoCabeada.IsChecked == true) { tipo = "Conexão via: Cabo \nTestes realizados: \n" + cabos + roteador + isolado + discador; } else { tipo = ""; } //solucao if (rdoSolucionado.IsChecked == true) { solucao = "Solucionado: Sim"; } else if (rdoNaoSolucionado.IsChecked == true) { solucao = "Solucionado: Não \n\nAgendamento \n" + endereco + telefone + referencia + periodo + descricao; } else { solucao = ""; } txtAtendimento.Text = nome + cpf + codCliente + protocolo + plano + tipo + solucao; AtendimentoController atendimentoController = new AtendimentoController(); Models.Atendimento novoatendimento = new Models.Atendimento(); novoatendimento.Problema = txtAtendimento.Text; novoatendimento.ClienteID = clienteAtendimento.ClienteID; atendimentoController.Adicionar(novoatendimento); MessageBox.Show("Atendimento salvo"); }
private List <string> GerarNotaFiscal(int grvId, string identificadorNota, int usuarioId, bool isDev) { Thread.CurrentThread.CurrentCulture = new CultureInfo("pt-BR"); DataBase.SystemEnvironment = isDev ? SystemEnvironment.Development : SystemEnvironment.Production; DataBase.SetContextInfo(usuarioId); var acao = Acao.Solicitação; var returnList = new List <string>(); #region NFe var NfeList = new List <NfeEntity>(); // STATUS: // C: Cadastro; // A: Aguardando Processamento (envio da solicitação com sucesso, para a Prefeitura); // P: Processado (download da Nfe e atualização da Nfe no Sistema concluídos com sucesso); // R: Reprocessar (marcação manual para o envio de uma nova solicitação de Nfe para o mesmo GRV, esta opção gera um novo registro de Nfe); // S: Aguardando Reprocessamento; // T: Reprocessado (conclusão do reprocessamento); // N: CaNcelado. // E: Erro (quando a Prefeitura indicou algum problema); // I: Inválido (quando ocorreu um erro Mob-Link); // M: Cadastro Manual var Nfe = new NfeEntity { GrvId = grvId, IdentificadorNota = identificadorNota }; if (!string.IsNullOrWhiteSpace(Nfe.IdentificadorNota)) { Nfe = new NfeController().Selecionar(Nfe, true); if (Nfe == null) { new NfeWsErroController().CadastrarErroGenerico(Nfe.GrvId, usuarioId, Nfe.IdentificadorNota, OrigemErro.MobLink, acao, "Nota Fiscal não encontrada"); returnList.Add("AVISO: Nota Fiscal não encontrada"); return(returnList); } // Erro / Inválido / Cancelado if (Nfe.Status != 'E' && Nfe.Status != 'I' && Nfe.Status != 'N') { new NfeWsErroController().CadastrarErroGenerico(Nfe.GrvId, usuarioId, Nfe.IdentificadorNota, OrigemErro.MobLink, acao, "Nota Fiscal não está apto para reprocessamento"); returnList.Add("AVISO: Nota Fiscal não está apto para reprocessamento"); return(returnList); } } else if ((NfeList = new NfeController().Listar(Nfe)) != null) { var status = new char[] { 'C', 'A', 'P', 'R', 'S', 'T', 'M' }; if (NfeList.Where(w => status.Contains(w.Status)).Count() > 0) { if (NfeList.Count == 1) { Nfe = NfeList.FirstOrDefault(); if (Nfe.Status == 'C' && Nfe.DataCadastro.Date < DateTime.Now.Date) { Nfe.Status = 'I'; new NfeController().Atualizar(Nfe); } else { new NfeWsErroController().CadastrarErroGenerico(grvId, usuarioId, identificadorNota, OrigemErro.MobLink, acao, "GRV já possui Nota Fiscal cadastrada"); returnList.Add("AVISO: GRV já possui Nota Fiscal cadastrada"); return(returnList); } } else { new NfeWsErroController().CadastrarErroGenerico(grvId, usuarioId, identificadorNota, OrigemErro.MobLink, acao, "GRV já possui Nota Fiscal cadastrada"); returnList.Add("AVISO: GRV já possui Nota Fiscal cadastrada"); return(returnList); } } } #endregion NFe // GRV var grv = new GrvController().Selecionar(grvId); // Cliente var Cliente = new ClienteController().Selecionar(grv.ClienteId); // Depósito var Deposito = new DepositoController().Selecionar(grv.DepositoId); // Cliente Depósito var ClienteDeposito = new ClienteDepositoController().Selecionar(new ClienteDepositoEntity { ClienteId = grv.ClienteId, DepositoId = grv.DepositoId }); #region Regras da Nfe var NfeRegras = new NfeRegraController().Listar(new NfeRegraEntity { ClienteDepositoId = ClienteDeposito.ClienteDepositoId, Ativo = 1, RegraAtivo = 1 }); #endregion Regras da Nfe #region Regras do Faturamento if (new RegraFaturamentoController().Selecionar(grv.ClienteId, grv.DepositoId, new TipoRegraFaturamentoController().Selecionar("NFE").FaturamentoRegraTipoId) == null) { new NfeWsErroController().CadastrarErroGenerico(grvId, usuarioId, identificadorNota, OrigemErro.MobLink, acao, "CLIDEP sem regra de NFE definido"); returnList.Add("AVISO: CLIDEP sem regra de NFE definido"); return(returnList); } #endregion Regras do Faturamento #region Empresa var Empresa = new EmpresaEntity(); if ((Empresa = new EmpresaController().Selecionar(new EmpresaEntity { EmpresaId = ClienteDeposito.EmpresaId })) == null) { new NfeWsErroController().CadastrarErroGenerico(grvId, usuarioId, identificadorNota, OrigemErro.MobLink, acao, "Empresa associada não encontrada"); returnList.Add("AVISO: Empresa associada não encontrada"); return(returnList); } #endregion Empresa #region Atendimento var Atendimento = new AtendimentoEntity(); if ((Atendimento = new AtendimentoController().Selecionar(grvId)) == null) { new NfeWsErroController().CadastrarErroGenerico(grvId, usuarioId, identificadorNota, OrigemErro.MobLink, acao, "Atendimento não encontrado"); returnList.Add("AVISO: Atendimento não encontrado"); return(returnList); } #endregion Atendimento #region Faturamento var Faturamentos = new List <FaturamentoEntity>(); if ((Faturamentos = new FaturamentoController().Listar(Atendimento.AtendimentoId, 'P')) == null) { new NfeWsErroController().CadastrarErroGenerico(grvId, usuarioId, identificadorNota, OrigemErro.MobLink, acao, "Faturamento não encontrado"); returnList.Add("AVISO: Faturamento não encontrado ou sem valor para pagamento"); return(returnList); } #endregion Faturamento #region Valores somados da Composição do Faturamento var ComposicoesAgrupadas = new List <NfeViewFaturamentoComposicaoAgrupadoEntity>(); if ((ComposicoesAgrupadas = new NfeViewFaturamentoComposicaoAgrupadoController().Listar(grvId)) == null) { new NfeWsErroController().CadastrarErroGenerico(grvId, usuarioId, identificadorNota, OrigemErro.MobLink, acao, "Composição do Faturamento não encontrada"); returnList.Add("AVISO: Composição do Faturamento não encontrado"); return(returnList); } #endregion Valores somados da Composição do Faturamento #region Valores somados da Composição do Faturamento var ComposicoesAgrupadasDescricao = new List <NfeViewFaturamentoComposicaoAgrupadoDescricaoEntity>(); if ((ComposicoesAgrupadasDescricao = new NfeViewFaturamentoComposicaoAgrupadoDescricaoController().Listar(grvId)) == null) { new NfeWsErroController().CadastrarErroGenerico(grvId, usuarioId, identificadorNota, OrigemErro.MobLink, acao, "Composição do Faturamento não encontrada"); returnList.Add("AVISO: Composição do Faturamento não encontrado"); return(returnList); } #endregion Valores somados da Composição do Faturamento #region Composições var Composicoes = new List <NfeViewFaturamentoComposicaoEntity>(); if ((Composicoes = new NfeViewFaturamentoComposicaoController().Listar(grvId, Nfe.NfeId)) == null) { new NfeWsErroController().CadastrarErroGenerico(grvId, usuarioId, identificadorNota, OrigemErro.MobLink, acao, "Composição do Faturamento da Nota Fiscal não encontrada"); returnList.Add("AVISO: Composição do Faturamento não encontrado"); return(returnList); } #endregion Composições if (Nfe.NfeId > 0) { var Composicao = Composicoes.FirstOrDefault(); ComposicoesAgrupadas = ComposicoesAgrupadas.Where(w => w.CnaeId == Composicao.CnaeId && w.ListaServicoId == Composicao.ListaServicoId).ToList(); ComposicoesAgrupadasDescricao = ComposicoesAgrupadasDescricao.Where(w => w.CnaeId == Composicao.CnaeId && w.ListaServicoId == Composicao.ListaServicoId).ToList(); } var CapaAutorizacaoNfse = new CapaAutorizacaoNfse(); string json; List <NfeFaturamentoComposicaoEntity> NfeFaturamentoComposicaoList; StringBuilder descricaoConfiguracaoNfe = new StringBuilder(); foreach (var agrupamento in ComposicoesAgrupadas) { descricaoConfiguracaoNfe = new StringBuilder(); var aux = ComposicoesAgrupadasDescricao.Where(w => w.CnaeId == agrupamento.CnaeId && w.ListaServicoId == agrupamento.ListaServicoId).ToList(); foreach (var item in aux) { if (item.TipoDesconto != '\0') { descricaoConfiguracaoNfe.Append(item.DescricaoConfiguracaoNfe).Append(". QTD: ").Append(string.Format("{0:N2}", item.QuantidadeComposicao)).Append(". VALOR: R$ ").Append(string.Format("{0:N2}", item.ValorTipoComposicao)).Append(". DSCT: R$ ").Append(string.Format("{0:N2}", item.ValorDesconto)).Append(". TOT: R$ ").AppendLine(string.Format("{0:N2}", item.TotalComDesconto)); } else { descricaoConfiguracaoNfe.Append(item.DescricaoConfiguracaoNfe).Append(". QTD: ").Append(string.Format("{0:N2}", item.QuantidadeComposicao)).Append(". VALOR: R$ ").Append(string.Format("{0:N2}", item.ValorTipoComposicao)).Append(". TOT: R$ ").AppendLine(string.Format("{0:N2}", item.TotalComDesconto)); } } #region Preenchimento da Entidade try { CapaAutorizacaoNfse = new CapaAutorizacaoNfse { GrvId = grvId, IdentificadorNota = new DetranController().GetDetranSequence("NFE"), UsuarioId = usuarioId, Homologacao = isDev, Autorizacao = Autorizar(grv, Deposito, ClienteDeposito, NfeRegras, Empresa, Atendimento, agrupamento, descricaoConfiguracaoNfe.ToString().Trim(), isDev) }; } catch (Exception ex) { new NfeWsErroController().CadastrarErroGenerico(grvId, usuarioId, identificadorNota, OrigemErro.MobLink, acao, ex.Message); returnList.Add(ex.Message); continue; } #endregion Preenchimento da Entidade #region Cadastro do Envio/Reenvio try { if (Nfe.NfeId == 0) { // Cadastro do Envio Nfe = CadastrarNfe(grvId, Empresa.Cnpj, CapaAutorizacaoNfse.IdentificadorNota, usuarioId); } else { // Cadastro do Reenvio Nfe = CadastrarNfe(grvId, Empresa.Cnpj, CapaAutorizacaoNfse.IdentificadorNota, usuarioId, Nfe.NfeId); } } catch (Exception ex) { new NfeWsErroController().CadastrarErroGenerico(grvId, usuarioId, identificadorNota, OrigemErro.MobLink, acao, ex.Message); returnList.Add("Erro ao cadastrar a NF: " + ex.Message); continue; } Nfe.Cliente = Cliente.Nome; Nfe.Deposito = Deposito.Descricao; #endregion Cadastro do Envio/Reenvio #region Cadastro da Composição da Nota Fiscal NfeFaturamentoComposicaoList = new List <NfeFaturamentoComposicaoEntity>(); try { new NfeFaturamentoComposicaoController().Cadastrar(Nfe.NfeId, Composicoes.Where(w => w.Servico == agrupamento.Servico).ToList()); } catch (Exception ex) { new NfeWsErroController().CadastrarErroGenerico(grvId, usuarioId, identificadorNota, OrigemErro.MobLink, acao, ex.Message); returnList.Add("Erro ao cadastrar a composição da NF: " + ex.Message); continue; } #endregion Cadastro da Composição da Nota Fiscal #region Execução do Web Service try { json = new NfeSolicitarEmissaoNotaFiscalController().SolicitarEmissaoNotaFiscal(CapaAutorizacaoNfse); } catch (Exception ex) { new NfeWsErroController().CadastrarErroGenerico(grvId, usuarioId, identificadorNota, OrigemErro.MobLink, acao, ex.Message); returnList.Add("Erro na Execução do Web Service: " + ex.Message); continue; } returnList.Add(json); #endregion Execução do Web Service #region Processamento do resultado try { if (!ProcessarResultado(json, usuarioId, Nfe)) { continue; } } catch (Exception ex) { new NfeWsErroController().CadastrarErroGenerico(grvId, usuarioId, identificadorNota, OrigemErro.MobLink, acao, ex.Message); returnList.Add("Erro no processamento do resultado do Web Service: " + ex.Message); continue; } finally { Nfe = new NfeEntity(); } #endregion Processamento do resultado Nfe = new NfeEntity(); } return(returnList); }
private void CarregarDgAtendimentosRealizados() { AtendimentoController atendimentoControllerCarregar = new AtendimentoController(); dgAtendimentosRealizados.ItemsSource = atendimentoControllerCarregar.ListarTodos(); }