Пример #1
0
        public List <ArtigoDTO> ObterProdutosVendidosPorCategoria(ArtigoDTO dto)
        {
            var CategoryList = CategoriaRN.GetInstance().ObterPorFiltro(new CategoriaDTO
            {
                Codigo    = -1,
                Descricao = "",
                Sigla     = "",
                Categoria = "-1",
                Filial    = dto.Filial
            });
            var productList      = ObterProdutosVendidosPorPeriodo(dto);
            var CategoryBillList = new List <ArtigoDTO>();

            foreach (var category in CategoryList)
            {
                var ProductCategoryList = productList.Where(t => t.Categoria == category.Codigo.ToString() || t.SubCategoria == category.Codigo.ToString()).ToList();

                if (ProductCategoryList != null)
                {
                    dto = new ArtigoDTO
                    {
                        Designacao     = category.Descricao.ToUpper(),
                        PrecoCusto     = ProductCategoryList.Sum(t => t.PrecoCusto),
                        Quantidade     = ProductCategoryList.Sum(t => t.Quantidade),
                        PrecoVenda     = ProductCategoryList.Sum(t => t.PrecoVenda),
                        ValorStockPVP  = ProductCategoryList.Sum(t => t.ValorStockPVP),
                        Desconto       = ProductCategoryList.Sum(t => t.Desconto),
                        ImpostoLiquido = ProductCategoryList.Sum(t => t.ImpostoLiquido),
                        PrevisaoLucro  = ProductCategoryList.Sum(t => t.PrevisaoLucro)
                    };

                    CategoryBillList.Add(dto);
                }
            }

            return(CategoryBillList.OrderBy(t => t.Designacao).ToList());
        }
Пример #2
0
        public string ObterVendasPorSubFamilias(ArtigoDTO dto)
        {
            string tableColumns = "";
            var    CategoryList = CategoriaRN.GetInstance().ObterPorFiltro(new CategoriaDTO
            {
                Codigo    = -1,
                Descricao = "",
                Sigla     = "",
                Categoria = "-1",
                Filial    = dto.Filial
            });
            var productList = ObterProdutosVendidosPorPeriodo(dto).OrderBy(t => t.Designacao).ToList();
            int CategoryID  = (dto.Categoria != null && dto.Categoria != "-1" && dto.Categoria != "" && dto.Categoria != "0") ? int.Parse(dto.Categoria) : -1;

            if (dto.Categoria != null && dto.Categoria != "-1" && dto.Categoria != "" && dto.Categoria != "0")
            {
                CategoryList = CategoryList.Where(t => t.Codigo == int.Parse(dto.Categoria)).ToList();
            }

            int SubCategoryID = (dto.SubCategoria != null && dto.SubCategoria != "" && dto.SubCategoria != "-1" && dto.SubCategoria != "0") ? int.Parse(dto.SubCategoria) : -1;

            foreach (var category in CategoryList)
            {
                List <ArtigoDTO> ProductCategoryList = new List <ArtigoDTO>();
                if (SubCategoryID > 0)
                {
                    ProductCategoryList = productList.Where(t => t.Categoria == SubCategoryID.ToString()).ToList();
                }
                else
                {
                    ProductCategoryList = productList.Where(t => t.Categoria == category.Codigo.ToString() || t.SubCategoria == category.Codigo.ToString()).ToList();
                }

                decimal totalCategoryBilling = SubCategoryID > 0 ? ProductCategoryList.Where(t => t.Categoria == SubCategoryID.ToString()).Sum(t => (t.ValorStockPVP - t.Desconto) + t.ImpostoLiquido)
                    : ProductCategoryList.Sum(t => (t.ValorStockPVP - t.Desconto) + t.ImpostoLiquido);
                if (ProductCategoryList != null && ProductCategoryList.Sum(t => t.Quantidade) > 0)
                {
                    tableColumns += "<tr style='font-size:10px'>" +
                                    "<td colspan='9' style='background-color:#FFA500; text-align:left'><b>" + category.Descricao.ToUpper() + "</b></td><tr>";

                    var categoryItem = SubCategoryID > 0 ? ProductCategoryList.Where(t => t.Categoria == SubCategoryID.ToString()).ToList()
                    : ProductCategoryList.Where(t => t.Categoria == category.Codigo.ToString()).ToList();

                    decimal total = (categoryItem.Sum(t => t.ValorStockPVP) - categoryItem.Sum(t => t.Desconto)) + categoryItem.Sum(t => t.ImpostoLiquido);
                    if (total > 0 && SubCategoryID <= 0)
                    {
                        tableColumns += "<tr style='font-size:10px'><td style='text-align: left; background-color:yellow'>&nbsp" + category.Codigo + " - " + category.Descricao.ToUpper() + "</td>" +
                                        "<td style='text-align: center; background-color:yellow'>&nbsp" + String.Format("{0:N2}", categoryItem.Sum(t => t.Quantidade)) + "</td>" +
                                        "<td style='text-align: right; background-color:yellow'>&nbsp" + String.Format("{0:N2}", categoryItem.Sum(t => t.PrecoCusto)) + "</td>" +
                                        "<td style='text-align: right; background-color:yellow'>" + String.Format("{0:N2}", categoryItem.Sum(t => t.PrecoVenda)) + "</td>" +
                                        "<td style='text-align: right; background-color:yellow'>" + String.Format("{0:N2}", categoryItem.Sum(t => t.ValorStockPVP)) + "</td>" +
                                        "<td style='text-align: right; background-color:yellow'>" + String.Format("{0:N2}", categoryItem.Sum(t => t.Desconto)) + "</td>" +
                                        "<td style='text-align: right; background-color:yellow'>" + String.Format("{0:N2}", categoryItem.Sum(t => t.ImpostoLiquido)) + "</td>" +
                                        "<td style='text-align: right; background-color:yellow'>" + String.Format("{0:N2}", total) + "</td>" +
                                        "<td style='text-align: right; background-color:yellow'>" + String.Format("{0:N2}", categoryItem.Sum(t => t.PrevisaoLucro)) + "</td></tr>";

                        if (dto.LookupField1 != null && dto.LookupField1 != "")
                        {
                            string prodID = string.Empty;
                            foreach (var item in categoryItem.ToList())
                            {
                                if (prodID != item.Designacao)
                                {
                                    var product = categoryItem.Where(t => t.Designacao == item.Designacao).ToList();
                                    tableColumns += "<tr style='font-size:10px'><td style='text-align: left'>&nbsp" + item.Designacao.ToUpper() + "</td>" +
                                                    "<td style='text-align: center'>&nbsp" + String.Format("{0:N2}", product.Sum(t => t.Quantidade)) + "</td>" +
                                                    "<td style='text-align: right'>&nbsp" + String.Format("{0:N2}", product.Sum(t => t.PrecoCusto)) + "</td>" +
                                                    "<td style='text-align: right'>" + String.Format("{0:N2}", product.Sum(t => t.PrecoVenda)) + "</td>" +
                                                    "<td style='text-align: right'>" + String.Format("{0:N2}", product.Sum(t => t.ValorStockPVP)) + "</td>" +
                                                    "<td style='text-align: right'>" + String.Format("{0:N2}", product.Sum(t => t.Desconto)) + "</td>" +
                                                    "<td style='text-align: right'>" + String.Format("{0:N2}", product.Sum(t => t.ImpostoLiquido)) + "</td>" +
                                                    "<td style='text-align: right'>" + String.Format("{0:N2}", product.Sum(t => t.ValorLiquido)) + "</td>" +
                                                    "<td style='text-align: right'>" + String.Format("{0:N2}", product.Sum(t => t.PrevisaoLucro)) + "</td></tr>";
                                    prodID = item.Designacao;
                                }
                            }
                        }
                    }

                    var SubCategoryList = SubCategoryID > 0 ? productList.Where(t => t.Categoria == SubCategoryID.ToString()).ToList() : productList.Where(t => t.SubCategoria == category.Codigo.ToString()).ToList();
                    int id = 0;
                    if (SubCategoryList.Count > 0)
                    {
                        foreach (var subCategoryItem in SubCategoryList.ToList())
                        {
                            id = int.Parse(subCategoryItem.Categoria);

                            var SubCategoryLine = SubCategoryList.Where(t => t.Categoria == id.ToString()).ToList();
                            if (SubCategoryLine.Count > 0)
                            {
                                decimal totalLiquido = (SubCategoryLine.Sum(t => t.ValorStockPVP) - SubCategoryLine.Sum(t => t.Desconto)) + SubCategoryLine.Sum(t => t.ImpostoLiquido);
                                tableColumns += "<tr style='font-size:10px'><td style='text-align: left ; background-color:yellow'>&nbsp" + subCategoryItem.Categoria + " - " + subCategoryItem.CurtaDescricao.ToUpper() + "</td>" +
                                                "<td style='text-align: center; background-color:yellow'>&nbsp" + String.Format("{0:N2}", SubCategoryLine.Sum(t => t.Quantidade)) + "</td>" +
                                                "<td style='text-align: right; background-color:yellow'>&nbsp" + String.Format("{0:N2}", SubCategoryLine.Sum(t => t.PrecoCusto)) + "</td>" +
                                                "<td style='text-align: right; background-color:yellow'>" + String.Format("{0:N2}", SubCategoryLine.Sum(t => t.PrecoVenda)) + "</td>" +
                                                "<td style='text-align: right; background-color:yellow'>" + String.Format("{0:N2}", SubCategoryLine.Sum(t => t.ValorStockPVP)) + "</td>" +
                                                "<td style='text-align: right; background-color:yellow'>" + String.Format("{0:N2}", SubCategoryLine.Sum(t => t.Desconto)) + "</td>" +
                                                "<td style='text-align: right; background-color:yellow'>" + String.Format("{0:N2}", SubCategoryLine.Sum(t => t.ImpostoLiquido)) + "</td>" +
                                                "<td style='text-align: right; background-color:yellow'>" + String.Format("{0:N2}", totalLiquido) + "</td>" +
                                                "<td style='text-align: right; background-color:yellow'>" + String.Format("{0:N2}", SubCategoryLine.Sum(t => t.PrevisaoLucro)) + "</td></tr>";
                            }
                            if (dto.LookupField1 != null && dto.LookupField1 != "")
                            {
                                string prodID = string.Empty;
                                foreach (var item in SubCategoryLine)
                                {
                                    if (prodID != item.Designacao)
                                    {
                                        var product = SubCategoryList.Where(t => t.Designacao == item.Designacao).ToList();
                                        tableColumns += "<tr style='font-size:10px'><td style='text-align: left'>&nbsp" + item.Designacao.ToUpper() + "</td>" +
                                                        "<td style='text-align: center'>&nbsp" + String.Format("{0:N2}", product.Sum(t => t.Quantidade)) + "</td>" +
                                                        "<td style='text-align: right'>&nbsp" + String.Format("{0:N2}", product.Sum(t => t.PrecoCusto)) + "</td>" +
                                                        "<td style='text-align: right'>" + String.Format("{0:N2}", product.Sum(t => t.PrecoVenda)) + "</td>" +
                                                        "<td style='text-align: right'>" + String.Format("{0:N2}", product.Sum(t => t.ValorStockPVP)) + "</td>" +
                                                        "<td style='text-align: right'>" + String.Format("{0:N2}", product.Sum(t => t.Desconto)) + "</td>" +
                                                        "<td style='text-align: right'>" + String.Format("{0:N2}", product.Sum(t => t.ImpostoLiquido)) + "</td>" +
                                                        "<td style='text-align: right'>" + String.Format("{0:N2}", product.Sum(t => t.ValorLiquido)) + "</td>" +
                                                        "<td style='text-align: right'>" + String.Format("{0:N2}", product.Sum(t => t.PrevisaoLucro)) + "</td></tr>";
                                        prodID = item.Designacao;
                                    }
                                }
                            }
                            SubCategoryList = SubCategoryList.Where(t => t.Categoria != id.ToString()).ToList();
                        }
                    }
                    else
                    {
                        /*
                         * if (dto.LookupField1 != null && dto.LookupField1 != "")
                         * {
                         *  string prodID = string.Empty;
                         *  foreach (var item in ProductCategoryList.ToList())
                         *  {
                         *      if (prodID != item.Designacao)
                         *      {
                         *          var product = ProductCategoryList.Where(t => t.Designacao == item.Designacao).ToList();
                         *          tableColumns += "<tr style='font-size:10px'><td style='text-align: left'>&nbsp" + item.Designacao.ToUpper() + "</td>" +
                         *          "<td style='text-align: center'>&nbsp" + String.Format("{0:N2}", product.Sum(t => t.Quantidade)) + "</td>" +
                         *          "<td style='text-align: right'>&nbsp" + String.Format("{0:N2}", product.Sum(t => t.PrecoCusto)) + "</td>" +
                         *          "<td style='text-align: right'>" + String.Format("{0:N2}", product.Sum(t => t.PrecoVenda)) + "</td>" +
                         *          "<td style='text-align: right'>" + String.Format("{0:N2}", product.Sum(t => t.ValorStockPVP)) + "</td>" +
                         *          "<td style='text-align: right'>" + String.Format("{0:N2}", product.Sum(t => t.Desconto)) + "</td>" +
                         *          "<td style='text-align: right'>" + String.Format("{0:N2}", product.Sum(t => t.ImpostoLiquido)) + "</td>" +
                         *          "<td style='text-align: right'>" + String.Format("{0:N2}", product.Sum(t => t.ValorLiquido)) + "</td>" +
                         *          "<td style='text-align: right'>" + String.Format("{0:N2}", product.Sum(t => t.PrevisaoLucro)) + "</td></tr>";
                         *          prodID = item.Designacao;
                         *      }
                         *  }
                         * }*/
                    }

                    tableColumns += "<tr style='background-color: #AFEEEE; font-size: 10px'>" +
                                    "<th style='text-align:right'>TOTAL EM " + category.Descricao.ToUpper() + "</th>" +
                                    " <th style = 'text-align: center' > " + String.Format("{0:N2}", ProductCategoryList.Sum(t => t.Quantidade)) + "</th>" +
                                    " <th style = 'text-align: right' > " + String.Format("{0:N2}", ProductCategoryList.Sum(t => t.PrecoCusto)) + "</th>" +
                                    " <th style = 'text-align: right' > " + String.Format("{0:N2}", ProductCategoryList.Sum(t => t.PrecoVenda)) + "</th>" +
                                    " <th style = 'text-align: right' > " + String.Format("{0:N2}", ProductCategoryList.Sum(t => t.ValorStockPVP)) + "</th>" +
                                    " <th style = 'text-align: right' > " + String.Format("{0:N2}", ProductCategoryList.Sum(t => t.Desconto)) + "</th>" +
                                    " <th style = 'text-align: right' > " + String.Format("{0:N2}", ProductCategoryList.Sum(t => t.ImpostoLiquido)) + "</th>" +
                                    " <th style = 'text-align: right' > " + String.Format("{0:N2}", totalCategoryBilling) + "</th>" +
                                    " <th style = 'text-align: right' > " + String.Format("{0:N2}", ProductCategoryList.Sum(t => t.PrevisaoLucro)) + "</th>" +
                                    "</tr>";
                }
            }

            if (CategoryID <= 0)
            {
                tableColumns += "<tr style='background-color: silver; font-size: 10px'>" +
                                "<th style='text-align:right'>TOTAL GERAL</th>" +
                                " <th style = 'text-align: center'> " + String.Format("{0:N2}", productList.Sum(t => t.Quantidade)) + "</th>" +
                                " <th style = 'text-align: right'> " + String.Format("{0:N2}", productList.Sum(t => t.PrecoCusto)) + "</th>" +
                                " <th style = 'text-align: right'> " + String.Format("{0:N2}", productList.Sum(t => t.PrecoVenda)) + "</th>" +
                                " <th style = 'text-align: right'> " + String.Format("{0:N2}", productList.Sum(t => t.ValorStockPVP)) + "</th>" +
                                " <th style = 'text-align: right'> " + String.Format("{0:N2}", productList.Sum(t => t.Desconto)) + "</th>" +
                                " <th style = 'text-align: right'> " + String.Format("{0:N2}", productList.Sum(t => t.ImpostoLiquido)) + "</th>" +
                                " <th style = 'text-align: right'> " + String.Format("{0:N2}", ((productList.Sum(t => t.ValorStockPVP) - productList.Sum(t => t.Desconto)) + productList.Sum(t => t.ImpostoLiquido))) + "</th>" +
                                " <th style = 'text-align: right'> " + String.Format("{0:N2}", productList.Sum(t => t.PrevisaoLucro)) + "</th>" +
                                "</tr>";
            }

            return(tableColumns);
        }