Beispiel #1
0
        //GET api/Invoices/PrintSalesDoc?fiscalYear=2018&section=1&docType=FAT&number=1
        public IHttpActionResult PrintSalesDoc([FromUri] string fiscalYear, [FromUri] string section, [FromUri] string docType, [FromUri] int number, [FromUri] bool toFile = false)
        {
            try
            {
                DocumentKey docKey = new Helpers.DocumentKey()
                {
                    SectionCode   = section,
                    DocTypeAbbrev = docType,
                    FiscalYear    = fiscalYear,
                    Number        = number,
                };

                byte[] reportBytes = Functions.GetReportBytes(TpDocumentoAEmitir.Encomendas, docKey);

                if (toFile)
                {
                    string docFileNAme = System.Web.Hosting.HostingEnvironment.MapPath($@"~/App_Data/{docType}_{number}.pdf");
                    File.WriteAllBytes(docFileNAme, reportBytes);
                    return(Ok(docFileNAme));
                }

                return(Ok(reportBytes));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        //GET api/Invoices/PrintSalesDoc?fiscalYear=2018&section=1&docType=FAT&number=1
        public IHttpActionResult GetReportBytes([FromUri] string fiscalYear, [FromUri] string section, [FromUri] string docType, [FromUri] int number)
        {
            try
            {
                DocumentKey docKey = new Helpers.DocumentKey()
                {
                    SectionCode   = section,
                    DocTypeAbbrev = docType,
                    FiscalYear    = fiscalYear,
                    Number        = number,
                };

                byte[] reportBytes = Functions.GetReportBytes(TpDocumentoAEmitir.Vendas, docKey);

                return(Ok(reportBytes));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public IHttpActionResult SaveExternalInvoice([FromBody] Models.mySale document)
        {
            byte[] reportBytes;

            MovVenda        sale;
            MovVendaLin     saleLine;
            var             byRefFalse        = false;
            var             stockAvailable    = true;
            var             affectsOtherLines = true;
            var             fixedAssociation  = true;
            var             freeAssociation   = true;
            var             checkStock        = false;
            var             famForQty         = false;
            var             famForPrice       = false;
            TpProcuraArtigo searchItem        = TpProcuraArtigo.NaoEncontrou;
            int             numberLine;
            string          itemCode;

            try
            {
                sale = Eti.Aplicacao.Movimentos.MovVendas.GetNew(document.DocTypeAbbrev, document.SectionCode);
                sale.Cabecalho.CodExercicio = document.FiscalYear;

                sale.Cabecalho.Data           = document.Date.Date;
                sale.Cabecalho.DataVencimento = document.ExpirationDate;

                sale.Cabecalho.CodEntidade = document.EntityCode;
                sale.AlteraEntidade(TpEntidade.Cliente, sale.Cabecalho.CodEntidade, true, true);

                sale.Cabecalho.AbrevMoeda = document.CurrencyCode;
                sale.AlteraMoeda(document.CurrencyCode, ref byRefFalse, false);

                foreach (SalesLine line in document.Lines.OrderBy(p => p.LineNumber))
                {
                    itemCode = line.ItemCode;

                    numberLine = sale.Lines.Count + 1;
                    sale.AddLin(ref numberLine);
                    saleLine           = sale.Lines[numberLine];
                    saleLine.TipoLinha = TpLinha.Artigo;

                    saleLine.CodArtigo = itemCode;
                    sale.AlteraArtigo(numberLine, ref itemCode, ref affectsOtherLines, ref fixedAssociation, ref freeAssociation, ref searchItem, checkStock, ref stockAvailable, ref famForQty, ref famForPrice);
                    saleLine.DescArtigo = line.ItemDescription;

                    saleLine.Quantidade = line.Quantity;
                    sale.AlteraQuantidade(numberLine, saleLine.Quantidade, ref affectsOtherLines, false, ref stockAvailable);

                    saleLine.PrecoUnitario = Convert.ToDouble(line.UnitPriceExcludedVAT);
                    sale.AlteraPrecoUnitario(numberLine, saleLine.PrecoUnitario, ref byRefFalse);

                    saleLine.TaxaIva    = Convert.ToDouble(line.VATTax);
                    saleLine.CodTaxaIva = Eti.Aplicacao.Tabelas.TaxasIvas.GetTaxaIva(Convert.ToDecimal(saleLine.TaxaIva));
                    sale.AlteraTaxaIVA(numberLine, saleLine.CodTaxaIva);

                    saleLine.Desconto1 = line.Discount1;
                    sale.AlteraDesconto(1, numberLine, saleLine.Desconto1);

                    saleLine.Desconto2 = line.Discount2;
                    sale.AlteraDesconto(2, numberLine, saleLine.Desconto2);

                    saleLine.Desconto3 = line.Discount3;
                    sale.AlteraDesconto(3, numberLine, saleLine.Desconto3);

                    saleLine.DescontoValorLinha = line.DiscountValue;
                    sale.AlteraDesconto(4, numberLine, saleLine.DescontoValorLinha);
                }

                /// Marca como documento externo, para não recalcular informação de combustiveis
                sale.IsDocExterno = true;
                /// sale.AlteraInfoCertificacao("999", "1", "sdfhkdfFASDGFSfgsfgjsklgfsk394wrkd", "FT 1/598");

                /// INFORMAÇÃO COMBUSTÍVEIS
                foreach (dynamic customInfo in document.CustomInfo)
                {
                    sale.AddISPLines(new List <EC748.CombustiveisInfConsumidor.Models.ISPCombustivel>()
                    {
                        new EC748.CombustiveisInfConsumidor.Models.ISPCombustivel()
                        {
                            ISPCateg      = customInfo.ISPCateg,
                            ISPTaxa       = customInfo.ISPTaxa,
                            ISPUnid       = customInfo.ISPUnid,
                            Quantidade    = customInfo.Quantidade,
                            TaxaCalculada = customInfo.TaxaCalculada,
                            TipoComb      = customInfo.TipoComb,
                        }
                    });

                    sale.AddISPInfoLines(new List <EC748.CombustiveisInfConsumidor.Models.ISPCombustivelInfo>()
                    {
                        new EC748.CombustiveisInfConsumidor.Models.ISPCombustivelInfo()
                        {
                            EmissaoUnidade  = customInfo.EmissaoUnidade,
                            EmissaoCO2      = customInfo.EmissaoCO2,
                            FossilPerc      = customInfo.FossilPerc,
                            ISPCategoria    = customInfo.ISPCateg,
                            ISPNomenclatura = customInfo.ISPNomenclatura,
                            RenovavelPerc   = customInfo.RenovavelPerc,
                            SobreCusto      = customInfo.SobreCusto,
                            tpCombustivel   = customInfo.TipoComb
                        }
                    });
                }
                /// INFORMAÇÃO COMBUSTÍVEIS

                var validate = sale.Validate(true);
                if (validate)
                {
                    var blockingStock = false;
                    Eti.Aplicacao.Movimentos.MovVendas.Update(ref sale, ref blockingStock, true, 0, "");
                }

                if (!string.IsNullOrEmpty(sale.EtiErrorCode))
                {
                    throw new Exception($@"ErrorCode:{sale.EtiErrorCode}{Environment.NewLine}
                                            EtiErrorDescription:{sale.EtiErrorDescription}");
                }
                else
                {
                    DocumentKey docKey = new Helpers.DocumentKey()
                    {
                        SectionCode   = sale.Cabecalho.CodSeccao,
                        DocTypeAbbrev = sale.Cabecalho.AbrevTpDoc,
                        FiscalYear    = sale.Cabecalho.CodExercicio,
                        Number        = sale.Cabecalho.Numero
                    };

                    reportBytes = Functions.GetReportBytes(TpDocumentoAEmitir.Vendas, docKey);
                }

                return(Ok(reportBytes));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Beispiel #4
0
        //api/Purchases/GeneratePurchaseDoc
        //data: {
        //"FiscalYear":"2018",
        //"SectionCode":"1",
        //"DocTypeAbbrev":"V/FAT",
        //"EntityCode":"502395028",
        //"Date":"2018/01/25",
        //"ExpirationDate":"2018/02/24",
        //"CurrencyCode":"EUR",
        //"Lines":[
        //	{
        //		"LineNumber": "1",
        //		"ItemCode": "AMORT",
        //		"ItemDescription": "AMORTECEDOR 001",
        //      "BatchCode" : "LOTE_1",
        //      "BatchDescription" : "Lote 0001".
        //      "EntryDate" : "2018-03-27"
        //      "ExpirationDate" : "2019-03-27"
        //		"Quantity": "2",
        //		"VATTax": "23",
        //		"UnitPriceExcludedVAT": "39.90",
        //		"Discount1": "5",
        //		"Discount2": "0",
        //		"Discount3": "0",
        //		"DiscountValue": "0"
        //  }
        //]}
        public IHttpActionResult GeneratePurchaseDoc([FromBody] Models.myPurchase document)
        {
            byte[] reportBytes;

            MovCompra       purch;
            MovCompraLin    purchLine;
            var             byRefFalse        = false;
            var             stockAvailable    = true;
            var             affectsOtherLines = true;
            var             fixedAssociation  = true;
            var             freeAssociation   = true;
            var             checkStock        = false;
            TpProcuraArtigo searchItem        = TpProcuraArtigo.NaoEncontrou;
            int             numberLine;
            string          itemCode;

            try
            {
                purch = Eti.Aplicacao.Movimentos.MovCompras.GetNew(document.DocTypeAbbrev, document.SectionCode);
                purch.Cabecalho().CodExercicio = document.FiscalYear;

                purch.Cabecalho().AplicacaoOrigem = "WS";

                purch.Cabecalho().Data           = document.Date.Date;
                purch.Cabecalho().DataVencimento = document.ExpirationDate;

                purch.Cabecalho().CodEntidade = document.EntityCode;
                purch.AlteraEntidade(TpEntidade.Fornecedor, purch.Cabecalho().CodEntidade, true, true);

                purch.Cabecalho().AbrevMoeda = document.CurrencyCode;
                purch.AlteraMoeda(document.CurrencyCode, ref byRefFalse, false);

                foreach (PurchaseLine line in document.Lines.OrderBy(p => p.LineNumber))
                {
                    itemCode = line.ItemCode;

                    numberLine = purch.Lines.Count + 1;
                    purch.AddLin(ref numberLine);
                    purchLine           = purch.Lines[numberLine];
                    purchLine.TipoLinha = TpLinha.Artigo;

                    purchLine.CodArtigo = itemCode;
                    purch.AlteraArtigo(numberLine, ref itemCode, ref affectsOtherLines, ref fixedAssociation, ref freeAssociation, ref searchItem, checkStock, ref stockAvailable);
                    purchLine.DescArtigo = line.ItemDescription;

                    //Cria lote caso não exista
                    var item = Eti.Aplicacao.Tabelas.Artigos.Find(itemCode);
                    if (item.Lotes)
                    {
                        var inactive = false;
                        var exists   = false;

                        exists = Eti.Aplicacao.Tabelas.Artigos.ExisteLote(itemCode, line.BatchCode, ref inactive);

                        if (!exists)
                        {
                            Eti.Aplicacao.Tabelas.Artigos.GravaLote(itemCode, line.BatchCode, line.BatchDescription, line.EntryDate, line.ExpirationDate, "", "", "", "", "");

                            purchLine.Lote = line.BatchCode;

                            checkStock     = true;
                            stockAvailable = false;

                            //exists : devolve se o lote existe ou não
                            //inactive: devolve se está inativo
                            //se checkStock = true devolve no stockAvailable se existe stock disponivel
                            purch.AlteraLote(numberLine, itemCode, line.BatchCode, ref exists, ref inactive, checkStock, ref stockAvailable);
                        }
                    }


                    purchLine.Quantidade = line.Quantity;
                    purch.AlteraQuantidade(numberLine, purchLine.Quantidade, ref affectsOtherLines, false, ref stockAvailable);

                    purchLine.PrecoUnitario = Convert.ToDouble(line.UnitPriceExcludedVAT);
                    purch.AlteraPrecoUnitario(numberLine, purchLine.PrecoUnitario);

                    purchLine.TaxaIva    = Convert.ToDouble(line.VATTax);
                    purchLine.CodTaxaIva = Eti.Aplicacao.Tabelas.TaxasIvas.GetTaxaIva(Convert.ToDecimal(purchLine.TaxaIva));
                    purch.AlteraTaxaIVA(numberLine, purchLine.CodTaxaIva);

                    purchLine.Desconto1 = line.Discount1;
                    purch.AlteraDesconto(1, numberLine, purchLine.Desconto1);

                    purchLine.Desconto2 = line.Discount2;
                    purch.AlteraDesconto(2, numberLine, purchLine.Desconto2);

                    purchLine.Desconto3 = line.Discount3;
                    purch.AlteraDesconto(3, numberLine, purchLine.Desconto3);

                    purchLine.DescontoValorLinha = line.DiscountValue;
                    purch.AlteraDesconto(4, numberLine, purchLine.DescontoValorLinha);
                }

                var validate = purch.Validate(true);
                if (validate)
                {
                    var blockingStock = false;
                    Eti.Aplicacao.Movimentos.MovCompras.Update(ref purch, ref blockingStock, true, 0, "");
                }

                if (!string.IsNullOrEmpty(purch.EtiErrorCode))
                {
                    throw new Exception($@"ErrorCode:{purch.EtiErrorCode}{Environment.NewLine}
                                            EtiErrorDescription:{purch.EtiErrorDescription}");
                }
                else
                {
                    DocumentKey docKey = new Helpers.DocumentKey()
                    {
                        SectionCode   = purch.Cabecalho().CodSeccao,
                        DocTypeAbbrev = purch.Cabecalho().AbrevTpDoc,
                        FiscalYear    = purch.Cabecalho().CodExercicio,
                        Number        = purch.Cabecalho().Numero
                    };

                    reportBytes = Functions.GetReportBytes(TpDocumentoAEmitir.Compras, docKey);
                }

                return(Ok(reportBytes));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Beispiel #5
0
        //api/Invoices/GenerateSalesDoc
        //data: {
        //"FiscalYear":"2018",
        //"SectionCode":"1",
        //"DocTypeAbbrev":"FAT",
        //"EntityCode":"502395028",
        //"Date":"2018/01/25",
        //"ExpirationDate":"2018/02/24",
        //"CurrencyCode":"EUR",
        //"Lines":[
        //	{
        //		"LineNumber": "1",
        //		"ItemCode": "AMORT",
        //		"ItemDescription": "AMORTECEDOR 001",
        //		"Quantity": "2",
        //		"VATTax": "23",
        //		"UnitPriceExcludedVAT": "39.90",
        //		"Discount1": "5",
        //		"Discount2": "0",
        //		"Discount3": "0",
        //		"DiscountValue": "0"
        //  }
        //]}
        public IHttpActionResult GenerateSalesDoc([FromBody] Models.mySale document)
        {
            byte[] reportBytes;

            MovVenda        sale;
            MovVendaLin     saleLine;
            var             byRefFalse        = false;
            var             stockAvailable    = true;
            var             affectsOtherLines = true;
            var             fixedAssociation  = true;
            var             freeAssociation   = true;
            var             checkStock        = false;
            var             famForQty         = false;
            var             famForPrice       = false;
            TpProcuraArtigo searchItem        = TpProcuraArtigo.NaoEncontrou;
            int             numberLine;
            string          itemCode;

            try
            {
                sale = Eti.Aplicacao.Movimentos.MovVendas.GetNew(document.DocTypeAbbrev, document.SectionCode);
                sale.Cabecalho.CodExercicio = document.FiscalYear;

                sale.Cabecalho.AplicacaoOrigem = "WS";

                sale.Cabecalho.Data           = document.Date.Date;
                sale.Cabecalho.DataVencimento = document.ExpirationDate;

                sale.Cabecalho.CodEntidade = document.EntityCode;
                sale.AlteraEntidade(TpEntidade.Cliente, sale.Cabecalho.CodEntidade, true, true);

                sale.Cabecalho.AbrevMoeda = document.CurrencyCode;
                sale.AlteraMoeda(document.CurrencyCode, ref byRefFalse, false);

                foreach (SalesLine line in document.Lines.OrderBy(p => p.LineNumber))
                {
                    itemCode = line.ItemCode;

                    numberLine = sale.Lines.Count + 1;
                    sale.AddLin(ref numberLine);
                    saleLine           = sale.Lines[numberLine];
                    saleLine.TipoLinha = TpLinha.Artigo;

                    saleLine.CodArtigo = itemCode;
                    sale.AlteraArtigo(numberLine, ref itemCode, ref affectsOtherLines, ref fixedAssociation, ref freeAssociation, ref searchItem, checkStock, ref stockAvailable, ref famForQty, ref famForPrice);
                    saleLine.DescArtigo = line.ItemDescription;

                    saleLine.Quantidade = line.Quantity;
                    sale.AlteraQuantidade(numberLine, saleLine.Quantidade, ref affectsOtherLines, false, ref stockAvailable);

                    saleLine.PrecoUnitario = Convert.ToDouble(line.UnitPriceExcludedVAT);
                    sale.AlteraPrecoUnitario(numberLine, saleLine.PrecoUnitario, ref byRefFalse);

                    saleLine.TaxaIva    = Convert.ToDouble(line.VATTax);
                    saleLine.CodTaxaIva = Eti.Aplicacao.Tabelas.TaxasIvas.GetTaxaIva(Convert.ToDecimal(saleLine.TaxaIva));
                    sale.AlteraTaxaIVA(numberLine, saleLine.CodTaxaIva);

                    saleLine.Desconto1 = line.Discount1;
                    sale.AlteraDesconto(1, numberLine, saleLine.Desconto1);

                    saleLine.Desconto2 = line.Discount2;
                    sale.AlteraDesconto(2, numberLine, saleLine.Desconto2);

                    saleLine.Desconto3 = line.Discount3;
                    sale.AlteraDesconto(3, numberLine, saleLine.Desconto3);

                    saleLine.DescontoValorLinha = line.DiscountValue;
                    sale.AlteraDesconto(4, numberLine, saleLine.DescontoValorLinha);
                }

                var validate = sale.Validate(true);
                if (validate)
                {
                    var blockingStock = false;
                    Eti.Aplicacao.Movimentos.MovVendas.Update(ref sale, ref blockingStock, true, 0, "");
                }

                if (!string.IsNullOrEmpty(sale.EtiErrorCode))
                {
                    throw new Exception($@"ErrorCode:{sale.EtiErrorCode}{Environment.NewLine}
                                            EtiErrorDescription:{sale.EtiErrorDescription}");
                }
                else
                {
                    DocumentKey docKey = new Helpers.DocumentKey()
                    {
                        SectionCode   = sale.Cabecalho.CodSeccao,
                        DocTypeAbbrev = sale.Cabecalho.AbrevTpDoc,
                        FiscalYear    = sale.Cabecalho.CodExercicio,
                        Number        = sale.Cabecalho.Numero
                    };

                    reportBytes = Functions.GetReportBytes(TpDocumentoAEmitir.Vendas, docKey);
                }

                return(Ok(reportBytes));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }