Ejemplo n.º 1
0
        void CalculaPreco()
        {
            string produto = edtProduto.Text.Trim();
            string subcod  = edtSubCodigo.Text.Trim();
            int    qtde;

            int.TryParse(edtQtde.Text.Trim(), out qtde);
            if ((fornecedor.Length == 0) || (caracteristica.Length == 0) || (produto.Length == 0) || (tabela.Length == 0))
            {
                return;
            }
            if (tabelas == null)
            {
                return;
            }
            preco_tabela   = tabelas.Preco(fornecedor, tabela, produto, subcod);
            preco_unitario = preco_tabela;
            cOrcamentos orcamento = new cOrcamentos();

            per_frete     = cCaracteristicas.Frete(fornecedor, caracteristica);
            preco_formula = preco_unitario;
            Globais.CalculaFormula(ref preco_formula, formula, ipi, per_frete, 0);
            edtPrecoFormula.Text = preco_formula.ToString("#,###,##0.00");
            if (qtde > 0)
            {
                edtPrecoTotal.Text = (Globais.Arredonda(preco_formula) * qtde).ToString("#,###,##0.00");
            }
        }
Ejemplo n.º 2
0
        public MainForm(string[] args)
        {
            InitializeComponent();
            Grid.Inicializa();

            if (args.Length == 2)
            {
                vendedorAcao      = args[0];
                situacaoAcao      = args[1];
                btnInclui.Enabled = false;
                btnExclui.Enabled = false;
                alteracaoRestrita = true;
            }
            else
            {
                if (args.Length > 0)
                {
                    //login = false;
                    Globais.sUsuario       = args[0];
                    Globais.sFilial        = args[1];
                    Globais.bAdministrador = args[2][0] == 'S';
                }
                if (args.Length > 4)
                {
                    // 3 = -clienteacao
                    clienteAcao = args[4];
                }
            }
            //else login = true;
            dgvCadastro.Width = 910;
            orcamento         = new cOrcamentos();
        }
Ejemplo n.º 3
0
        void FrmAnexosOrcamentoLoad(object sender, EventArgs e)
        {
            orcamento = new cOrcamentos();
            string codigo = edtCodigo.Text.Trim();

            orcamento.CarregaAnexos(dgvCadastro, fornecedor, data, cod_orcamento);
            DesabilitaEdicao();
        }
Ejemplo n.º 4
0
        void CalculaValores()
        {
            cOrcamentos orcamentos = new cOrcamentos();
            float       valor      = orcamentos.RecalculaTotal(edtFornecedor.Text, dtpData.Value, Globais.StrToShort(edtCodigo.Text), cbxCaracteristicas.Text.Trim(), "");

            edtValor.Text = valor.ToString("#,###,##0.00");
            float total;

            total         = Globais.StrToFloat(edtValor.Text) - Globais.StrToFloat(edtDesconto.Text);    // - Globais.StrToFloat(edtVlrConsultor.Text);
            edtTotal.Text = total.ToString("#,###,##0.00");
        }
Ejemplo n.º 5
0
        void CbxTabelasSelectedIndexChanged(object sender, EventArgs e)
        {
            if (carregando)
            {
                return;
            }
            cOrcamentos orcamentos = new cOrcamentos();

            if (cbxCaracteristicas.Text.Trim().Length == 0)
            {
                return;
            }
            float valor = orcamentos.RecalculaTotal(edtFornecedor.Text, dtpData.Value, Globais.StrToShort(edtCodigo.Text), cbxCaracteristicas.Text.Trim(), cbxTabelas.Text.Trim());

            edtValor.Text = valor.ToString("#,###,##0.00");
            float total;

            total         = Globais.StrToFloat(edtValor.Text) - Globais.StrToFloat(edtDesconto.Text);    // - Globais.StrToFloat(edtVlrConsultor.Text);
            edtTotal.Text = total.ToString("#,###,##0.00");
        }
