Ejemplo n.º 1
0
        public bool AlteraValor(string parceiro, string tabela, string codigo, string sub_codigo, string valor, ref string msg)
        {
            string sql = "update PRECOS set " +
                         "VLR_PRECO=? " +
                         "where COD_PARCEIRO='" + parceiro + "' and " +
                         "      COD_TABELA='" + tabela + "' and " +
                         "      COD_PRODUTO='" + codigo + "' and " +
                         "      SUB_CODIGO='" + sub_codigo + "'";
            float       f   = Globais.StrToFloat(valor);    // / 1.075f;
            FbCommand   cmd = new FbCommand(sql, Globais.bd);
            FbParameter prm = cmd.Parameters.Add("VLR_PRECO", FbDbType.Decimal);

            prm.Direction = ParameterDirection.Output;
            prm.Value     = f;
            try
            {
                Log.Grava(Globais.sUsuario, cmd.CommandText);
                cmd.ExecuteNonQuery();
            }
            catch (Exception err)
            {
                Log.Grava(Globais.sUsuario, "erro:" + err.Message);
                msg = err.Message;
                return(false);
            }
            msg = "OK";
            return(true);
        }
Ejemplo n.º 2
0
        public static void MostraFormula(ref float valor, string formula, float ipi, float frete, float frete_real, DataTable tab)
        {
            float fator;
            int   len = formula.Trim().Length;

            for (int i = 0; i < len; i += 4)
            {
                int x = 0;
                if (((i + 4) < len) && (formula[i + 4] == ','))
                {
                    x = 3;
                }
                if (formula[i] == 'x')
                {
                    fator  = Globais.StrToFloat(formula.Substring(i + 1, 3 + x));
                    valor *= fator;
                    tab.Rows.Add(new object[] { formula.Substring(i, 4 + x), valor });
                    i += x;
                    continue;
                }
                if (formula.Substring(i, 4).CompareTo("+IPI") == 0)
                {
                    fator  = ipi;
                    valor += (valor * fator / (float)100);
                    tab.Rows.Add(new object[] { "IPI +" + ipi.ToString("#0.##") + "%", valor });
                }
                else
                if (formula.Substring(i, 4).CompareTo("+FRE") == 0)
                {
                    fator  = frete;
                    valor += (valor * fator / (float)100);
                    tab.Rows.Add(new object[] { "FRETE +" + frete.ToString("#0") + "%", valor });
                }
                else
                if (formula.Substring(i, 4).CompareTo("+FRR") == 0)
                {
                    valor += frete_real;
                    tab.Rows.Add(new object[] { "FRETE REAL +" + frete_real.ToString("#,###,##0.00"), valor });
                }
                else
                {
                    fator  = Globais.StrToFloat(formula.Substring(i, 4 + x));
                    valor += (valor * fator / (float)100);
                    tab.Rows.Add(new object[] { formula.Substring(i, 4 + x) + "%", valor });
                }
                i += x;
            }
        }
Ejemplo n.º 3
0
        public static void CalculaFormula(ref float valor, string formula, float ipi, float frete, float frete_real)
        {
            float fator = 0;
            int   len   = formula.Trim().Length;

            for (int i = 0; i < len; i += 4)
            {
                int x = 0;
                if (((i + 4) < len) && (formula[i + 4] == ','))
                {
                    x = 3;
                }
                if (formula[i] == 'x')
                {
                    fator  = Globais.StrToFloat(formula.Substring(i + 1, 3 + x));
                    valor *= fator;
                    i     += x;
                    continue;
                }
                if (formula.Substring(i, 4).CompareTo("+IPI") == 0)
                {
                    fator  = ipi;
                    valor += (valor * fator / (float)100);
                }
                else
                if (formula.Substring(i, 4).CompareTo("+FRE") == 0)
                {
                    fator  = frete;
                    valor += (valor * fator / (float)100);
                }
                else
                if (formula.Substring(i, 4).CompareTo("+FRR") == 0)
                {
                    valor += frete_real;
                }
                else
                {
                    fator  = Globais.StrToFloat(formula.Substring(i, 4 + x));
                    valor += (valor * fator / (float)100);
                }
                i += x;
            }
        }
Ejemplo n.º 4
0
        public static void DesfazFormula(ref float valor, string formula, float ipi, float frete, float frete_real)
        {
            float fator = 0;
            int   len   = formula.Trim().Length;

            for (int i = len - 4; i >= 0; i -= 4)
            {
                int x = 0;
                if (formula[i + 1] == ',')
                {
                    i -= 3;
                    x  = 3;
                }
                if (formula[i] == 'x')
                {
                    fator = (Globais.StrToFloat(formula.Substring(i + 1, 3 + x)) - 1) * 100;
                }
                else
                if (formula.Substring(i, 4).CompareTo("+IPI") == 0)
                {
                    fator = ipi;
                }
                else
                if (formula.Substring(i, 4).CompareTo("+FRE") == 0)
                {
                    fator = frete;
                }
                else
                {
                    fator = Globais.StrToFloat(formula.Substring(i, 4 + x));
                }
                if (formula.Substring(i, 4).CompareTo("+FRR") != 0)
                {
                    valor = (valor * 100) / (100 + fator);
                }
                else
                {
                    valor = valor + frete_real;
                }
            }
        }
Ejemplo n.º 5
0
        public PedidoConsolidado2(string arquivo, string filtro_pedidos, bool por_item, bool por_pedido, bool por_cliente, bool por_fabrica, bool mostrar_valores, bool mostrar_subcodigo, string observacao_fabrica, List <string> pedidosDestacarIpi)
        {
            #region seleciona pedidos
            ArrayList pedidos = new ArrayList();
            string    sql     =
                "select " +
                "p.COD_FORNECEDOR,p.DAT_ORCAMENTO,p.COD_ORCAMENTO,p.COD_PEDIDO,p.NRO_PEDIDO,p.OBSERVACAO,p.VLR_PEDIDO," +
                "o.COD_CLIENTE,o.COD_CARACTERISTICA,o.COD_VENDEDOR,o.VLR_DESCONTO,c.NOM_PARCEIRO, " +
                "f.DES_FORMULA,f.DES_FORMULA_PEDIDO, " +
                "(select 1 from PEDIDOS p2 where p2.COD_FORNECEDOR=p.COD_FORNECEDOR and p2.DAT_ORCAMENTO=p.DAT_ORCAMENTO and p2.COD_ORCAMENTO=p.COD_ORCAMENTO and p2.COD_PEDIDO=2), " +
                "p.VLR_INICIAL " +
                "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 PARCEIROS c on c.COD_PARCEIRO=o.COD_CLIENTE " +
                "inner join CARACTERISTICAS f on f.COD_FORNECEDOR=o.COD_FORNECEDOR and f.COD_CARACTERISTICA=o.COD_CARACTERISTICA " +
                "where " + filtro_pedidos + " " +
                "order by p.COD_FORNECEDOR,p.DAT_ORCAMENTO,p.COD_ORCAMENTO,p.COD_PEDIDO";
            //StreamWriter sw = new StreamWriter(new FileStream("c:\\softplace\\softplace.log", FileMode.Create));
            //sw.WriteLine(sql);
            //sw.Close();

            FbCommand    cmd    = new FbCommand(sql, Globais.bd);
            FbDataReader reader = cmd.ExecuteReader(CommandBehavior.Default);
            if (!por_fabrica)
            {
                por_cliente = true;
            }
            string ultimo_cliente = "";
            while (reader.Read())
            {
                DadosPedido dados = new DadosPedido();
                dados.COD_FORNECEDOR = reader.GetString(0).Trim();
                dados.DAT_ORCAMENTO  = reader.GetDateTime(1);
                dados.COD_ORCAMENTO  = reader.GetInt16(2);
                dados.COD_PEDIDO     = reader.GetInt16(3);
                dados.NRO_PEDIDO     = !reader.IsDBNull(4) ? reader.GetInt16(4) : (short)0;
                //MessageBox.Show("Pedido:" + dados.NRO_PEDIDO.ToString());
                dados.OBSERVACAO         = !reader.IsDBNull(5) ? reader.GetString(5).Trim() : "";
                dados.VLR_PEDIDO         = !reader.IsDBNull(6) ? reader.GetFloat(6) : 0f;
                dados.VLR_INICIAL        = !reader.IsDBNull(15) ? reader.GetFloat(15) : 0f;
                dados.COD_CLIENTE        = !reader.IsDBNull(7) ? reader.GetString(7).Trim() : "";
                dados.COD_CARACTERISTICA = !reader.IsDBNull(8) ? reader.GetString(8).Trim() : "";
                dados.COD_VENDEDOR       = !reader.IsDBNull(9) ? reader.GetString(9).Trim() : "";
                dados.VLR_DESCONTO       = !reader.IsDBNull(10) ? reader.GetFloat(10) : 0f;
                dados.NOM_PARCEIRO       = !reader.IsDBNull(11) ? reader.GetString(11).Trim() : "";
                dados.DES_FORMULA        = !reader.IsDBNull(12) ? reader.GetString(12).Trim() : "";
                dados.DES_FORMULA_PEDIDO = !reader.IsDBNull(13) ? reader.GetString(13).Trim() : "";
                if (dados.DES_FORMULA_PEDIDO.Length == 0)
                {
                    dados.DES_FORMULA_PEDIDO = dados.DES_FORMULA;
                }
                if (!dados.COD_CLIENTE.Equals(ultimo_cliente))
                {
                    if (!ultimo_cliente.Equals(""))
                    {
                        por_cliente = false;
                    }
                    ultimo_cliente = dados.COD_CLIENTE;
                }
                if (dados.COD_PEDIDO == 1)
                {
                    if (!reader.IsDBNull(14))
                    {
                        dados.VLR_DESCONTO = 0;
                    }
                    dados.CarregaItens();
                }
                else
                {
                    DadosItem item = new DadosItem();
                    item.QTD_ITEM    = 1;
                    item.VLR_PRECO   = dados.VLR_PEDIDO;
                    item.COD_PRODUTO = "Serviço";
                    item.SUB_CODIGO  = "-";
                    item.DES_PRODUTO = dados.OBSERVACAO;
                    dados.itens      = new ArrayList();
                    dados.itens.Add(item);
                }
                pedidos.Add(dados);
            }
            reader.Close();
            if (pedidos.Count == 0)
            {
                return;
            }
            #endregion

            #region ordena os itens
            SortedList pedidos_ord = new SortedList();
            string     chave       = "";
            // #   fabrica  pedido   item
            // 0   0        0        0
            // 1   0        0        1
            // 2   0        1        0
            // 3   0        1        1
            // 4   1        0        0
            // 5   1        0        1
            // 6   1        1        0
            // 7   1        1        1
            string   zera_desconto_fornecedor = "";
            DateTime zera_desconto_data       = DateTime.Now;
            short    zera_desconto_orcamento  = 0;
            foreach (DadosPedido pedido in pedidos)
            {
                int i = 0;
                if (pedido.itens != null)
                {
                    foreach (DadosItem item in pedido.itens)
                    {
                        i++;
                        #region seta chave
                        if (por_fabrica)                 // 4 5 6 7
                        {
                            if (por_pedido)              // 6 7
                            {
                                if (por_item)            // 7
                                {
                                    // fabrica + pedido + item
                                    chave = pedido.COD_FORNECEDOR + pedido.DAT_ORCAMENTO.ToString("yyyy/MM/dd") + pedido.COD_ORCAMENTO.ToString("00000") + pedido.COD_PEDIDO.ToString("0") +
                                            item.COD_PRODUTO + item.SUB_CODIGO + item.COD_ESPECIFICOS +
                                            item.SEQ_ITEM;
                                }
                                else                         // 6
                                {
                                    // fabrica + pedido
                                    chave = pedido.COD_FORNECEDOR + pedido.DAT_ORCAMENTO.ToString("yyyy/MM/dd") + pedido.COD_ORCAMENTO.ToString("00000") + pedido.COD_PEDIDO.ToString("0") +
                                            item.SEQ_ITEM;
                                }
                            }
                            else                     // 4 5
                            {
                                if (por_item)        // 5
                                {
                                    // fabrica + item
                                    chave = pedido.COD_FORNECEDOR +
                                            item.COD_PRODUTO + item.SUB_CODIGO + item.COD_ESPECIFICOS +
                                            pedido.COD_FORNECEDOR + pedido.DAT_ORCAMENTO.ToString("yyyy/MM/dd") + pedido.COD_ORCAMENTO.ToString("00000") + pedido.COD_PEDIDO.ToString("0") + item.SEQ_ITEM;
                                }
                                else                         // 4
                                {
                                    // fabrica = fabrica + pedido
                                    chave = pedido.COD_FORNECEDOR + pedido.DAT_ORCAMENTO.ToString("yyyy/MM/dd") + pedido.COD_ORCAMENTO.ToString("00000") + pedido.COD_PEDIDO.ToString("0") +
                                            item.SEQ_ITEM;
                                }
                            }
                        }
                        else                  // 0 1 2 3
                        {
                            if (por_pedido)   // 2 3
                            {
                                if (por_item) // 3
                                {
                                    // pedido + item = fabrica + pedido + item
                                    chave = pedido.COD_FORNECEDOR + pedido.DAT_ORCAMENTO.ToString("yyyy/MM/dd") + pedido.COD_ORCAMENTO.ToString("00000") + pedido.COD_PEDIDO.ToString("0") +
                                            item.COD_PRODUTO + item.SUB_CODIGO + item.COD_ESPECIFICOS +
                                            item.SEQ_ITEM;
                                }
                                else                         // 2
                                {
                                    // pedido = fabrica + pedido
                                    chave = pedido.COD_FORNECEDOR + pedido.DAT_ORCAMENTO.ToString("yyyy/MM/dd") + pedido.COD_ORCAMENTO.ToString("00000") + pedido.COD_PEDIDO.ToString("0") +
                                            item.SEQ_ITEM;
                                }
                            }
                            else                     // 0 1
                            {
                                if (por_item)        // 1
                                {
                                    // por item
                                    chave = item.COD_PRODUTO + item.SUB_CODIGO + item.COD_ESPECIFICOS +
                                            pedido.COD_FORNECEDOR + pedido.DAT_ORCAMENTO.ToString("yyyy/MM/dd") + pedido.COD_ORCAMENTO.ToString("00000") + pedido.COD_PEDIDO.ToString("0") + item.SEQ_ITEM;
                                }
                                else                         // 0
                                {
                                    // nada = pedido
                                    chave = pedido.COD_FORNECEDOR + pedido.DAT_ORCAMENTO.ToString("yyyy/MM/dd") + pedido.COD_ORCAMENTO.ToString("00000") + pedido.COD_PEDIDO.ToString("0") +
                                            item.SEQ_ITEM;
                                }
                            }
                        }
                        #endregion

                        item.COD_FORNECEDOR     = pedido.COD_FORNECEDOR;
                        item.DAT_ORCAMENTO      = pedido.DAT_ORCAMENTO;
                        item.COD_ORCAMENTO      = pedido.COD_ORCAMENTO;
                        item.COD_PEDIDO         = pedido.COD_PEDIDO;
                        item.NRO_PEDIDO         = pedido.NRO_PEDIDO;
                        item.OBSERVACAO         = pedido.OBSERVACAO;
                        item.VLR_PEDIDO         = pedido.VLR_PEDIDO;
                        item.COD_CLIENTE        = pedido.COD_CLIENTE;
                        item.COD_CARACTERISTICA = pedido.COD_CARACTERISTICA;
                        item.COD_VENDEDOR       = pedido.COD_VENDEDOR;

                        // o desconto será feito no primeiro item do pedido
                        // alterado em 19/06/11
                        // o consolidado estava ficando errado quando o valor do pedido era alterado
                        if (pedido.COD_FORNECEDOR.Equals(zera_desconto_fornecedor) &&
                            (pedido.DAT_ORCAMENTO == zera_desconto_data) &&
                            (pedido.COD_ORCAMENTO == zera_desconto_orcamento))
                        {
                            // o desconto já foi feito no outro pedido desse orçamento
                            pedido.VLR_DESCONTO = 0;
                            pedido.VLR_INICIAL  = pedido.VLR_PEDIDO;                    // evita duplicação do desconto nos próximos itens
                        }
                        bool deuDesconto = false;
                        if (pedido.VLR_PEDIDO < pedido.VLR_INICIAL)
                        {
                            item.VLR_DESCONTO = pedido.VLR_INICIAL - pedido.VLR_PEDIDO;
                        }
                        else
                        if (pedido.VLR_PEDIDO > pedido.VLR_INICIAL)
                        {
                            item.VLR_DESCONTO = pedido.VLR_PEDIDO - pedido.VLR_INICIAL;
                        }
                        else
                        {
                            item.VLR_DESCONTO = pedido.VLR_DESCONTO;
                            deuDesconto       = true;
                        }
                        if ((item.VLR_DESCONTO > -0.2) && (item.VLR_DESCONTO < 0.2))
                        {
                            item.VLR_DESCONTO = 0;
                            deuDesconto       = false;
                        }
                        pedido.VLR_DESCONTO = 0;
                        pedido.VLR_INICIAL  = pedido.VLR_PEDIDO;                // evita duplicação do desconto nos próximos itens
                        if (deuDesconto)
                        {
                            zera_desconto_fornecedor = pedido.COD_FORNECEDOR;
                            zera_desconto_data       = pedido.DAT_ORCAMENTO;
                            zera_desconto_orcamento  = pedido.COD_ORCAMENTO;
                        }

                        item.NOM_PARCEIRO       = pedido.NOM_PARCEIRO;
                        item.DES_FORMULA        = pedido.DES_FORMULA;
                        item.DES_FORMULA_PEDIDO = pedido.DES_FORMULA_PEDIDO;
                        pedidos_ord.Add(chave, item);
                        //MessageBox.Show(chave);
                    }
                }
            }
            #endregion

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

                Tabela    table;              //= new Tabela(mostrar_valores ? 24 : 12);
                string    ultimo_fornecedor = "";
                string    ultimo_pedido     = "";
                DadosItem item0             = (DadosItem)pedidos_ord.GetByIndex(0);
                CabecalhoCliente(item0.COD_FORNECEDOR, item0.DAT_ORCAMENTO, item0.COD_ORCAMENTO, !por_cliente);
                if (por_fabrica)
                {
                    CabecalhoFornecedor(item0.COD_FORNECEDOR);
                }
                if (por_pedido)
                {
                    CabecalhoPedido(item0.COD_FORNECEDOR, item0.DAT_ORCAMENTO, item0.COD_ORCAMENTO, item0.NRO_PEDIDO, item0.COD_VENDEDOR, item0.OBSERVACAO);
                }
                int itens_tabela = 0;
                //doc.Add(table);

                table = new Tabela(mostrar_valores ? 24 : 12);
                CabecalhoTabela(table, mostrar_valores);
                float total    = 0;
                float desconto = 0;
                for (int i = 0; i < pedidos_ord.Count; i++)
                {
                    DadosItem item = (DadosItem)pedidos_ord.GetByIndex(i);
                    if (item.QTD_ITEM == 0)                     // item agrupado
                    {
                        continue;
                    }

                    string chave_fornecedor = item.COD_FORNECEDOR;
                    string chave_pedido     = item.DAT_ORCAMENTO.ToString("yyyy/MM/dd") + item.COD_ORCAMENTO.ToString("00000");

                    string chaveDestacar = item.COD_FORNECEDOR.Trim() + ":" + item.DAT_ORCAMENTO.ToString("M/d/yyyy") + ":" + item.COD_ORCAMENTO.ToString() + ":" + item.COD_PEDIDO.ToString();
                    bool   destacar      = false;
                    foreach (string aux in pedidosDestacarIpi)
                    {
                        if (aux.Equals(chaveDestacar))
                        {
                            destacar = true;
                            break;
                        }
                    }
                    if (!destacar)
                    {
                        if (item.PER_IPI > 0)
                        {
                            item.VLR_PRECO += (item.PER_IPI * item.VLR_PRECO / 100);
                        }
                        item.PER_IPI = 0;
                    }

                    #region agrupa por item
                    if (por_item)
                    {
                        string chave_item = item.COD_PRODUTO + item.SUB_CODIGO + item.COD_ESPECIFICOS + item.VLR_PRECO.ToString();
                        for (int j = i + 1; j < pedidos_ord.Count; j++)
                        {
                            DadosItem proximo       = (DadosItem)pedidos_ord.GetByIndex(j);
                            string    chave_proximo = proximo.COD_PRODUTO + proximo.SUB_CODIGO + proximo.COD_ESPECIFICOS + proximo.VLR_PRECO.ToString();
                            if (chave_item.Equals(chave_proximo))
                            {
                                item.QTD_ITEM   += proximo.QTD_ITEM;
                                proximo.QTD_ITEM = 0;
                            }
                        }
                    }
                    #endregion

                    bool quebrou_pedido = false;
                    if (ultimo_fornecedor != chave_fornecedor)
                    {
                        if (por_fabrica)
                        {
                            if (itens_tabela > 0)
                            {
                                if (mostrar_valores)
                                {
                                    Totais(table, total, desconto, por_fabrica);
                                }
                                total    = 0;
                                desconto = 0;
                                doc.Add(table);
                                RodapeFornecedor(observacao_fabrica);
                                doc.NewPage();
                                table = new Tabela(mostrar_valores ? 24 : 12);
                                CabecalhoRelatorio();
                                CabecalhoFornecedor(item.COD_FORNECEDOR);
                                if (por_pedido)
                                {
                                    if (ultimo_pedido != chave_pedido)
                                    {
                                        quebrou_pedido = true;
                                        CabecalhoPedido(item.COD_FORNECEDOR, item.DAT_ORCAMENTO, item.COD_ORCAMENTO, item.NRO_PEDIDO, item.COD_VENDEDOR, item.OBSERVACAO);
                                        ultimo_pedido = chave_pedido;
                                    }
                                }
                                itens_tabela = 0;
                                CabecalhoTabela(table, mostrar_valores);
                            }
                        }

                        ultimo_fornecedor = chave_fornecedor;
                    }
                    if (!quebrou_pedido && por_pedido && (ultimo_pedido != chave_pedido))
                    {
                        if (itens_tabela > 0)
                        {
                            if (mostrar_valores)
                            {
                                Totais(table, total, desconto, por_fabrica);
                            }
                            total    = 0;
                            desconto = 0;
                            doc.Add(table);
                            table = new Tabela(mostrar_valores ? 24 : 12);
                            CabecalhoPedido(item.COD_FORNECEDOR, item.DAT_ORCAMENTO, item.COD_ORCAMENTO, item.NRO_PEDIDO, item.COD_VENDEDOR, item.OBSERVACAO);
                            itens_tabela = 0;
                            CabecalhoTabela(table, mostrar_valores);
                        }

                        ultimo_pedido = chave_pedido;
                    }

                    desconto += item.VLR_DESCONTO;

                    if (mostrar_subcodigo)
                    {
                        table.AddCell(CelulaGrid(item.COD_PRODUTO + "-" + item.SUB_CODIGO, mostrar_valores ? 4 : 2, false, false));
                    }
                    else
                    {
                        table.AddCell(CelulaGrid(item.COD_PRODUTO, mostrar_valores ? 4 : 2, false, false));
                    }
                    table.AddCell(CelulaGrid(item.DES_PRODUTO, mostrar_valores ? 6 : 5, false, false));
                    table.AddCell(CelulaGrid(item.COD_ESPECIFICOS, mostrar_valores ? 4 : 3, false, false));
                    table.AddCell(CelulaGrid(item.QTD_ITEM.ToString(), 2, false, false));

                    float per_frete = cCaracteristicas.Frete(item.COD_FORNECEDOR, item.COD_CARACTERISTICA);
                    if (mostrar_valores)
                    {
                        float ipi    = item.PER_IPI;
                        float preco  = item.VLR_PRECO;
                        float semipi = item.VLR_PRECO;
                        if (item.COD_PEDIDO == 1)
                        {
                            if (!item.IDT_ESPECIAL.Equals("S"))
                            {
                                Globais.CalculaFormula(ref preco, item.DES_FORMULA_PEDIDO, ipi, per_frete, 0);
                                Globais.CalculaFormula(ref semipi, item.DES_FORMULA_PEDIDO, 0, per_frete, 0);
                            }
                            else
                            {
                                // desfaz formula
                                Globais.DesfazFormula(ref preco, item.DES_FORMULA, ipi, per_frete, 0);
                                Globais.DesfazFormula(ref semipi, item.DES_FORMULA, ipi, per_frete, 0);
                                // refaz parte do pedido
                                Globais.CalculaFormula(ref preco, item.DES_FORMULA_PEDIDO, ipi, per_frete, 0);
                                Globais.CalculaFormula(ref semipi, item.DES_FORMULA_PEDIDO, 0, per_frete, 0);
                            }
                        }
                        else
                        {
                            ipi = 0;
                        }
                        total += preco * item.QTD_ITEM;

                        table.AddCell(CelulaGrid(semipi.ToString("###,###,##0.00"), 2, false, true));
                        table.AddCell(CelulaGrid((semipi * item.QTD_ITEM).ToString("###,###,##0.00"), 2, false, true));
                        table.AddCell(CelulaGrid(ipi.ToString("#0.00") + "%", 2, false, true));
                        table.AddCell(CelulaGrid((preco * item.QTD_ITEM).ToString("###,###,##0.00"), 2, false, true));
                    }

                    itens_tabela++;
                }
                if (itens_tabela > 0)
                {
                    if (mostrar_valores)
                    {
                        Totais(table, total, desconto, por_fabrica);
                    }
                    total    = 0;
                    desconto = 0;
                    doc.Add(table);
                    if (por_fabrica)
                    {
                        RodapeFornecedor(observacao_fabrica);
                    }
                }
                doc.Close();
                fs.Close();
            }
            catch (Exception e)
            {
                Log.Grava(Globais.sUsuario, "erro:" + e.Message);
                MessageBox.Show("Erro na geração do relatório\r\n" + e.Message);
                return;
            }
        }
Ejemplo n.º 6
0
        public bool Altera(
            int COD_TITULO,
            string COD_USUARIO,
            DateTime DAT_EMISSAO,
            DateTime DAT_VENCIMENTO,
            string COD_PARCEIRO,
            string COD_FUNCIONARIO,
            string COD_NATUREZA,
            string IDT_TIPO,
            float VLR_PREVISTO,
            bool chkDAT_PAGAMENTO,
            DateTime DAT_PAGAMENTO,
            float VLR_PAGO,
            string COD_FORMA,
            string COD_DOC_ORIGEM,
            string COD_DOC_GERADO,
            string COD_PENDENCIA,
            string TXT_OBSERVACAO,
            ArrayList pedidos,
            ref string msg)
        {
            string data     = chkDAT_PAGAMENTO ? "'" + DAT_PAGAMENTO.ToString("M/d/yyyy") + "'" : "null";
            string natureza = COD_NATUREZA.Length > 0 ? "'" + COD_NATUREZA + "'": "null";
            string forma    = COD_FORMA.Length > 0 ? "'" + COD_FORMA + "'": "null";
            string fk_pendencia;

            if (COD_PENDENCIA.Trim().Length > 0)
            {
                fk_pendencia = "'" + COD_PENDENCIA + "'";
            }
            else
            {
                fk_pendencia = "null";
            }
            string sql =
                "update TITULOS_PAGAR set " +
                "COD_USUARIO='" + COD_USUARIO + "'," +
                "DAT_EMISSAO='" + DAT_EMISSAO.ToString("M/d/yyyy") + "'," +
                "DAT_VENCIMENTO='" + DAT_VENCIMENTO.ToString("M/d/yyyy") + "'," +
                "COD_PARCEIRO='" + COD_PARCEIRO + "'," +
                "COD_FUNCIONARIO='" + COD_FUNCIONARIO + "'," +
                "COD_NATUREZA=" + natureza + "," +
                "IDT_TIPO='" + IDT_TIPO + "'," +
                "VLR_PREVISTO=" + VLR_PREVISTO.ToString().Replace(',', '.') + "," +
                "DAT_PAGAMENTO=" + data + "," +
                "VLR_PAGO=" + VLR_PAGO.ToString().Replace(',', '.') + "," +
                "COD_FORMA=" + forma + "," +
                "COD_DOC_ORIGEM='" + COD_DOC_ORIGEM + "'," +
                "COD_DOC_GERADO='" + COD_DOC_GERADO + "'," +
                "COD_PENDENCIA=" + fk_pendencia + "," +
                "TXT_OBSERVACAO='" + TXT_OBSERVACAO + "' " +
                "where COD_TITULO=" + COD_TITULO;
            FbCommand cmd = new FbCommand(sql, Globais.bd);

            try
            {
                Log.Grava(Globais.sUsuario, cmd.CommandText);
                cmd.ExecuteNonQuery();
            }
            catch (Exception err)
            {
                Log.Grava(Globais.sUsuario, "erro:" + err.Message);
                msg = err.Message;
                return(false);
            }


            sql = "delete from pedidos_pagos " +
                  "where COD_TITULO=" + COD_TITULO;
            cmd = new FbCommand(sql, Globais.bd);
            try
            {
                Log.Grava(Globais.sUsuario, cmd.CommandText);
                cmd.ExecuteNonQuery();
            }
            catch (Exception err)
            {
                Log.Grava(Globais.sUsuario, "erro:" + err.Message);
                msg = err.Message;
                return(false);
            }

            foreach (string ped in pedidos)
            {
                string   fornecedor_ped = "";
                DateTime data_ped       = DateTime.Now;
                string   orcamento_ped  = "";
                string   pedido_ped     = "";
                Globais.SeparaPedido(ped, ref fornecedor_ped, ref data_ped, ref orcamento_ped, ref pedido_ped);
                sql = "insert into pedidos_pagos values(" +
                      "'" + fornecedor_ped + "'," +
                      "'" + data_ped.ToString("M/d/yyyy") + "'," +
                      orcamento_ped + "," +
                      pedido_ped + "," +
                      COD_TITULO + ")";
                cmd = new FbCommand(sql, Globais.bd);
                try
                {
                    Log.Grava(Globais.sUsuario, cmd.CommandText);
                    cmd.ExecuteNonQuery();
                }
                catch (Exception err)
                {
                    Log.Grava(Globais.sUsuario, "erro:" + err.Message);
                    msg = err.Message;
                    return(false);
                }
            }
            msg = "OK";
            return(true);
        }
Ejemplo n.º 7
0
        public bool Inclui(
            string COD_USUARIO,
            DateTime DAT_EMISSAO,
            DateTime DAT_VENCIMENTO,
            string COD_PARCEIRO,
            string COD_FUNCIONARIO,
            string COD_NATUREZA,
            string IDT_TIPO,
            float VLR_PREVISTO,
            bool chkDAT_PAGAMENTO,
            DateTime DAT_PAGAMENTO,
            float VLR_PAGO,
            string COD_FORMA,
            string COD_DOC_ORIGEM,
            string COD_DOC_GERADO,
            string COD_PENDENCIA,
            string TXT_OBSERVACAO,
            ArrayList pedidos,
            ref string msg,
            ref int codigo)
        {
            codigo = 1;
            string       data     = chkDAT_PAGAMENTO ? "'" + DAT_PAGAMENTO.ToString("M/d/yyyy") + "'" : "null";
            string       natureza = COD_NATUREZA.Length > 0 ? "'" + COD_NATUREZA + "'": "null";
            string       forma    = COD_FORMA.Length > 0 ? "'" + COD_FORMA + "'": "null";
            FbCommand    cmd      = new FbCommand("select max(COD_TITULO) from TITULOS_PAGAR ", Globais.bd);
            FbDataReader reader   = cmd.ExecuteReader(CommandBehavior.SingleRow);

            if (reader.Read())
            {
                if (!reader.IsDBNull(0))
                {
                    codigo = reader.GetInt32(0) + 1;
                }
            }
            reader.Close();

            string fk_pendencia;

            if (COD_PENDENCIA.Trim().Length > 0)
            {
                fk_pendencia = "'" + COD_PENDENCIA + "'";
            }
            else
            {
                fk_pendencia = "null";
            }
            string sql =
                "insert into TITULOS_PAGAR values(" +
                codigo + "," +
                "'" + COD_USUARIO + "'," +
                "'" + DAT_EMISSAO.ToString("M/d/yyyy") + "'," +
                "'" + DAT_VENCIMENTO.ToString("M/d/yyyy") + "'," +
                "'" + COD_PARCEIRO + "'," +
                "'" + COD_FUNCIONARIO + "'," +
                natureza + "," +
                "'" + IDT_TIPO + "'," +
                VLR_PREVISTO.ToString().Replace(',', '.') + "," +
                data + "," +
                VLR_PAGO.ToString().Replace(',', '.') + "," +
                forma + "," +
                "'" + COD_DOC_ORIGEM + "'," +
                "'" + COD_DOC_GERADO + "'," +
                fk_pendencia + "," +
                "'" + TXT_OBSERVACAO + "')";
            FbCommand cmd2 = new FbCommand(sql, Globais.bd);

            try
            {
                Log.Grava(Globais.sUsuario, cmd2.CommandText);
                cmd2.ExecuteNonQuery();
            }
            catch (Exception err)
            {
                Log.Grava(Globais.sUsuario, "erro:" + err.Message);
                msg = err.Message;
                return(false);
            }

            foreach (string ped in pedidos)
            {
                string   fornecedor_ped = "";
                DateTime data_ped       = DateTime.Now;
                string   orcamento_ped  = "";
                string   pedido_ped     = "";
                Globais.SeparaPedido(ped, ref fornecedor_ped, ref data_ped, ref orcamento_ped, ref pedido_ped);
                sql = "insert into pedidos_pagos values(" +
                      "'" + fornecedor_ped + "'," +
                      "'" + data_ped.ToString("M/d/yyyy") + "'," +
                      orcamento_ped + "," +
                      pedido_ped + "," +
                      codigo + ")";
                cmd = new FbCommand(sql, Globais.bd);
                try
                {
                    Log.Grava(Globais.sUsuario, cmd.CommandText);
                    cmd.ExecuteNonQuery();
                }
                catch (Exception err)
                {
                    Log.Grava(Globais.sUsuario, "erro:" + err.Message);
                    msg = err.Message;
                    return(false);
                }
            }

            msg = "OK";
            return(true);
        }
Ejemplo n.º 8
0
        public Table GeraItens(ArrayList areas, bool mostrar_valores, bool mostrar_subcodigo, float total_pedido, float total_desconto, bool destacar_ipi)
        {
            int colunas = 24;
            int col0    = 4;
            int col1    = 6;
            int col2    = 4;
            int col3    = 2;
            int col4    = 2;
            int col5    = 2;
            int col6    = 2;
            int col7    = 2;

            if (!destacar_ipi)
            {
                colunas = 18;
                col0    = 3;
                col2    = 3;
            }
            if (!mostrar_valores)
            {
                colunas = 12;
                col0    = 2;
                col1    = 5;
                col2    = 3;
            }
            Table table = new Table(colunas);

            table.Padding         = 4;
            table.TableFitsPage   = true;
            table.BorderWidth     = 1;
            table.WidthPercentage = 100;
            table.Alignment       = Element.ALIGN_LEFT;
            table.AddCell(CelulaGrid("Item", col0, true, false));
            table.AddCell(CelulaGrid("Descrição", col1, true, false));
            table.AddCell(CelulaGrid("Códigos Específicos", col2, true, false));
            table.AddCell(CelulaGrid("Qtde", col3, true, false));
            if (mostrar_valores)
            {
                table.AddCell(CelulaGrid("Unitário", col4, true, true));
                table.AddCell(CelulaGrid("Total", col5, true, true));
                if (destacar_ipi)
                {
                    table.AddCell(CelulaGrid("IPI", col6, true, true));
                    table.AddCell(CelulaGrid("Total c/ IPI", col7, true, true));
                }
            }

            float total_tot   = 0;
            float total_ipi   = 0;
            float total_final = 0;

            foreach (Area area in areas)
            {
                foreach (Item item in area.itens)
                {
                    if (mostrar_subcodigo)
                    {
                        table.AddCell(CelulaGrid(item.codigo + "-" + item.subcodigo, col0, false, false));
                    }
                    else
                    {
                        table.AddCell(CelulaGrid(item.codigo, col0, false, false));
                    }
                    table.AddCell(CelulaGrid(item.descricao, col1, false, false));
                    table.AddCell(CelulaGrid(item.especificos, col2, false, false));
                    table.AddCell(CelulaGrid(item.qtde.ToString(), col3, false, false));
                    if (mostrar_valores)
                    {
                        if (destacar_ipi)
                        {
                            table.AddCell(CelulaGrid(item.vlr_semipi.ToString("###,###,##0.00"), col4, false, true));
                            table.AddCell(CelulaGrid((Globais.Arredonda(item.vlr_semipi * item.qtde)).ToString("###,###,##0.00"), col5, false, true));
                            table.AddCell(CelulaGrid(item.ipi.ToString("#0.00") + "%", col6, false, true));
                            table.AddCell(CelulaGrid((Globais.Arredonda(item.vlr_unitario * item.qtde)).ToString("###,###,##0.00"), col7, false, true));
                        }
                        else
                        {
                            table.AddCell(CelulaGrid(item.vlr_unitario.ToString("###,###,##0.00"), col4, false, true));
                            table.AddCell(CelulaGrid((Globais.Arredonda(item.vlr_unitario * item.qtde)).ToString("###,###,##0.00"), col5, false, true));
                        }
                    }
                    //table.AddCell(CelulaGrid((item.vlr_unitario*item.qtde*(1+(item.ipi/100))).ToString("###,###,##0.00"), 2, false, true));
                    total_tot += (Globais.Arredonda(item.vlr_semipi * item.qtde));
                    total_ipi += (Globais.Arredonda(item.vlr_semipi * item.ipi / 100 * item.qtde));
                    float unitario = Globais.Arredonda(item.vlr_unitario);
                    float f1       = Globais.Arredonda(item.vlr_unitario * item.qtde);
                    float f2       = unitario * item.qtde;
                    total_final += (Globais.Arredonda(item.vlr_unitario * item.qtde));
                }
            }
            if (!mostrar_valores)
            {
                return(table);
            }

            if (destacar_ipi)
            {
                table.AddCell(CelulaGrid("Totais", colunas - 6, true, false));
                table.AddCell(CelulaGrid(total_tot.ToString("###,###,##0.00"), 2, true, true));
                table.AddCell(CelulaGrid(total_ipi.ToString("###,###,##0.00"), 2, true, true));
            }
            else
            {
                table.AddCell(CelulaGrid("Totais", colunas - 2, true, false));
            }
            table.AddCell(CelulaGrid(total_final.ToString("###,###,##0.00"), 2, true, true));

            if (total_pedido == 0)
            {
                if (cab2.vlr_desconto > 0)
                {
                    table.AddCell(CelulaGrid("Desconto", colunas - 2, true, false));
                    table.AddCell(CelulaGrid(cab2.vlr_desconto.ToString("###,###,##0.00"), 2, true, true));
                    table.AddCell(CelulaGrid("Valor Final", colunas - 2, true, false));
                    table.AddCell(CelulaGrid((total_final - cab2.vlr_desconto).ToString("###,###,##0.00"), 2, true, true));
                }
                else
                {
                    if (cab1.valor < total_final)
                    {
                        table.AddCell(CelulaGrid("Desconto", colunas - 2, true, false));
                        table.AddCell(CelulaGrid((total_final - cab1.valor).ToString("###,###,##0.00"), 2, true, true));
                        table.AddCell(CelulaGrid("Valor Final", colunas - 2, true, false));
                        table.AddCell(CelulaGrid(cab1.valor.ToString("###,###,##0.00"), 2, true, true));
                    }
                    else
                    if (cab1.valor > total_final)
                    {
                        table.AddCell(CelulaGrid("Ajuste", colunas - 2, true, false));
                        table.AddCell(CelulaGrid((cab1.valor - total_final).ToString("###,###,##0.00"), 2, true, true));
                        table.AddCell(CelulaGrid("Valor Final", colunas - 2, true, false));
                        table.AddCell(CelulaGrid(cab1.valor.ToString("###,###,##0.00"), 2, true, true));
                    }
                }
            }
            else
            {
                if (total_desconto > 0)
                {
                    table.AddCell(CelulaGrid("Desconto", colunas - 2, true, false));
                    table.AddCell(CelulaGrid(total_desconto.ToString("###,###,##0.00"), 2, true, true));
                    table.AddCell(CelulaGrid("Valor Final", colunas - 2, true, false));
                    table.AddCell(CelulaGrid((total_final - total_desconto).ToString("###,###,##0.00"), 2, true, true));
                }
                else
                {
                    if (total_pedido < total_final)
                    {
                        table.AddCell(CelulaGrid("Desconto", colunas - 2, true, false));
                        table.AddCell(CelulaGrid((total_final - total_pedido).ToString("###,###,##0.00"), 2, true, true));
                        table.AddCell(CelulaGrid("Valor Final", colunas - 2, true, false));
                        table.AddCell(CelulaGrid(total_pedido.ToString("###,###,##0.00"), 2, true, true));
                    }
                    else
                    if (total_pedido > total_final)
                    {
                        table.AddCell(CelulaGrid("Ajuste", colunas - 2, true, false));
                        table.AddCell(CelulaGrid((total_pedido - total_final).ToString("###,###,##0.00"), 2, true, true));
                        table.AddCell(CelulaGrid("Valor Final", colunas - 2, true, false));
                        table.AddCell(CelulaGrid(total_pedido.ToString("###,###,##0.00"), 2, true, true));
                    }
                }
            }

            return(table);
            //doc.Add(table);
        }
Ejemplo n.º 9
0
        private void Parte2(DataGridView dgv, bool justificativas)
        {
            CelulaCabecalho cell;
            CelulaItem      cellI;
            Tabela          table = new Tabela(11);

            // cabecalho
            cell         = new CelulaCabecalho(Frase("Fornecedor", 10));
            cell.Colspan = 2;
            table.AddCell(cell);

            cell         = new CelulaCabecalho(Frase("Data", 10));
            cell.Colspan = 1;
            table.AddCell(cell);

            cell         = new CelulaCabecalho(Frase("Orçamento", 10));
            cell.Colspan = 1;
            table.AddCell(cell);

            cell         = new CelulaCabecalho(Frase("Pedido", 10));
            cell.Colspan = 1;
            table.AddCell(cell);

            cell         = new CelulaCabecalho(Frase("Cliente", 10));
            cell.Colspan = 2;
            table.AddCell(cell);

            cell                     = new CelulaCabecalho(Frase("Vlr Pedido", 10));
            cell.Colspan             = 1;
            cell.HorizontalAlignment = Element.ALIGN_RIGHT;
            table.AddCell(cell);

            cell                     = new CelulaCabecalho(Frase("Valor", 10));
            cell.Colspan             = 1;
            cell.HorizontalAlignment = Element.ALIGN_RIGHT;
            table.AddCell(cell);

            cell                     = new CelulaCabecalho(Frase("%Pago", 10));
            cell.Colspan             = 1;
            cell.HorizontalAlignment = Element.ALIGN_RIGHT;
            table.AddCell(cell);

            cell                     = new CelulaCabecalho(Frase("Comissão", 10));
            cell.Colspan             = 1;
            cell.HorizontalAlignment = Element.ALIGN_RIGHT;
            table.AddCell(cell);

            percentual_comissao = 0;
            total_comissao      = 0;
            total_pedido        = 0;
            total_valor         = 0;
            total_pago          = 0;
            total_pagar         = 0;
            nitens = 0;

            foreach (DataGridViewRow row in dgv.Rows)
            {
                /*
                 * if (!(bool)row.Cells["S"].Value)
                 * {
                 *      continue;
                 * }
                 * bool pg=false;
                 * if (por_vendedor)
                 *      pg = row.Cells["IdtVendedor"].Value.ToString().Equals("S");
                 * if (por_consultor)
                 *      pg = row.Cells["IdtConsultor"].Value.ToString().Equals("S");
                 * if (por_filial)
                 *      pg = row.Cells["IdtFilial"].Value.ToString().Equals("S");
                 */
                bool pg = (bool)row.Cells["PG"].Value;

                if (!mostra_pagar && !pg)
                {
                    continue;
                }
                if (!mostra_pago && pg)
                {
                    continue;
                }
                cellI         = new CelulaItem(Frase(row.Cells["Fornecedor"].Value.ToString(), 10));
                cellI.Colspan = 2;
                table.AddCell(cellI);

                cellI         = new CelulaItem(Frase(row.Cells["Data"].Value.ToString(), 10));
                cellI.Colspan = 1;
                table.AddCell(cellI);

                cellI         = new CelulaItem(Frase(row.Cells["Orcamento"].Value.ToString(), 10));
                cellI.Colspan = 1;
                table.AddCell(cellI);

                cellI         = new CelulaItem(Frase(row.Cells["Pedido"].Value.ToString(), 10));
                cellI.Colspan = 1;
                table.AddCell(cellI);

                cellI         = new CelulaItem(Frase(row.Cells["Cliente"].Value.ToString(), 10));
                cellI.Colspan = 2;
                table.AddCell(cellI);

                cellI                     = new CelulaItem(Frase(Globais.StrToFloat(row.Cells["ValorPedido"].Value.ToString()).ToString("#,###,##0.00"), 10));
                cellI.Colspan             = 1;
                cellI.HorizontalAlignment = Element.ALIGN_RIGHT;
                table.AddCell(cellI);

                cellI                     = new CelulaItem(Frase(Globais.StrToFloat(row.Cells["Valor"].Value.ToString()).ToString("#,###,##0.00"), 10));
                cellI.Colspan             = 1;
                cellI.HorizontalAlignment = Element.ALIGN_RIGHT;
                table.AddCell(cellI);

                //cellI = new CelulaItem(Frase(Globais.StrToFloat(row.Cells["PerVendedor"].Value.ToString()).ToString("#0.00"), 10));
                cellI                     = new CelulaItem(Frase(Globais.StrToFloat(row.Cells["Pago"].Value.ToString()).ToString("#0.00"), 10));
                cellI.Colspan             = 1;
                cellI.HorizontalAlignment = Element.ALIGN_RIGHT;
                table.AddCell(cellI);

                float comissao = Globais.StrToFloat(row.Cells["Comissao"].Value.ToString());
                //float valor = Globais.StrToFloat(row.Cells["Valor"].Value.ToString());
                //float per_pago = Globais.StrToFloat(row.Cells["PerVendedor"].Value.ToString());
                //float comissao = per_pago * valor / 100f;
                cellI                     = new CelulaItem(Frase(comissao.ToString("#,###,##0.00"), 10));
                cellI.Colspan             = 1;
                cellI.HorizontalAlignment = Element.ALIGN_RIGHT;
                table.AddCell(cellI);
                percentual_comissao += Globais.StrToFloat(row.Cells["Pago"].Value.ToString());
                total_comissao      += comissao;
                total_pedido        += Globais.StrToFloat(row.Cells["ValorPedido"].Value.ToString());
                total_valor         += Globais.StrToFloat(row.Cells["Valor"].Value.ToString());
                if ((bool)row.Cells["PG"].Value)
                {
                    total_pago += comissao;
                }
                else
                {
                    total_pagar += comissao;
                }

                if (justificativas)
                {
                    string justificativa = row.Cells["Justificativa"].Value.ToString().Trim();
                    if (justificativa.Length > 0)
                    {
                        cellI         = new CelulaItem(Frase("Justificativa: " + justificativa, 10));
                        cellI.Colspan = 11;
                        table.AddCell(cellI);
                    }
                }
                nitens++;
            }
            doc.Add(table);
        }
Ejemplo n.º 10
0
        public float DiferencaFormulas(string fornecedor, string caracteristica, DateTime data, short orcamento, ref string servico)
        {
            string    formula = "", formula_pedido = "";
            float     total_orcamento = 0, total_pedido = 0;
            FbCommand cmd = new FbCommand("select DES_FORMULA,DES_FORMULA_PEDIDO,TXT_SERVICO " +
                                          "from CARACTERISTICAS " +
                                          "where COD_FORNECEDOR='" + fornecedor + "' and " +
                                          "      COD_CARACTERISTICA='" + caracteristica + "'",
                                          Globais.bd);
            FbDataReader reader = cmd.ExecuteReader(CommandBehavior.Default);

            if (reader.Read())
            {
                formula        = !reader.IsDBNull(0) ? reader.GetString(0).Trim() : "";
                formula_pedido = !reader.IsDBNull(1) ? reader.GetString(1).Trim() : "";
                servico        = !reader.IsDBNull(2) ? reader.GetString(2).Trim() : "";
            }
            reader.Close();
            if (formula_pedido.Length == 0)
            {
                return(0f);
            }
            if (formula_pedido.CompareTo(formula) == 0)
            {
                return(0f);
            }

            string sql = "select " +
                         "       a.cod_produto," +
                         "       a.sub_codigo," +
                         "       a.qtd_item," +
                         "       a.vlr_preco," +
                         "       a.vlr_preco_tabela, " +
                         "       a.idt_especial," +
                         "       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.cod_area,a.seq_item";

            cmd    = new FbCommand(sql, Globais.bd);
            reader = cmd.ExecuteReader(CommandBehavior.Default);
            string codigo;
            string sub_codigo;
            short  qtd;
            float  preco_unitario;
            float  preco_tabela;
            bool   especial;
            float  ipi;

            //float fator;
            //float preco;
            while (reader.Read())
            {
                float valor_orcamento = 0, valor_pedido = 0;
                codigo         = reader.GetString(0).Trim();
                sub_codigo     = reader.GetString(1).Trim();
                qtd            = reader.GetInt16(2);
                preco_unitario = reader.GetFloat(3) * qtd;
                preco_tabela   = reader.GetFloat(4) * qtd;
                especial       = reader.GetString(5).Trim().CompareTo("S") == 0;;
                ipi            = reader.GetFloat(6);
                if (especial)
                {
                    // desfaz formula
                    preco_tabela = preco_unitario;
                    Globais.DesfazFormula(ref preco_tabela, formula, ipi, 0, 0);

                    /*
                     * for (int i=formula.Trim().Length-4; i>=0; i-=4)
                     * {
                     *      if (formula[i] == 'x')
                     *      {
                     *              fator = (Globais.StrToFloat(formula.Substring(i+1, 3)) - 1) * 100;
                     *      }
                     *      if (formula.Substring(i, 4).CompareTo("+IPI") == 0)
                     *      {
                     *              fator = ipi;
                     *      }
                     *      else
                     *      {
                     *              fator = Globais.StrToFloat(formula.Substring(i, 4));
                     *      }
                     *      preco_tabela = (preco_tabela * 100) / (100 + fator);
                     * }
                     */
                }
                //if (!especial)
                //{
                valor_orcamento = preco_tabela;
                valor_pedido    = preco_tabela;
                float per_frete = cCaracteristicas.Frete(fornecedor, caracteristica);
                Globais.CalculaFormula(ref valor_orcamento, 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));
                 *              valor_orcamento *= fator;
                 *              continue;
                 *      }
                 *      if (formula.Substring(i, 4).CompareTo("+IPI") == 0)
                 *      {
                 *              fator = ipi;
                 *              valor_orcamento += (valor_orcamento * fator / (float)100);
                 *      }
                 *      else
                 *      {
                 *              fator = Globais.StrToFloat(formula.Substring(i, 4));
                 *              valor_orcamento += (valor_orcamento * fator / (float)100);
                 *      }
                 * }
                 */
                Globais.CalculaFormula(ref valor_pedido, formula_pedido, ipi, per_frete, 0);

                /*
                 * for (int i=0; i<formula_pedido.Trim().Length; i+=4)
                 * {
                 *      if (formula_pedido[i] == 'x')
                 *      {
                 *              fator = Globais.StrToFloat(formula_pedido.Substring(i+1, 3));
                 *              valor_pedido *= fator;
                 *              continue;
                 *      }
                 *      if (formula_pedido.Substring(i, 4).CompareTo("+IPI") == 0)
                 *      {
                 *              fator = ipi;
                 *              valor_pedido += (valor_pedido * fator / (float)100);
                 *      }
                 *      else
                 *      {
                 *              fator = Globais.StrToFloat(formula_pedido.Substring(i, 4));
                 *              valor_pedido += (valor_pedido * fator / (float)100);
                 *      }
                 * }
                 */
/*
 *                              }
 *                              else
 *                              {
 *                                      preco = preco_unitario;
 *                                      valor_orcamento += preco;
 *                                      valor_pedido += preco;
 *                              }
 */
                total_orcamento += valor_orcamento;
                total_pedido    += valor_pedido;
            }
            reader.Close();
            return(total_orcamento - total_pedido);
        }
Ejemplo n.º 11
0
        public static void Barras(PdfContentByte cb, ArrayList valores, ArrayList labels, float y0, float max)
        {
            float h = PageSize.LETTER.Width;             // paisagem
            float w = PageSize.LETTER.Height;

            cb.SetFontAndSize(BaseFont.CreateFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED), 10);

            cb.MoveTo(110, h - 10 - y0);
            cb.LineTo(110, h - 320 - y0);
            for (int y = 320; y >= 20; y -= 30)
            {
                cb.MoveTo(100, h - y - y0);
                cb.LineTo(620, h - y - y0);
            }
            for (int x = 110; x <= 620; x += 40)
            {
                cb.MoveTo(x, h - 320 - y0);
                cb.LineTo(x, h - 325 - y0);
            }
            cb.FillStroke();

            float vlr = 100;

            while (vlr < max)
            {
                vlr *= 2;
            }
            float d = vlr / 10;

            vlr = 0;
            for (int y = 320; y >= 20; y -= 30)
            {
                cb.BeginText();
                cb.SetTextMatrix(10, h - y - y0);
                cb.ShowText(vlr.ToString("###,###,##0.00").PadLeft(14));
                vlr += d;
                cb.EndText();
            }

            int[,] cores = new int[, ]
            {
                { 255, 0, 0 },
                { 0, 255, 0 },
                { 0, 0, 255 },
                { 255, 255, 0 },
                { 255, 0, 255 },
                { 0, 255, 255 },
                { 255, 128, 0 },
                { 0, 255, 128 },
                { 128, 0, 255 },
                { 255, 128, 128 },
                { 128, 255, 128 },
                { 128, 128, 255 }
            };

            int i = 0;

            foreach (float valor in valores)
            {
                Legenda(cb, i, valor, labels[i].ToString(), cores, 500, y0, 0);
                i++;
            }

            i = 0;
            int x1 = 115;
            int y1;

            foreach (string descricao in labels)
            {
                int    j     = 0;
                string valor = "";
                foreach (float v in valores)
                {
                    valor = v.ToString("#,###,##0.00");
                    if (j++ == i)
                    {
                        break;
                    }
                }

                cb.SetRGBColorFill(cores[i, 0], cores[i, 1], cores[i, 2]);
                y1 = (int)(Globais.StrToFloat(valor) / d * 30);
                cb.Rectangle(x1, h - y0 - 319, 30, y1);
                cb.Fill();
                x1 += 40;
                i++;
            }
        }