public static void RecalculaParc(TList_PreVenda_DT_Vencto lParc, TRegistro_PreVenda val, int index) { if (lParc != null) { if (lParc.Sum(p => p.Vl_parcela) != (val.Vl_prevenda - val.Vl_devcred)) { decimal vl_parc = val.Vl_prevenda - val.Vl_devcred - lParc.Sum(p => p.Vl_parcela); decimal nParcelas = (lParc.Count - (index + 1)); if (nParcelas.Equals(0)) { nParcelas = 1; } vl_parc = (vl_parc / nParcelas); for (int i = ++index; i < lParc.Count; i++) { lParc[i].Vl_parcela += vl_parc; } lParc[lParc.Count - 1].Vl_parcela += val.Vl_prevenda - val.Vl_devcred - lParc.Sum(p => p.Vl_parcela); //Recalcular Parcelas se valor informado for maior que valor a faturar decimal somaParcAnt = SomaParcelasAnt(lParc, index); if ((somaParcAnt) > val.Vl_prevenda - val.Vl_devcred) { lParc[index - 1].Vl_parcela = (val.Vl_prevenda - val.Vl_devcred - (somaParcAnt - lParc[index - 1].Vl_parcela) - nParcelas); for (int i = index; i < lParc.Count; i++) { lParc[i].Vl_parcela = 1; } } } } }
public static TList_PreVenda_DT_Vencto ReCalcula_VlParcela(TRegistro_PreVenda val, bool St_calcular) { //Recalcular vl.parcela quando for faturar prevenda com duplicata TList_PreVenda_DT_Vencto retorno = new TList_PreVenda_DT_Vencto(); if (((val.Vl_prevenda - val.Vl_devcred) > 0) && (!string.IsNullOrEmpty(val.Cd_condPgto)) && (val.QTD_Parcelas > 0) && (St_calcular)) { decimal vl_parcela = Math.Round((val.Vl_prevenda - val.Vl_devcred) / val.QTD_Parcelas, 2); int cont = 1; val.DT_Vencto.ForEach(p => { retorno.Add(new CamadaDados.Faturamento.PDV.TRegistro_PreVenda_DT_Vencto() { DiasVencto = p.DiasVencto, Vl_parcela = vl_parcela, id_parcela = cont++ }); }); if (retorno.Count > 0) { retorno[retorno.Count - 1].Vl_parcela += val.Vl_prevenda - val.Vl_devcred - retorno.Sum(p => p.Vl_parcela); } } return(retorno); }
public static TList_PreVenda_DT_Vencto Calcula_Parcelas(TRegistro_PreVenda val, bool St_calcular) { TList_PreVenda_DT_Vencto retorno = new TList_PreVenda_DT_Vencto(); if (((val.Vl_prevenda - val.Vl_devcred) > 0) && (!string.IsNullOrEmpty(val.Cd_condPgto)) && (val.QTD_Parcelas > 0) && (St_calcular)) { TList_Parcelas Lista_Parcela = TLanCalcParcelas.CalcularParcelas(val.Vl_prevenda - val.Vl_devcred, val.Vl_prevenda - val.Vl_devcred, val.Dt_emissao.Value, val.QTD_Parcelas, val.Parcelas_Dias_Desdobro); int cont = 1; Lista_Parcela.ForEach(p => { retorno.Add( new CamadaDados.Faturamento.PDV.TRegistro_PreVenda_DT_Vencto() { DiasVencto = p.Dt_vencimento.Value.Subtract(val.Dt_prevenda.Value).Days, Vl_parcela = p.Vl_parcela, id_parcela = cont++ }); }); } return(retorno); }
public static void RatearAcrescimo(TRegistro_PreVenda val, decimal Tot_acrescimo, decimal Pc_acrescimo) { if (val != null) { decimal tot_subtotal = val.lItens.Sum(p => p.Vl_subtotal); if (Pc_acrescimo.Equals(decimal.Zero)) { Pc_acrescimo = Math.Round(decimal.Divide(decimal.Multiply(Tot_acrescimo, 100), tot_subtotal), 2, MidpointRounding.AwayFromZero); } if (Tot_acrescimo.Equals(decimal.Zero)) { Tot_acrescimo = Math.Round(decimal.Divide(decimal.Multiply(Pc_acrescimo, tot_subtotal), 100), 2, MidpointRounding.AwayFromZero); } val.lItens.ForEach(p => { p.Vl_acrescimo = Math.Round(decimal.Multiply(p.Vl_subtotal, decimal.Divide(Pc_acrescimo, 100)), 2, MidpointRounding.AwayFromZero); p.Pc_acrescimo = Pc_acrescimo; }); decimal dif = Tot_acrescimo - val.lItens.Sum(p => p.Vl_acrescimo); if (dif != decimal.Zero) { val.lItens.FindLast(p => p.Vl_acrescimo + dif >= decimal.Zero).Vl_acrescimo += dif; } } }
public static string FecharComanda(TRegistro_PreVenda val, BancoDados.TObjetoBanco banco) { bool st_transacao = false; TCD_PreVenda qtb_orc = new TCD_PreVenda(); try { if (banco == null) { st_transacao = qtb_orc.CriarBanco_Dados(true); } else { qtb_orc.Banco_Dados = banco; } //Gravar Venda Restaurante val.lVenda.ForEach(p => { p.st_restaurante = true; Faturamento.PDV.TCN_VendaRapida.GravarVendaRapida(p, null, null, qtb_orc.Banco_Dados); }); //Mudar status Delivery para fechado //todo aqui qtb_orc.executarSql("update TB_RES_PreVenda set ST_Delivery = 'F', Dt_Alt = GETDATE() " + "where cd_empresa = '" + val.Cd_empresa.Trim() + "' " + "and id_prevenda = " + val.id_prevenda.ToString(), null); if (st_transacao) { qtb_orc.Banco_Dados.Commit_Tran(); } return(val.id_prevenda.ToString()); } catch (Exception ex) { if (st_transacao) { qtb_orc.Banco_Dados.RollBack_Tran(); } throw new Exception("Erro gravar pre venda: " + ex.Message.Trim()); } finally { if (st_transacao) { qtb_orc.deletarBanco_Dados(); } } }
public static void RatearFrete(TRegistro_PreVenda val, decimal Tot_frete) { if (val != null) { //Ratear Frete de acordo com a % do Item val.lItens.ForEach(p => { decimal pc_frete = Math.Round(decimal.Multiply(decimal.Divide(p.Vl_subtotal, val.lItens.Sum(x => x.Vl_subtotal)), 100), 2, MidpointRounding.AwayFromZero); p.Vl_frete = Math.Round(decimal.Divide(decimal.Multiply(Tot_frete, pc_frete), 100), 2, MidpointRounding.AwayFromZero); }); val.lItens[val.lItens.Count - 1].Vl_frete += Tot_frete - val.lItens.Sum(p => p.Vl_frete); } }
public static string CancelarPreVenda(TRegistro_PreVenda val, BancoDados.TObjetoBanco banco) { bool st_transacao = false; TCD_PreVenda qtb_orc = new TCD_PreVenda(); try { if (banco == null) { st_transacao = qtb_orc.CriarBanco_Dados(true); } else { qtb_orc.Banco_Dados = banco; } val.lItens.ForEach(p => { p.st_registro = "C"; TCN_PreVenda_Item.Gravar(p, qtb_orc.Banco_Dados); }); val.st_ativo = "C"; qtb_orc.Gravar(val); if (st_transacao) { qtb_orc.Banco_Dados.Commit_Tran(); } return("OK"); } catch (Exception ex) { if (st_transacao) { qtb_orc.Banco_Dados.RollBack_Tran(); } throw new Exception("Erro excluir pre venda: " + ex.Message.Trim()); } finally { if (st_transacao) { qtb_orc.deletarBanco_Dados(); } } }
public static string Excluir(TRegistro_PreVenda val, BancoDados.TObjetoBanco banco) { bool st_transacao = false; TCD_PreVenda qtb_orc = new TCD_PreVenda(); try { if (banco == null) { st_transacao = qtb_orc.CriarBanco_Dados(true); } else { qtb_orc.Banco_Dados = banco; } //Verificar se venda possui cupom emitido pelo delivery if (new TCD_ItensPreVenda_X_ItensCupom(qtb_orc.Banco_Dados).BuscarEscalar( new TpBusca[] { new TpBusca() { vNM_Campo = "a.CD_Empresa", vOperador = "=", vVL_Busca = "'" + val.Cd_empresa.Trim() + "'" }, new TpBusca() { vNM_Campo = "a.ID_PreVenda", vOperador = "=", vVL_Busca = val.id_prevenda.ToString() }, new TpBusca() { vNM_Campo = string.Empty, vOperador = "exists", vVL_Busca = "(select 1 from TB_PDV_NFCe x " + "where x.cd_empresa = a.cd_empresa " + "and x.id_nfce = a.id_cupom) " } }, "1") == null) { //Se não tiver excluir venda rápida CamadaDados.Faturamento.PDV.TList_VendaRapida lVendaRapida = new CamadaDados.Faturamento.PDV.TCD_VendaRapida(qtb_orc.Banco_Dados).Select( new TpBusca[] { new TpBusca() { vNM_Campo = string.Empty, vOperador = "exists", vVL_Busca = "(select 1 from TB_RES_ItensPreVenda_X_ItensCupom x " + "where x.cd_empresa = a.cd_empresa " + "and x.id_vendarapida = a.id_vendarapida " + "and x.cd_empresa = '" + val.Cd_empresa.Trim() + "' " + "and x.id_prevenda = " + val.id_prevenda.ToString() + ") " } }, 0, string.Empty, string.Empty); //Exclui Venda Rápida if (lVendaRapida.Count > 0) { Faturamento.PDV.TCN_VendaRapida.ExcluirVendaRapida(lVendaRapida, qtb_orc.Banco_Dados); } } else { throw new Exception("Não é permitido cancelar venda que possui cupom fiscal!\r\n" + "Para excluir cupom fiscal acesse:\r\n" + "Faturamento>>Frente Caixa>>>Consulta - Venda Frente Caixa."); } val.lDelItens.ForEach(p => { p.st_registro = "C"; TCN_PreVenda_Item.Gravar(p, qtb_orc.Banco_Dados); }); val.lItens.ForEach(p => { p.st_registro = "C"; TCN_PreVenda_Item.Gravar(p, qtb_orc.Banco_Dados); }); //St_registro val.st_ativo = "C"; //Cancelamento do cartao qtb_orc.executarEscalar("update TB_RES_Cartao " + "set ST_Registro = 'C' " + "where ID_Cartao = " + val.id_cartao + " " + "update TB_RES_Cartao " + "set dt_fechamento = GETDATE() " + "where ID_Cartao = " + val.id_cartao + " ", null); qtb_orc.Gravar(val); if (st_transacao) { qtb_orc.Banco_Dados.Commit_Tran(); } return("OK"); } catch (Exception ex) { if (st_transacao) { qtb_orc.Banco_Dados.RollBack_Tran(); } throw new Exception("Erro excluir pre venda: " + ex.Message.Trim()); } finally { if (st_transacao) { qtb_orc.deletarBanco_Dados(); } } }
public static string Gravar(TRegistro_PreVenda val, BancoDados.TObjetoBanco banco) { bool st_transacao = false; TCD_PreVenda qtb_orc = new TCD_PreVenda(); try { if (banco == null) { st_transacao = qtb_orc.CriarBanco_Dados(true); } else { qtb_orc.Banco_Dados = banco; } string ret = qtb_orc.Gravar(val); val.id_prevenda = Convert.ToDecimal(CamadaDados.TDataQuery.getPubVariavel(ret, "@P_ID_PREVENDA")); //Comentado pos item já esta sendo cancelado pela tela de pre-venda do restaurante, //Código poderá ser reaproveitado quando item não for gravado na hora do lançamento. //val.lDelItens.ForEach(p => //{ // p.id_prevenda = val.id_prevenda; // TCN_PreVenda_Item.Excluir(p, qtb_orc.Banco_Dados); //}); val.lItens.ForEach(p => { p.id_prevenda = val.id_prevenda; TCN_PreVenda_Item.Gravar(p, qtb_orc.Banco_Dados); p.lSabores.ForEach(o => { o.Id_PreVenda = val.id_prevenda; o.Cd_Empresa = val.Cd_empresa; if (!string.IsNullOrEmpty(o.Id_ItemStr)) { TCN_SaboresItens.Gravar(o, qtb_orc.Banco_Dados); } }); }); if (st_transacao) { qtb_orc.Banco_Dados.Commit_Tran(); } return(val.id_prevenda.ToString()); } catch (Exception ex) { if (st_transacao) { qtb_orc.Banco_Dados.RollBack_Tran(); } throw new Exception("Erro gravar pre venda: " + ex.Message.Trim()); } finally { if (st_transacao) { qtb_orc.deletarBanco_Dados(); } } }
private void ImprimirReduzido(TRegistro_PreVenda val, string porta, string Tp_impressora) { //Buscar dados da empresa CamadaDados.Diversos.TList_CadEmpresa lEmpresa = CamadaNegocio.Diversos.TCN_CadEmpresa.Busca(val.Cd_empresa, string.Empty, string.Empty, null); if (lEmpresa.Count < 1) { throw new Exception("Não foi possivel localizar empresa " + val.Cd_empresa); } if (!string.IsNullOrEmpty(Tp_impressora)) { PDV.TGerenciarImpNaoFiscal.IniciarPorta(porta); try { StringBuilder imp = new StringBuilder(); imp.AppendLine(" PRÉ-VENDA N: " + val.Id_prevendastr + " " + val.Dt_emissaostr); imp.AppendLine(" ========================================="); imp.AppendLine(" DADOS EMPRESA "); imp.AppendLine(" ========================================="); imp.AppendLine(" " + lEmpresa[0].Nm_empresa.Trim().ToUpper()); imp.AppendLine(" " + lEmpresa[0].Ds_endereco.Trim().ToUpper() + "," + lEmpresa[0].rEndereco.Numero); imp.AppendLine(" " + lEmpresa[0].rEndereco.Bairro.Trim().ToUpper()); imp.AppendLine(" -----------------------------------------"); imp.AppendLine(" DADOS CLIENTE "); imp.AppendLine(" -----------------------------------------"); imp.AppendLine(" " + val.Cd_clifor.Trim() + "-" + val.Nm_clifor.Trim().ToUpper()); //Buscar clifor config object obj_clifor = new CamadaDados.Faturamento.Cadastros.TCD_CFGCupomFiscal().BuscarEscalar( new TpBusca[] { new TpBusca() { vNM_Campo = "a.cd_empresa", vOperador = "=", vVL_Busca = "'" + val.Cd_empresa.Trim() + "'" } }, "a.cd_clifor"); if ((obj_clifor == null ? false : obj_clifor.ToString() != val.Cd_clifor) && (!string.IsNullOrEmpty(val.Cd_clifor))) { //Buscar dados cliente CamadaDados.Financeiro.Cadastros.TRegistro_CadClifor rCliente = CamadaNegocio.Financeiro.Cadastros.TCN_CadClifor.Busca_Clifor_Codigo(val.Cd_clifor, null); if (!string.IsNullOrEmpty(rCliente.Nm_fantasia)) { imp.Append(" " + rCliente.Nm_fantasia.Trim().ToUpper()); } if (rCfg.St_impcpfcnpjbool) { if ((!string.IsNullOrEmpty(rCliente.Nr_cgc.SoNumero())) || (!string.IsNullOrEmpty(rCliente.Nr_cpf.SoNumero()))) { imp.AppendLine(" CNPJ/CPF: " + (!string.IsNullOrEmpty(rCliente.Nr_cgc.SoNumero()) ? rCliente.Nr_cgc : rCliente.Nr_cpf)); } } } imp.Append(" " + val.Ds_endereco.Trim().ToUpper()); if ((obj_clifor == null ? false : obj_clifor.ToString() != val.Cd_clifor) && (!string.IsNullOrEmpty(val.Cd_clifor))) { //Buscar Endereco do cliente CamadaDados.Financeiro.Cadastros.TList_CadEndereco lEndereco = new CamadaDados.Financeiro.Cadastros.TCD_CadEndereco().Select( new TpBusca[] { new TpBusca() { vNM_Campo = "a.cd_clifor", vOperador = "=", vVL_Busca = "'" + val.Cd_clifor.Trim() + "'" }, new TpBusca() { vNM_Campo = "a.cd_endereco", vOperador = "=", vVL_Busca = "'" + val.Cd_endereco.Trim() + "'" } }, 0, string.Empty); if (lEndereco.Count > 0) { if (!string.IsNullOrEmpty(lEndereco[0].Numero)) { imp.AppendLine(", " + lEndereco[0].Numero.Trim().ToUpper()); } if (!string.IsNullOrEmpty(lEndereco[0].Bairro)) { imp.AppendLine(" " + lEndereco[0].Bairro.Trim().ToUpper()); } if (!string.IsNullOrEmpty(lEndereco[0].DS_Cidade)) { imp.AppendLine(" " + lEndereco[0].DS_Cidade.Trim().ToUpper() + " - " + lEndereco[0].UF); } if (!string.IsNullOrEmpty(lEndereco[0].Fone.SoNumero())) { imp.AppendLine(" " + lEndereco[0].Fone.Trim().ToUpper() + (!string.IsNullOrEmpty(lEndereco[0].Celular.SoNumero()) ? "/" + lEndereco[0].Celular.Trim().ToUpper() : string.Empty)); } if (!string.IsNullOrEmpty(lEndereco[0].Cep.SoNumero())) { imp.AppendLine(" CEP: " + lEndereco[0].Cep); } if (!string.IsNullOrEmpty(lEndereco[0].Proximo)) { imp.AppendLine(" " + lEndereco[0].Proximo.Trim().ToUpper()); } } } else { imp.AppendLine(); imp.AppendLine(); } if (!string.IsNullOrEmpty(val.Nm_vendedor)) { imp.AppendLine((" VENDEDOR: " + val.Nm_vendedor.Trim()).FormatStringDireita(42, ' ')); } imp.AppendLine(" -----------------------------------------"); imp.AppendLine(" PRODUTO QTD VAL.UNIT SUBTOTAL"); imp.AppendLine(" -----------------------------------------"); val.lItens.ForEach(p => { imp.AppendLine(" " + (p.Cd_produto.Trim() + "-" + p.Ds_produto.Trim().ToUpper())); imp.Append(p.Quantidade.ToString("N3", new System.Globalization.CultureInfo("en-US", true)).FormatStringEsquerda(13, ' ') + "x"); imp.Append(p.Vl_unitario.ToString("N2", new System.Globalization.CultureInfo("en-US", true)).FormatStringEsquerda(14, ' ')); imp.Append(p.Vl_subtotal.ToString("N2", new System.Globalization.CultureInfo("en-US", true)).FormatStringEsquerda(10, ' ')); imp.AppendLine(); if (p.Vl_desconto > decimal.Zero) { imp.AppendLine(" DESCONTO: " + p.Vl_desconto.ToString("N2", new System.Globalization.CultureInfo("en-US", true))); } if (p.Vl_acrescimo > decimal.Zero) { imp.AppendLine(" ACRESCIMO: " + p.Vl_acrescimo.ToString("N2", new System.Globalization.CultureInfo("en-US", true))); } if (p.Vl_juro_fin > decimal.Zero) { imp.AppendLine(" JURO FIN.: " + p.Vl_juro_fin.ToString("N2", new System.Globalization.CultureInfo("en-US", true))); } }); imp.Append(" -----------------------------------------------"); imp.Append(" ACRESCIMOS JUROS FIN. FRETE DESCONTO LIQUIDO"); imp.Append(val.lItens.Sum(p => p.Vl_acrescimo).ToString("N2", new System.Globalization.CultureInfo("en-US", true)).FormatStringEsquerda(12, ' ')); imp.Append(val.lItens.Sum(p => p.Vl_juro_fin).ToString("N2", new System.Globalization.CultureInfo("en-US", true)).FormatStringEsquerda(11, ' ')); imp.Append(val.lItens.Sum(p => p.Vl_frete).ToString("N2", new System.Globalization.CultureInfo("en-US", true)).FormatStringEsquerda(7, ' ')); imp.Append(val.lItens.Sum(p => p.Vl_desconto).ToString("N2", new System.Globalization.CultureInfo("en-US", true)).FormatStringEsquerda(9, ' ')); imp.AppendLine(val.lItens.Sum(p => p.Vl_liquido).ToString("N2", new System.Globalization.CultureInfo("en-US", true)).FormatStringEsquerda(9, ' ')); imp.AppendLine(" -------------------------------------------"); if (!string.IsNullOrEmpty(val.Cd_portador)) { imp.AppendLine(" FORMA PGTO : " + val.Cd_portador.Trim() + "-" + val.Ds_portador.Trim()); } //Buscar Parcelas TList_PreVenda_DT_Vencto lParc = CamadaNegocio.Faturamento.PDV.TCN_PreVenda_DT_Vencto.Buscar(val.Id_prevendastr, val.Cd_empresa, null); if (lParc.Count > 0) { imp.AppendLine(" COND.PGTO : " + val.Cd_condPgto.Trim() + "-" + val.Ds_condPgto.Trim()); imp.AppendLine(" VENCIMENTO VALOR "); lParc.OrderBy(p => p.Dt_vencto).ToList().ForEach(p => imp.AppendLine(" " + p.Dt_vencto.ToString("dd/MM/yyyy").FormatStringDireita(20, ' ') + p.Vl_parcela.ToString("C2", new System.Globalization.CultureInfo("pt-BR")))); imp.AppendLine(); imp.AppendLine(); } imp.AppendLine(); imp.AppendLine(); imp.AppendLine(" -----------------------------------------"); imp.AppendLine(" Cliente "); imp.AppendLine(); imp.AppendLine(); //Imprimir observacao cupom if (!string.IsNullOrEmpty(val.Ds_observacao)) { string obs = val.Ds_observacao.Trim(); imp.AppendLine(" -----------------------------------------"); imp.AppendLine(" OBSERVAÇÕES "); imp.AppendLine(" -----------------------------------------"); while (true) { if (obs.Length <= 40) { imp.AppendLine(" " + obs); break; } else { imp.AppendLine(" " + obs.Substring(0, 40)); obs = obs.Remove(0, 40); } } } imp.AppendLine(" -----------------------------------------"); imp.AppendLine(" Este recibo nao tem valor Fiscal "); imp.AppendLine(); imp.AppendLine(); imp.AppendLine(); imp.AppendLine(); imp.AppendLine(); PDV.TGerenciarImpNaoFiscal.Texto(imp.ToString()); PDV.TGerenciarImpNaoFiscal.Guilhotina(); } catch (Exception ex) { MessageBox.Show("Erro: " + ex.Message.Trim()); } finally { PDV.TGerenciarImpNaoFiscal.FecharPorta(); } } else { System.IO.FileInfo f = null; System.IO.StreamWriter w = null; f = new System.IO.FileInfo(System.IO.Path.GetTempPath() + System.IO.Path.DirectorySeparatorChar + "Orcamento.txt"); w = f.CreateText(); try { w.WriteLine(" PRÉ-VENDA N: " + val.Id_prevendastr + " " + val.Dt_emissaostr); w.WriteLine(" ========================================="); w.WriteLine(" DADOS EMPRESA "); w.WriteLine(" ========================================="); w.WriteLine(" " + lEmpresa[0].Nm_empresa.Trim().ToUpper()); w.WriteLine(" " + lEmpresa[0].Ds_endereco.Trim().ToUpper() + "," + lEmpresa[0].rEndereco.Numero); w.WriteLine(" " + lEmpresa[0].rEndereco.Bairro.Trim().ToUpper()); w.WriteLine(" -----------------------------------------"); w.WriteLine(" DADOS CLIENTE "); w.WriteLine(" -----------------------------------------"); w.WriteLine(" " + val.Cd_clifor.Trim() + "-" + val.Nm_clifor.Trim().ToUpper()); object obj_clifor = new CamadaDados.Faturamento.Cadastros.TCD_CFGCupomFiscal().BuscarEscalar( new TpBusca[] { new TpBusca() { vNM_Campo = "a.cd_empresa", vOperador = "=", vVL_Busca = "'" + val.Cd_empresa.Trim() + "'" } }, "a.cd_clifor"); if ((obj_clifor == null ? false : obj_clifor.ToString() != val.Cd_clifor) && (!string.IsNullOrEmpty(val.Cd_clifor))) { //Buscar dados cliente CamadaDados.Financeiro.Cadastros.TRegistro_CadClifor rCliente = CamadaNegocio.Financeiro.Cadastros.TCN_CadClifor.Busca_Clifor_Codigo(val.Cd_clifor, null); if (!string.IsNullOrEmpty(rCliente.Nm_fantasia)) { w.WriteLine(" " + rCliente.Nm_fantasia.Trim().ToUpper()); } if (rCfg.St_impcpfcnpjbool) { if ((!string.IsNullOrEmpty(rCliente.Nr_cgc.SoNumero())) || (!string.IsNullOrEmpty(rCliente.Nr_cpf.SoNumero()))) { w.WriteLine(" CNPJ/CPF: " + (!string.IsNullOrEmpty(rCliente.Nr_cgc.SoNumero()) ? rCliente.Nr_cgc : rCliente.Nr_cpf)); } } } w.Write(" " + val.Ds_endereco.Trim().ToUpper()); if ((obj_clifor == null ? false : obj_clifor.ToString() != val.Cd_clifor) && (!string.IsNullOrEmpty(val.Cd_clifor))) { //Buscar Endereco do cliente CamadaDados.Financeiro.Cadastros.TList_CadEndereco lEndereco = new CamadaDados.Financeiro.Cadastros.TCD_CadEndereco().Select( new TpBusca[] { new TpBusca() { vNM_Campo = "a.cd_clifor", vOperador = "=", vVL_Busca = "'" + val.Cd_clifor.Trim() + "'" }, new TpBusca() { vNM_Campo = "a.cd_endereco", vOperador = "=", vVL_Busca = "'" + val.Cd_endereco.Trim() + "'" } }, 0, string.Empty); if (lEndereco.Count > 0) { if (!string.IsNullOrEmpty(lEndereco[0].Numero)) { w.WriteLine(", " + lEndereco[0].Numero.Trim().ToUpper()); } if (!string.IsNullOrEmpty(lEndereco[0].Bairro)) { w.WriteLine(" " + lEndereco[0].Bairro.Trim().ToUpper()); } if (!string.IsNullOrEmpty(lEndereco[0].DS_Cidade)) { w.WriteLine(" " + lEndereco[0].DS_Cidade.Trim().ToUpper() + " - " + lEndereco[0].UF); } if (!string.IsNullOrEmpty(lEndereco[0].Fone.SoNumero())) { w.WriteLine(" " + lEndereco[0].Fone.Trim().ToUpper() + (!string.IsNullOrEmpty(lEndereco[0].Celular.SoNumero()) ? "/" + lEndereco[0].Celular.Trim().ToUpper() : string.Empty)); } if (!string.IsNullOrEmpty(lEndereco[0].Cep.SoNumero())) { w.WriteLine(" CEP: " + lEndereco[0].Cep); } if (!string.IsNullOrEmpty(lEndereco[0].Proximo)) { w.WriteLine(" " + lEndereco[0].Proximo.Trim().ToUpper()); } } } else { w.WriteLine(); w.WriteLine(); } if (!string.IsNullOrEmpty(val.Nm_vendedor)) { w.WriteLine((" VENDEDOR: " + val.Nm_vendedor.Trim()).FormatStringDireita(42, ' ')); } w.WriteLine(" -----------------------------------------"); w.WriteLine(" PRODUTO QTD VAL.UNIT SUBTOTAL"); w.WriteLine(" -----------------------------------------"); val.lItens.ForEach(p => { w.WriteLine(" " + (p.Cd_produto.Trim() + "-" + p.Ds_produto.Trim().ToUpper())); w.Write(p.Quantidade.ToString("N3", new System.Globalization.CultureInfo("en-US", true)).FormatStringEsquerda(13, ' ') + "x"); w.Write(p.Vl_unitario.ToString("N2", new System.Globalization.CultureInfo("en-US", true)).FormatStringEsquerda(14, ' ')); w.Write(p.Vl_subtotal.ToString("N2", new System.Globalization.CultureInfo("en-US", true)).FormatStringEsquerda(10, ' ')); w.WriteLine(); if (p.Vl_desconto > decimal.Zero) { w.WriteLine(" DESCONTO: " + p.Vl_desconto.ToString("N2", new System.Globalization.CultureInfo("en-US", true))); } if (p.Vl_acrescimo > decimal.Zero) { w.WriteLine(" ACRESCIMO: " + p.Vl_acrescimo.ToString("N2", new System.Globalization.CultureInfo("en-US", true))); } if (p.Vl_juro_fin > decimal.Zero) { w.WriteLine(" JURO FIN.: " + p.Vl_juro_fin.ToString("N2", new System.Globalization.CultureInfo("en-US", true))); } }); w.WriteLine(" -----------------------------------------"); w.WriteLine(" ACRESCIMOS JUROS FIN. DESCONTO LIQUIDO "); w.Write(val.lItens.Sum(p => p.Vl_acrescimo).ToString("N2", new System.Globalization.CultureInfo("en-US", true)).FormatStringEsquerda(12, ' ')); w.Write(val.lItens.Sum(p => p.Vl_juro_fin).ToString("N2", new System.Globalization.CultureInfo("en-US", true)).FormatStringEsquerda(11, ' ')); w.Write(val.lItens.Sum(p => p.Vl_desconto).ToString("N2", new System.Globalization.CultureInfo("en-US", true)).FormatStringEsquerda(9, ' ')); w.WriteLine(val.lItens.Sum(p => p.Vl_liquido).ToString("N2", new System.Globalization.CultureInfo("en-US", true)).FormatStringEsquerda(9, ' ')); w.WriteLine(" -----------------------------------------"); if (!string.IsNullOrEmpty(val.Cd_portador)) { w.WriteLine(" FORMA PGTO : " + val.Cd_portador.Trim() + "-" + val.Ds_portador.Trim()); } //Buscar Parcelas TList_PreVenda_DT_Vencto lParc = CamadaNegocio.Faturamento.PDV.TCN_PreVenda_DT_Vencto.Buscar(val.Id_prevendastr, val.Cd_empresa, null); if (lParc.Count > 0) { w.WriteLine(" COND.PGTO : " + val.Cd_condPgto.Trim() + "-" + val.Ds_condPgto.Trim()); w.WriteLine(" VENCIMENTO VALOR "); lParc.OrderBy(p => p.Dt_vencto).ToList().ForEach(p => w.WriteLine(" " + p.Dt_vencto.ToString("dd/MM/yyyy").FormatStringDireita(20, ' ') + p.Vl_parcela.ToString("C2", new System.Globalization.CultureInfo("pt-BR")))); w.WriteLine(); w.WriteLine(); } w.WriteLine(); w.WriteLine(); w.WriteLine(" -----------------------------------------"); w.WriteLine(" Cliente "); w.WriteLine(); w.WriteLine(); //Imprimir observacao cupom if (!string.IsNullOrEmpty(val.Ds_observacao)) { string obs = val.Ds_observacao.Trim(); w.WriteLine("Observacoes".FormatStringDireita(42, '-')); while (true) { if (obs.Length <= 40) { w.WriteLine(" " + obs); break; } else { w.WriteLine(" " + obs.Substring(0, 40)); obs = obs.Remove(0, 40); } } } w.WriteLine(" -----------------------------------------"); w.WriteLine(" Este recibo nao tem valor Fiscal "); w.Write(Convert.ToChar(27)); w.Write(Convert.ToChar(109)); w.Flush(); decimal copias = CamadaNegocio.ConfigGer.TCN_CadParamGer.VlNumericoEmpresa("QTD_VIA_REC_ECF", val.Cd_empresa, null); if (copias.Equals(decimal.Zero)) { copias = 1; } for (int i = 0; i < copias; i++) { f.CopyTo(porta); } } catch (Exception ex) { throw new Exception("Erro na impressao: " + ex.Message.Trim()); } finally { w.Dispose(); f = null; } } }
private void abrirCartao() { if (tpModo != TTpModo.tm_busca) { return; } if (!string.IsNullOrEmpty(nr_cartao.Text.ToString().Trim().SoNumero()) && !string.IsNullOrEmpty(txtDados.Text)) { DataTable rClifor = new TCD_Clifor().Buscar( new TpBusca[] { new TpBusca() { vNM_Campo = "a.cd_clifor", vOperador = "=", vVL_Busca = "'" + cd_clifor.ToString().Trim() + "'" } }, 1); if (rClifor.Rows.Count.Equals(0)) { return; } // busca cartao se estiver aberto TList_Cartao lCartao = new TCD_Cartao().Select( new TpBusca[] { new TpBusca() { vNM_Campo = "a.nr_cartao", vOperador = "=", vVL_Busca = "'" + nr_cartao.Text.ToString().Trim().SoNumero() + "'" }, new TpBusca() { vNM_Campo = "a.st_registro", vOperador = "=", vVL_Busca = "'A'" } }, 1, string.Empty, string.Empty); if (lCartao.Count > 0) { MessageBox.Show("Erro: O número " + nr_cartao.Text.ToString().Trim().SoNumero() + " de cartão consta como aberto!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); nr_cartao.Text = ""; nr_cartao.Focus(); return; } else if (lcfg[0].bool_mesacartao || lcfg[0].Tp_cartao.Equals("0")) { // abre um novo cartao rotativo TRegistro_Cartao rcartao = new TRegistro_Cartao(); rcartao.nr_cartao = nr_cartao.Text.ToString().Trim().SoNumero(); rcartao.Dt_abertura = CamadaDados.UtilData.Data_Servidor(); rcartao.St_registro = "A"; rcartao.vl_limitecartao = decimal.Zero; rcartao.st_menor = cbMenor.Checked; rcartao.Cd_empresa = lcfg[0].cd_empresa; rcartao.Cd_Clifor = rClifor.Rows[0].ItemArray[1].ToString().Trim(); rcartao.Nm_Clifor = nome_clifor.Text; TRegistro_PreVenda pre = new TRegistro_PreVenda(); pre.Dt_venda = CamadaDados.UtilData.Data_Servidor(); rcartao.lPreVenda.Add(pre); TCN_Cartao.Gravar(rcartao, null); MessageBox.Show("O cartão de número: " + nr_cartao.Text.ToString().Trim().SoNumero() + " foi aberto com sucesso!", "Mensagem", MessageBoxButtons.OK); } else if (lCartao.Count.Equals(0)) { TList_Cartao cartaonovo = new TCD_Cartao().Select( new TpBusca[] { new TpBusca() { vNM_Campo = "a.nr_cartao", vOperador = "=", vVL_Busca = nr_cartao.Text.ToString().Trim().SoNumero() } }, 1, string.Empty, string.Empty); // abre um novo cartao if (cartaonovo.Count > 0) { TRegistro_Cartao rcartao = new TRegistro_Cartao(); rcartao.nr_cartao = nr_cartao.Text.ToString().Trim().SoNumero(); rcartao.Dt_abertura = DateTime.Now; rcartao.St_registro = "A"; rcartao.Cd_Clifor = cartaonovo[0].Cd_Clifor; rcartao.vl_limitecartao = cartaonovo[0].vl_limitecartao; rcartao.status_menor = cartaonovo[0].status_menor; rcartao.Cd_empresa = lcfg[0].cd_empresa; rcartao.Cd_Clifor = rClifor.Rows[0].ItemArray[1].ToString().Trim(); rcartao.Nm_Clifor = nome_clifor.Text; TRegistro_PreVenda pre = new TRegistro_PreVenda(); rcartao.lPreVenda.Add(pre); TCN_Cartao.Gravar(rcartao, null); } } } else { MessageBox.Show("Informe o número do cartão!", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); } tpModo = TTpModo.tm_Standby; afternovo(); }
public static string Gravar(TRegistro_PreVenda val, BancoDados.TObjetoBanco banco) { bool st_transacao = false; TCD_PreVenda qtb_pre = new TCD_PreVenda(); try { if (banco == null) { st_transacao = qtb_pre.CriarBanco_Dados(true); } else { qtb_pre.Banco_Dados = banco; } val.Id_prevendastr = CamadaDados.TDataQuery.getPubVariavel(qtb_pre.Gravar(val), "@P_ID_PREVENDA"); //Gravar itens venda val.lItensDel.ForEach(p => TCN_ItensPreVenda.Excluir(p, qtb_pre.Banco_Dados)); val.lItens.ForEach(p => { p.Cd_empresa = val.Cd_empresa; p.Id_prevenda = val.Id_prevenda; TCN_ItensPreVenda.Gravar(p, qtb_pre.Banco_Dados); }); //Excluir financeiro TList_PreVenda_DT_Vencto lParc = TCN_PreVenda_DT_Vencto.Buscar(val.Id_prevendastr, val.Cd_empresa, qtb_pre.Banco_Dados); lParc.ForEach(p => TCN_PreVenda_DT_Vencto.Excluir(p, qtb_pre.Banco_Dados)); //Gravar financeiro val.DT_Vencto.ForEach(p => { p.Cd_empresa = val.Cd_empresa; p.Id_prevenda = val.Id_prevenda; TCN_PreVenda_DT_Vencto.Gravar(p, qtb_pre.Banco_Dados); }); //Resgatar Pontos Fidelidade if (val.lItens.Exists(p => p.Qtd_pontosutilizados > decimal.Zero)) { //Buscar listagem de pontos com saldo a recuperar CamadaDados.Faturamento.Fidelizacao.TList_PontosFidelidade lPontos = new CamadaDados.Faturamento.Fidelizacao.TCD_PontosFidelidade(qtb_pre.Banco_Dados).Select( new TpBusca[] { new TpBusca() { vNM_Campo = "a.cd_empresa", vOperador = "=", vVL_Busca = "'" + val.Cd_empresa.Trim() + "'" }, new TpBusca() { vNM_Campo = "a.cd_clifor", vOperador = "=", vVL_Busca = "'" + val.Cd_clifor.Trim() + "'" }, new 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 TpBusca() { vNM_Campo = "isnull(a.st_registro, 'A')", vOperador = "<>", vVL_Busca = "'C'" } }, 0, string.Empty, string.Empty); val.lItens.Where(p => p.Qtd_pontosutilizados > decimal.Zero).ToList().ForEach(p => { decimal pontos_resgatar = p.Qtd_pontosutilizados; decimal pontos = decimal.Zero; DateTime dt_atual = CamadaDados.UtilData.Data_Servidor(qtb_pre.Banco_Dados); foreach (CamadaDados.Faturamento.Fidelizacao.TRegistro_PontosFidelidade rPonto in lPontos.OrderBy(v => v.Dt_registro).ToList()) { if (pontos_resgatar > decimal.Zero) { pontos = pontos_resgatar < rPonto.SD_Pontos ? pontos_resgatar : rPonto.SD_Pontos; CamadaNegocio.Faturamento.Fidelizacao.TCN_ResgatePontos.Gravar( new CamadaDados.Faturamento.Fidelizacao.TRegistro_ResgatePontos() { Cd_empresa = rPonto.Cd_empresa, Id_ponto = rPonto.Id_ponto, Login = Utils.Parametros.pubLogin, Qt_pontos = pontos, Dt_resgate = dt_atual, Id_prevenda = val.Id_prevenda, Id_itemprevenda = p.Id_itemprevenda, St_registro = "A" }, qtb_pre.Banco_Dados); pontos_resgatar -= pontos; rPonto.Pontos_res += pontos; } else { break; } } }); } if (st_transacao) { qtb_pre.Banco_Dados.Commit_Tran(); } return(val.Id_prevendastr); } catch (Exception ex) { if (st_transacao) { qtb_pre.deletarBanco_Dados(); } throw new Exception("Erro gravar venda: " + ex.Message.Trim()); } finally { if (st_transacao) { qtb_pre.deletarBanco_Dados(); } } }