Ejemplo n.º 1
0
 void FComissaoLimiarLoad(object sender, EventArgs e)
 {
     comissao    = new cComissaoLimiar();
     this.Cursor = Cursors.WaitCursor;
     comissao.Carrega(fornecedor, caracteristica, dgvCadastro);
     this.Cursor = Cursors.Default;
 }
Ejemplo n.º 2
0
        void DgvCadastroRowEnter(object sender, DataGridViewCellEventArgs e)
        {
            edtResumo.Text         = dgvCadastro.Rows[e.RowIndex].Cells["Resumo"].Value.ToString();
            edtUsuario.Text        = dgvCadastro.Rows[e.RowIndex].Cells["Usuário"].Value.ToString();
            dtpData.Value          = DateTime.Parse(dgvCadastro.Rows[e.RowIndex].Cells["Data"].Value.ToString());
            edtObservacao.Text     = dgvCadastro.Rows[e.RowIndex].Cells["Observação"].Value.ToString();
            edtTabela.Text         = dgvCadastro.Rows[e.RowIndex].Cells["Tabela"].Value.ToString();
            edtCaracteristica.Text = dgvCadastro.Rows[e.RowIndex].Cells["Característica"].Value.ToString();
            fornecedor             = dgvCadastro.Rows[e.RowIndex].Cells["Fornecedor"].Value.ToString();
            cliente   = dgvCadastro.Rows[e.RowIndex].Cells["Cliente"].Value.ToString();
            consultor = dgvCadastro.Rows[e.RowIndex].Cells["Consultor"].Value.ToString();
            DateTime data   = DateTime.Parse(dgvCadastro.Rows[e.RowIndex].Cells["Data"].Value.ToString());
            short    codigo = Globais.StrToShort(dgvCadastro.Rows[e.RowIndex].Cells["Cod"].Value.ToString());

            CarregaAnexos(fornecedor, data, codigo);


            // seta a comissao de acordo com o limiar da caracteristica
            if ((dgvCadastro.Rows[e.RowIndex].Cells["Fornecedor"].Value != null) &&
                (dgvCadastro.Rows[e.RowIndex].Cells["Característica"].Value != null))
            {
                float           vlr_itens      = Globais.StrToFloat(dgvCadastro.Rows[e.RowIndex].Cells["Valor Itens"].Value.ToString());
                float           vlr_desconto   = Globais.StrToFloat(dgvCadastro.Rows[e.RowIndex].Cells["Desconto"].Value.ToString());
                float           per_consultor  = Globais.StrToFloat(dgvCadastro.Rows[e.RowIndex].Cells["Comissão Consultor"].Value.ToString());
                string          caracteristica = dgvCadastro.Rows[e.RowIndex].Cells["Característica"].Value.ToString().Trim();
                float           limiar         = Globais.StrToFloat(dgvCadastro.Rows[e.RowIndex].Cells["Limiar"].Value.ToString());
                float           sinal          = orcamento.CalculaSinal(fornecedor, caracteristica, vlr_itens, vlr_desconto, per_consultor, limiar);
                cComissaoLimiar comissao       = new cComissaoLimiar();
                float           vlr_orcamento  = vlr_itens - vlr_desconto;
                float           per_comissao   = comissao.Calcula(fornecedor, caracteristica, vlr_orcamento, sinal);
                edtPerComissao.Text = per_comissao.ToString("#0.00");
                edtVlrComissao.Text = (per_comissao * vlr_orcamento / 100f).ToString("###,##0.00");
            }
        }
Ejemplo n.º 3
0
        /*
         * private void calcula_itens(string fornecedor, DateTime data, short orcamento, string formula, float per_calculo, ref float per_recalculo)
         * {
         *      FbCommand cmd =  new FbCommand("select " +
         *                           "       a.seq_item, " +
         *                           "       a.qtd_item, " +
         *                           "       a.idt_especial, " +
         *                           "       a.vlr_preco, " +
         *                           "       b.per_ipi " +
         *                           "from ITENS a, PRODUTOS b " +
         *                           "where a.cod_fornecedor='" + fornecedor + "' and " +
         *                               "      a.dat_orcamento='" + data.ToString("M/d/yyyy") + "' and " +
         *                               "      a.cod_orcamento=" + orcamento + " and " +
         *                                       "      a.cod_fornecedor=b.cod_parceiro and " +
         *                                       "      a.cod_produto=b.cod_produto and " +
         *                                       "      a.sub_codigo=b.sub_codigo " +
         *                               "      order by a.seq_item",
         *                               Globais.bd);
         *      float valor_recalculo = 0;
         *      FbDataReader reader = cmd.ExecuteReader(CommandBehavior.Default);
         *      while (reader.Read())
         *      {
         *              short seq = (short)(!reader.IsDBNull(0) ? (int)reader.GetInt16(0) : 0);
         *              short qtd = (short)(!reader.IsDBNull(1) ? (int)reader.GetInt16(1) : 0);
         *              string especial = (reader.IsDBNull(2) ? reader.GetString(2) : "");
         *              float valor = (!reader.IsDBNull(3) ? (int)reader.GetFloat(3) : 0f);
         *              float ipi = (!reader.IsDBNull(4) ? (int)reader.GetFloat(4) : 0f);
         *              valor_recalculo = valor;
         *              Globais.CalculaFormula(ref valor_recalculo, formula, 0);
         *              per_recalculo = valor_recalculo * per_calculo / valor;
         *      }
         *      reader.Close();
         * }
         */

        void calcula()
        {
            cComissaoLimiar comissao_limiar = new cComissaoLimiar();
            float           tot_pedido      = 0;
            float           tot_valor       = 0;
            float           tot_calculo     = 0;
            float           tot_recalculo   = 0;
            float           tot_pago        = 0;
            float           tot_comissao    = 0;
            float           valor_pago      = 0;
            float           valor_pagar     = 0;
            int             n = 0;

            if (rbtVendedor.Checked || rbtFilial.Checked)
            {
                dgvCadastro.Columns["Vendedor"].HeaderText = "Vendedor";
            }
            else
            {
                dgvCadastro.Columns["Vendedor"].HeaderText = "Consultor";
            }
            dgvCadastro.Rows.Clear();
            cCaracteristicas carac = new cCaracteristicas();
            int isel = 0;

            foreach (DataGridViewRow sel in dgvSelecao.Rows)
            {
                if (!(bool)sel.Cells["S"].Value)
                {
                    isel++;
                    continue;
                }

                int             i   = dgvCadastro.Rows.Add();
                DataGridViewRow row = dgvCadastro.Rows[i];
                row.Cells["isel"].Value = isel;
                DateTime data      = DateTime.Parse(sel.Cells["Data"].Value.ToString());
                short    orcamento = CodOrcamento(sel.Cells["Orçamento"].Value.ToString());

                float  valor = Globais.StrToFloat(sel.Cells["Valor"].Value.ToString());
                string fornecedor = sel.Cells["Fornecedor Orçamento"].Value.ToString();
                string caracteristica = sel.Cells["Característica"].Value.ToString();
                string venpro = "", venser = "", conpro = "", conser = "", filpro = "", filser = "";
                carac.FormulasComissao(fornecedor, caracteristica, ref venpro, ref venser, ref conpro, ref conser, ref filpro, ref filser);
                float sinal      = Globais.StrToFloat(sel.Cells["Sinal"].Value.ToString());
                int   cod_pedido = Globais.StrToInt(sel.Cells["CodPedido"].Value.ToString());

                float vlr_frete      = Globais.StrToFloat(sel.Cells["Valor Frete"].Value.ToString());
                float vlr_frete_item = 0;
                float per_frete      = 0;
                if (vlr_frete > 0)
                {
                    vlr_frete_item = cPedidos.RateiaFrete(fornecedor, data, orcamento, (short)cod_pedido, ref vlr_frete);
                }
                else
                {
                    per_frete = cCaracteristicas.Frete(fornecedor, caracteristica);
                }

                float  per_pago = 0;
                bool   pago     = false;
                string formula  = "";
                if (rbtVendedor.Checked)
                {
                    pago     = sel.Cells["IdtVendedor"].Value.ToString().Equals("S");
                    per_pago = Globais.StrToFloat(sel.Cells["PerVendedor"].Value.ToString());
                    row.Cells["Justificativa"].Value = sel.Cells["JusVendedor"].Value.ToString();
                    if (cod_pedido == 1)
                    {
                        formula = venpro;
                    }
                    else
                    {
                        formula = venser;
                    }
                }
                if (rbtConsultor.Checked)
                {
                    pago     = sel.Cells["IdtConsultor"].Value.ToString().Equals("S");
                    per_pago = Globais.StrToFloat(sel.Cells["PerConsultor"].Value.ToString());
                    row.Cells["Justificativa"].Value = sel.Cells["JusConsultor"].Value.ToString();
                    if (cod_pedido == 1)
                    {
                        formula = conpro;
                    }
                    else
                    {
                        formula = conser;
                    }
                }
                if (rbtFilial.Checked)
                {
                    pago     = sel.Cells["IdtFilial"].Value.ToString().Equals("S");
                    per_pago = Globais.StrToFloat(sel.Cells["PerFilial"].Value.ToString());
                    row.Cells["Justificativa"].Value = sel.Cells["JusFilial"].Value.ToString();
                    if (cod_pedido == 1)
                    {
                        formula = venpro;
                    }
                    else
                    {
                        formula = venser;
                    }
                }
                float valor_pedido = valor;
                Globais.CalculaFormula(ref valor, formula, 0, per_frete, vlr_frete_item);
                isel++;
                float per_calculo = 0;
                if (rbtConsultor.Checked)
                {
                    per_calculo = Globais.StrToFloat(sel.Cells["Comissão Consultor"].Value.ToString());
                }
                else
                if (rbtFilial.Checked)
                {
                    if (cod_pedido == 1)
                    {
                        per_calculo = Globais.StrToFloat(sel.Cells["Comissão Filial"].Value.ToString());
                    }
                    else
                    {
                        per_calculo = 100;
                    }
                }
                else
                {
                    per_calculo = comissao_limiar.Calcula(fornecedor, caracteristica, valor, sinal);
                }
                row.Cells["PG"].Value = pago;
                float valor_recalculo = valor;
                float per_recalculo   = per_calculo;
                if (formula.Length > 0)
                {
                    //calcula_itens(fornecedor, data, orcamento, formula, per_calculo, ref per_recalculo);
                }
                //if ((per_pago == 0) && !pago_zerado)
                if ((per_pago == 0) && !pago)
                {
                    per_pago = per_calculo;
                }
                float comissao = per_pago * valor / 100f;
                bool  pg       = row.Cells["PG"].Value != null?bool.Parse(row.Cells["PG"].Value.ToString()) : false;

                tot_pedido    += valor_pedido;
                tot_valor     += valor;
                tot_calculo   += per_calculo;
                tot_recalculo += per_recalculo;
                tot_pago      += per_pago;
                tot_comissao  += comissao;
                if (!pg)
                {
                    valor_pagar += comissao;
                }
                else
                {
                    valor_pago += comissao;
                }
                n++;
                row.Cells["Fornecedor"].Value          = sel.Cells["Fornecedor"].Value.ToString();
                row.Cells["FornecedorOrcamento"].Value = sel.Cells["Fornecedor Orçamento"].Value.ToString();
                row.Cells["Data"].Value      = DateTime.Parse(sel.Cells["Data"].Value.ToString()).ToString("d/M/yyyy");
                row.Cells["Orcamento"].Value = sel.Cells["Orçamento"].Value.ToString();
                row.Cells["Pedido"].Value    = sel.Cells["Ped"].Value.ToString();
                row.Cells["CodPedido"].Value = sel.Cells["CodPedido"].Value.ToString();
                row.Cells["Cliente"].Value   = sel.Cells["Cliente"].Value.ToString();
                if (rbtVendedor.Checked || rbtFilial.Checked)
                {
                    row.Cells["Vendedor"].Value = sel.Cells["Vendedor"].Value.ToString();
                }
                else
                {
                    row.Cells["Vendedor"].Value = sel.Cells["Consultor"].Value.ToString();
                }
                row.Cells["ValorPedido"].Value = valor_pedido.ToString("#,###,##0.00");
                row.Cells["Valor"].Value       = valor.ToString("#,###,##0.00");

                row.Cells["Calculo"].Value = per_calculo.ToString("#0.00");
                //row.Cells["Recalculo"].Value = per_recalculo.ToString("#0.00");
                row.Cells["Pago"].Value     = per_pago.ToString("#0.00");
                row.Cells["Comissao"].Value = comissao.ToString("#,###,##0.00");

                if (rbtVendedor.Checked)
                {
                    edtJustificativa.Text = sel.Cells["JusVendedor"].Value.ToString();
                }
                if (rbtConsultor.Checked)
                {
                    edtJustificativa.Text = sel.Cells["JusConsultor"].Value.ToString();
                }
                if (rbtFilial.Checked)
                {
                    edtJustificativa.Text = sel.Cells["JusFilial"].Value.ToString();
                }
            }
            edtTotPedido.Text = tot_pedido.ToString("#,###,##0.00");
            edtTotValor.Text  = tot_valor.ToString("#,###,##0.00");
            if (n > 0)
            {
                edtTotCalculo.Text = (tot_calculo / n).ToString("#0.00");
                //edtTotRecalculo.Text= (tot_recalculo / n).ToString("#0.00");
                edtTotPago.Text = (tot_pago / n).ToString("#0.00");
            }
            else
            {
                edtTotCalculo.Text = 0.ToString("#0.00");
                //edtTotRecalculo.Text= (tot_recalculo / n).ToString("#0.00");
                edtTotPago.Text = 0.ToString("#0.00");
            }
            edtTotComissao.Text = tot_comissao.ToString("#,###,##0.00");
            edtValorPago.Text   = valor_pago.ToString("#,###,##0.00");
            edtValorPagar.Text  = valor_pagar.ToString("#,###,##0.00");
        }
Ejemplo n.º 4
0
        public bool Gera(char tipo, string arquivo, string titulo, bool idt_inicial, DateTime data_inicial, bool idt_final, DateTime data_final, bool pagos, bool abertos)
        {
            FluxoCaixa fluxo = new FluxoCaixa();

            /*
             * PDF pdf = new PDF(arquivo);
             * pdf.Abre();
             * fluxo.Parte1(pdf, titulo, idt_inicial, data_inicial, idt_final, data_final);
             */

            FileStream fs     = new FileStream(arquivo, FileMode.Create);
            Document   doc    = new Document(PageSize.LETTER.Rotate());
            PdfWriter  writer = PdfWriter.GetInstance(doc, fs);

            doc.Open();
            PdfContentByte buf = writer.DirectContent;

            string periodo = "";

            if (idt_inicial || idt_final)
            {
                periodo = "Período: ";
                if (idt_inicial && idt_final)
                {
                    periodo += "de " + data_inicial.ToString("dd/MM/yyyy") + " até " + data_final.ToString("dd/MM/yyyy");
                }
                else
                {
                    if (idt_inicial)
                    {
                        periodo += "a partir de " + data_inicial.ToString("dd/MM/yyyy");
                    }
                    else
                    {
                        periodo += "até " + data_final.ToString("dd/MM/yyyy");
                    }
                }
            }

            if (pagos && !abertos)
            {
                Graficos.Cabecalho(doc, titulo + "- Pagos", periodo);
            }
            else
            if (!pagos && abertos)
            {
                Graficos.Cabecalho(doc, titulo + "- Abertos", periodo);
            }
            else
            {
                Graficos.Cabecalho(doc, titulo, periodo);
            }


            string where;
            string where2 = "";
            string col_cod;
            string col_per;

            if (tipo == 'v')
            {
                col_cod = "O.COD_VENDEDOR";
                col_per = "P.PER_VENDEDOR";
                if (pagos && abertos)
                {
                    where = "where P.DAT_PEDIDO is not null ";
                }
                else
                if (pagos)
                {
                    where = "where P.IDT_VENDEDOR = 'S' and P.DAT_PEDIDO is not null ";
                }
                else
                {
                    where = "where P.IDT_VENDEDOR <> 'S' and P.DAT_PEDIDO is not null ";
                }
            }
            else
            if (tipo == 'c')
            {
                col_cod = "O.COD_CONSULTOR";
                col_per = "P.PER_CONSULTOR";
                if (pagos && abertos)
                {
                    where = "where P.DAT_PEDIDO is not null ";
                }
                else
                if (pagos)
                {
                    where = "where P.IDT_CONSULTOR = 'S' and P.DAT_PEDIDO is not null ";
                }
                else
                {
                    where = "where P.IDT_CONSULTOR <> 'S' and P.DAT_PEDIDO is not null ";
                }
            }
            else
            {
                col_cod = "P.COD_FORNECEDOR";
                col_per = "0";
                where   = "where P.COD_PEDIDO = '1' and P.DAT_PEDIDO is not null ";
                where2  = "where P.COD_PEDIDO = '2' and P.DAT_PEDIDO is not null ";
            }
            if (idt_inicial || idt_final)
            {
                if (idt_inicial && idt_final)
                {
                    where  += "and (P.DAT_PEDIDO between '" + data_inicial.ToString("M/d/yyyy") + "' and '" + data_final.ToString("M/d/yyyy") + "') ";
                    where2 += "and (P.DAT_PEDIDO between '" + data_inicial.ToString("M/d/yyyy") + "' and '" + data_final.ToString("M/d/yyyy") + "') ";
                }
                else
                {
                    if (idt_inicial)
                    {
                        where  += "and (P.DAT_PEDIDO >= '" + data_inicial.ToString("M/d/yyyy") + "') ";
                        where2 += "and (P.DAT_PEDIDO >= '" + data_inicial.ToString("M/d/yyyy") + "') ";
                    }
                    else
                    {
                        where  += "and (P.DAT_PEDIDO <= '" + data_final.ToString("M/d/yyyy") + "') ";
                        where2 += "and (P.DAT_PEDIDO <= '" + data_final.ToString("M/d/yyyy") + "') ";
                    }
                }
            }
            string sql =
                "select " +
                col_cod + "," +
                "P.VLR_PEDIDO," +
                col_per + "," +
                "O.PER_CONSULTOR as PER_CONSULTOR_ORC," +
                "O.VLR_ORCAMENTO," +
                "O.VLR_DESCONTO," +
                "O.COD_CARACTERISTICA," +
                "C.PER_LIMIAR," +
                "C.PER_FILIAL," +
                "O.COD_FORNECEDOR," +
                "P.VLR_FRETE," +
                "C.PER_FRETE," +
                "P.DAT_ORCAMENTO," +
                "P.COD_ORCAMENTO," +
                "P.COD_PEDIDO " +
                "from PEDIDOS P " +
                "inner join ORCAMENTOS O " +
                "on O.COD_FORNECEDOR=P.COD_FORNECEDOR and O.DAT_ORCAMENTO=P.DAT_ORCAMENTO and O.COD_ORCAMENTO=P.COD_ORCAMENTO " +
                "inner join CARACTERISTICAS C " +
                "on C.COD_FORNECEDOR=O.COD_FORNECEDOR and C.COD_CARACTERISTICA=O.COD_CARACTERISTICA " +
                where;

            if (tipo == 'f')
            {
                sql = sql +
                      "union " +
                      "select " +
                      "'SERVICO-' || P.COD_FORNECEDOR," +
                      "P.VLR_PEDIDO," +
                      col_per + "," +
                      "O.PER_CONSULTOR as PER_CONSULTOR_ORC, " +
                      "O.VLR_ORCAMENTO," +
                      "O.VLR_DESCONTO," +
                      "O.COD_CARACTERISTICA," +
                      "C.PER_LIMIAR," +
                      "C.PER_FILIAL," +
                      "O.COD_FORNECEDOR," +
                      "P.VLR_FRETE," +
                      "C.PER_FRETE," +
                      "P.DAT_ORCAMENTO," +
                      "P.COD_ORCAMENTO," +
                      "P.COD_PEDIDO " +
                      "from PEDIDOS P " +
                      "inner join ORCAMENTOS O " +
                      "on O.COD_FORNECEDOR=P.COD_FORNECEDOR and O.DAT_ORCAMENTO=P.DAT_ORCAMENTO and O.COD_ORCAMENTO=P.COD_ORCAMENTO " +
                      "inner join CARACTERISTICAS C " +
                      "on C.COD_FORNECEDOR=O.COD_FORNECEDOR and C.COD_CARACTERISTICA=O.COD_CARACTERISTICA " +
                      where2;
            }
            sql = sql +
                  "order by 1";
            StreamWriter log = new StreamWriter("gerencial.log");

            log.WriteLine(sql);
            log.Flush();
            FbCommand    cmd    = new FbCommand(sql, Globais.bd);
            FbDataReader reader = cmd.ExecuteReader(CommandBehavior.Default);

            string    codigo;
            float     valor;
            float     percentual;
            string    ultimo     = "";
            float     total      = 0;
            ArrayList valores    = new ArrayList();
            ArrayList descricoes = new ArrayList();

            VendedorConsultor vendedor_consultor = null;
            ArrayList         lista     = new ArrayList();
            cOrcamentos       orcamento = new cOrcamentos();
            cComissaoLimiar   comissao  = new cComissaoLimiar();
            cCaracteristicas  carac     = new cCaracteristicas();

            while (reader.Read())
            {
                codigo     = reader.GetString(0);
                valor      = reader.GetFloat(1);
                percentual = reader.GetFloat(2);

                float  vlr_itens      = reader.GetFloat(4);
                float  vlr_desconto   = reader.GetFloat(5);
                string caracteristica = reader.GetString(6);
                float  limiar         = reader.GetFloat(7);
                string fornecedor     = reader.GetString(9);

                float    vlr_frete      = reader.IsDBNull(10) ? 0 : reader.GetFloat(10);
                float    per_frete      = reader.IsDBNull(11) ? 0 : reader.GetFloat(11);
                DateTime dat_orcamento  = reader.GetDateTime(12);
                short    cod_orcamento  = reader.GetInt16(13);
                short    cod_pedido     = reader.GetInt16(14);
                float    vlr_frete_item = 0;
                if (vlr_frete > 0)
                {
                    vlr_frete_item = cPedidos.RateiaFrete(fornecedor, dat_orcamento, cod_orcamento, cod_pedido, ref vlr_frete);
                }

                string venpro = "", venser = "", conpro = "", conser = "", filpro = "", filser = "";
                carac.FormulasComissao(fornecedor, caracteristica, ref venpro, ref venser, ref conpro, ref conser, ref filpro, ref filser);

                if (percentual == 0)
                {
                    if (tipo == 'v')
                    {
                        if (codigo.StartsWith("SERVICO-"))
                        {
                            //Globais.CalculaFormula(ref valor, venser, 0, per_frete, vlr_frete_item);
                        }
                        else
                        {
                            //Globais.CalculaFormula(ref valor, venpro, 0, per_frete, vlr_frete_item);
                        }
                        percentual = reader.GetFloat(3);                         // consultor
                        float vlr_orcamento = vlr_itens - vlr_desconto;
                        float sinal         = orcamento.CalculaSinal(fornecedor, caracteristica, vlr_itens, vlr_desconto, percentual, limiar);
                        percentual = comissao.Calcula(fornecedor, caracteristica, valor, sinal);
                    }
                    else
                    if (tipo == 'c')
                    {
                        if (codigo.StartsWith("SERVICO-"))
                        {
                            //Globais.CalculaFormula(ref valor, conser, 0, per_frete, vlr_frete_item);
                        }
                        else
                        {
                            //Globais.CalculaFormula(ref valor, conpro, 0, per_frete, vlr_frete_item);
                        }
                        percentual = reader.GetFloat(3);
                    }
                    else
                    {
                        if (codigo.StartsWith("SERVICO-"))
                        {
                            //Globais.CalculaFormula(ref valor, filser, 0, per_frete, vlr_frete_item);
                            percentual = 100;
                        }
                        else
                        {
                            //Globais.CalculaFormula(ref valor, filpro, 0, per_frete, vlr_frete_item);
                            percentual = reader.GetFloat(8);
                        }
                    }
                }
                if (!codigo.Equals(ultimo))
                {
                    if (!ultimo.Equals(""))
                    {
                        lista.Add(vendedor_consultor);
                    }
                    ultimo                        = codigo;
                    vendedor_consultor            = new VendedorConsultor();
                    vendedor_consultor.codigo     = codigo;
                    vendedor_consultor.vendas     = 0;
                    vendedor_consultor.percentual = 0;
                    vendedor_consultor.n          = 0;
                }
                vendedor_consultor.vendas     += valor;
                vendedor_consultor.percentual += percentual;
                if (percentual > 0.01)
                {
                    vendedor_consultor.n++;
                }
                total += valor;
                log.WriteLine(valor.ToString() + " " + total.ToString());
                log.Flush();
            }
            log.Close();
            if (!ultimo.Equals(""))
            {
                lista.Add(vendedor_consultor);
            }
            reader.Close();

            foreach (VendedorConsultor vc in lista)
            {
                valores.Add(vc.vendas);
                descricoes.Add(vc.codigo);
            }

            //if (valores.Count > 12)
            //{
            ArrayList valores12    = new ArrayList();
            ArrayList descricoes12 = new ArrayList();
            int       max          = valores.Count > 12 ? 11 : valores.Count;

            //for (int i=0; i<11; i++)
            for (int i = 0; i < max; i++)
            {
                float maior = -1;
                int   v = 0, imaior = -1;
                foreach (float vlr in valores)
                {
                    if (vlr > maior)
                    {
                        maior  = vlr;
                        imaior = v;
                    }
                    v++;
                }
                float  vmaior = float.Parse(valores[imaior].ToString());
                string dmaior = descricoes[imaior].ToString();
                valores12.Add(vmaior);
                descricoes12.Add(dmaior);
                valores.RemoveAt(imaior);
                descricoes.RemoveAt(imaior);
            }
            if (valores.Count > 12)
            {
                float voutros = 0;
                foreach (float vlr in valores)
                {
                    voutros += vlr;
                }
                valores12.Add(voutros);
                descricoes12.Add("OUTROS");
            }
            Graficos.Pizza(buf, valores12, descricoes12, 200, 250, 120);
            //}
            //else
            //Graficos.Pizza(buf, valores, descricoes, 200, 250, 120);
            doc.NewPage();

            Tabela table = new Tabela(tipo == 'f' ? 3 : 4);

            if (tipo == 'v')
            {
                fluxo.AdicionaCelula(table, "Vendedor", BaseFont.HELVETICA_BOLD, 8, iTextSharp.text.Color.LIGHT_GRAY, 1);
            }
            else
            if (tipo == 'c')
            {
                fluxo.AdicionaCelula(table, "Consultor", BaseFont.HELVETICA_BOLD, 8, iTextSharp.text.Color.LIGHT_GRAY, 1);
            }
            else
            {
                fluxo.AdicionaCelula(table, "Fornecedor", BaseFont.HELVETICA_BOLD, 8, iTextSharp.text.Color.LIGHT_GRAY, 1);
            }
            fluxo.AdicionaCelula(table, "Vendas", BaseFont.HELVETICA_BOLD, 8, iTextSharp.text.Color.LIGHT_GRAY, Element.ALIGN_RIGHT, 1);
            fluxo.AdicionaCelula(table, "% Total", BaseFont.HELVETICA_BOLD, 8, iTextSharp.text.Color.LIGHT_GRAY, Element.ALIGN_RIGHT, 1);
            if (tipo != 'f')
            {
                fluxo.AdicionaCelula(table, "Média Comissão", BaseFont.HELVETICA_BOLD, 8, iTextSharp.text.Color.LIGHT_GRAY, Element.ALIGN_RIGHT, 1);
            }
            foreach (VendedorConsultor vc in lista)
            {
                fluxo.AdicionaCelula(table, vc.codigo, BaseFont.HELVETICA, 8, Element.ALIGN_LEFT, 1);
                fluxo.AdicionaCelula(table, vc.vendas.ToString("#,###,##0.00"), BaseFont.HELVETICA, 8, Element.ALIGN_RIGHT, 1);
                fluxo.AdicionaCelula(table, (vc.vendas * 100 / total).ToString("#,###,##0.00"), BaseFont.HELVETICA, 8, Element.ALIGN_RIGHT, 1);
                if (tipo != 'f')
                {
                    fluxo.AdicionaCelula(table, (vc.percentual / vc.n).ToString("#,###,##0.00"), BaseFont.HELVETICA, 8, Element.ALIGN_RIGHT, 1);
                }
            }

            fluxo.AdicionaCelula(table, "Total", BaseFont.HELVETICA_BOLD, 8, Color.GRAY, 1);
            fluxo.AdicionaCelula(table, total.ToString("#,###,##0.00"), BaseFont.HELVETICA, 8, Color.GRAY, Element.ALIGN_RIGHT, 1);
            fluxo.AdicionaCelula(table, "", BaseFont.HELVETICA_BOLD, 8, Color.GRAY, tipo == 'f' ? 1 : 2);
            doc.Add(table);
            doc.Close();
            return(true);
        }