예제 #1
0
        public string GerarNotaFiscal(Domain.Pedido pedido)
        {
            try
            {
                NotaFiscal notaFiscal = new NotaFiscal();
                var        result     = EmitirNotaFiscal(notaFiscal, pedido);

                if (!string.IsNullOrWhiteSpace(result))
                {
                    return(result);
                }

                var provider             = new SQLServerProvider();
                var notaFiscalRepository = new NotaFiscalRepository(provider);

                if (!notaFiscalRepository.InserirNotaFiscal(notaFiscal))
                {
                    return("Erro ao inserir Nota Fiscal");
                }

                GerarXml(provider, notaFiscal);
            }
            catch (Exception e)
            {
                throw e;
            }

            return(string.Empty);
        }
예제 #2
0
 public NotaFiscalController(NotaFiscalRepository notaFiscalRepo, PedidoRepository pedidoRepo, ItemPedidoRepository itemPedidoRepo, ItemNotaRepository itemNotaRepo)
 {
     _notaRepo       = notaFiscalRepo;
     _pedidoRepo     = pedidoRepo;
     _itemPedidoRepo = itemPedidoRepo;
     _itemNotaRepo   = itemNotaRepo;
 }
예제 #3
0
 /// <summary>
 /// Construtor serviço nota fiscal
 /// </summary>
 /// <param name="notaFiscalBusiness">Objeto de negócio</param>
 /// <param name="impostoUtil">Objeto utilitário</param>
 /// <param name="notaFiscalRepository">Repositório de dados</param>
 public NotaFiscalService(NotaFiscalBusiness notaFiscalBusiness, ImpostoUtil impostoUtil,
                          NotaFiscalRepository notaFiscalRepository)
 {
     this.notaFiscalBusiness   = notaFiscalBusiness;
     this.impostoUtil          = impostoUtil;
     this.notaFiscalRepository = notaFiscalRepository;
 }
예제 #4
0
        public void EmitirNotaFiscal(Pedido pedido)
        {
            this.NumeroNotaFiscal = 99999;
            this.Serie            = new Random().Next(Int32.MaxValue);
            this.NomeCliente      = pedido.NomeCliente;

            this.EstadoDestino = pedido.EstadoOrigem;
            this.EstadoOrigem  = pedido.EstadoDestino;

            foreach (PedidoItem itemPedido in pedido.ItensDoPedido)
            {
                NotaFiscalItem notaFiscalItem = new NotaFiscalItem();

                //Uso padrao de Projeto Clain of Responsability, para resolver o problema de manutanção e sujeira de codigo
                CalculaCfop cfop = new CalculaCfop();
                notaFiscalItem.Cfop = cfop.ObtemCfop(pedido);

                //Centralizo para cada classe responsavel
                notaFiscalItem.AliquotaIcms = ICMS.ObtemAliquotaIcms(pedido);
                notaFiscalItem.TipoIcms     = ICMS.ObtemTipoIcms(pedido);
                notaFiscalItem.BaseIcms     = ICMS.CalculaBaseIcms(notaFiscalItem.Cfop, itemPedido.ValorItemPedido);
                notaFiscalItem.ValorIcms    = ICMS.CalculaValorIcms(notaFiscalItem);

                if (itemPedido.Brinde)
                {
                    notaFiscalItem.TipoIcms     = "60";
                    notaFiscalItem.AliquotaIcms = 0.18;
                    notaFiscalItem.ValorIcms    = notaFiscalItem.BaseIcms * notaFiscalItem.AliquotaIcms;
                }
                notaFiscalItem.NomeProduto   = itemPedido.NomeProduto;
                notaFiscalItem.CodigoProduto = itemPedido.CodigoProduto;

                // caulculo IPI
                notaFiscalItem.AliquotaIpi = IPI.CalculaAliquotaIpi(itemPedido.Brinde);
                notaFiscalItem.BaseIpi    += itemPedido.ValorItemPedido;
                notaFiscalItem.ValorIpi    = IPI.CalculaValorIpi(notaFiscalItem.BaseIpi, notaFiscalItem.AliquotaIpi);

                //Desconto Sudeste
                notaFiscalItem.Desconto = DescontosSudeste.ObtemDesconto(this.EstadoDestino);

                this.ItensDaNotaFiscal.Add(notaFiscalItem);
            }

            //Validação se persistiu xml com sucesso
            if (!Xml.Exportar(pedido))
            {
                throw new Exception("Problemas para gravar Xml");
            }

            // Salvando no Banco
            var idNota = NotaFiscalRepository.InsertNotaFiscal(this);

            foreach (var item in this.ItensDaNotaFiscal.ToList())
            {
                item.IdNotaFiscal = idNota;
                NotaFiscalRepository.InsertNotaFiscalItem(item);
            }
        }