Ejemplo n.º 6
0
        void BtnDuplicaClick(object sender, EventArgs e)
        {
            if (dgvCadastro.Rows.Count == 0)
            {
                return;
            }
            fEntradaItem frm = new fEntradaItem();

            frm.Text                    = "Entre com o código da nova área";
            frm.lblItem.Text            = "Nova Área";
            frm.edtItem.CharacterCasing = CharacterCasing.Upper;
            frm.ShowDialog();
            cOrcamentos o = new cOrcamentos();

            o.Duplica(fornecedor, data, cod_orcamento, edtArea.Text.Trim(), frm.edtItem.Text);
            o.CarregaItens(dgvCadastro, fornecedor, data, cod_orcamento, formula, tabela);
            Colore();
            if (dgvCadastro.Rows.Count > 0)
            {
                AtualizaDadosLocal(0);
            }
            Posiciona(edtArea.Text, edtCodigo.Text, edtSubCodigo.Text);
        }
Ejemplo n.º 7
0
        void BtnConfirmaClick(object sender, EventArgs e)
        {
            // verifica se os dados do cliente estão preenchidos
            cParceiro parceiro = new cParceiro();

            string mensagem = "";

            for (;;)
            {
                mensagem = "";
                if (!parceiro.Le(cliente))
                {
                    MessageBox.Show("Cliente não cadastrado");
                    return;
                }

                if (parceiro.NOM_PARCEIRO.Length == 0)
                {
                    mensagem = "NOME não preenchido";
                }

                if (parceiro.NRO_CPF_CNPJ.Length == 0)
                {
                    mensagem = mensagem + "\nCPF/CNPJ não preenchido";
                }

                bool entrega = false;
                if (parceiro.DES_LOGRADOURO_ENTREGA.Length == 0)
                {
                    if (parceiro.DES_LOGRADOURO.Length == 0)
                    {
                        mensagem = mensagem + "\nLOGRADOURO não preenchido";
                    }
                }
                else
                {
                    entrega = true;
                }

                if (!entrega)
                {
                    if (parceiro.NRO_ENDERECO.Length == 0)
                    {
                        mensagem = mensagem + "\nNRO não preenchido";
                    }
                    if (parceiro.NOM_BAIRRO.Length == 0)
                    {
                        mensagem = mensagem + "\nBAIRRO não preenchido";
                    }
                    if (parceiro.NOM_CIDADE.Length == 0)
                    {
                        mensagem = mensagem + "\nCIDADE não preenchido";
                    }
                    if (parceiro.COD_ESTADO.Length == 0)
                    {
                        mensagem = mensagem + "\nESTADO não preenchido";
                    }
                    if (parceiro.NRO_CEP.Length == 0)
                    {
                        mensagem = mensagem + "\nCEP não preenchido";
                    }
                }
                else
                {
                    if (parceiro.NRO_ENDERECO_ENTREGA.Length == 0)
                    {
                        mensagem = mensagem + "\nNRO não preenchido";
                    }
                    if (parceiro.NOM_BAIRRO_ENTREGA.Length == 0)
                    {
                        mensagem = mensagem + "\nBAIRRO não preenchido";
                    }
                    if (parceiro.NOM_CIDADE_ENTREGA.Length == 0)
                    {
                        mensagem = mensagem + "\nCIDADE não preenchida";
                    }
                    if (parceiro.COD_ESTADO_ENTREGA.Length == 0)
                    {
                        mensagem = mensagem + "\nESTADO não preenchido";
                    }
                    if (parceiro.NRO_CEP_ENTREGA.Length == 0)
                    {
                        mensagem = mensagem + "\nCEP não preenchido";
                    }
                }

                if ((parceiro.NRO_FONE1.Length == 0) &&
                    (parceiro.NRO_CELULAR.Length == 0))
                {
                    mensagem = mensagem + "\nFONE não preenchido";
                }

                if (mensagem.Length == 0)
                {
                    break;
                }
                DialogResult r = MessageBox.Show(mensagem, "Atualizar cadastro?",
                                                 MessageBoxButtons.YesNo,
                                                 MessageBoxIcon.Question);
                if (r == DialogResult.No)
                {
                    break;
                }

                cControleAcesso acesso = new cControleAcesso();
                frmCadParceiros frmCad = new frmCadParceiros(true);
                frmCad.where    = "where COD_PARCEIRO='" + cliente + "'";
                frmCad.ReadOnly = !acesso.PermissaoPrograma(Globais.sUsuario, Globais.sFilial, 2, "fCadParceiros");
                frmCad.ShowDialog();
            }
            if (mensagem.Length != 0)
            {
                return;
            }

            cOrcamentos orc   = new cOrcamentos();
            ArrayList   itens = orc.VerificaEspecificos(fornecedor, data, orcamento);

            if (itens.Count > 0)
            {
                mensagem = "Itens sem código específico:";
                foreach (string item in itens)
                {
                    mensagem = mensagem + "\n" + item;
                }
                MessageBox.Show(mensagem, "Erro na consistência");
                return;
            }


            string   msg          = "";
            cPedidos pedidos      = new cPedidos();
            string   cod_condicao = cbxCondicoesPagto.Text.Trim();

            if (cod_condicao.Length > 10)
            {
                cod_condicao = cbxCondicoesPagto.Text.Substring(0, 10).Trim();
            }
            int    nro_pedido = 0;
            string idt_frete  = rbtCliente.Checked ? "C" : "F";

            if (dif > 0)
            {
                result = pedidos.Inclui(fornecedor, data, orcamento, 1, vlr_itens - dif, Globais.sUsuario, DateTime.Now,
                                        dtpEntrega.Value, dtpEntrega.Checked ? "S" : "N",
                                        dtpMontagem.Value, dtpMontagem.Checked ? "S" : "N",
                                        cod_condicao, edtTransportadora.Text, "", idt_frete,
                                        ref nro_pedido, ref msg);
            }
            else
            {
                result = pedidos.Inclui(fornecedor, data, orcamento, 1, vlr_itens - vlr_desconto, Globais.sUsuario, DateTime.Now,
                                        dtpEntrega.Value, dtpEntrega.Checked ? "S" : "N",
                                        dtpMontagem.Value, dtpMontagem.Checked ? "S" : "N",
                                        cod_condicao, edtTransportadora.Text, "", idt_frete,
                                        ref nro_pedido, ref msg);
            }
            if (!result)
            {
                MessageBox.Show("Pedido\n" + msg, "Erro na geração do pedido", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (dif > 0)
            {
                // se as fórmulas forem diferentes gera pedido de serviços para SOFTPLACE
                pedidos.Inclui(fornecedor, data, orcamento, 2, dif - vlr_desconto, Globais.sUsuario, DateTime.Now,
                               dtpEntrega.Value, dtpEntrega.Checked ? "S" : "N",
                               dtpMontagem.Value, dtpMontagem.Checked ? "S" : "N",
                               cod_condicao, edtTransportadora.Text, servico, idt_frete,
                               ref nro_pedido, ref msg);

                if (!result)
                {
                    MessageBox.Show("Serviços\n" + msg, "Erro na geração do pedido", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                MessageBox.Show("Pedidos gerados com sucesso");
            }
            else
            {
                MessageBox.Show("Pedido gerado com sucesso");
            }
            Close();
        }
Ejemplo n.º 8
0
        void FCadItensLoad(object sender, EventArgs e)
        {
            cControleAcesso acesso = new cControleAcesso();

            acessoProdutos = Globais.bAdministrador || acesso.PermissaoPrograma(Globais.sUsuario, Globais.sFilial, 2, "fCadProdutos");
            orcamento      = new cOrcamentos();
            per_frete      = orcamento.Frete(fornecedor, data, cod_orcamento);
            orcamento.CarregaItens(dgvCadastro, fornecedor, data, cod_orcamento, formula, tabela);
            Colore();
            if (pedido)
            {
                foreach (DataGridViewRow row in dgvCadastro.Rows)
                {
                    DataGridViewCell cell;

                    cell = row.Cells["Especial"];
                    if (cell.Value.ToString().Equals("S"))
                    {
                        cell = row.Cells["Preço Unitário"];
                        float preco = Globais.StrToFloat(cell.Value.ToString());
                        // desfaz formula
                        Globais.DesfazFormula(ref preco, formula, ipi, per_frete, 0);

                        /*
                         * float fator=0;
                         * for (int i=formula_orcamento.Trim().Length-4; i>=0; i-=4)
                         * {
                         *      if (formula_orcamento[i] == 'x')
                         *      {
                         *              fator = (Globais.StrToFloat(formula_orcamento.Substring(i+1, 3)) - 1) * 100;
                         *      }
                         *      if (formula_orcamento.Substring(i, 4).CompareTo("+IPI") == 0)
                         *      {
                         *              fator = ipi;
                         *      }
                         *      else
                         *      {
                         *              fator = Globais.StrToFloat(formula_orcamento.Substring(i, 4));
                         *      }
                         *      preco = (preco * 100) / (100 + fator);
                         * }
                         */
                        // refaz parte do pedido
                        Globais.CalculaFormula(ref preco, formula, ipi, per_frete, 0);

                        /*
                         * for (int i=0; i<formula.Trim().Length; i+=4)
                         * {
                         *      if (formula[i] == 'x')
                         *      {
                         *              fator = Globais.StrToFloat(formula.Substring(i+1, 3));
                         *              preco *= fator;
                         *              continue;
                         *      }
                         *      if (formula.Substring(i, 4).CompareTo("+IPI") == 0)
                         *      {
                         *              fator = ipi;
                         *              preco += (preco * fator / (float)100);
                         *      }
                         *      else
                         *      {
                         *              fator = Globais.StrToFloat(formula.Substring(i, 4));
                         *              preco += (preco * fator / (float)100);
                         *      }
                         * }
                         */
                        cell.Value = preco;
                        cell       = row.Cells["Preço"];
                        cell.Value = preco;
                    }
                }
            }

            if (dgvCadastro.Rows.Count > 0)
            {
                AtualizaDadosLocal(0);
            }
            lblOrcamento.Text = "Orçamento: " + fornecedor.Trim() + " - " + data.ToString("d/M/yyyy") + " - " + cod_orcamento +
                                "        Cliente: " + cliente;
            tabelas = new cTabelas();
            DesabilitaEdicao();
            SetaEdicaoLocal(false);
            ultimo_produto   = "";
            ultimo_subcodigo = "";
            col_sorted       = "";
            ord_sorted       = SortOrder.Ascending;
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        private bool Confirma()
        {
            string fornecedor = edtFornecedor.Text.Trim();

            if (fornecedor.CompareTo("") == 0)
            {
                MessageBox.Show("Fornecedor", "Campo obrigatório",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                edtFornecedor.Focus();
                return(false);
            }
            if (cbxUsuarios.Text.Trim().Length == 0)
            {
                MessageBox.Show("Vendedor", "Campo obrigatório",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                cbxUsuarios.Focus();
                return(false);
            }
            if (edtCliente.Text.Trim().Length == 0)
            {
                MessageBox.Show("Cliente", "Campo obrigatório",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                edtCliente.Focus();
                return(false);
            }
            if (cbxTabelas.Text.Trim().Length == 0)
            {
                MessageBox.Show("Tabela Preços", "Campo obrigatório",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                cbxTabelas.Focus();
                return(false);
            }
            if (cbxCaracteristicas.Text.Trim().Length == 0)
            {
                MessageBox.Show("Característica Venda", "Campo obrigatório",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                cbxCaracteristicas.Focus();
                return(false);
            }
            string      msg           = "";
            int         codigo        = 0;
            cOrcamentos orcamentos    = new cOrcamentos();
            float       per_consultor = Globais.StrToFloat(edtPerConsultor.Text);

            if (acao == 'i')
            {
                result         = orcamentos.Inclui(fornecedor, dtpData.Value, cbxUsuarios.Text, edtCliente.Text, edtContato.Text, edtConsultor.Text, cbxTabelas.Text, cbxCaracteristicas.Text, edtResumo.Text, edtObservacao.Text, cbxSituacao.Text.Substring(0, 1), per_consultor, ref msg, ref codigo);
                edtCodigo.Text = codigo.ToString();
            }
            else
            {
                codigo = Globais.StrToInt(edtCodigo.Text);
                result = orcamentos.Altera(fornecedor, dtpData.Value, codigo, cbxUsuarios.Text, edtCliente.Text, edtContato.Text, edtConsultor.Text, cbxTabelas.Text, cbxCaracteristicas.Text, Globais.StrToFloat(edtDesconto.Text), edtResumo.Text, edtObservacao.Text, cbxSituacao.Text.Substring(0, 1), per_consultor, ref msg);
            }
            if (!result)
            {
                if (acao == 'i')
                {
                    MessageBox.Show(edtCodigo.Text + "\n" + msg, "Erro na inclusão do orçamento", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show(edtCodigo.Text + "\n" + msg, "Erro na alteração do orçamento", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            return(result);
        }