Esempio n. 1
0
        private bool ValidarKm(ref decimal Km_atual)
        {
            Km_maximo = decimal.Zero;
            bool retorno = true;

            //Validar KM Atual
            if ((!string.IsNullOrEmpty(placa.Text)) &&
                (placa.Text.Trim() != "-") &&
                (km.Value > decimal.Zero))
            {
                object obj = new CamadaDados.PostoCombustivel.TCD_VendaCombustivel().BuscarEscalar(
                    new TpBusca[]
                {
                    new TpBusca()
                    {
                        vNM_Campo = "replace(a.placaveiculo, '-', '')",
                        vOperador = "=",
                        vVL_Busca = "'" + placa.Text.Trim().Replace("-", "") + "'"
                    }
                }, "isnull(a.km_atual, 0)", string.Empty, "a.dt_abastecimento desc", null);
                if (obj != null)
                {
                    //Buscar ultimo KM Informado para a placa
                    if (decimal.Parse(obj.ToString()) > km.Value)
                    {
                        Km_atual = decimal.Parse(obj.ToString());
                        retorno  = false;
                    }
                }
            }
            return(retorno);
        }
Esempio n. 2
0
 private void bb_processarDiferenca_Click(object sender, EventArgs e)
 {
     if ((!string.IsNullOrEmpty(CD_Empresa.Text)) &&
         (!string.IsNullOrEmpty(id_bico.Text)) &&
         (dt_encerrante.Text.Trim() != "/  /"))
     {
         if (volumediferenca.Value.Equals(decimal.Zero))
         {
             MessageBox.Show("Não existe diferença para processar.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
             return;
         }
         if (volumediferenca.Value > decimal.Zero)
         {
             MessageBox.Show("Para acertar diferença positiva deve se recalcular o encerrante de abertura ou de encerramento.",
                             "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
             return;
         }
         if (MessageBox.Show("Confirma lancamento de abastecida com o valor da diferença?",
                             "Pergunta", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
             == DialogResult.Yes)
         {
             try
             {
                 //Buscar valor unitario
                 object obj_unit = new CamadaDados.PostoCombustivel.TCD_VendaCombustivel().BuscarEscalar(
                     new Utils.TpBusca[]
                 {
                     new Utils.TpBusca()
                     {
                         vNM_Campo = "a.cd_empresa",
                         vOperador = "=",
                         vVL_Busca = "'" + CD_Empresa.Text.Trim() + "'"
                     },
                     new Utils.TpBusca()
                     {
                         vNM_Campo = "a.id_bico",
                         vOperador = "=",
                         vVL_Busca = id_bico.Text
                     }
                 }, "a.vl_unitario", string.Empty, "a.dt_abastecimento desc", null);
                 CamadaNegocio.PostoCombustivel.TCN_VendaCombustivel.Gravar(
                     new CamadaDados.PostoCombustivel.TRegistro_VendaCombustivel()
                 {
                     Cd_empresa       = CD_Empresa.Text,
                     Id_bicostr       = id_bico.Text,
                     Volumeabastecido = Math.Abs(volumediferenca.Value),
                     Vl_unitario      = decimal.Parse(obj_unit.ToString()),
                     Vl_subtotal      = volumediferenca.Value * decimal.Parse(obj_unit.ToString()),
                     Dt_abastecimento = dt_encerrante.Data,
                     St_afericao      = "N",
                     Tp_registro      = "M",
                     St_registro      = "A"
                 }, null);
                 MessageBox.Show("Venda combustivel gravada com sucesso.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
             catch (Exception ex)
             { MessageBox.Show(ex.Message.Trim(), "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); }
         }
     }
 }
Esempio n. 3
0
        private void BuscarVolumeVendido()
        {
            if ((!string.IsNullOrEmpty(CD_Empresa.Text)) &&
                (!string.IsNullOrEmpty(id_bico.Text)) &&
                (dt_encerrante.Text.Trim() != "/  /"))
            {
                object obj_volume =
                    new CamadaDados.PostoCombustivel.TCD_VendaCombustivel().BuscarEscalar(
                        new Utils.TpBusca[]
                {
                    new Utils.TpBusca()
                    {
                        vNM_Campo = "a.cd_empresa",
                        vOperador = "=",
                        vVL_Busca = "'" + CD_Empresa.Text.Trim() + "'"
                    },
                    new Utils.TpBusca()
                    {
                        vNM_Campo = "a.id_bico",
                        vOperador = "=",
                        vVL_Busca = id_bico.Text
                    },
                    new Utils.TpBusca()
                    {
                        vNM_Campo = "convert(datetime, floor(convert(decimal(30,10), a.dt_abastecimento)))",
                        vOperador = "=",
                        vVL_Busca = "'" + dt_encerrante.Data.ToString("yyyyMMdd") + "'"
                    }
                }, "isnull(sum(isnull(a.volumeabastecido, 0)), 0)");
                volumevendido.Value = obj_volume != null?decimal.Parse(obj_volume.ToString()) : decimal.Zero;

                volumediferenca.Value = encerranteabertura.Value + volumevendido.Value - encerrantefechamento.Value;
            }
        }
Esempio n. 4
0
 private void gBico_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex == 0)
     {
         if (!(bsBico.Current as CamadaDados.PostoCombustivel.Cadastros.TRegistro_BicoBomba).St_processar)
         {
             (bsBico.List as CamadaDados.PostoCombustivel.Cadastros.TList_BicoBomba).ForEach(p => p.St_processar = false);
             bsBico.ResetBindings(true);
         }
         (bsBico.Current as CamadaDados.PostoCombustivel.Cadastros.TRegistro_BicoBomba).St_processar =
             !(bsBico.Current as CamadaDados.PostoCombustivel.Cadastros.TRegistro_BicoBomba).St_processar;
         bsBico.ResetCurrentItem();
         if ((bsBico.Current as CamadaDados.PostoCombustivel.Cadastros.TRegistro_BicoBomba).St_processar)
         {
             (bsVendaCombustivel.Current as CamadaDados.PostoCombustivel.TRegistro_VendaCombustivel).Id_bico =
                 (bsBico.Current as CamadaDados.PostoCombustivel.Cadastros.TRegistro_BicoBomba).Id_bico;
             sigla_unidade.Text = (bsBico.Current as CamadaDados.PostoCombustivel.Cadastros.TRegistro_BicoBomba).Sigla_unidade;
             if (!string.IsNullOrEmpty(Cd_tabelapreco))
             {
                 vl_unitario.Value = CamadaNegocio.Estoque.Cadastros.TCN_LanPrecoItem.Busca_ConsultaPreco(cbEmpresa.SelectedValue.ToString(),
                                                                                                          (bsBico.Current as CamadaDados.PostoCombustivel.Cadastros.TRegistro_BicoBomba).Cd_produto,
                                                                                                          Cd_tabelapreco,
                                                                                                          null);
                 vl_unitario.Enabled = vl_unitario.Equals(decimal.Zero);
                 // busca valor encerrante bico do ultimo abastecimento por bico
                 string id_bico = (bsBico.Current as CamadaDados.PostoCombustivel.Cadastros.TRegistro_BicoBomba).Id_bicostr;
                 object obj     =
                     new CamadaDados.PostoCombustivel.TCD_VendaCombustivel().BuscarEscalar(
                         new TpBusca[]
                 {
                     new TpBusca()
                     {
                         vNM_Campo = "a.id_bico",
                         vOperador = "=",
                         vVL_Busca = "'" + id_bico + "'"
                     },
                     new TpBusca()
                     {
                         vNM_Campo = "a.cd_empresa",
                         vOperador = "=",
                         vVL_Busca = "'" + cbEmpresa.SelectedValue.ToString() + "'"
                     }
                 }, "a.encerrantebico", string.Empty, "a.dt_abastecimento desc", null);
                 encerranteIni.Text    = obj.ToString();
                 encerranteFinal.Value = encerranteIni.Value + volumeabastecido.Value;
             }
             else
             {
                 vl_unitario.Enabled = true;
             }
             volumeabastecido.Focus();
         }
         else
         {
             (bsVendaCombustivel.Current as CamadaDados.PostoCombustivel.TRegistro_VendaCombustivel).Id_bico = null;
         }
         bsVendaCombustivel.ResetCurrentItem();
     }
 }
Esempio n. 5
0
        private void afterGrava()
        {
            if (!ValidaCPF())
            {
                return;
            }
            if (!string.IsNullOrEmpty(nm_clifor.Text))
            {
                if (nm_clifor.Text.Trim().Length < 2)
                {
                    MessageBox.Show("Nome do cliente deve possuir dois ou mais caracteres.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    nm_clifor.Focus();
                    return;
                }
            }
            decimal KM = decimal.Zero;

            if (ValidarKm(ref KM))
            {
                DialogResult = DialogResult.OK;
            }

            else if (MessageBox.Show("KM Atual não pode ser menor ou igual ao ultimo KM informado para a placa (Ultimo KM: " + KM.ToString("N0", new System.Globalization.CultureInfo("pt-BR")) + ").\r\n" +
                                     "Deseja corrigir ultimo KM informado?", "Pergunta",
                                     MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
            {
                //Buscar abastecida do ultimo KM
                CamadaDados.PostoCombustivel.TList_VendaCombustivel lVenda =
                    new CamadaDados.PostoCombustivel.TCD_VendaCombustivel().Select(
                        new TpBusca[]
                {
                    new TpBusca()
                    {
                        vNM_Campo = "replace(a.placaveiculo, '-', '')",
                        vOperador = "=",
                        vVL_Busca = "'" + placa.Text.Trim().Replace("-", "") + "'"
                    }
                }, 1, "isnull(a.km_atual, 0)", "a.dt_abastecimento desc");
                if (lVenda.Count > 0)
                {
                    using (TFCorrigirKM fKM = new TFCorrigirKM())
                    {
                        fKM.Ultimo_km = lVenda[0].Km_atual;
                        fKM.Km_atual  = km.Value;
                        if (fKM.ShowDialog() == DialogResult.OK)
                        {
                            try
                            {
                                lVenda[0].Km_atual = fKM.Km_corrigido;
                                CamadaNegocio.PostoCombustivel.TCN_VendaCombustivel.Gravar(lVenda[0], null);
                                MessageBox.Show("Ultimo KM corrigido com sucesso.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                DialogResult = DialogResult.OK;
                            }
                            catch (Exception ex)
                            { MessageBox.Show(ex.Message.Trim(), "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); }
                        }
                    }
                }
            }
            else if (MessageBox.Show("Deseja informar KM maximo do hodometro?", "Pergunta", MessageBoxButtons.YesNo,
                                     MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
            {
                using (Componentes.TFQuantidade fQtd = new Componentes.TFQuantidade())
                {
                    fQtd.Ds_label = "KM Maximo Hodometro";
                    fQtd.ShowDialog();
                    if (fQtd.Quantidade >= KM)
                    {
                        Km_maximo    = fQtd.Quantidade;
                        DialogResult = DialogResult.OK;
                    }
                }
            }
        }
Esempio n. 6
0
 private void bb_imprimir_Click(object sender, EventArgs e)
 {
     if (bsValeResgate.Current != null)
     {
         if ((bsValeResgate.Current as CamadaDados.Faturamento.Fidelizacao.TRegistro_ValeResgate).St_impressobool)
         {
             MessageBox.Show("Não é permitido reimprimir vale.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
             return;
         }
         try
         {
             //Imprimir Vale
             List <string> Texto = new List <string>();
             Texto.Add("                RESGATE PONTOS                 ");
             Texto.Add("PLACA: " + (bsValeResgate.Current as CamadaDados.Faturamento.Fidelizacao.TRegistro_ValeResgate).Placa +
                       "          VALE: " + (bsValeResgate.Current as CamadaDados.Faturamento.Fidelizacao.TRegistro_ValeResgate).Id_valestr);
             Texto.Add("DATA EMISSAO: " + CamadaDados.UtilData.Data_Servidor().ToString("dd/MM/yyyy HH:mm:ss"));
             //Buscar Convenio e clifor
             CamadaDados.PostoCombustivel.TList_VendaCombustivel lVenda =
                 new CamadaDados.PostoCombustivel.TCD_VendaCombustivel().Select(
                     new Utils.TpBusca[]
             {
                 new Utils.TpBusca()
                 {
                     vNM_Campo = string.Empty,
                     vOperador = "exists",
                     vVL_Busca = "(select 1 from VTB_FAT_PONTOSFIDELIDADE x " +
                                 "inner join TB_FAT_ResgatePontos y " +
                                 "on x.CD_Empresa = y.CD_Empresa " +
                                 "and x.ID_Ponto = y.ID_Ponto " +
                                 "where x.cd_empresa = a.CD_Empresa " +
                                 "and x.Id_Cupom = a.Id_Cupom " +
                                 "and y.ID_Vale = " + (bsValeResgate.Current as CamadaDados.Faturamento.Fidelizacao.TRegistro_ValeResgate).Id_valestr + ")"
                 }
             }, 1, string.Empty, string.Empty);
             //Buscar Nº Dias Validade
             if (rCfgPosto.diasValidadeVale > decimal.Zero)
             {
                 Texto.Add("DT.VALIDADE: " + CamadaDados.UtilData.Data_Servidor().AddDays(int.Parse(rCfgPosto.diasValidadeVale.ToString())).ToString("dd/MM/yyyy"));
             }
             Texto.Add(string.Empty);
             Texto.Add(string.Empty);
             //Verificar se existe msg especifica para clifor do convenio
             //Buscar msg
             if (!string.IsNullOrEmpty(lVenda[0].Nm_clifor))
             {
                 Texto.Add(lVenda[0].Nm_clifor);
                 Texto.Add(string.Empty);
                 Texto.Add(string.Empty);
             }
             string Ds_msgVale_Clifor =
                 new CamadaDados.PostoCombustivel.TCD_Convenio_Clifor().BuscarEscalar(
                     new Utils.TpBusca[]
             {
                 new Utils.TpBusca()
                 {
                     vNM_Campo = "a.cd_clifor",
                     vOperador = "=",
                     vVL_Busca = "'" + lVenda[0].Cd_clifor.Trim() + "'"
                 },
                 new Utils.TpBusca()
                 {
                     vNM_Campo = "a.id_convenio",
                     vOperador = "=",
                     vVL_Busca = lVenda[0].Id_conveniostr
                 }
             }, "a.ds_msgvale").ToString();
             if (string.IsNullOrEmpty(Ds_msgVale_Clifor))
             {
                 Texto.Add(rCfgPosto.Ds_msgvale.Trim().ToUpper());
             }
             else
             {
                 Texto.Add(Ds_msgVale_Clifor);
             }
             Texto.Add(string.Empty);
             Texto.Add(string.Empty);
             object obj = new CamadaDados.Faturamento.Fidelizacao.TCD_PontosFidelidade().BuscarEscalar(
                 new Utils.TpBusca[]
             {
                 new Utils.TpBusca()
                 {
                     vNM_Campo = "a.cd_empresa",
                     vOperador = "=",
                     vVL_Busca = "'" + rCfgPosto.Cd_empresa.Trim() + "'"
                 },
                 new Utils.TpBusca()
                 {
                     vNM_Campo = string.Empty,
                     vOperador = string.Empty,
                     vVL_Busca = "a.dt_validade is null or convert(datetime, floor(convert(decimal(30,10), a.dt_validade))) >= convert(datetime, floor(convert(decimal(30,10), getdate())))"
                 },
                 new Utils.TpBusca()
                 {
                     vNM_Campo = "replace(a.placa, '-', '')",
                     vOperador = "=",
                     vVL_Busca = "'" + placa.Text.Replace("-", string.Empty) + "'"
                 }
             }, "isnull(sum(isnull(a.qt_pontos, 0) - isnull(a.pontos_res, 0)), 0)");
             Texto.Add("PONTOS RESGATAR: " + (obj == null ? "0" : obj.ToString()));
             ImprimirVale(Texto);
             //Marcar vale como impresso
             try
             {
                 (bsValeResgate.Current as CamadaDados.Faturamento.Fidelizacao.TRegistro_ValeResgate).St_impresso = "S";
                 CamadaNegocio.Faturamento.Fidelizacao.TCN_ValeResgate.Gravar(bsValeResgate.Current as CamadaDados.Faturamento.Fidelizacao.TRegistro_ValeResgate, null);
                 afterBusca();
             }
             catch (Exception ex)
             { MessageBox.Show(ex.Message.Trim(), "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); }
         }
         catch { }
     }
 }
Esempio n. 7
0
 private void BuscarDetalhes()
 {
     if ((!string.IsNullOrEmpty(cd_empresa.Text)) &&
         (!string.IsNullOrEmpty(id_tanque.Text)) &&
         (dt_medicao.Text.Trim() != "/  /") &&
         (tp_medicao.SelectedValue != null))
     {
         //Buscar Ultima afericao tanque
         object obj = new CamadaDados.PostoCombustivel.TCD_MedicaoTanque().BuscarEscalar(
             new Utils.TpBusca[]
         {
             new Utils.TpBusca()
             {
                 vNM_Campo = "a.cd_empresa",
                 vOperador = "=",
                 vVL_Busca = "'" + cd_empresa.Text.Trim() + "'"
             },
             new Utils.TpBusca()
             {
                 vNM_Campo = "a.id_tanque",
                 vOperador = "=",
                 vVL_Busca = id_tanque.Text
             }
         }, "a.qtd_combustivel", string.Empty, "a.dt_medicao desc", null);
         if (obj != null)
         {
             ultima_afericao.Value = decimal.Parse(obj.ToString());
         }
         //Buscar volume vendido
         obj = new CamadaDados.PostoCombustivel.TCD_VendaCombustivel().BuscarEscalar(
             new Utils.TpBusca[]
         {
             new Utils.TpBusca()
             {
                 vNM_Campo = "a.cd_empresa",
                 vOperador = "=",
                 vVL_Busca = "'" + cd_empresa.Text.Trim() + "'"
             },
             new Utils.TpBusca()
             {
                 vNM_Campo = "c.id_tanque",
                 vOperador = "=",
                 vVL_Busca = id_tanque.Text
             },
             new Utils.TpBusca()
             {
                 vNM_Campo = "ISNULL(a.ST_Afericao, 'N')",
                 vOperador = "<>",
                 vVL_Busca = "'S'"
             },
             new Utils.TpBusca()
             {
                 vNM_Campo = "convert(datetime, floor(convert(decimal(30,10), a.dt_abastecimento)))",
                 vOperador = "=",
                 vVL_Busca = "'" + (tp_medicao.SelectedValue.ToString().Equals("A") ? dt_medicao.Data.AddDays(-1).ToString("yyyyMMdd") : dt_medicao.Data.ToString("yyyyMMdd")) + "'"
             }
         }, "isnull(sum(isnull(a.volumeabastecido, 0)), 0)");
         if (obj != null)
         {
             vendas_dia.Value = decimal.Parse(obj.ToString());
         }
         //Buscar compras dia
         obj = new CamadaDados.Faturamento.NotaFiscal.TCD_LanFaturamento_Item().BuscarEscalar(
             new Utils.TpBusca[]
         {
             new Utils.TpBusca()
             {
                 vNM_Campo = "a.cd_empresa",
                 vOperador = "=",
                 vVL_Busca = "'" + cd_empresa.Text.Trim() + "'"
             },
             new Utils.TpBusca()
             {
                 vNM_Campo = "nf.tp_movimento",
                 vOperador = "=",
                 vVL_Busca = "'E'"
             },
             new Utils.TpBusca()
             {
                 vNM_Campo = "isnull(nfcmi.st_mestra, 'N')",
                 vOperador = "<>",
                 vVL_Busca = "'S'"
             },
             new Utils.TpBusca()
             {
                 vNM_Campo = "isnull(nf.st_registro, 'A')",
                 vOperador = "<>",
                 vVL_Busca = "'C'"
             },
             new Utils.TpBusca()
             {
                 vNM_Campo = "convert(datetime, floor(convert(decimal(30,10), nf.dt_saient)))",
                 vOperador = "=",
                 vVL_Busca = "'" + (tp_medicao.SelectedValue.ToString().Equals("A") ? dt_medicao.Data.AddDays(-1).ToString("yyyyMMdd") : dt_medicao.Data.ToString("yyyyMMdd")) + "'"
             },
             new Utils.TpBusca()
             {
                 vNM_Campo = string.Empty,
                 vOperador = "exists",
                 vVL_Busca = "(select 1 from tb_pdc_tanque x " +
                             "where x.cd_empresa = a.cd_empresa " +
                             "and x.cd_local = a.cd_local " +
                             "and x.id_tanque = " + id_tanque.Text + ")"
             }
         }, "isnull(sum(isnull(a.Quantidade, 0)), 0)");
         if (obj != null)
         {
             compras_dia.Value = decimal.Parse(obj.ToString());
         }
     }
 }
Esempio n. 8
0
 private void afterGrava()
 {
     if (pDados.validarCampoObrigatorio())
     {
         if (bsConvenio.Current == null)
         {
             MessageBox.Show("Não existe portador selecionado para receber convenio.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
             return;
         }
         if (cpf_motorista.Focused)
         {
             cpf_motorista_Leave(cpf_motorista.Text, new EventArgs());
             return;
         }
         if (st_exigirrequisicao.Checked && string.IsNullOrEmpty(nr_requisicao.Text))
         {
             MessageBox.Show("Convênio exige REQUISIÇÃO para abastecimento.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
             nr_requisicao.Focus();
             return;
         }
         if (st_exigirnomemot.Checked && string.IsNullOrEmpty(nm_motorista.Text))
         {
             MessageBox.Show("Convênio exige NOME DO MOTORISTA.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
             nm_motorista.Focus();
             return;
         }
         if ((bsConvenio.Current as CamadaDados.PostoCombustivel.TRegistro_Convenio).lClifor.Find(p => p.Cd_produto.Equals(lVenda[0].Cd_produto)).Tp_pontos_fid.Trim().ToUpper().Equals("P") &&
             (placa.Text.Trim().Length < 8))
         {
             MessageBox.Show("Convenio exige PLACA para gerar pontuação.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
             placa.Focus();
             return;
         }
         if ((bsConvenio.Current as CamadaDados.PostoCombustivel.TRegistro_Convenio).lClifor.Find(p => p.Cd_produto.Equals(lVenda[0].Cd_produto)).Tp_pontos_fid.Trim().ToUpper().Equals("M") &&
             string.IsNullOrEmpty(cpf_motorista.Text.SoNumero()))
         {
             MessageBox.Show("Convenio exige CPF MOTORISTA para gerar pontuação.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
             cpf_motorista.Focus();
             return;
         }
         decimal KM = decimal.Zero;
         if (!this.ValidarKm(ref KM))
         {
             if (MessageBox.Show("KM Atual não pode ser menor ou igual ao ultimo KM informado para a placa (Ultimo KM: " + KM.ToString("N0", new System.Globalization.CultureInfo("pt-BR")) + ").\r\n" +
                                 "Deseja corrigir ultimo KM informado?", "Pergunta",
                                 MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
             {
                 //Buscar abastecida do ultimo KM
                 CamadaDados.PostoCombustivel.TList_VendaCombustivel lVendaUltimoKM =
                     new CamadaDados.PostoCombustivel.TCD_VendaCombustivel().Select(
                         new TpBusca[]
                 {
                     new TpBusca()
                     {
                         vNM_Campo = "replace(a.placaveiculo, '-', '')",
                         vOperador = "=",
                         vVL_Busca = "'" + placa.Text.Trim().Replace("-", "") + "'"
                     }
                 }, 1, string.Empty, "a.dt_abastecimento desc");
                 if (lVendaUltimoKM.Count > 0)
                 {
                     using (PDV.TFCorrigirKM fKM = new PDV.TFCorrigirKM())
                     {
                         fKM.Ultimo_km = lVendaUltimoKM[0].Km_atual;
                         fKM.Km_atual  = km.Value;
                         if (fKM.ShowDialog() == DialogResult.OK)
                         {
                             try
                             {
                                 lVendaUltimoKM[0].Km_atual = fKM.Km_corrigido;
                                 CamadaNegocio.PostoCombustivel.TCN_VendaCombustivel.Gravar(lVendaUltimoKM[0], null);
                                 MessageBox.Show("Ultimo KM corrigido com sucesso.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
                             }
                             catch (Exception ex)
                             { MessageBox.Show(ex.Message.Trim(), "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); }
                         }
                     }
                 }
             }
             else
             {
                 if (MessageBox.Show("Deseja informar KM maximo do hodometro?", "Pergunta", MessageBoxButtons.YesNo,
                                     MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                 {
                     using (Componentes.TFQuantidade fQtd = new Componentes.TFQuantidade())
                     {
                         fQtd.Ds_label = "KM Maximo Hodometro";
                         fQtd.ShowDialog();
                         if (fQtd.Quantidade >= KM)
                         {
                             Km_maximo = fQtd.Quantidade;
                         }
                         else
                         {
                             km.Focus();
                             return;
                         }
                     }
                 }
                 else
                 {
                     km.Focus();
                     return;
                 }
             }
         }
         object obj_km = new CamadaDados.PostoCombustivel.TCD_Convenio_Placa().BuscarEscalar(
             new TpBusca[]
         {
             new TpBusca()
             {
                 vNM_Campo = "a.cd_empresa",
                 vOperador = "=",
                 vVL_Busca = "'" + (bsConvenio.Current as CamadaDados.PostoCombustivel.TRegistro_Convenio).Cd_empresa.Trim() + "'"
             },
             new TpBusca()
             {
                 vNM_Campo = "a.id_convenio",
                 vOperador = "=",
                 vVL_Busca = (bsConvenio.Current as CamadaDados.PostoCombustivel.TRegistro_Convenio).Id_conveniostr
             },
             new TpBusca()
             {
                 vNM_Campo = "a.cd_clifor",
                 vOperador = "=",
                 vVL_Busca = "'" + cd_clifor.Text.Trim() + "'"
             },
             new TpBusca()
             {
                 vNM_Campo = "a.cd_endereco",
                 vOperador = "=",
                 vVL_Busca = "'" + cd_endereco.Text.Trim() + "'"
             },
             new TpBusca()
             {
                 vNM_Campo = "a.cd_produto",
                 vOperador = "=",
                 vVL_Busca = "'" + lVenda[0].Cd_produto.Trim() + "'"
             },
             new TpBusca()
             {
                 vNM_Campo = "a.placa",
                 vOperador = "=",
                 vVL_Busca = "'" + placa.Text.Trim() + "'"
             }
         }, "a.st_km");
         if ((bsConvenio.Current as CamadaDados.PostoCombustivel.TRegistro_Convenio).lClifor.Find(p => p.Cd_produto.Equals(lVenda[0].Cd_produto)).St_placaconveniadabool&& (obj_km == null))
         {
             MessageBox.Show("Convenio permite abastecer somente placa cadastrada.\r\n" +
                             "A placa " + placa.Text + " não consta na lista permitida pelo convenio " + (bsConvenio.Current as CamadaDados.PostoCombustivel.TRegistro_Convenio).Id_conveniostr,
                             "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
             placa.Focus();
             return;
         }
         if ((obj_km == null ? false : obj_km.ToString().Trim().ToUpper().Equals("S")) && km.Value.Equals(decimal.Zero))
         {
             MessageBox.Show("Convenio exige KM atual para a placa informada.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
             km.Focus();
             return;
         }
         if ((bsConvenio.Current as CamadaDados.PostoCombustivel.TRegistro_Convenio).lClifor.Find(p => p.Cd_produto.Equals(lVenda[0].Cd_produto)).St_motconveniadobool)
         {
             if (new CamadaDados.PostoCombustivel.TCD_Convenio_Motorista().BuscarEscalar(
                     new TpBusca[]
             {
                 new TpBusca()
                 {
                     vNM_Campo = "a.cd_empresa",
                     vOperador = "=",
                     vVL_Busca = "'" + (bsConvenio.Current as CamadaDados.PostoCombustivel.TRegistro_Convenio).Cd_empresa.Trim() + "'"
                 },
                 new TpBusca()
                 {
                     vNM_Campo = "a.id_convenio",
                     vOperador = "=",
                     vVL_Busca = (bsConvenio.Current as CamadaDados.PostoCombustivel.TRegistro_Convenio).Id_conveniostr
                 },
                 new TpBusca()
                 {
                     vNM_Campo = "a.cd_clifor",
                     vOperador = "=",
                     vVL_Busca = "'" + cd_clifor.Text.Trim() + "'"
                 },
                 new TpBusca()
                 {
                     vNM_Campo = "a.cd_endereco",
                     vOperador = "=",
                     vVL_Busca = "'" + cd_endereco.Text.Trim() + "'"
                 },
                 new TpBusca()
                 {
                     vNM_Campo = "a.cd_produto",
                     vOperador = "=",
                     vVL_Busca = "'" + lVenda[0].Cd_produto.Trim() + "'"
                 },
                 new TpBusca()
                 {
                     vNM_Campo = "a.cpf_motorista",
                     vOperador = "=",
                     vVL_Busca = "'" + cpf_motorista.Text.Trim() + "'"
                 }
             }, "1") == null)
             {
                 MessageBox.Show("Convenio permite abastecer somente motorista cadastrado.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 cpf_motorista.Focus();
                 return;
             }
         }
         if (lCred == null)
         {
             if (CamadaNegocio.ConfigGer.TCN_CadParamGer.BuscaVL_Bool("ST_IDENT_CLIFOR_CRED", (bsConvenio.Current as CamadaDados.PostoCombustivel.TRegistro_Convenio).Cd_empresa, null).Trim().ToUpper().Equals("S"))
             {
                 if (CamadaNegocio.Financeiro.Adiantamento.TCN_LanAdiantamento.Buscar(string.Empty,
                                                                                      (bsConvenio.Current as CamadaDados.PostoCombustivel.TRegistro_Convenio).Cd_empresa,
                                                                                      cd_clifor.Text,
                                                                                      string.Empty,
                                                                                      "'R'",
                                                                                      string.Empty,
                                                                                      decimal.Zero,
                                                                                      string.Empty,
                                                                                      string.Empty,
                                                                                      decimal.Zero,
                                                                                      decimal.Zero,
                                                                                      false,
                                                                                      false,
                                                                                      true,
                                                                                      string.Empty,
                                                                                      false,
                                                                                      true,
                                                                                      string.Empty,
                                                                                      string.Empty,
                                                                                      0,
                                                                                      string.Empty,
                                                                                      null).Count > 0)
                 {
                     this.DevolverCredito();
                 }
             }
         }
         if (vl_dupvencidas.Value > decimal.Zero)
         {
             MessageBox.Show("Cliente possui duplicata vencida.", "Lembrete", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         this.DialogResult = DialogResult.OK;
     }
 }
Esempio n. 9
0
        private void ImprimirDanfe()
        {
            //Verificar status NFe
            object obj = new CamadaDados.Faturamento.NFCe.TCD_Lote_X_NFCe().BuscarEscalar(
                new Utils.TpBusca[]
            {
                new Utils.TpBusca()
                {
                    vNM_Campo = "a.cd_empresa",
                    vOperador = "=",
                    vVL_Busca = "'" + rNFCe.Cd_empresa.Trim() + "'"
                },
                new Utils.TpBusca()
                {
                    vNM_Campo = "a.id_cupom",
                    vOperador = "=",
                    vVL_Busca = rNFCe.Id_nfcestr
                },
                new Utils.TpBusca()
                {
                    vNM_Campo = string.Empty,
                    vOperador = "exists",
                    vVL_Busca = "(select 1 from TB_FAT_LoteNFCe x " +
                                "where x.id_lote = a.id_lote " +
                                "and x.cd_empresa = a.cd_empresa " +
                                "and x.st_registro = 'P' " +
                                "and x.status = '104')"
                }
            }, "a.status");

            if (obj != null)
            {
                if (obj.ToString().Trim().Equals("100"))
                {
                    try
                    {
                        FormRelPadrao.Relatorio Rel = new FormRelPadrao.Relatorio();
                        Rel.Altera_Relatorio = Altera_Relatorio;
                        BindingSource dts = new BindingSource();
                        dts.DataSource    = new CamadaDados.Faturamento.PDV.TList_NFCe_Item();
                        Rel.DTS_Relatorio = dts;// bsItens;
                        //DTS Cupom
                        BindingSource bsNFCe = new BindingSource();
                        bsNFCe.DataSource = new CamadaDados.Faturamento.PDV.TList_NFCe()
                        {
                            rNFCe
                        };
                        TGerarQRCode.GerarQRCode2(rNFCe);
                        Rel.Adiciona_DataSource("DTS_NFCE", bsNFCe);
                        //Buscar Empresa
                        BindingSource bsEmpresa = new BindingSource();
                        bsEmpresa.DataSource = CamadaNegocio.Diversos.TCN_CadEmpresa.Busca(rNFCe.Cd_empresa,
                                                                                           string.Empty,
                                                                                           string.Empty,
                                                                                           null);
                        Rel.Adiciona_DataSource("DTS_EMP", bsEmpresa);
                        //Forma Pagamento
                        BindingSource bsPagto = new BindingSource();
                        if (rNFCe.lDup.Count > 0)
                        {
                            rNFCe.lPagto.Add(new CamadaDados.Faturamento.PDV.TRegistro_MovCaixa()
                            {
                                Tp_portador = "05",
                                Vl_recebido = rNFCe.lDup[0].Vl_documento
                            });
                        }

                        //Ocorre quando cupom emitido pelo delivery
                        //logo não informando condição de pagamento
                        if (rNFCe.lPagto.Count.Equals(0))
                        {
                            rNFCe.lPagto.Add(new CamadaDados.Faturamento.PDV.TRegistro_MovCaixa()
                            {
                                Tp_portador = "01",
                                Vl_recebido = rNFCe.lItem.Sum(p => p.Vl_subtotal)
                            });
                        }

                        bsPagto.DataSource = rNFCe.lPagto;
                        Rel.Adiciona_DataSource("DTS_PAGTO", bsPagto);
                        //Parametros
                        Rel.Parametros_Relatorio.Add("TOT_IMP_APROX", rNFCe.lItem.Sum(p => p.Vl_imposto_Aprox));
                        Rel.Parametros_Relatorio.Add("QTD_ITENS", rNFCe.lItem.Count);
                        Rel.Parametros_Relatorio.Add("TOT_SUBTOTAL", rNFCe.lItem.Sum(p => p.Vl_subtotal));
                        Rel.Parametros_Relatorio.Add("TOT_ACRESCIMO", rNFCe.lItem.Sum(p => p.Vl_acrescimo));
                        Rel.Parametros_Relatorio.Add("TOT_DESCONTO", rNFCe.lItem.Sum(p => p.Vl_desconto));
                        Rel.Parametros_Relatorio.Add("ST_VIAEMPRESA", "N");
                        obj = new CamadaDados.Faturamento.NFCe.TCD_LoteNFCe().BuscarEscalar(
                            new Utils.TpBusca[]
                        {
                            new Utils.TpBusca()
                            {
                                vNM_Campo = string.Empty,
                                vOperador = "exists",
                                vVL_Busca = "(select 1 from TB_FAT_Lote_X_NFCe x " +
                                            "where x.cd_empresa = a.cd_empresa " +
                                            "and x.id_lote = a.id_lote " +
                                            "and x.status = '100')"
                            }
                        }, "a.tp_ambiente");
                        Rel.Parametros_Relatorio.Add("TP_AMBIENTE", obj == null ? string.Empty : obj.ToString());
                        string dadoscf = CamadaNegocio.Faturamento.PDV.TCN_NFCe.BuscarPlacaKM(rNFCe.Cd_empresa,
                                                                                              rNFCe.Id_nfcestr,
                                                                                              null);
                        if (!string.IsNullOrEmpty(dadoscf))
                        {
                            string[] linhas        = dadoscf.Split(new char[] { ':' });
                            string   placa         = string.Empty;
                            string   km            = string.Empty;
                            string   frota         = string.Empty;
                            string   requisicao    = string.Empty;
                            string   nm_motorista  = string.Empty;
                            string   cpf_motorista = string.Empty;
                            string   media         = string.Empty;
                            string   virg          = string.Empty;
                            foreach (string s in linhas)
                            {
                                string[] colunas = s.Split(new char[] { '/' });
                                placa         += virg + colunas[0];
                                km            += virg + colunas[1];
                                frota         += virg + colunas[2];
                                requisicao    += virg + colunas[3];
                                nm_motorista  += virg + colunas[4];
                                cpf_motorista += virg + colunas[5];
                                media         += virg + colunas[6];
                                virg           = ",";
                            }
                            if (!string.IsNullOrEmpty(placa))
                            {
                                Rel.Parametros_Relatorio.Add("PLACA", placa);
                            }
                            if (!string.IsNullOrEmpty(km))
                            {
                                Rel.Parametros_Relatorio.Add("KM", km);
                            }
                            if (!string.IsNullOrEmpty(media))
                            {
                                Rel.Parametros_Relatorio.Add("MEDIA", media + " KM/LT");
                            }
                            if (!string.IsNullOrEmpty(frota))
                            {
                                Rel.Parametros_Relatorio.Add("FROTA", frota);
                            }
                            if (!string.IsNullOrEmpty(requisicao))
                            {
                                Rel.Parametros_Relatorio.Add("REQUISICAO", requisicao);
                            }
                            if (!string.IsNullOrEmpty(nm_motorista))
                            {
                                Rel.Parametros_Relatorio.Add("NM_MOTORISTA", nm_motorista);
                            }
                            if (!string.IsNullOrEmpty(cpf_motorista))
                            {
                                Rel.Parametros_Relatorio.Add("CPF_MOTORISTA", cpf_motorista);
                            }
                        }
                        Rel.Nome_Relatorio = "DANFE_NFCE";
                        Rel.NM_Classe      = "TFConsultaFrenteCaixa";
                        Rel.Modulo         = "FAT";
                        Rel.Ident          = "DANFE_NFCE";
                        if (CamadaNegocio.ConfigGer.TCN_CadParamGer.BuscaVlBool("ST_IMP_DANFE_NFCE_DETALHADA", null))
                        {
                            BindingSource bsItens = new BindingSource();
                            bsItens.DataSource = CamadaNegocio.Faturamento.PDV.TCN_NFCe_Item.Buscar(rNFCe.Id_nfcestr,
                                                                                                    rNFCe.Cd_empresa,
                                                                                                    string.Empty,
                                                                                                    null);
                            //Buscar Encerrantes das Abastecidas
                            (bsItens.List as CamadaDados.Faturamento.PDV.TList_NFCe_Item).Where(p => p.St_combustivel).ToList().ForEach(p =>
                            {
                                CamadaDados.PostoCombustivel.TList_VendaCombustivel lVComp =
                                    new CamadaDados.PostoCombustivel.TCD_VendaCombustivel().Select(
                                        new Utils.TpBusca[]
                                {
                                    new Utils.TpBusca()
                                    {
                                        vNM_Campo = string.Empty,
                                        vOperador = "exists",
                                        vVL_Busca = "(select 1 from tb_pdv_cupom_x_vendarapida x " +
                                                    "where x.cd_empresa = a.cd_empresa " +
                                                    "and x.id_vendarapida = a.id_cupom " +
                                                    "and x.id_lanctovenda = a.id_lancto " +
                                                    "and x.cd_empresa = '" + p.Cd_empresa.Trim() + "' " +
                                                    "and x.id_cupom = " + p.ID_NFCe.Value.ToString() + " " +
                                                    "and x.id_lancto = " + p.Id_lancto.Value.ToString() + ")"
                                    }
                                }, 0, string.Empty, string.Empty);
                                if (lVComp.Count > 0)
                                {
                                    p.NR_Bico       = lVComp[0].Id_bicostr;
                                    p.EncerranteFin = lVComp[0].Encerrantebico;
                                }
                            });
                            Rel.DTS_Relatorio = bsItens;
                        }
                        if (rNFCe.Id_contingencia.HasValue)
                        {
                            if (Rel.Parametros_Relatorio.ContainsKey("ST_VIAEMPRESA"))
                            {
                                Rel.Parametros_Relatorio["ST_VIAEMPRESA"] = "S";
                            }
                            else
                            {
                                Rel.Parametros_Relatorio.Add("ST_VIAEMPRESA", "S");
                            }
                        }

                        //Verificar se existe Impressora padrão para o PDV
                        obj = new CamadaDados.Faturamento.Cadastros.TCD_PontoVenda().BuscarEscalar(
                            new Utils.TpBusca[]
                        {
                            new Utils.TpBusca()
                            {
                                vNM_Campo = "a.cd_terminal",
                                vOperador = "=",
                                vVL_Busca = "'" + Utils.Parametros.pubTerminal.Trim() + "'"
                            }
                        }, "a.impressorapadrao");
                        string print = obj == null ? string.Empty : obj.ToString();
                        if (string.IsNullOrEmpty(print))
                        {
                            using (Parametros.Diversos.TFListaImpressoras fLista = new Parametros.Diversos.TFListaImpressoras())
                            {
                                if (fLista.ShowDialog() == DialogResult.OK)
                                {
                                    if (!string.IsNullOrEmpty(fLista.Impressora))
                                    {
                                        print = fLista.Impressora;
                                    }
                                }
                            }
                        }
                        //Verificar se cliente possui email
                        obj = new CamadaDados.Financeiro.Cadastros.TCD_CadClifor().BuscarEscalar(
                            new Utils.TpBusca[] { new Utils.TpBusca {
                                                      vNM_Campo = "a.cd_clifor", vOperador = "=", vVL_Busca = "'" + rNFCe.Cd_clifor.Trim() + "'"
                                                  } }, "a.email");
                        //Imprimir
                        if (!string.IsNullOrEmpty(print) || obj != null)
                        {
                            Rel.ImprimiGraficoReduzida(print,
                                                       !string.IsNullOrEmpty(print),
                                                       false,
                                                       obj == null ? null : string.IsNullOrEmpty(obj.ToString()) ? null : new List <string> {
                                obj.ToString()
                            },
                                                       "NFC-e " + rNFCe.Nm_empresa.Trim(),
                                                       "Segue em anexo arquivo da NFC-e no formato .PDF",
                                                       1);
                            if (rNFCe.Id_contingencia.HasValue && rNFCe.rCfgNFCe.Tp_ambiente_nfce.Equals(1) && !string.IsNullOrEmpty(print))
                            {
                                Rel.ImprimiGraficoReduzida(print,
                                                           true,
                                                           false,
                                                           null,
                                                           string.Empty,
                                                           string.Empty,
                                                           1);
                            }
                        }
                    }
                    catch { }
                }
                else
                {
                    MessageBox.Show("Lote Processado com Sucesso.\r\nNFCe não foi aceita pela receita.\r\n" +
                                    "Verifique o erro na tela de controle de NFCe.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                MessageBox.Show("Erro ao processar Lote NFCe.\r\n" +
                                "Verifique o erro na tela de controle de NFCe.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }