예제 #1
0
        public Document relatorioDevolucoes(bool tipo = false, Document doc = null, Paragraph informacao = null, Paragraph titulo = null, Paragraph metodoPagamento = null)
        {
            selecionado = 3;
            string caminho = "";

            if (tipo)
            {
                Document docLimpo = new Document(PageSize.A4);

                //colocando margens no pdf
                docLimpo.SetMargins(40, 40, 40, 80);
                doc = docLimpo;
                string aux = deData.ToString("dd-MM-yyyy") + " - " + ateData.ToString("dd-MM-yyyy");

                caminho = @"C:\pdv\relatorios\devolucoes-" + aux.ToString() + ".pdf";


                PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(caminho, FileMode.Create));

                doc.Open();

                Paragraph tituloLimpo = new Paragraph();
                titulo           = tituloLimpo;
                titulo.Font      = FontFactory.GetFont("Arial", 18);
                titulo.Alignment = Element.ALIGN_CENTER;
                titulo.Add("Devoluções " + deData.ToString("dd/MM/yyyy") + " - " + ateData.ToString("dd/MM/yyyy") + " \n\n");
                doc.Add(titulo);

                Paragraph informacaoLimpo = new Paragraph();
                informacao           = informacaoLimpo;
                informacao.Font      = FontFactory.GetFont("Arial", 12, BaseColor.BLUE);
                informacao.Alignment = Element.ALIGN_LEFT;

                Paragraph metodoPagamentoLimpo = new Paragraph();
                metodoPagamento           = metodoPagamentoLimpo;
                metodoPagamento.Font      = FontFactory.GetFont("Arial", 14);
                metodoPagamento.Alignment = Element.ALIGN_LEFT;
            }
            informacao.Font = FontFactory.GetFont("Arial", 14, BaseColor.RED);

            DadosTableAdapters.Itens_DevolucaoTableAdapter auxDevo       = new DadosTableAdapters.Itens_DevolucaoTableAdapter();
            DadosTableAdapters.ItensDaVendaTableAdapter    auxItensVenda = new DadosTableAdapters.ItensDaVendaTableAdapter();
            var devolucao = auxDevo.retornarDevolucoes(Convert.ToDateTime(deData.ToString("dd/MM/yyyy")), Convert.ToDateTime(ateData.ToString("dd/MM/yyyy")));

            if (devolucao.Count > 0)
            {
                DadosTableAdapters.ProdutoTableAdapter dadosProduto = new DadosTableAdapters.ProdutoTableAdapter();
                PdfPTable table5 = new PdfPTable(4);
                table5.AddCell("Código da devolução");
                table5.AddCell("Código da Venda");
                table5.AddCell("Produto");
                table5.AddCell("Quantidade");

                double totalDevolucao = 0;

                for (int i = 0; i < devolucao.Count; i++)
                {
                    metodoPagamento.Clear();
                    metodoPagamento.Add("\n\nDevoluções\n\n");
                    doc.Add(metodoPagamento);
                    //planejar melhor essa parte de colocar os itens devolvidos no fechamento.
                    table5.AddCell(devolucao[i]["idItensDevolucao"].ToString());

                    table5.AddCell(devolucao[i]["idVenda"].ToString());

                    var produto = dadosProduto.retornarProdutoPorId(Convert.ToInt32(devolucao[i]["idProduto"]));

                    table5.AddCell(produto[0]["prodNome"].ToString());

                    table5.AddCell(devolucao[i]["quantidadeDevolucao"].ToString());


                    totalDevolucao += Convert.ToDouble(devolucao[i]["valorProduto"]);
                }
                doc.Add(table5);
                informacao.Add("\n\nDevoluções: R$-" + totalDevolucao.ToString("F2"));
                doc.Add(informacao);
            }
            if (tipo)
            {
                doc.Close();
                abrirPdf(caminho);
                //MessageBox.Show("Relatório gerado com sucesso!");
            }
            return(doc);
        }