示例#1
0
        public static void SAFX202(IMongoCollection <BsonDocument> collection)
        {
            var pipeline = new[] { new BsonDocument()
                                   {
                                       { "$lookup",
                                         new BsonDocument()
                                         {
                                             { "from", "companies" },
                                             { "localField", "company_uuid" },
                                             { "foreignField", "uuid" },
                                             { "as", "company" }
                                         } }
                                   }, new BsonDocument()
                                   {
                                       { "$project", new BsonDocument()
                                         {
                                             { "device_info.pos_id", 1 },
                                             { "document.number", 1 },
                                             { "activated_at", 1 },
                                             { "document.status", 1 },
                                             { "customer.name", 1 },
                                             { "customer.identification.cnpj", 1 },
                                             { "document.qrcode_url", 1 },
                                             { "document.xml", 1 },
                                             { "payments", 1 },
                                             { "company", 1 },
                                             { "cart_items", 1 }
                                         } }
                                   } };

            var results = collection.Aggregate <SAFX202Model>(pipeline).ToList();

            var estabelecimentos = new EmpresaEstabelecimento().GetAll();

            List <SAFX202> listToFile = new List <SAFX202>();

            foreach (var itemSale in results.Where(x => x.company != null && x.document != null && x.document.xml != null))
            {
                var estabelecimento = estabelecimentos.FirstOrDefault(x => x.CNPJ == itemSale.company[0].fiscal_informations.cnpj);

                if (estabelecimento != null)
                {
                    itemSale.document.DealXml();

                    foreach (var cartItem in itemSale.cart_items)
                    {
                        listToFile.Add(new SAFX202(itemSale, cartItem, estabelecimento));
                    }
                }
            }

            //foreach(var resultItem in listToFile)
            //{
            //    Console.WriteLine($"{resultItem.COD_EMPRESA}  {resultItem.COD_ESTAB} {resultItem.NUM_EQUIP} {resultItem.NUM_CUPOM} {resultItem.DATA_EMISSAO} {resultItem.NUM_ITEM} {resultItem.IND_PRODUTO} {resultItem.COD_PRODUTO} {resultItem.COD_CFO} {resultItem.COD_CONTA} {resultItem.COD_SITUACAO_A} {resultItem.COD_SITUACAO_B} {resultItem.QTDE} {resultItem.VLR_UNIT} {resultItem.VLR_ITEM} {resultItem.VLR_DESC} {resultItem.VLR_ACRES} {resultItem.VLR_TOT_LIQ} {resultItem.VLR_BASE_ICMS} {resultItem.VLR_ICMS} {resultItem.VLR_ALIQ_ICMS} {resultItem.COD_SIT_TRIB_PIS} {resultItem.QTD_BASE_PIS} {resultItem.VLR_ALIQ_PIS_R} {resultItem.VLR_BASE_PIS} {resultItem.VLR_PIS} {resultItem.VLR_ALIQ_PIS} {resultItem.COD_SIT_TRIB_COFINS} {resultItem.QTD_BASE_COFINS} {resultItem.VLR_ALIQ_COFINS_R} {resultItem.VLR_BASE_COFINS} {resultItem.VLR_COFINS} {resultItem.VLR_ALIQ_COFINS} {resultItem.VLR_BASE_PIS_ST} {resultItem.VLR_PIS_ST} {resultItem.VLR_BASE_COFINS_ST} {resultItem.VLR_COFINS_ST} {resultItem.VLR_ALIQ_COFINS_ST} {resultItem.VLR_DESP_ACS} {resultItem.COD_OBSERVACAO} {resultItem.COD_NAT_REC} {resultItem.VLR_EXC_BASE_PISCOFINS}");
            //}

            GenerateTxt(listToFile);
        }
示例#2
0
        public ActionResult Post([FromBody] EmpresaEstabelecimento empresa)
        {
            _repository.Add(empresa);


            //mostrar para o usuario tem que mapear para produtoDTO

            // retorna uma rota pra o produto criado
            return(new CreatedAtRouteResult("Detalhes", new { id = empresa.Id }, empresa));
        }
示例#3
0
 public EmpresaEstabelecimento Add(EmpresaEstabelecimento model)
 {
     try
     {
         _empresaRepository.Add(model);
         return(_empresaRepository.GetEmpresaById(model.Id));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
示例#4
0
        // recebe o id do produto e os dados do produto a ser alterado pelo fromBody
        public ActionResult Put(int id, [FromBody] EmpresaEstabelecimento empresa)
        {
            // verficar se o id passado na url é igual o id do produto que está sendo alterado
            if (id != empresa.Id)
            {
                return(BadRequest());
            }
            // antes de chamar o metodo mapea o produtoDTo para produto

            // se o id for igual altera o produto atraves deste metodo abaixo
            _repository.Update(empresa);

            return(Ok());
        }
示例#5
0
 public EmpresaEstabelecimento Update(int id, EmpresaEstabelecimento model)
 {
     try
     {
         var empresa = _empresaRepository.GetEmpresaById(id);
         if (empresa == null)
         {
             return(null);
         }
         else
         {
             _repository.Update(model);
         }
         return(_empresaRepository.GetEmpresaById(model.Id));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
        public IList <SAFX201> SAFX201()
        {
            var hora_inicio = "00:00:00";
            var hora_fim    = "23:59:59";
            var data_inicio = Inicio.ToString("yyyy-MM-dd");
            var data_fim    = Fim.ToString("yyyy-MM-dd");

            var filter = new BsonDocument()
            {
                { "$match", new BsonDocument()
                  {
                      { "activated_at", new BsonDocument()
                        {
                            { "$gte", DateTime.Parse($"{data_inicio}T{hora_inicio}.000-03:00") },
                            { "$lt", DateTime.Parse($"{data_fim}T{hora_fim}.000-03:00") }
                        } },
                      { "company_uuid", Company }
                  } }
            };

            var pipeline = new[] { filter, new BsonDocument()
                                   {
                                       { "$lookup",
                                         new BsonDocument()
                                         {
                                             { "from", "companies" },
                                             { "localField", "company_uuid" },
                                             { "foreignField", "uuid" },
                                             { "as", "company" }
                                         } }
                                   }, new BsonDocument()
                                   {
                                       { "$project", new BsonDocument()
                                         {
                                             { "device_info.pos_id", 1 },
                                             { "document.number", 1 },
                                             { "activated_at", 1 },
                                             { "document.status", 1 },
                                             { "customer.name", 1 },
                                             { "customer.identification.cnpj", 1 },
                                             { "document.qrcode_url", 1 },
                                             { "document.access_key", 1 },
                                             { "document.type", 1 },
                                             { "payments", 1 },
                                             { "company", 1 },
                                             { "cart_items", 1 }
                                         } }
                                   } };

            var results = collection.Aggregate <BsonDocument>(pipeline).ToList();

            var list = new List <SAFX201>();

            var estabelecimentos = new EmpresaEstabelecimento().GetAll();


            foreach (var document in results)
            {
                //device info
                var hasNumEquip = document.TryGetElement("device_info", out BsonElement numEquip);
                var hasPosId    = false;
                if (hasNumEquip)
                {
                    var deviceInfoDoc = document.GetElement("device_info").Value.AsBsonDocument;
                    hasPosId = deviceInfoDoc.TryGetElement("pos_id", out numEquip);
                }

                //device info
                var     hasCompany = document.TryGetElement("company", out BsonElement comnpany);
                Company company    = null;
                if (hasCompany)
                {
                    company = BsonSerializer.Deserialize <Company>(document.GetElement("company").Value.AsBsonArray.First().AsBsonDocument);
                }

                //document
                var         hasDocument     = document.TryGetElement("document", out BsonElement documentElement);
                var         hasDocStatus    = false;
                var         hasDocQrCode    = false;
                var         hasDocNumber    = false;
                var         hasDocAccessKey = false;
                var         hasType         = false;
                BsonElement documentStatus;
                BsonElement documentQrCode;
                BsonElement documentNumber;
                BsonElement documentAccessKey;
                BsonElement documentType;
                if (hasDocument)
                {
                    var documentDoc = document.GetElement("document").Value.AsBsonDocument;
                    hasDocStatus    = documentDoc.TryGetElement("status", out documentStatus);
                    hasDocQrCode    = documentDoc.TryGetElement("qrcode_url", out documentQrCode);
                    hasDocNumber    = documentDoc.TryGetElement("number", out documentNumber);
                    hasDocAccessKey = documentDoc.TryGetElement("access_key", out documentAccessKey);
                    hasType         = documentDoc.TryGetElement("type", out documentType);
                }

                if (hasType && documentType.Value.BsonType != BsonType.Null)
                {
                    var type = documentType.Value.ToString();
                    if (type.Equals("devolution"))
                    {
                        continue;
                    }
                }

                //customer
                var         hasCustomer               = document.TryGetElement("customer", out BsonElement customerElement);
                var         hasCustomerName           = false;
                var         hasCustomerIdentification = false;
                BsonElement customerName;
                BsonElement customerIdentification;


                if (hasCustomer)
                {
                    var customerDoc = document.GetElement("customer").Value.AsBsonDocument;
                    hasCustomerName           = customerDoc.TryGetElement("name", out customerName);
                    hasCustomerIdentification = customerDoc.TryGetElement("identification", out customerIdentification);
                }

                //payments
                var         hasPayments   = document.TryGetElement("payments", out BsonElement payments);
                var         hasRealAmount = false;
                var         hasAmount     = false;
                BsonArray   paymentsList;
                BsonElement paymentRealAmount;
                BsonElement paymentAmount;
                if (hasPayments)
                {
                    paymentsList  = payments.Value.AsBsonArray;
                    hasRealAmount = paymentsList.First().AsBsonDocument.TryGetElement("real_amount", out paymentRealAmount);
                    hasAmount     = paymentsList.First().AsBsonDocument.TryGetElement("amount", out paymentAmount);
                }

                //cart_item
                var       hasCartItems = document.TryGetElement("cart_items", out BsonElement cartItens);
                BsonArray itemList;
                double    valorDiscount = 0;
                if (hasCartItems)
                {
                    itemList = cartItens.Value.AsBsonArray;
                    var s = itemList
                            .GroupBy(x => Convert.ToDouble(x.AsBsonDocument.GetElement("discount").Value))
                            .Select(n => n.Sum(s => Convert.ToDouble(s.AsBsonDocument.GetElement("discount").Value))).ToList();

                    if (s.Any())
                    {
                        valorDiscount = s.FirstOrDefault();
                    }
                }

                var empresaEstabelecimento = estabelecimentos.FirstOrDefault(x => x.CNPJ == company.fiscal_informations.cnpj);

                if (empresaEstabelecimento != null)
                {
                    var model = new SAFX201
                    {
                        COD_EMPRESA        = empresaEstabelecimento != null ? empresaEstabelecimento.COD_EMPRESA : "H00",
                        COD_ESTAB          = empresaEstabelecimento != null ? empresaEstabelecimento.COD_ESTAB : "H001",
                        NUM_EQUIP          = hasPosId ? numEquip.Value.ToString().Replace("-", "") : "0",
                        NUM_CUPOM          = hasDocNumber ? documentNumber.Value.ToString() : "0",
                        DATA_EMISSAO       = document.GetElement("activated_at").Value.BsonType == BsonType.Null ? DateTime.Now.ToString("yyyyMMdd") : DateTime.Parse(document.GetElement("activated_at").Value.ToString()).ToString("yyyyMMdd"),
                        COD_MODELO         = "59",
                        IND_SITUACAO_CUPOM = hasDocStatus ? (documentStatus.Value.ToString().Equals("cancelled") ? "02" : documentStatus.Value.ToString().Equals("rejected") ? "04" : "00") : "00",
                        NOME_CLIENTE       = (hasCustomerName ? customerName.Value.ToString() : ""),
                        CPF_CNPJ_CLIENTE   = (hasCustomerIdentification ? customerIdentification.Value.ToString() : "").PadLeft(14, ' '),
                        NUM_AUTENTIC_NFE   = "0",
                        VLR_TOT_LIQ        = (hasAmount ? paymentAmount.Value.ToString() : "0"),
                        VLR_ACRES          = "0",
                        VLR_DESC           = valorDiscount.ToString(),
                        VLR_DESP_ACS       = "0",
                    };

                    model.VLR_TOT = (double.Parse(model.VLR_TOT_LIQ) + valorDiscount).ToString();

                    if (hasDocAccessKey && documentAccessKey.Value.BsonType != BsonType.Null)
                    {
                        var key = documentAccessKey.Value.ToString();
                        if (key.Contains("CFe"))
                        {
                            if (key.Length > 3)
                            {
                                model.NUM_AUTENTIC_NFE = key.Remove(0, 3);
                            }
                        }
                        else
                        {
                            model.NUM_AUTENTIC_NFE = key;
                        }
                    }

                    model.NUM_AUTENTIC_NFE.PadLeft(44, '0');
                    list.Add(model);
                }
            }

            return(list);
        }
        public async Task <IList <SAFX202Csv> > SAFX202CSV()
        {
            var hora_inicio = "00:00:00";
            var hora_fim    = "23:59:59";
            var data_inicio = Inicio.ToString("yyyy-MM-dd");
            var data_fim    = Fim.ToString("yyyy-MM-dd");

            var filter = new BsonDocument()
            {
                { "$match", new BsonDocument()
                  {
                      { "activated_at", new BsonDocument()
                        {
                            { "$gte", DateTime.Parse($"{data_inicio}T{hora_inicio}.000-03:00") },
                            { "$lt", DateTime.Parse($"{data_fim}T{hora_fim}.000-03:00") }
                        } },
                      { "company_uuid", Company }
                  } }
            };

            //var pipeline = new[] { filter, new BsonDocument() {
            var pipeline = new[] { filter, new BsonDocument()
                                   {
                                       { "$lookup",
                                         new BsonDocument()
                                         {
                                             { "from", "companies" },
                                             { "localField", "company_uuid" },
                                             { "foreignField", "uuid" },
                                             { "as", "company" }
                                         } }
                                   }, new BsonDocument()
                                   {
                                       { "$project", new BsonDocument()
                                         {
                                             { "device_info.pos_id", 1 },
                                             { "document.number", 1 },
                                             { "activated_at", 1 },
                                             { "document.status", 1 },
                                             { "customer.name", 1 },
                                             { "customer.identification.cnpj", 1 },
                                             { "document.qrcode_url", 1 },
                                             { "document.xml", 1 },
                                             { "payments", 1 },
                                             { "company", 1 },
                                             { "cart_items", 1 }
                                         } }
                                   } };

            var results = await collection.Aggregate <SAFX202Model>(pipeline).ToListAsync();

            var estabelecimentos = new EmpresaEstabelecimento().GetAll();

            List <SAFX202Csv> listToFile = new List <SAFX202Csv>();
            var data = results.Where(x => x.company != null && x.document != null && x.document.xml != null);

            foreach (var itemSale in data)
            //Parallel.ForEach(data, itemSale =>
            {
                var estabelecimento = estabelecimentos
                                      .FirstOrDefault(x => x.CNPJ == itemSale.company[0].fiscal_informations.cnpj);

                if (estabelecimento != null)
                {
                    itemSale.document.DealXml();

                    foreach (var cartItem in itemSale.cart_items)
                    {
                        //var model = new SAFX202Csv(itemSale, cartItem, estabelecimento);

                        var model = new SAFX202Csv();
                        var list  = model.DataGen(itemSale, cartItem, estabelecimento);
                        if (list.Any())
                        {
                            if (list.Any())
                            {
                                list.ToList().ForEach(x => listToFile.Add(x));
                            }
                        }
                    }
                }
            }//);

            return(listToFile);
        }
示例#8
0
        public static void SAFX201(IMongoCollection <BsonDocument> collection)
        {
            var pipeline = new[] { new BsonDocument()
                                   {
                                       { "$lookup",
                                         new BsonDocument()
                                         {
                                             { "from", "companies" },
                                             { "localField", "company_uuid" },
                                             { "foreignField", "uuid" },
                                             { "as", "company" }
                                         } }
                                   }, new BsonDocument()
                                   {
                                       { "$project", new BsonDocument()
                                         {
                                             { "device_info.pos_id", 1 },
                                             { "document.number", 1 },
                                             { "activated_at", 1 },
                                             { "document.status", 1 },
                                             { "customer.name", 1 },
                                             { "customer.identification.cnpj", 1 },
                                             { "document.qrcode_url", 1 },
                                             { "payments", 1 },
                                             { "company", 1 },
                                             { "cart_items", 1 }
                                         } }
                                   } };

            var results = collection.Aggregate <BsonDocument>(pipeline).ToList();

            var list = new List <SAFX201>();

            var estabelecimentos = new EmpresaEstabelecimento().GetAll();


            foreach (var document in results)
            {
                //device info
                var hasNumEquip = document.TryGetElement("device_info", out BsonElement numEquip);
                var hasPosId    = false;
                if (hasNumEquip)
                {
                    var deviceInfoDoc = document.GetElement("device_info").Value.AsBsonDocument;
                    hasPosId = deviceInfoDoc.TryGetElement("pos_id", out numEquip);
                }

                //device info
                var     hasCompany = document.TryGetElement("company", out BsonElement comnpany);
                Company company    = null;
                if (hasCompany)
                {
                    company = BsonSerializer.Deserialize <Company>(document.GetElement("company").Value.AsBsonArray.First().AsBsonDocument);
                }

                //document
                var         hasDocument     = document.TryGetElement("document", out BsonElement documentElement);
                var         hasDocStatus    = false;
                var         hasDocQrCode    = false;
                var         hasDocNumber    = false;
                var         hasDocAccessKey = false;
                BsonElement documentStatus;
                BsonElement documentQrCode;
                BsonElement documentNumber;
                BsonElement documentAccessKey;
                if (hasDocument)
                {
                    var documentDoc = document.GetElement("document").Value.AsBsonDocument;
                    hasDocStatus    = documentDoc.TryGetElement("status", out documentStatus);
                    hasDocQrCode    = documentDoc.TryGetElement("qrcode_url", out documentQrCode);
                    hasDocNumber    = documentDoc.TryGetElement("number", out documentNumber);
                    hasDocAccessKey = documentDoc.TryGetElement("access_key", out documentAccessKey);
                }

                //customer
                var         hasCustomer               = document.TryGetElement("customer", out BsonElement customerElement);
                var         hasCustomerName           = false;
                var         hasCustomerIdentification = false;
                BsonElement customerName;
                BsonElement customerIdentification;


                if (hasCustomer)
                {
                    var customerDoc = document.GetElement("customer").Value.AsBsonDocument;
                    hasCustomerName           = customerDoc.TryGetElement("name", out customerName);
                    hasCustomerIdentification = customerDoc.TryGetElement("identification", out customerIdentification);
                }

                //payments
                var         hasPayments   = document.TryGetElement("payments", out BsonElement payments);
                var         hasRealAmount = false;
                var         hasAmount     = false;
                BsonArray   paymentsList;
                BsonElement paymentRealAmount;
                BsonElement paymentAmount;
                if (hasPayments)
                {
                    paymentsList  = payments.Value.AsBsonArray;
                    hasRealAmount = paymentsList.First().AsBsonDocument.TryGetElement("real_amount", out paymentRealAmount);
                    hasAmount     = paymentsList.First().AsBsonDocument.TryGetElement("amount", out paymentAmount);
                }

                var empresaEstabelecimento = estabelecimentos.FirstOrDefault(x => x.CNPJ == company.fiscal_informations.cnpj);

                if (empresaEstabelecimento != null)
                {
                    list.Add(new SAFX201
                    {
                        COD_EMPRESA        = empresaEstabelecimento != null ? empresaEstabelecimento.COD_EMPRESA : "H00",
                        COD_ESTAB          = empresaEstabelecimento != null ? empresaEstabelecimento.COD_ESTAB : "H001",
                        NUM_EQUIP          = hasPosId ? numEquip.Value.ToString().Replace("-", "") : "000000000",
                        NUM_CUPOM          = hasDocNumber ? documentNumber.Value.ToString().PadLeft(6, '0') : "000000",
                        DATA_EMISSAO       = document.GetElement("activated_at").Value.BsonType == BsonType.Null ? DateTime.Now.ToString("yyyymmdd") : DateTime.Parse(document.GetElement("activated_at").Value.ToString()).ToString("yyyymmdd"),
                        COD_MODELO         = "59",
                        IND_SITUACAO_CUPOM = hasDocStatus ? (documentStatus.Value.ToString().Equals("cancelled") ? "02" : documentStatus.Value.ToString().Equals("rejected") ? "04" : "00") : "00",
                        NOME_CLIENTE       = (hasCustomerName ? customerName.Value.ToString() : "").PadLeft(60, ' '),
                        CPF_CNPJ_CLIENTE   = (hasCustomerIdentification ? customerIdentification.Value.ToString() : "").PadLeft(14, ' '),
                        NUM_AUTENTIC_NFE   = hasDocAccessKey && documentAccessKey.Value.BsonType != BsonType.Null ? documentAccessKey.Value.ToString().PadLeft(80, ' ') : "".PadLeft(80, ' '),
                        VLR_TOT            = (hasAmount ? paymentAmount.Value.ToString() : "").PadLeft(17, '0'),
                        VLR_ACRES          = "00000000000000000",
                        VLR_DESC           = "00000000000000000",
                        VLR_DESP_ACS       = "00000000000000000",
                        VLR_TOT_LIQ        = (hasRealAmount ? paymentRealAmount.Value.ToString() : "").PadLeft(17, '0'),
                    });
                }
            }

            GenerateTxt(list);

            foreach (var item in list)
            {
                Console.WriteLine($"{item.COD_EMPRESA}  {item.COD_ESTAB}  {item.NUM_EQUIP} {item.NUM_CUPOM} {item.DATA_EMISSAO} {item.COD_MODELO} {item.IND_SITUACAO_CUPOM} {item.NOME_CLIENTE} {item.CPF_CNPJ_CLIENTE} {item.NUM_AUTENTIC_NFE} {item.VLR_TOT} {item.VLR_DESC} {item.VLR_ACRES} {item.VLR_TOT_LIQ} {item.VLR_DESP_ACS}");
            }
        }