private void afterBusca() { Utils.TpBusca[] filtro = new Utils.TpBusca[1]; filtro[0].vNM_Campo = "cf.cd_empresa"; filtro[0].vOperador = "="; filtro[0].vVL_Busca = "'" + Cd_empresa.Trim() + "'"; if (dt_ini.Text.Trim() != "/ /") { Array.Resize(ref filtro, filtro.Length + 1); filtro[filtro.Length - 1].vNM_Campo = "convert(datetime, floor(convert(decimal(30,10), cf.dt_emissao)))"; filtro[filtro.Length - 1].vOperador = ">="; filtro[filtro.Length - 1].vVL_Busca = "'" + DateTime.Parse(dt_ini.Text).ToString("yyyyMMdd") + "'"; } if (dt_fin.Text.Trim() != "/ /") { Array.Resize(ref filtro, filtro.Length + 1); filtro[filtro.Length - 1].vNM_Campo = "convert(datetime, floor(convert(decimal(30,10), cf.dt_emissao)))"; filtro[filtro.Length - 1].vOperador = "<="; filtro[filtro.Length - 1].vVL_Busca = "'" + DateTime.Parse(dt_fin.Text).ToString("yyyyMMdd") + "'"; } CamadaDados.Faturamento.PDV.TList_VendaRapida_Item lItens = new CamadaDados.Faturamento.PDV.TCD_VendaRapida_Item().SelectCFFechamento(filtro); //Agrupar por produto bsGrupoProd.DataSource = lItens.GroupBy(p => p.Ds_produto, (aux, venda) => new { produto = aux, quantidade = venda.Sum(x => x.Quantidade), vl_subtotal = venda.Sum(x => x.Vl_subtotal), vl_desconto = venda.Sum(x => x.Vl_desconto), vl_liquido = venda.Sum(x => x.Vl_subtotalliquido) }); //Totalizar tot_venda.Value = lItens.Sum(p => p.Vl_subtotal); tot_desconto.Value = lItens.Sum(p => p.Vl_desconto); tot_liquido.Value = lItens.Sum(p => p.Vl_subtotalliquido); bsItens.DataSource = lItens; }
private void afterBusca() { if (string.IsNullOrEmpty(CD_Empresa.Text)) { MessageBox.Show("Obrigatorio informar empresa.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information); CD_Empresa.Focus(); return; } Utils.TpBusca[] filtro = new Utils.TpBusca[5]; //Empresa filtro[0].vNM_Campo = "vr.cd_empresa"; filtro[0].vOperador = "="; filtro[0].vVL_Busca = "'" + CD_Empresa.Text.Trim() + "'"; //Venda Ativa filtro[1].vNM_Campo = "isnull(vr.st_registro, 'A')"; filtro[1].vOperador = "<>"; filtro[1].vVL_Busca = "'C'"; //Nao ter gerado cupom filtro[2].vNM_Campo = string.Empty; filtro[2].vOperador = "not exists"; filtro[2].vVL_Busca = "(select 1 from tb_pdv_cupom_x_vendarapida x " + "where x.cd_empresa = a.cd_empresa " + "and x.id_vendarapida = a.id_vendarapida " + "and x.id_lanctovenda = a.id_lanctovenda)"; //Nao ter gerado pedido filtro[3].vNM_Campo = string.Empty; filtro[3].vOperador = "not exists"; filtro[3].vVL_Busca = "(select 1 from TB_PDV_Pedido_X_VendaRapida x " + "inner join TB_FAT_Pedido y " + "on x.nr_pedido = y.nr_pedido " + "where x.cd_empresa = a.cd_empresa " + "and x.id_vendarapida = a.id_vendarapida " + "and x.id_lanctovenda = a.id_lanctovenda " + "and isnull(y.st_pedido, 'F') <> 'C')"; //Item nao pode ser servico filtro[4].vNM_Campo = "isnull(tp.st_servico, 'N')"; filtro[4].vOperador = "<>"; filtro[4].vVL_Busca = "'S'"; //Cupom finalizador somente de produto combustivel if (st_combustivel.Checked) { Array.Resize(ref filtro, filtro.Length + 1); filtro[filtro.Length - 1].vNM_Campo = "isnull(tp.st_combustivel, 'N')"; filtro[filtro.Length - 1].vOperador = "="; filtro[filtro.Length - 1].vVL_Busca = "'S'"; } if (!string.IsNullOrEmpty(id_venda.Text)) { Array.Resize(ref filtro, filtro.Length + 1); filtro[filtro.Length - 1].vNM_Campo = "a.id_vendarapida"; filtro[filtro.Length - 1].vOperador = "="; filtro[filtro.Length - 1].vVL_Busca = id_venda.Text; } if (!string.IsNullOrEmpty(cd_clifor.Text)) { Array.Resize(ref filtro, filtro.Length + 1); filtro[filtro.Length - 1].vNM_Campo = "vr.cd_clifor"; filtro[filtro.Length - 1].vOperador = "="; filtro[filtro.Length - 1].vVL_Busca = "'" + cd_clifor.Text.Trim() + "'"; } if (dt_ini.Text.Trim() != "/ /") { Array.Resize(ref filtro, filtro.Length + 1); filtro[filtro.Length - 1].vNM_Campo = "convert(datetime, floor(convert(decimal(30,10), vr.dt_emissao)))"; filtro[filtro.Length - 1].vOperador = ">="; filtro[filtro.Length - 1].vVL_Busca = "'" + string.Format(new System.Globalization.CultureInfo("en-US", true), Convert.ToDateTime(dt_ini.Text).ToString("yyyyMMdd")) + " 00:00:00'"; } if (dt_fin.Text.Trim() != "/ /") { Array.Resize(ref filtro, filtro.Length + 1); filtro[filtro.Length - 1].vNM_Campo = "convert(datetime, floor(convert(decimal(30,10), vr.dt_emissao)))"; filtro[filtro.Length - 1].vOperador = "<="; filtro[filtro.Length - 1].vVL_Busca = "'" + string.Format(new System.Globalization.CultureInfo("en-US", true), Convert.ToDateTime(dt_fin.Text).ToString("yyyyMMdd")) + " 23:59:59'"; } if (!string.IsNullOrEmpty(cd_produto.Text)) { Array.Resize(ref filtro, filtro.Length + 1); filtro[filtro.Length - 1].vNM_Campo = "a.cd_produto"; filtro[filtro.Length - 1].vOperador = "="; filtro[filtro.Length - 1].vVL_Busca = "'" + cd_produto.Text.Trim() + "'"; } if (!string.IsNullOrEmpty(tp_produto.Text)) { Array.Resize(ref filtro, filtro.Length + 1); filtro[filtro.Length - 1].vNM_Campo = "tp.tp_produto"; filtro[filtro.Length - 1].vOperador = "="; filtro[filtro.Length - 1].vVL_Busca = "'" + tp_produto.Text.Trim() + "'"; } if (!string.IsNullOrEmpty(login.Text)) { Array.Resize(ref filtro, filtro.Length + 1); filtro[filtro.Length - 1].vNM_Campo = string.Empty; filtro[filtro.Length - 1].vOperador = "exists"; filtro[filtro.Length - 1].vVL_Busca = "(select 1 from tb_pdv_sessao x " + "where x.id_pdv = a.id_pdv " + "and x.id_sessao = a.id_sessao " + "and x.login = '******')"; } if (vl_inicial.Value > 0) { Array.Resize(ref filtro, filtro.Length + 1); filtro[filtro.Length - 1].vNM_Campo = "vr.vl_cupom"; filtro[filtro.Length - 1].vVL_Busca = vl_inicial.Value.ToString("N2", new System.Globalization.CultureInfo("en-US", true)); filtro[filtro.Length - 1].vOperador = ">="; } if (vl_final.Value > 0) { Array.Resize(ref filtro, filtro.Length + 1); filtro[filtro.Length - 1].vNM_Campo = "vr.vl_cupom"; filtro[filtro.Length - 1].vVL_Busca = vl_final.Value.ToString("N2", new System.Globalization.CultureInfo("en-US", true)); filtro[filtro.Length - 1].vOperador = "<="; } if (st_vendacaixaaberto.Checked) { Array.Resize(ref filtro, filtro.Length + 1); filtro[filtro.Length - 1].vNM_Campo = string.Empty; filtro[filtro.Length - 1].vOperador = "exists"; filtro[filtro.Length - 1].vVL_Busca = "(select 1 from tb_pdv_cupom_x_movcaixa x " + "inner join tb_pdv_caixa y " + "on x.id_caixa = y.id_caixa " + "where x.id_cupom = a.id_cupom " + "and isnull(y.st_registro, 'A') = 'A')"; } CamadaDados.Faturamento.PDV.TList_VendaRapida_Item lItem = new CamadaDados.Faturamento.PDV.TCD_VendaRapida_Item().Select(filtro, 0, string.Empty, string.Empty); tot_venda.Value = lItem.Sum(p => p.Vl_subtotal); tot_desconto.Value = lItem.Sum(p => p.Vl_desconto); tot_liquido.Value = lItem.Sum(p => p.Vl_subtotalliquido); bsItens.DataSource = lItem; }