예제 #5
0
        /// <summary>
        /// Gera a nota fiscal a partir do pedido
        /// </summary>
        /// <param name="pedido">Pedido para a emissão da nova nota fiscal</param>
        public void GerarNotaFiscal(Pedido pedido)
        {
            NotaFiscalHelper notaFiscalHelper = new NotaFiscalHelper();
            NotaFiscal       notaFiscal       = notaFiscalHelper.CriaNotaFiscal(pedido);

            NotaFiscalRepository notaFiscalRepository = new NotaFiscalRepository();

            notaFiscalRepository.Salvar(notaFiscal);
        }
예제 #6
0
 public NotaFiscalBusiness()
 {
     notaFiscalRepository      = new NotaFiscalRepository();
     produtoRepository         = new ProdutoRepository();
     lojaRepository            = new LojaRepository();
     logRepository             = new LogRepository();
     categoriaBusiness         = new CategoriaBusiness();
     medidaBusiness            = new MedidaBusiness();
     notaFiscalProdutoBusiness = new NotaFiscalProdutoBusiness();
 }
예제 #7
0
        public void SalvarNotaFiscalTest_ItemTipoIcms_Null()
        {
given:
            NotaFiscal nota = FactoryNotaFiscal();

            nota.ItensDaNotaFiscal[0].TipoIcms = null;

when:
            NotaFiscalRepository repository = new NotaFiscalRepository();

            repository.SalvarNotaFiscal(nota);
        }
예제 #8
0
        public void SalvarNotaFiscalTest_NomeCliente_Null()
        {
given:
            NotaFiscal nota = FactoryNotaFiscal();

            nota.NomeCliente = null;

when:
            NotaFiscalRepository repository = new NotaFiscalRepository();

            repository.SalvarNotaFiscal(nota);
        }
예제 #9
0
        public void SalvarNotaFiscalTest_Origem_Null()
        {
given:
            NotaFiscal nota = FactoryNotaFiscal();

            nota.EstadoOrigem = null;

when:
            NotaFiscalRepository repository = new NotaFiscalRepository();

            repository.SalvarNotaFiscal(nota);
        }
예제 #10
0
        public void SalvarNotaFiscalTest()
        {
given:
            NotaFiscal nota = FactoryNotaFiscal();

when:
            NotaFiscalRepository repository = new NotaFiscalRepository();
            var result = repository.SalvarNotaFiscal(nota);

then:
            Assert.IsNotNull(result.Id);
        }
예제 #11
0
        public void GerarNotaFiscal(Domain.Pedido pedido)
        {
            PedidoService pedidoService = new PedidoService();

            NotaFiscal notaFiscal = pedidoService.TratarPedido(pedido);

            XmlService.SalvarXml <NotaFiscal>(notaFiscal, ConfigurationManager.AppSettings["arquivo"]);

            NotaFiscalRepository respositorio = new NotaFiscalRepository();

            respositorio.Salvar(notaFiscal);
        }
        public NotaFiscal GerarNotaFiscal(Pedido pedido)
        {
            PedidoService pedidoService = new PedidoService();
            NotaFiscal    notaFiscal    = pedidoService.EmitirNotaFiscal(pedido);

            GravarXmlNotaFiscal(notaFiscal);
            NotaFiscalRepository repository = new NotaFiscalRepository();

            notaFiscal = repository.SalvarNotaFiscal(notaFiscal);

            return(notaFiscal);
        }
예제 #13
0
        private async void EnviarEmailCmd_Execute(IClosable closable)
        {
            var notaFiscalRepository = new NotaFiscalRepository(new NFeContext());
            var config = await ConfiguracaoService.GetConfiguracaoAsync();

            var notaFiscal = await notaFiscalRepository.GetNotaFiscalByChaveAsync(ChaveNotaSelecionada, config.IsProducao? 1 : 2);

            string xmlPath = notaFiscal.XmlPath;
            await MailManager.EnviarEmailDestinatario(Email, xmlPath);

            Email = string.Empty;
            closable.Close();
        }
예제 #14
0
        public List <string> PopularEstadosDestino()
        {
            List <string>        listaEstadosDestino = new List <string>();
            NotaFiscalRepository nfRepository        = new NotaFiscalRepository();
            DataTable            dtEstadosDestino    = nfRepository.PopularEstadosDestino();

            foreach (DataRow row in dtEstadosDestino.Rows)
            {
                listaEstadosDestino.Add(row[0].ToString());
            }

            return(listaEstadosDestino);
        }
        public void Set_Transportador()
        {
            var connection = DbConnectionFactory.CreatePersistent(Guid.NewGuid().ToString());

            _fakeDbContext = new FakeDbContext(connection);
            _notaFiscal    = new NotaFiscal();
            _repository    = new NotaFiscalRepository(_fakeDbContext);

            _notaFiscalSeed = ObjectMother.NotaFiscalValida;

            _fakeDbContext.NotasFiscais.Add(_notaFiscalSeed);

            _fakeDbContext.SaveChanges();
        }
예제 #16
0
        public void ExportToXMLAndBD()
        {
            try
            {
                Mocks mock = new Mocks();

                NotaFiscalRepository notaFiscalRepository = new NotaFiscalRepository();
                notaFiscalRepository.Salvar(mock.NotaFiscal());
            }
            catch (Exception)
            {
                Assert.Fail();
            }
        }
예제 #17
0
 protected override void Filtrar()
 {
     if (!string.IsNullOrEmpty(Filter) && Filter.Length >= Settings.Default.MinLenghtPesquisa)
     {
         Collection.Clear();
         if (Entrada)
         {
             Collection.AddRange(NotaFiscalRepository.GetByRangeEntrada(Filter, Settings.Default.TakePesquisa));
         }
         else
         {
             Collection.AddRange(NotaFiscalRepository.GetByRangeSaida(Filter, Settings.Default.TakePesquisa));
         }
     }
 }
예제 #18
0
        public void GerarNotaFiscal(Domain.Pedido pedido)
        {
            try
            {
                NotaFiscal notaFiscal = new NotaFiscal()
                                        .EmitirNotaFiscal(pedido)
                                        .GerarNotaFiscalXML();

                notaFiscal = new NotaFiscalRepository().P_Nota_Fiscal(notaFiscal);

                notaFiscal.ItensDaNotaFiscal
                .ForEach(t => new NotaFiscalItemRepository().P_Nota_Fiscal_Item(t, notaFiscal.Id));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #19
0
        public void SalvarXmlTest()
        {
            NotaFiscalRepository notaFiscalRepository = new NotaFiscalRepository();

            NotaFiscal notaFiscal = new NotaFiscal()
            {
                Id = 1,
                NumeroNotaFiscal = 1,
                Serie            = 1,
                NomeCliente      = "TESTE 0",
                EstadoDestino    = "SP",
                EstadoOrigem     = "RJ"
            };

            notaFiscalRepository.CreateXML(notaFiscal);

            //notaFiscalRepository.SalvarXml(notaFiscal);

            //NotaFiscal notaFiscalList = notaFiscalRepository.CarregarXml().FirstOrDefault();
        }
예제 #20
0
        public string EmitirNotaFiscal(NotaFiscal notaFiscal, Pedido pedido)
        {
            var provider             = new SQLServerProvider();
            var notaFiscalRepository = new NotaFiscalRepository(provider);

            notaFiscal.NumeroNotaFiscal = notaFiscalRepository.BuscarUltimaNotaFiscal();
            notaFiscal.Serie            = new Random().Next(Int32.MaxValue);
            notaFiscal.NomeCliente      = pedido.NomeCliente;
            notaFiscal.EstadoDestino    = pedido.EstadoDestino;
            notaFiscal.EstadoOrigem     = pedido.EstadoOrigem;

            var notaFiscalItemList = new List <NotaFiscalItem>();
            var result             = ProcessarItemPedido(pedido, notaFiscal, notaFiscalItemList);

            if (!string.IsNullOrWhiteSpace(result))
            {
                return(result);
            }

            notaFiscal.ItensDaNotaFiscal = notaFiscalItemList;
            return(string.Empty);
        }
예제 #21
0
        public void GerarNotaFiscal(Domain.Pedido pedido)
        {
            NotaFiscal notaFiscal = new NotaFiscal();

            notaFiscal.EmitirNotaFiscal(pedido);

            string path     = ConfigurationManager.AppSettings["SavePath"];
            string filePath = $"{path}\\NF_{notaFiscal.NumeroNotaFiscal}.xml";
            string file     = GerarArquivoXml(filePath, notaFiscal, new string[] { "NotaFiscal" }, new string[] { "ItensDaNotaFiscal" }, new string[] { "Item" });

            if (File.Exists(file))
            {
                var repository = new NotaFiscalRepository();
                notaFiscal.Id = repository.P_NOTA_FISCAL(notaFiscal);

                foreach (var item in notaFiscal.ItensDaNotaFiscal)
                {
                    item.IdNotaFiscal = notaFiscal.Id;
                    repository.P_NOTA_FISCAL_ITEM(item);
                }
            }
        }
예제 #22
0
        public void GerarNotaFiscal(Domain.Pedido pedido)
        {
            NotaFiscal notaFiscal = new NotaFiscal();

            notaFiscal.EmitirNotaFiscal(pedido);

            NotaFiscalItemService notaFiscalItemService = new NotaFiscalItemService();

            notaFiscalItemService.PreencherItensNF(pedido, notaFiscal);

            //Método responsável pela geração da classe em XML utilizando Serializer
            if (GerarXMLNotaFiscal(notaFiscal))
            {
                NotaFiscalRepository repo = new NotaFiscalRepository();
                notaFiscal.Id = repo.SalvarNotaFiscal(notaFiscal);

                //Atualizando os itens da NF com o ID salvo no BD
                notaFiscal.ItensDaNotaFiscal.ForEach(q => q.IdNotaFiscal = notaFiscal.Id);

                NotaFiscalItemRepository repoItem = new NotaFiscalItemRepository();
                repoItem.SalvarItensNF(notaFiscal.ItensDaNotaFiscal);
            }
        }
예제 #23
0
        public void TestMethod4()
        {
            NotaFiscalDesconto   notaFiscal           = new NotaFiscalDesconto();
            NotaFiscalRepository notaFiscalRepository = new NotaFiscalRepository();
            NotaFiscalService    NotaFiscalService    = new NotaFiscalService();
            Pedido pedido = new Pedido();


            pedido.EstadoOrigem  = "SP";
            pedido.EstadoDestino = "RJ";
            pedido.NomeCliente   = "Carlos Lui";

            pedido.ItensDoPedido.Add(
                new PedidoItem()
            {
                Brinde          = false,
                CodigoProduto   = "1256",
                NomeProduto     = "Tenis",
                ValorItemPedido = 200
            });


            NotaFiscalService.Gravar(pedido);
        }
예제 #24
0
        public void GerarNotaFiscalTest()
        {
            NotaFiscalRepository notaFiscalRepository = new NotaFiscalRepository();

            //arrange
            Pedido pedido = new Pedido("SP", "RO", "Cliente A", _itens);

            pedido.AddItem(new PedidoItem("Produto A", Guid.NewGuid().ToString().Substring(0, 10), Math.Round(new Random().NextDouble(), 4), true));
            pedido.AddItem(new PedidoItem("Produto B", Guid.NewGuid().ToString().Substring(0, 10), Math.Round(new Random().NextDouble(), 4), false));
            pedido.AddItem(new PedidoItem("Produto C", Guid.NewGuid().ToString().Substring(0, 10), Math.Round(new Random().NextDouble(), 4), false));

            if (pedido.IsValid)
            {
                NotaFiscal notaFiscal = new NotaFiscal(pedido.NomeCliente, pedido.EstadoDestino, pedido.EstadoOrigem, _itens);

                if (notaFiscal.IsValid)
                {
                    //act
                    notaFiscalRepository.GravarNotaFiscal(notaFiscal);
                }
            }

            Assert.IsTrue(notaFiscalRepository.IsValid);
        }
 public NotaFiscalService()
 {
     _rep = new NotaFiscalRepository();
 }
예제 #26
0
        public int EmitirNotaFiscal(Pedido pedido)
        {
            NotaFiscalRepository nfRepository = new NotaFiscalRepository();

            this.NumeroNotaFiscal = nfRepository.RetornarMaxNumeroNota() + 1;
            this.Serie            = new Random().Next(Int32.MaxValue);
            this.NomeCliente      = pedido.NomeCliente;

            this.EstadoDestino = pedido.EstadoDestino;
            this.EstadoOrigem  = pedido.EstadoOrigem;


            string cfop = nfRepository.BuscaDefinicaoCFOP(this.EstadoOrigem, this.EstadoDestino);

            if (cfop != "")
            {
                foreach (PedidoItem itemPedido in pedido.ItensDoPedido)
                {
                    NotaFiscalItem notaFiscalItem = new NotaFiscalItem();

                    notaFiscalItem.Cfop         = cfop;
                    notaFiscalItem.IdNotaFiscal = this.NumeroNotaFiscal;

                    if (this.EstadoDestino == this.EstadoOrigem)
                    {
                        notaFiscalItem.TipoIcms     = "60";
                        notaFiscalItem.AliquotaIcms = 0.18;
                    }
                    else
                    {
                        notaFiscalItem.TipoIcms     = "10";
                        notaFiscalItem.AliquotaIcms = 0.17;
                    }
                    if (notaFiscalItem.Cfop == "6.009")
                    {
                        notaFiscalItem.BaseIcms = itemPedido.ValorItemPedido * 0.90; //redução de base
                    }
                    else
                    {
                        notaFiscalItem.BaseIcms = itemPedido.ValorItemPedido;
                    }
                    notaFiscalItem.ValorIcms = notaFiscalItem.BaseIcms * notaFiscalItem.AliquotaIcms;

                    if (itemPedido.Brinde)
                    {
                        //Cálculo ICMS
                        notaFiscalItem.TipoIcms     = "60";
                        notaFiscalItem.AliquotaIcms = 0.18;
                        notaFiscalItem.ValorIcms    = notaFiscalItem.BaseIcms * notaFiscalItem.AliquotaIcms;

                        //Cálculo IPI
                        notaFiscalItem.BaseIpi     = itemPedido.ValorItemPedido;
                        notaFiscalItem.AliquotaIpi = 0.1;
                    }
                    notaFiscalItem.ValorIpi = notaFiscalItem.BaseIpi * notaFiscalItem.AliquotaIpi;

                    notaFiscalItem.NomeProduto   = itemPedido.NomeProduto;
                    notaFiscalItem.CodigoProduto = itemPedido.CodigoProduto;

                    ItensDaNotaFiscal.Add(notaFiscalItem);
                }

                int sucessoXML = GerarXML(this);

                if (sucessoXML == 0)
                {
                    nfRepository.InserirPedido(this);

                    //operação bem sucedida
                    return(0);
                }
                else
                {
                    return(sucessoXML);
                }
            }

            else
            {
                // Erro de Estado/Destino não possui definição de CFOP
                return(1);
            }
        }
예제 #27
0
        public int GerarXML(NotaFiscal notafiscal)
        {
            NotaFiscalRepository nfRepository = new NotaFiscalRepository();

            try
            {
                string        diretorio = nfRepository.BuscarDiretorioXML();
                XmlTextWriter xml       = new XmlTextWriter(diretorio + @"\NotaFiscal_" + notafiscal.NumeroNotaFiscal + ".xml", System.Text.Encoding.UTF8);
                xml.WriteStartDocument(true);
                xml.Formatting  = Formatting.Indented;
                xml.Indentation = 2;
                xml.WriteStartElement("NotaFiscal");

                xml.WriteStartElement("NumeroNotaFiscal");
                xml.WriteString(notafiscal.NumeroNotaFiscal.ToString());
                xml.WriteEndElement();

                xml.WriteStartElement("Serie");
                xml.WriteString(notafiscal.Serie.ToString());
                xml.WriteEndElement();

                xml.WriteStartElement("NomeCliente");
                xml.WriteString(notafiscal.NomeCliente.ToString());
                xml.WriteEndElement();

                xml.WriteStartElement("EstadoOrigem");
                xml.WriteString(notafiscal.EstadoOrigem.ToString());
                xml.WriteEndElement();

                xml.WriteStartElement("EstadoDestino");
                xml.WriteString(notafiscal.EstadoDestino.ToString());
                xml.WriteEndElement();

                xml.WriteStartElement("NumeroNotaFiscal");
                xml.WriteString(notafiscal.NumeroNotaFiscal.ToString());
                xml.WriteEndElement();

                xml.WriteStartElement("ItensPedido");

                foreach (var item in notafiscal.ItensDaNotaFiscal)
                {
                    xml.WriteStartElement("IdNotaFiscal");
                    xml.WriteString(item.IdNotaFiscal.ToString());
                    xml.WriteEndElement();

                    xml.WriteStartElement("Cfop");
                    xml.WriteString(item.Cfop.ToString());
                    xml.WriteEndElement();

                    xml.WriteStartElement("TipoIcms");
                    xml.WriteString(item.TipoIcms.ToString());
                    xml.WriteEndElement();

                    xml.WriteStartElement("BaseIcms");
                    xml.WriteString(item.BaseIcms.ToString());
                    xml.WriteEndElement();

                    xml.WriteStartElement("AliquotaIcms");
                    xml.WriteString(item.AliquotaIcms.ToString());
                    xml.WriteEndElement();

                    xml.WriteStartElement("ValorIcms");
                    xml.WriteString(item.ValorIcms.ToString());
                    xml.WriteEndElement();

                    xml.WriteStartElement("NomeProduto");
                    xml.WriteString(item.NomeProduto.ToString());
                    xml.WriteEndElement();

                    xml.WriteStartElement("CodigoProduto");
                    xml.WriteString(item.CodigoProduto.ToString());
                    xml.WriteEndElement();

                    xml.WriteStartElement("BaseIpi");
                    xml.WriteString(item.BaseIpi.ToString());
                    xml.WriteEndElement();

                    xml.WriteStartElement("AliquotaIpi");
                    xml.WriteString(item.AliquotaIpi.ToString());
                    xml.WriteEndElement();

                    xml.WriteStartElement("ValorIpi");
                    xml.WriteString(item.ValorIpi.ToString());
                    xml.WriteEndElement();
                }


                xml.WriteEndElement();
                xml.WriteEndDocument();

                xml.Flush();
                xml.Close();

                return(0);
            }
            catch (Exception ex)
            {
                return(1);
            }
        }
예제 #28
0
        public void ShouldReturnSuccessWhenNotaFiscalItemIsValid()
        {
            var obj = new NotaFiscalRepository(_conexaoBD);

            Assert.IsTrue(obj.Valid);
        }
 public ReportsController()
 {
     _rep = new NotaFiscalRepository();
 }
예제 #30
0
        public void ShouldReturnErrorWhenNotaFiscalRepositoryIsInvalid()
        {
            var obj = new NotaFiscalRepository(null);

            Assert.IsTrue(obj.Invalid);
        }