public static void GerarPedidoPecas(ref CamadaDados.Faturamento.Pedido.TRegistro_Pedido rPed, CamadaDados.Servicos.TRegistro_LanServico rOs, List <CamadaDados.Servicos.TRegistro_LanServicosPecas> lPecas, CamadaDados.Servicos.Cadastros.TRegistro_OSE_ParamOS rParam) { if (!string.IsNullOrEmpty(rParam.Cfg_pedido_item)) { if (rPed == null) { rPed = new CamadaDados.Faturamento.Pedido.TRegistro_Pedido(); rPed.CD_Empresa = rOs != null ? rOs.Cd_empresa : string.Empty; rPed.DT_Pedido = DateTime.Now; rPed.CFG_Pedido = rParam.Cfg_pedido_item; rPed.Cd_vendedor = rOs != null?rOs.lEvolucao.Exists(p => !string.IsNullOrEmpty(p.Cd_tecnico)) ? rOs.lEvolucao.FindLast(p => !string.IsNullOrEmpty(p.Cd_tecnico)).Cd_tecnico : string.Empty : string.Empty; rPed.TP_Movimento = "S"; //Pedido de saida rPed.ST_Pedido = "F"; //Pedido fechado rPed.ST_Registro = "F"; //Pedido fechado rPed.CD_Clifor = rOs != null ? rOs.Cd_clifor : string.Empty; rPed.CD_Endereco = rOs != null ? rOs.Cd_endereco : string.Empty; rPed.Cd_moeda = rParam.Cd_moeda; rPed.CD_TRANSPORTADORA = rParam.Cd_transportadora; rPed.CD_ENDERECOTRANSP = rParam.Cd_enderecoTransp; } foreach (CamadaDados.Servicos.TRegistro_LanServicosPecas p in lPecas) { CamadaDados.Faturamento.Pedido.TRegistro_LanPedido_Item reg = new CamadaDados.Faturamento.Pedido.TRegistro_LanPedido_Item(); reg.Cd_Empresa = p.Cd_empresa; reg.Cd_local = p.Cd_local; reg.Cd_vendedor = p.Cd_tecnico; reg.Cd_produto = p.Cd_produto; reg.Ds_produto = p.Ds_produto; reg.Cd_unidade_est = p.Cd_unidproduto; reg.Cd_unidade_valor = p.Cd_unidproduto; reg.Quantidade = p.Qtd_faturar > decimal.Zero ? p.Qtd_faturar : p.Quantidade; if (rParam.St_sum_d_a_unitbool) { reg.Vl_unitario = p.Vl_unitario - decimal.Round(decimal.Divide(p.Vl_desconto, p.Quantidade), 5, MidpointRounding.AwayFromZero) + decimal.Round(decimal.Divide(p.Vl_acrescimo, p.Quantidade), 5, MidpointRounding.AwayFromZero); reg.Vl_subtotal = reg.Vl_unitario * p.Qtd_faturar > decimal.Zero ? p.Qtd_faturar : p.Quantidade; reg.Vl_desc = decimal.Zero; reg.Vl_acrescimo = decimal.Zero; } else { reg.Vl_unitario = p.Vl_unitario; reg.Vl_subtotal = p.Vl_unitario * (p.Qtd_faturar > decimal.Zero ? p.Qtd_faturar : p.Quantidade); reg.Vl_desc = p.Vl_desconto; reg.Vl_acrescimo = p.Vl_acrescimo; } reg.Tp_pedOS = "IT"; reg.lPecaOS.Add(p); rPed.Pedido_Itens.Add(reg); } } else { throw new Exception("Não existe configuracao para emitir pedido de peças para o tipo de ordem " + rOs.Tp_ordemstr); } }
private void faturarContrato(string Tp_nf) { if (bsContrato.Current != null) { if ((bsContrato.Current as CamadaDados.Graos.TRegistro_CadContrato).St_registro.Trim().ToUpper().Equals("A")) { //Buscar Pedido do contrato CamadaDados.Faturamento.Pedido.TRegistro_Pedido rPed = CamadaNegocio.Faturamento.Pedido.TCN_Pedido.Busca_Registro_Pedido((bsContrato.Current as CamadaDados.Graos.TRegistro_CadContrato).Nr_pedidostr, null); //Verificar se o pedido tem configuracao fiscal para emitir nota if (new CamadaDados.Faturamento.Cadastros.TCD_CadCFGPedidoFiscal().BuscarEscalar( new Utils.TpBusca[] { new Utils.TpBusca() { vNM_Campo = "a.cfg_pedido", vOperador = "=", vVL_Busca = "'" + rPed.CFG_Pedido.Trim() + "'" }, new Utils.TpBusca() { vNM_Campo = "a.tp_fiscal", vOperador = "in", vVL_Busca = "(" + Tp_nf + ")" } }, "1") == null) { MessageBox.Show("Não existe configuração fiscal para o tipo de pedido " + rPed.CFG_Pedido.Trim() + ".", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } using (Faturamento.TFLanFaturamento fFaturamento = new Faturamento.TFLanFaturamento()) { if (Tp_nf.ToUpper().Equals("'NO'") || Tp_nf.ToUpper().Equals("'CP', 'CF'") || Tp_nf.ToUpper().Equals("'FT'")) { fFaturamento.vTp_movimento = rPed.TP_Movimento; } else if (rPed.TP_Movimento.Trim().ToUpper().Equals("E")) { fFaturamento.vTp_movimento = "S"; } else { fFaturamento.vTp_movimento = "E"; } fFaturamento.Nr_pedidoFaturar = rPed.Nr_pedido.ToString(); fFaturamento.vTp_NFFiscal = Tp_nf; fFaturamento.ShowDialog(); this.afterBusca(); } } else { MessageBox.Show("É permitido faturar somente pedido fechado.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
public TFItensContrato() { InitializeComponent(); this.rped = null; this.Cd_empresa = string.Empty; this.Nm_empresa = string.Empty; this.Cd_clifor = string.Empty; this.Nm_clifor = string.Empty; this.Cd_endereco = string.Empty; this.Ds_endereco = string.Empty; this.Cd_tabeladesconto = string.Empty; this.St_alterar = false; this.IndexItem = 0; }
public static void GerarPedidoGarantia(ref CamadaDados.Faturamento.Pedido.TRegistro_Pedido rPed, CamadaDados.Servicos.TRegistro_LanServico rOs, List <CamadaDados.Servicos.TRegistro_LanServicosPecas> lPecas, CamadaDados.Servicos.Cadastros.TRegistro_OSE_ParamOS rParam) { if (!string.IsNullOrEmpty(rParam.Cfg_pedido_garantia)) { if (rPed == null) { rPed = new CamadaDados.Faturamento.Pedido.TRegistro_Pedido(); rPed.CD_Empresa = rOs.Cd_empresa; rPed.DT_Pedido = DateTime.Now; rPed.CFG_Pedido = rParam.Cfg_pedido_garantia; rPed.TP_Movimento = "S"; //Pedido de saida rPed.ST_Pedido = "F"; //Pedido fechado rPed.ST_Registro = "F"; //Pedido fechado rPed.CD_Clifor = rOs.Cd_clifor; rPed.CD_Endereco = rOs.Cd_endereco; rPed.Cd_moeda = rParam.Cd_moeda; rPed.CD_TRANSPORTADORA = rParam.Cd_transportadora; rPed.CD_ENDERECOTRANSP = rParam.Cd_enderecoTransp; } foreach (CamadaDados.Servicos.TRegistro_LanServicosPecas p in lPecas) { CamadaDados.Faturamento.Pedido.TRegistro_LanPedido_Item reg = new CamadaDados.Faturamento.Pedido.TRegistro_LanPedido_Item(); reg.Cd_Empresa = rOs.Cd_empresa; reg.Cd_local = p.Cd_local; reg.Cd_vendedor = p.Cd_tecnico; reg.Cd_produto = p.Cd_produto; reg.Ds_produto = p.Ds_produto; reg.Cd_unidade_est = p.Cd_unidproduto; reg.Cd_unidade_valor = p.Cd_unidproduto; reg.Quantidade = p.Quantidade; reg.Vl_unitario = p.Vl_unitario; reg.Vl_subtotal = p.Vl_subtotal; reg.Vl_desc = p.Vl_desconto; reg.Vl_acrescimo = p.Vl_acrescimo; reg.Tp_pedOS = "GR"; reg.lPecaOS.Add(p); rPed.Pedido_Itens.Add(reg); } } else { throw new Exception("Não existe configuracao para emitir pedido de garantia para o tipo de ordem " + rOs.Tp_ordemstr); } }
private void GerarRemessa(TRegistro_CargaAvulsa rCarga) { CamadaDados.Diversos.TList_CfgEmpresa lCfgEmpresa = CamadaNegocio.Diversos.TCN_CfgEmpresa.Buscar(rCarga.Cd_empresa, null); if (lCfgEmpresa.Count.Equals(0)) { MessageBox.Show("Não existe configuração parâmetro Empresa: " + rCarga.Cd_empresa, "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } CamadaDados.Faturamento.Pedido.TRegistro_Pedido rPed = null; try { Proc_Commoditties.TProcessaPedidoCargaAvulsa.GerarPedidoCarga(ref rPed, rCarga, lCfgEmpresa[0]); CamadaNegocio.Faturamento.Pedido.TCN_Pedido.Grava_Pedido(rPed, null); //Buscar pedido rPed = CamadaNegocio.Faturamento.Pedido.TCN_Pedido.Busca_Registro_Pedido(rPed.Nr_pedido.ToString(), null); //Buscar itens pedido CamadaNegocio.Faturamento.Pedido.TCN_Pedido.Busca_Pedido_Itens(rPed, false, null); for (int i = 0; i < rCarga.lItens.Count; i++) { rPed.Pedido_Itens[i].lItensCargaAvulsa.Add(rCarga.lItens[i]); } //Gerar Nota Fiscal TRegistro_LanFaturamento rFat = Proc_Commoditties.TProcessaPedFaturar.ProcessaPedFaturar(rPed, false, decimal.Zero); //Gravar Nota Fiscal TCN_LanFaturamento.GravarFaturamento(rFat, null, null); using (srvNFE.TFGerenciarNFe fGerNfe = new srvNFE.TFGerenciarNFe()) { fGerNfe.rNfe = CamadaNegocio.Faturamento.NotaFiscal.TCN_LanFaturamento.BuscarNF(rFat.Cd_empresa, rFat.Nr_lanctofiscalstr, null); fGerNfe.ShowDialog(); } } catch (Exception ex) { if (rPed != null) { CamadaNegocio.Faturamento.Pedido.TCN_Pedido.Deleta_Pedido(rPed, null); } MessageBox.Show(ex.Message.Trim(), "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void FaturarRomaneio() { using (TFFaturarRomaneioCompra fFat = new TFFaturarRomaneioCompra()) { if (fFat.ShowDialog() == DialogResult.OK) { if (fFat.lCompra != null) { CamadaDados.Faturamento.Pedido.TRegistro_Pedido rPed = null; try { rPed = Proc_Commoditties.TProcessarRomaneioCompra.ProcessarPedido(fFat.lCompra, fFat.Cd_empresa, fFat.Cd_clifor); //Gravar Pedido CamadaNegocio.Faturamento.Pedido.TCN_Pedido.Grava_Pedido(rPed, null); try { //Buscar pedido rPed = CamadaNegocio.Faturamento.Pedido.TCN_Pedido.Busca_Registro_Pedido(rPed.Nr_pedido.ToString(), null); //Buscar itens pedido CamadaNegocio.Faturamento.Pedido.TCN_Pedido.Busca_Pedido_Itens(rPed, false, null); //Gerar Nota Fiscal CamadaDados.Faturamento.NotaFiscal.TRegistro_LanFaturamento rFat = Proc_Commoditties.TProcessaPedFaturar.ProcessaPedFaturar(rPed, false, decimal.Zero); //Gravar Nota Fiscal CamadaNegocio.Faturamento.NotaFiscal.TCN_LanFaturamento.GravarFaturamento(rFat, null, null); MessageBox.Show("Nota Fiscal gravada com sucesso.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information); //Gravar preço automaticamente CamadaNegocio.Estoque.Cadastros.TCN_AtualizaPrecoPerc.AtualizarPreco(rFat.ItensNota, null); } catch { throw new Exception("Pedido compra gravado com sucesso.\r\n" + "Erro gravar nota fiscal.\r\n" + "Localize o pedido de compra Nº" + rPed.Nr_pedido.ToString() + " e fature novamente."); } } catch (Exception ex) { MessageBox.Show(ex.Message.Trim(), "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } afterBusca(); } } } }
public static void GerarPedidoMudanca(ref CamadaDados.Faturamento.Pedido.TRegistro_Pedido rPed, CamadaDados.Mudanca.TRegistro_LanMudanca rMudanca, decimal valor, CamadaDados.Mudanca.Cadastros.TList_CFGMudanca lCfg) { if (!string.IsNullOrEmpty(lCfg[0].CFG_PedServico)) { if (rPed == null) { rPed = new CamadaDados.Faturamento.Pedido.TRegistro_Pedido(); rPed.CD_Empresa = rMudanca != null ? rMudanca.Cd_empresa : string.Empty; rPed.DT_Pedido = DateTime.Now; rPed.CFG_Pedido = lCfg[0].CFG_PedServico; rPed.TP_Movimento = "S"; //Pedido de saida rPed.ST_Pedido = "F"; //Pedido fechado rPed.ST_Registro = "F"; //Pedido fechado rPed.CD_Clifor = rMudanca != null ? rMudanca.Cd_clifor : string.Empty; rPed.CD_Endereco = rMudanca != null ? rMudanca.Cd_endereco : string.Empty; CamadaDados.Faturamento.Pedido.TRegistro_LanPedido_Item reg = new CamadaDados.Faturamento.Pedido.TRegistro_LanPedido_Item(); reg.Cd_Empresa = rMudanca.Cd_empresa; reg.Cd_local = "000001"; reg.Cd_produto = lCfg[0].CD_ServPadrao; reg.Ds_produto = lCfg[0].DS_ServPadrao; reg.Quantidade = 1; reg.Vl_unitario = valor; reg.Vl_subtotal = valor; reg.Tp_pedOS = "SV"; rPed.Pedido_Itens.Add(reg); } } else { throw new Exception("Não existe configuracao para emitir pedido de serviço para mudança!"); } }
public static void GerarPedidoCarga(ref CamadaDados.Faturamento.Pedido.TRegistro_Pedido rPed, CamadaDados.Faturamento.Entrega.TRegistro_CargaAvulsa rCarga, CamadaDados.Diversos.TRegistro_CfgEmpresa rParam) { if (!string.IsNullOrEmpty(rParam.CFG_PedRemCargaAvulsa)) { if (rPed == null) { rPed = new CamadaDados.Faturamento.Pedido.TRegistro_Pedido(); rPed.CD_Empresa = rCarga.Cd_empresa; rPed.DT_Pedido = DateTime.Now; rPed.CFG_Pedido = rParam.CFG_PedRemCargaAvulsa; rPed.TP_Movimento = "S"; //Pedido de saida rPed.ST_Pedido = "F"; //Pedido fechado rPed.ST_Registro = "F"; //Pedido fechado rPed.CD_Clifor = rParam.Cd_clifor; rPed.CD_Endereco = rParam.Cd_endereco; //Buscar Moeda Padrao TList_Moeda tabela = CamadaNegocio.ConfigGer.TCN_CadParamGer_X_Empresa.BuscarMoedaPadrao(rCarga.Cd_empresa, null); if (tabela != null) { if (tabela.Count > 0) { rPed.Cd_moeda = tabela[0].Cd_moeda; } } } //Buscar Local Arm object LocalArm = new CamadaDados.Estoque.Cadastros.TCD_CadLocalArm_X_Empresa().BuscarEscalar( new TpBusca[] { new TpBusca() { vNM_Campo = "a.cd_empresa", vOperador = "=", vVL_Busca = "'" + rCarga.Cd_empresa.Trim() + "'" } }, "a.CD_Local"); if (LocalArm == null) { throw new Exception("Não existe Local de armazenagem configurado para Empresa" + rCarga.Cd_empresa.Trim() + "!"); } for (int i = 0; i < rCarga.lItens.Count; i++) { //Buscar Preço decimal vl_preco = CamadaNegocio.Estoque.Cadastros.TCN_LanPrecoItem.Busca_ConsultaPreco(rCarga.Cd_empresa, rCarga.lItens[i].Cd_produto, rParam.Cd_tabelapreco, null); CamadaDados.Faturamento.Pedido.TRegistro_LanPedido_Item reg = new CamadaDados.Faturamento.Pedido.TRegistro_LanPedido_Item(); reg.Cd_Empresa = rCarga.lItens[i].Cd_empresa; reg.Cd_local = LocalArm.ToString(); reg.Cd_produto = rCarga.lItens[i].Cd_produto; reg.Ds_produto = rCarga.lItens[i].Ds_produto; reg.Cd_unidade_est = rCarga.lItens[i].Cd_unidade; reg.Quantidade = rCarga.lItens[i].Quantidade; reg.Vl_unitario = vl_preco; reg.Vl_subtotal = vl_preco * rCarga.lItens[i].Quantidade; rPed.Pedido_Itens.Add(reg); } } else { throw new Exception("Não existe configuracao para emitir pedido de remessa para a Empresa " + rCarga.Cd_empresa); } }
public static void ProcessarNFDevolucao(CamadaDados.Faturamento.NotaFiscal.TRegistro_LanFaturamento rNf, BancoDados.TObjetoBanco banco) { bool st_transacao = false; TCD_Condicional qtb_cond = new TCD_Condicional(); try { if (banco == null) { st_transacao = qtb_cond.CriarBanco_Dados(true); } //Buscar moeda padrao string moeda = CamadaNegocio.ConfigGer.TCN_CadParamGer.BuscaVL_String_Empresa("CD_MOEDA_PADRAO", rNf.Cd_empresa, qtb_cond.Banco_Dados); if (string.IsNullOrEmpty(moeda)) { throw new Exception("Não existe moeda padrão configurada para a empresa " + rNf.Cd_empresa); } //Gravar Pedido CamadaDados.Faturamento.Pedido.TRegistro_Pedido rPed = new CamadaDados.Faturamento.Pedido.TRegistro_Pedido(); rPed.CD_Empresa = rNf.Cd_empresa; rPed.CD_Clifor = rNf.Cd_clifor; rPed.CD_Endereco = rNf.Cd_endereco; rPed.Cd_moeda = moeda; rPed.Cd_moeda = moeda; rPed.CFG_Pedido = rNf.lCFGFiscal[0].Cfg_pedido; rPed.DT_Pedido = rNf.Dt_emissao; rPed.TP_Movimento = rNf.Tp_movimento; //Pedido de saida rPed.ST_Pedido = "F"; //Pedido fechado rPed.ST_Registro = "F"; //Pedido fechado //Montar itens do pedido rNf.ItensNota.ForEach(p => { rPed.Pedido_Itens.Add(new CamadaDados.Faturamento.Pedido.TRegistro_LanPedido_Item() { Cd_Empresa = p.Cd_empresa, Cd_local = p.Cd_local, Cd_produto = p.Cd_produto, Cd_condfiscal_produto = p.Cd_condfiscal_produto, Cd_unidade_est = p.Cd_unidade, Cd_unidade_valor = p.Cd_unidade, Quantidade = p.Quantidade, Vl_unitario = p.Vl_unitario, Vl_subtotal = p.Vl_subtotal }); }); CamadaNegocio.Faturamento.Pedido.TCN_Pedido.Grava_Pedido(rPed, qtb_cond.Banco_Dados); //Gravar Nota Fiscal rNf.Nr_pedido = rPed.Nr_pedido; for (int i = 0; i < rPed.Pedido_Itens.Count; i++) { rNf.ItensNota[i].Nr_pedido = rPed.Pedido_Itens[i].Nr_pedido.Value; rNf.ItensNota[i].Id_pedidoitem = rPed.Pedido_Itens[i].Id_pedidoitem; } NotaFiscal.TCN_LanFaturamento.GravarFaturamento(rNf, null, qtb_cond.Banco_Dados); //Amarrar Itens NF a Itens Condicional rNf.ItensNota.ForEach(p => Gravar(new TRegistro_DevolucaoCF() { Cd_empresa = p.Cd_empresa, Id_cupom = p.rItemCF.ID_NFCe, Id_lancto = p.rItemCF.Id_lancto, Nr_lanctofiscal = p.Nr_lanctofiscal, Id_nfitem = p.Id_nfitem }, qtb_cond.Banco_Dados)); if (st_transacao) { qtb_cond.Banco_Dados.Commit_Tran(); } } catch (Exception ex) { if (st_transacao) { qtb_cond.Banco_Dados.RollBack_Tran(); } throw new Exception("Erro processar NF Condicional: " + ex.Message.Trim()); } finally { if (st_transacao) { qtb_cond.deletarBanco_Dados(); } } }
public static List <CamadaDados.Faturamento.Pedido.TRegistro_Pedido> ProcessarOS(List <CamadaDados.Servicos.TRegistro_LanServico> lOS) { if (lOS.Count.Equals(0)) { throw new Exception("Não existe OS selecionada para PROCESSAR."); } CamadaDados.Servicos.Cadastros.TList_OSE_ParamOS lParam = CamadaNegocio.Servicos.Cadastros.TCN_OSE_ParamOS.Buscar(lOS[0].Tp_ordemstr, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, 0, string.Empty, null); if (lParam.Count > 0) { List <CamadaDados.Faturamento.Pedido.TRegistro_Pedido> lRet = new List <CamadaDados.Faturamento.Pedido.TRegistro_Pedido>(); CamadaDados.Faturamento.Pedido.TRegistro_Pedido rPedGarantia = null; CamadaDados.Faturamento.Pedido.TRegistro_Pedido rPedPecas = null; CamadaDados.Faturamento.Pedido.TRegistro_Pedido rPedServ = null; lOS.ForEach(p => { //Buscar Pecas/Servicos da OS p.lPecas = CamadaNegocio.Servicos.TCN_LanServicoPecas.Buscar(p.Id_osstr, p.Cd_empresa, string.Empty, string.Empty, string.Empty, decimal.Zero, decimal.Zero, decimal.Zero, decimal.Zero, decimal.Zero, string.Empty, string.Empty, false, 0, null); //Verificar se existe peca para faturar em garantia if (p.lPecas.Exists(v => v.St_atendimentogarantiabool)) { //Gerar pedido das pecas em garantia TProcessaPedidoOS.GerarPedidoGarantia(ref rPedGarantia, p, p.lPecas.FindAll(v => v.St_atendimentogarantiabool && (!v.St_servicobool)), lParam[0]); } if (lParam[0].St_gerarpedidoservicoseparadobool) { if (p.lPecas.Exists(v => (!v.St_atendimentogarantiabool) && v.St_servicobool)) { TProcessaPedidoOS.GerarPedidoServico(ref rPedServ, p, p.lPecas.FindAll(v => (!v.St_atendimentogarantiabool) && v.St_servicobool), lParam[0]); } if (p.lPecas.Exists(v => (!v.St_atendimentogarantiabool) && (!v.St_servicobool))) { TProcessaPedidoOS.GerarPedidoPecas(ref rPedPecas, p, p.lPecas.FindAll(v => (!v.St_atendimentogarantiabool) && (!v.St_servicobool)), lParam[0]); } } else if (p.lPecas.Exists(v => !v.St_atendimentogarantiabool)) { TProcessaPedidoOS.GerarPedidoPecas(ref rPedPecas, p, p.lPecas.FindAll(v => !v.St_atendimentogarantiabool), lParam[0]); } }); if (rPedGarantia != null) { lRet.Add(rPedGarantia); } if (rPedPecas != null) { //Gerar Financeiro do pedido using (TFCondPgtoPedido fCond = new TFCondPgtoPedido()) { fCond.rPed = rPedPecas; fCond.ShowDialog(); } lRet.Add(rPedPecas); } if (rPedServ != null) { //Gerar Financeiro do pedido using (TFCondPgtoPedido fCond = new TFCondPgtoPedido()) { fCond.rPed = rPedServ; fCond.ShowDialog(); } lRet.Add(rPedServ); } return(lRet); } else { throw new Exception("Não existe configuração para o tipo de OS."); } }
public static void ProcessarLoteOS(TRegistro_LoteOS val, BancoDados.TObjetoBanco banco) { bool st_transacao = false; TCD_LoteOS qtb_lote = new TCD_LoteOS(); try { if (banco == null) { st_transacao = qtb_lote.CriarBanco_Dados(true); } else { qtb_lote.Banco_Dados = banco; } if (val.St_gerarpedidoremessa) { //Buscar config. os para gerar pedido de remessa de envio de mercadoria para conserto CamadaDados.Servicos.Cadastros.TList_OSE_ParamOS lParam = CamadaNegocio.Servicos.Cadastros.TCN_OSE_ParamOS.Buscar(val.lOs[0].Tp_ordemstr, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, 0, string.Empty, qtb_lote.Banco_Dados); if (lParam.Count > 0) { if (lParam[0].Cfg_pedido_transpremessaenvio.Trim().Equals(string.Empty)) { throw new Exception("Não existe configuração de remessa de envio para o tipo de ordem serviço: " + val.lOs[0].Tp_ordemstr.Trim()); } if (lParam[0].Cd_moeda.Trim().Equals(string.Empty)) { throw new Exception("Não existe configuração de moeda para o tipo de ordem serviço: " + val.lOs[0].Tp_ordemstr.Trim()); } //Gerar pedido de remessa CamadaDados.Faturamento.Pedido.TRegistro_Pedido pedido = new CamadaDados.Faturamento.Pedido.TRegistro_Pedido(); pedido.CD_Empresa = val.Cd_empresa; pedido.DT_Pedido = val.Dt_enviolote; pedido.TP_Movimento = "S"; pedido.CFG_Pedido = lParam[0].Cfg_pedido_transpremessaenvio; pedido.CD_Clifor = val.Cd_fornecedor; pedido.CD_Endereco = val.Cd_endfornecedor; pedido.CD_TRANSPORTADORA = lParam[0].Cd_transportadora; pedido.CD_ENDERECOTRANSP = lParam[0].Cd_enderecoTransp; pedido.ST_Pedido = "F"; pedido.ST_Registro = "F"; pedido.Cd_moeda = lParam[0].Cd_moeda; //Itens do pedido pedido.Pedido_Itens = val.lItensPedido; string ret_ped = CamadaNegocio.Faturamento.Pedido.TCN_Pedido.Grava_Pedido(pedido, qtb_lote.Banco_Dados); val.Nr_pedido = Convert.ToDecimal(ret_ped); } else { throw new Exception("Não existe configuração para o tipo de ordem serviço: " + val.lOs[0].Tp_ordemstr.Trim()); } } //Gravar lote val.St_registro = "P"; GravarLoteOS(val, qtb_lote.Banco_Dados); if (st_transacao) { qtb_lote.Banco_Dados.Commit_Tran(); } } catch (Exception ex) { if (st_transacao) { qtb_lote.Banco_Dados.RollBack_Tran(); } throw new Exception("Erro processar lote: " + ex.Message.Trim()); } finally { if (st_transacao) { qtb_lote.deletarBanco_Dados(); } } }
private void VincularCfNFe() { using (Proc_Commoditties.TFVincularECFNF fVincular = new Proc_Commoditties.TFVincularECFNF()) { if (fVincular.ShowDialog() == DialogResult.OK) { if (fVincular.lCupom != null) { if (fVincular.lCupom.Count > 0) { CamadaDados.Faturamento.Pedido.TRegistro_Pedido rPed = null; try { rPed = Proc_Commoditties.TProcessaCFVinculadoNF.ProcessarPedido(fVincular.lCupom, fVincular.pCd_empresa, fVincular.pCd_cliente); //Gravar Pedido CamadaNegocio.Faturamento.Pedido.TCN_Pedido.Grava_Pedido(rPed, null); //Buscar pedido rPed = CamadaNegocio.Faturamento.Pedido.TCN_Pedido.Busca_Registro_Pedido(rPed.Nr_pedido.ToString(), null); //Buscar itens pedido CamadaNegocio.Faturamento.Pedido.TCN_Pedido.Busca_Pedido_Itens(rPed, false, null); //Se o CMI do pedido gerar financeiro CamadaDados.Financeiro.Duplicata.TList_RegLanParcela lParcVinculado = new CamadaDados.Financeiro.Duplicata.TList_RegLanParcela(); //Buscar parcelas em aberto dos cupons que estao sendo vinculados fVincular.lCupom.ForEach(p => { new CamadaDados.Financeiro.Duplicata.TCD_LanParcela().Select( new TpBusca[] { new TpBusca() { vNM_Campo = "isnull(dup.st_registro, 'A')", vOperador = "<>", vVL_Busca = "'C'" }, new TpBusca() { vNM_Campo = "isnull(a.st_registro, 'A')", vOperador = "in", vVL_Busca = "('A', 'P')" }, new TpBusca() { vNM_Campo = string.Empty, vOperador = "exists", vVL_Busca = "(select 1 from tb_pdv_cupom_x_vendarapida x " + "inner join tb_pdv_cupomfiscal_x_duplicata y " + "on x.cd_empresa = y.cd_empresa " + "and x.id_vendarapida = y.id_cupom " + "where y.cd_empresa = a.cd_empresa " + "and y.nr_lancto = a.nr_lancto " + "and x.cd_empresa = '" + p.Cd_empresa.Trim() + "' " + "and x.id_cupom = " + p.Id_nfcestr + ")" } }, 0, string.Empty, "a.dt_vencto, c.nm_clifor", string.Empty).ForEach(v => lParcVinculado.Add(v)); }); //Gerar Nota Fiscal CamadaDados.Faturamento.NotaFiscal.TRegistro_LanFaturamento rFat = Proc_Commoditties.TProcessaPedFaturar.ProcessaPedFaturar(rPed, true, lParcVinculado.Sum(p => p.Vl_atual)); //Vincular Cupom a Nota Fiscal string Obs = string.Empty; string virg = string.Empty; fVincular.lCupom.ForEach(p => { rFat.lCupom.Add(p); string Placa_km = TCN_NFCe.BuscarPlacaKM(p.Cd_empresa, p.Id_nfcestr, null); Obs += virg + p.NR_NFCestr.Trim() + "-" + (string.IsNullOrEmpty(Placa_km) ? p.Placa : Placa_km.Trim()) + (!string.IsNullOrEmpty(p.Nr_requisicao) ? "/" + p.Nr_requisicao.Trim() : string.Empty); virg = ","; }); //Vincular financeiro a Nota Fiscal rFat.lParcAgrupar = lParcVinculado; if (!string.IsNullOrEmpty(Obs)) { rFat.Dadosadicionais = (!string.IsNullOrEmpty(rFat.Dadosadicionais) ? "\r\n" : string.Empty) + "Ref. CF-Placa/KM/Frota/Requisicao " + Obs.Trim(); } //Gravar Nota Fiscal CamadaNegocio.Faturamento.NotaFiscal.TCN_LanFaturamento.GravarFaturamento(rFat, null, null); if (rFat.Cd_modelo.Trim().Equals("55")) { if (MessageBox.Show("NFe gerada com sucesso.\r\n" + "Deseja enviar para receita?", "Pergunta", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes) { using (srvNFE.TFGerenciarNFe fGerNfe = new srvNFE.TFGerenciarNFe()) { fGerNfe.rNfe = CamadaNegocio.Faturamento.NotaFiscal.TCN_LanFaturamento.BuscarNF(rFat.Cd_empresa, rFat.Nr_lanctofiscalstr, null); fGerNfe.ShowDialog(); } } } } catch (Exception ex) { MessageBox.Show(ex.Message.Trim(), "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); CamadaNegocio.Faturamento.Pedido.TCN_Pedido.Deleta_Pedido(rPed, null); } } else { MessageBox.Show("Não existe cupom fiscal selecionado para vincular a Nota Fiscal.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } } }
public static CamadaDados.Faturamento.Pedido.TRegistro_Pedido ProcessarPedido(List <CamadaDados.Faturamento.CompraAvulsa.TRegistro_CompraAvulsa> lCompra, string Cd_empresa, string Cd_clifor) { if ((lCompra != null) && (!string.IsNullOrEmpty(Cd_empresa)) && (!string.IsNullOrEmpty(Cd_clifor))) { //Buscar moeda padrao string moeda = CamadaNegocio.ConfigGer.TCN_CadParamGer.BuscaVL_String_Empresa("CD_MOEDA_PADRAO", Cd_empresa); if (string.IsNullOrEmpty(moeda)) { throw new Exception("Não existe moeda padrão configurada para a empresa " + Cd_empresa); } //Buscar Endereco clifor object obj_end = new CamadaDados.Financeiro.Cadastros.TCD_CadEndereco().BuscarEscalar( new Utils.TpBusca[] { new Utils.TpBusca() { vNM_Campo = "a.cd_clifor", vOperador = "=", vVL_Busca = "'" + Cd_clifor.Trim() + "'" } }, "a.cd_endereco"); if (obj_end == null) { throw new Exception("Cliente " + Cd_clifor + " não possui endereço cadastrado."); } //Buscar config do romaneio de compra CamadaDados.Faturamento.Cadastros.TList_CfgCompraAvulsa lCfg = CamadaNegocio.Faturamento.Cadastros.TCN_CfgCompraAvulsa.Buscar(Cd_empresa, null); if (lCfg.Count < 1) { throw new Exception("Não existe configuração romaneio de compra para a empresa " + Cd_empresa); } //Criar objeto pedido CamadaDados.Faturamento.Pedido.TRegistro_Pedido rPed = new CamadaDados.Faturamento.Pedido.TRegistro_Pedido(); rPed.CD_Empresa = Cd_empresa; rPed.CD_Clifor = Cd_clifor; rPed.CD_Endereco = obj_end.ToString(); rPed.Cd_moeda = moeda; rPed.CFG_Pedido = lCfg[0].Cfg_pedido; rPed.DT_Pedido = CamadaDados.UtilData.Data_Servidor(); rPed.TP_Movimento = "E"; //Pedido de saida rPed.ST_Pedido = "F"; //Pedido fechado rPed.ST_Registro = "F"; //Pedido fechado //Montar itens do pedido lCompra.ForEach(p => //Buscar itens da compra CamadaNegocio.Faturamento.CompraAvulsa.TCN_Compra_Itens.Buscar(p.Cd_empresa, p.Id_comprastr, null).ForEach(v => { //Verificar se existe item no pedido if (rPed.Pedido_Itens.Exists(x => x.Cd_produto.Trim().Equals(v.Cd_produto.Trim()))) { rPed.Pedido_Itens.Find(x => x.Cd_produto.Trim().Equals(v.Cd_produto.Trim())).Quantidade += v.Quantidade; rPed.Pedido_Itens.Find(x => x.Cd_produto.Trim().Equals(v.Cd_produto.Trim())).Vl_subtotal += v.Vl_subtotal; rPed.Pedido_Itens.Find(x => x.Cd_produto.Trim().Equals(v.Cd_produto.Trim())).Vl_descCupom += v.Vl_desconto; rPed.Pedido_Itens.Find(x => x.Cd_produto.Trim().Equals(v.Cd_produto.Trim())).lItensCompra.Add(v); } else { rPed.Pedido_Itens.Add(new CamadaDados.Faturamento.Pedido.TRegistro_LanPedido_Item() { Cd_Empresa = v.Cd_empresa, Cd_local = v.Cd_local, Cd_produto = v.Cd_produto, Ds_produto = v.Ds_produto, Cd_unidade_est = v.Cd_unidade, Cd_unidade_valor = string.Empty, Quantidade = v.Quantidade, Vl_unitario = v.Vl_unitario, Vl_subtotal = v.Vl_subtotal, Vl_descCupom = v.Vl_desconto, lItensCompra = new CamadaDados.Faturamento.CompraAvulsa.TList_Compra_Itens() { v } }); } }) ); rPed.Pedido_Itens.ForEach(p => { p.Cd_unidade_valor = p.Cd_unidade_est; p.Vl_juro_fin = p.Vl_juroCupom; p.Vl_desc = p.Vl_descCupom; }); return(rPed); } else { return(null); } }
public static decimal FaturarTaxasContrato(CamadaDados.Balanca.TRegistro_PedidoAplicacao rPedAplic, List <TRegistro_TaxaDeposito> lTaxas, string Tp_taxa, CamadaDados.Faturamento.NotaFiscal.TRegistro_LanFaturamento rFat, BancoDados.TObjetoBanco banco) { bool st_transacao = false; TCD_LanTaxaDeposito qtb_taxa = new TCD_LanTaxaDeposito(); try { if (banco == null) { st_transacao = qtb_taxa.CriarBanco_Dados(true); } else { qtb_taxa.Banco_Dados = banco; } if (lTaxas.Count > 0) { //Buscar configuracao para o tipo de taxa que esta sendo faturada CamadaDados.Graos.TList_CFGTaxa CfgTaxa = CamadaNegocio.Graos.TCN_CFGTaxa.Buscar(Tp_taxa, string.Empty, string.Empty, string.Empty, qtb_taxa.Banco_Dados); if (CfgTaxa.Count.Equals(0)) { throw new Exception("Não existe configuração para o tipo de taxa."); } decimal retorno = decimal.Zero; if (Tp_taxa.Trim().ToUpper().Equals("V")) { CamadaDados.Faturamento.Pedido.TRegistro_Pedido rPed = new CamadaDados.Faturamento.Pedido.TRegistro_Pedido(); //Criar pedido para faturar rPed.CD_Empresa = rPedAplic.Cd_empresa; rPed.DT_Pedido = CamadaDados.UtilData.Data_Servidor(); rPed.CFG_Pedido = CfgTaxa[0].Cfg_pedido; rPed.TP_Movimento = "S"; //Pedido de entrada rPed.ST_Pedido = "F"; //Pedido fechado rPed.ST_Registro = "F"; //Pedido fechado rPed.CD_Clifor = rPedAplic.Cd_clifor; rPed.CD_Endereco = rPedAplic.Cd_endereco; rPed.Cd_moeda = CfgTaxa[0].Cd_moeda; //Criar itens do pedido rPed.Pedido_Itens.Add(new CamadaDados.Faturamento.Pedido.TRegistro_LanPedido_Item() { Cd_Empresa = rPedAplic.Cd_empresa, Cd_local = rPedAplic.Cd_local, Cd_produto = CfgTaxa[0].Cd_produto.Trim() != string.Empty ? CfgTaxa[0].Cd_produto : rPedAplic.Cd_produto, Ds_produto = CfgTaxa[0].Cd_produto.Trim() != string.Empty ? CfgTaxa[0].Ds_produto : rPedAplic.Ds_produto, Cd_unidade_est = (Tp_taxa.Trim().ToUpper().Equals("P") ? rPedAplic.Cd_unidade_estoque : CfgTaxa[0].Cd_unidproduto), Cd_unidade_valor = (Tp_taxa.Trim().ToUpper().Equals("P") ? rPedAplic.Cd_unidade : CfgTaxa[0].Cd_unidproduto), Quantidade = (Tp_taxa.Trim().ToUpper().Equals("P") ? lTaxas.Sum(p => p.Ps_Taxa) : 1), Vl_unitario = (Tp_taxa.Trim().ToUpper().Equals("P") ? rPedAplic.Vl_unitario : lTaxas.Sum(p => p.Vl_Taxa)), Vl_subtotal = (Tp_taxa.Trim().ToUpper().Equals("P") ? lTaxas.Sum(p => p.Ps_Taxa) * rPedAplic.Vl_unitario : lTaxas.Sum(p => p.Vl_Taxa)) }); //Gravar pedido CamadaNegocio.Faturamento.Pedido.TCN_Pedido.Grava_Pedido(rPed, qtb_taxa.Banco_Dados); lTaxas.ForEach(p => { //Gravar taxa x pedido item TCN_Taxa_X_PedidoItem.Gravar(new TRegistro_Taxa_X_PedidoItem() { Cd_produto = rPed.Pedido_Itens[0].Cd_produto, Id_lantaxa = p.Id_LanTaxa, Id_pedidoitem = rPed.Pedido_Itens[0].Id_pedidoitem, Nr_pedido = rPed.Nr_pedido }, qtb_taxa.Banco_Dados); //Alterar status das taxas para P - Processado p.St_registro = "P"; qtb_taxa.Gravar(p); }); retorno = rPed.Nr_pedido; } else if (rFat != null) { CamadaNegocio.Faturamento.NotaFiscal.TCN_LanFaturamento.GravarFaturamento(rFat, false, null, qtb_taxa.Banco_Dados); lTaxas.ForEach(p => { //Gravar Taxa X Nota Fiscal TCN_FatQuebraTec.Gravar(new TRegistro_FatQuebraTec() { Cd_empresa = rFat.Cd_empresa, Nr_lanctofiscal = rFat.Nr_lanctofiscal, Id_nfitem = rFat.ItensNota[0].Id_nfitem, Id_lantaxa = p.Id_LanTaxa }, qtb_taxa.Banco_Dados); //Alterar status das taxas para P - Processado p.St_registro = "P"; qtb_taxa.Gravar(p); }); retorno = rFat.Nr_lanctofiscal.Value; } if (st_transacao) { qtb_taxa.Banco_Dados.Commit_Tran(); } return(retorno); } else { throw new Exception("Não existe taxas para faturar."); } } catch (Exception ex) { if (banco == null) { qtb_taxa.Banco_Dados.RollBack_Tran(); } throw new Exception("Erro faturar taxas: " + ex.Message.Trim()); } finally { if (st_transacao) { qtb_taxa.deletarBanco_Dados(); } } }
private void afterGrava() { if (bsOS.Count > 0) { if (vl_minimopedido.Value > 0) { if (st_gerarpedidoservicoseparado.Checked) { if (vl_totalpecas.Value < vl_minimopedido.Value) { MessageBox.Show("Valor total das peças a ser faturado é menor que o valor minimo configurado para gerar pedido.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (vl_totalservicos.Value < vl_minimopedido.Value) { MessageBox.Show("Valor total dos serviços a ser faturado é menor que o valor minimo configurado para gerar pedido.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } else if ((vl_totalservicos.Value + vl_totalpecas.Value) < vl_minimopedido.Value) { MessageBox.Show("Valor total das peças e/ou serviços é menor que o valor minimo configurado para gerar pedido.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } if (BS_Pecas.Count < 1) { if (!(MessageBox.Show("Não existe peças/serviços para processar Ordem(s) de Serviço(s).\r\n" + "Confirma processamento mesmo assim?", "Pergunta", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)) { return; } } try { //Buscar evoluções (bsOS.Current as TRegistro_LanServico).lEvolucao = new CamadaDados.Servicos.TCD_LanServicoEvolucao().Select( new Utils.TpBusca[] { new Utils.TpBusca() { vNM_Campo = "a.id_os", vOperador = "=", vVL_Busca = (bsOS.Current as CamadaDados.Servicos.TRegistro_LanServico).Id_osstr }, new Utils.TpBusca() { vNM_Campo = "a.cd_empresa", vOperador = "=", vVL_Busca = "'" + (bsOS.Current as CamadaDados.Servicos.TRegistro_LanServico).Cd_empresa.Trim() + "'" } }, 0, string.Empty, "a.dt_inicio"); object obj = new CamadaDados.Servicos.Cadastros.TCD_TpOrdem().BuscarEscalar( new Utils.TpBusca[] { new Utils.TpBusca() { vNM_Campo = "a.tp_ordem", vOperador = "=", vVL_Busca = (bsOS.Current as TRegistro_LanServico).Tp_ordemstr } }, "a.tp_faturamento"); if (obj == null ? false : obj.ToString().ToString().Equals("V")) { if (BS_Pecas.Current != null) { (bsOS.Current as TRegistro_LanServico).lPecas = (BS_Pecas.List as CamadaDados.Servicos.TList_LanServicosPecas); } CamadaDados.Faturamento.Pedido.TRegistro_Pedido rPedGarantia = null; CamadaDados.Faturamento.PDV.TRegistro_PreVenda rPreVenda = Proc_Commoditties.TProcessarOS.ProcessarOSPeca(bsOS.Current as TRegistro_LanServico, ref rPedGarantia); CamadaNegocio.Servicos.TCN_LanServico.ProcessarOSPreVenda(bsOS.Current as TRegistro_LanServico, rPreVenda, rPedGarantia, null); MessageBox.Show("Ordem serviço processada com sucesso.", "Pergunta", MessageBoxButtons.OK, MessageBoxIcon.Information); if (rPedGarantia != null) { //Buscar pedido rPedGarantia = CamadaNegocio.Faturamento.Pedido.TCN_Pedido.Busca_Registro_Pedido(rPedGarantia.Nr_pedido.ToString(), null); //Buscar itens pedido CamadaNegocio.Faturamento.Pedido.TCN_Pedido.Busca_Pedido_Itens(rPedGarantia, false, null); //Gerar Nota Fiscal CamadaDados.Faturamento.NotaFiscal.TRegistro_LanFaturamento rFat = Proc_Commoditties.TProcessaPedFaturar.ProcessaPedFaturar(rPedGarantia, false, decimal.Zero); //Gravar Nota Fiscal CamadaNegocio.Faturamento.NotaFiscal.TCN_LanFaturamento.GravarFaturamento(rFat, null, null); if (rFat.Cd_modelo.Trim().Equals("55")) { if (MessageBox.Show("Deseja enviar NF-e para a receita agora?", "Pergunta", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes) { try { using (srvNFE.TFGerenciarNFe fGerNfe = new srvNFE.TFGerenciarNFe()) { fGerNfe.rNfe = CamadaNegocio.Faturamento.NotaFiscal.TCN_LanFaturamento.BuscarNF(rFat.Cd_empresa, rFat.Nr_lanctofiscalstr, null); fGerNfe.ShowDialog(); } } catch (Exception ex) { MessageBox.Show("Erro enviar NF-e: " + ex.Message.Trim(), "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } } else { CamadaNegocio.Servicos.TCN_LanServico.ProcessarServico((bsOS.List as CamadaDados.Servicos.TList_LanServico).FindAll(p => p.St_processarOS), St_osinterna ? null : Proc_Commoditties.TProcessaPedidoOS.ProcessarOS((bsOS.List as CamadaDados.Servicos.TList_LanServico).FindAll(p => p.St_processarOS)), null); MessageBox.Show("Ordem(s) de Serviço(s) processada(s) com sucesso.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information); } this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message.Trim()); } } else { MessageBox.Show("Não existe ordem de serviço marcada para processar.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public static CamadaDados.Faturamento.PDV.TRegistro_PreVenda ProcessarOSPeca(CamadaDados.Servicos.TRegistro_LanServico val, ref CamadaDados.Faturamento.Pedido.TRegistro_Pedido rPedGarantia) { CamadaDados.Faturamento.PDV.TRegistro_PreVenda rPreVenda = null; if (val.lPecas.Exists(p => !p.St_atendimentogarantiabool)) { //Buscar config OS CamadaDados.Servicos.Cadastros.TList_OSE_ParamOS lParam = CamadaNegocio.Servicos.Cadastros.TCN_OSE_ParamOS.Buscar(val.Tp_ordemstr, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, 1, string.Empty, null); if (lParam.Count > 0) { rPreVenda = new CamadaDados.Faturamento.PDV.TRegistro_PreVenda(); rPreVenda.Cd_empresa = val.Cd_empresa; rPreVenda.Cd_clifor = val.Cd_clifor; rPreVenda.Nm_clifor = val.Nm_clifor; rPreVenda.Cd_endereco = val.Cd_endereco; rPreVenda.Cd_vendedor = val.lEvolucao.Exists(p => !string.IsNullOrEmpty(p.Cd_tecnico)) ? val.lEvolucao.FindLast(p => !string.IsNullOrEmpty(p.Cd_tecnico)).Cd_tecnico : string.Empty; rPreVenda.Dt_emissao = CamadaDados.UtilData.Data_Servidor(); rPreVenda.St_registro = "A"; rPreVenda.Ds_observacao = val.Ds_observacoesgerais; val.lPecas.Where(p => !p.St_atendimentogarantiabool).ToList().ForEach(p => { if (string.IsNullOrEmpty(p.Cd_produto)) { object obj = new CamadaDados.Faturamento.CompraAvulsa.TCD_Compra_Itens().BuscarEscalar( new Utils.TpBusca[] { new Utils.TpBusca() { vNM_Campo = string.Empty, vOperador = "exists", vVL_Busca = "(select 1 from tb_fat_compraitens_x_pecaOS x " + "where x.cd_empresa = a.cd_empresa " + "and x.id_compra = a.id_compra " + "and x.id_itemcompra = a.id_itemcompra " + "and x.id_os = " + p.Id_osstr + " " + "and x.id_peca = " + p.Id_pecastr + ")" } }, "a.cd_produto"); if (obj != null) { p.Cd_produto = obj.ToString(); } else if (!string.IsNullOrEmpty(lParam[0].Cd_servicopadrao)) { p.Cd_produto = lParam[0].Cd_servicopadrao; } else { throw new Exception("Não existe serviço padrão configurado para faturar peça avulsa."); } } rPreVenda.lItens.Add(new CamadaDados.Faturamento.PDV.TRegistro_ItensPreVenda() { Cd_produto = p.Cd_produto, Quantidade = p.Quantidade, Vl_unitario = p.Vl_unitario, Vl_desconto = p.Vl_desconto, Vl_acrescimo = p.Vl_acrescimo, lPecasOS = new CamadaDados.Servicos.TList_LanServicosPecas() { p } }); }); } else { throw new Exception("Não existe configuração OS para a empresa " + val.Cd_empresa.Trim()); } } if (val.lPecas.Exists(p => p.St_atendimentogarantiabool)) { CamadaDados.Servicos.Cadastros.TList_OSE_ParamOS lParam = CamadaNegocio.Servicos.Cadastros.TCN_OSE_ParamOS.Buscar(val.Tp_ordemstr, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, 0, string.Empty, null); if (lParam.Count.Equals(0)) { throw new Exception("Não existe configuração para o tipo de OS."); } rPedGarantia = new CamadaDados.Faturamento.Pedido.TRegistro_Pedido(); rPedGarantia.CD_Empresa = val.Cd_empresa; rPedGarantia.DT_Pedido = DateTime.Now; rPedGarantia.CFG_Pedido = lParam[0].Cfg_pedido_garantia; rPedGarantia.TP_Movimento = "S"; //Pedido de saida rPedGarantia.ST_Pedido = "F"; //Pedido fechado rPedGarantia.ST_Registro = "F"; //Pedido fechado rPedGarantia.CD_Clifor = val.Cd_clifor; rPedGarantia.CD_Endereco = val.Cd_endereco; rPedGarantia.Cd_moeda = lParam[0].Cd_moeda; rPedGarantia.CD_TRANSPORTADORA = lParam[0].Cd_transportadora; rPedGarantia.CD_ENDERECOTRANSP = lParam[0].Cd_enderecoTransp; foreach (CamadaDados.Servicos.TRegistro_LanServicosPecas p in val.lPecas.FindAll(v => v.St_atendimentogarantiabool)) { CamadaDados.Faturamento.Pedido.TRegistro_LanPedido_Item reg = new CamadaDados.Faturamento.Pedido.TRegistro_LanPedido_Item(); reg.Cd_Empresa = val.Cd_empresa; reg.Cd_local = p.Cd_local; reg.Cd_vendedor = p.Cd_tecnico; reg.Cd_produto = p.Cd_produto; reg.Ds_produto = p.Ds_produto; reg.Cd_unidade_est = p.Cd_unidproduto; reg.Cd_unidade_valor = p.Cd_unidproduto; reg.Quantidade = p.Quantidade; reg.Vl_unitario = p.Vl_unitario; reg.Vl_subtotal = p.Vl_subtotal; reg.Vl_desc = p.Vl_desconto; reg.Vl_acrescimo = p.Vl_acrescimo; reg.Tp_pedOS = "GR"; reg.lPecaOS.Add(p); rPedGarantia.Pedido_Itens.Add(reg); } } return(rPreVenda); }
public static void ProcessarPedido(string Cd_clifor, string Cd_endereco, bool St_nfconsumo, string Placa, CamadaDados.Faturamento.Cadastros.TRegistro_CFGCupomFiscal rCfg, List <CamadaDados.Faturamento.PDV.TRegistro_VendaRapida_Item> lItens, ref CamadaDados.Faturamento.Pedido.TRegistro_Pedido rPedPproduto, ref CamadaDados.Faturamento.Pedido.TRegistro_Pedido rPedServico) { if (lItens.Count > 0) { //Buscar moeda padrao string moeda = CamadaNegocio.ConfigGer.TCN_CadParamGer.BuscaVL_String_Empresa("CD_MOEDA_PADRAO", lItens[0].Cd_empresa); if (string.IsNullOrEmpty(moeda)) { throw new Exception("Não existe moeda padrão configurada para a empresa " + lItens[0].Cd_empresa); } if ((!St_nfconsumo) && string.IsNullOrEmpty(rCfg.Cfg_pedido)) { throw new Exception("Não existe configuração para emitir NF direta venda para a empresa " + lItens[0].Cd_empresa.Trim()); } if (St_nfconsumo && string.IsNullOrEmpty(rCfg.Cfg_pedvendaconsumo)) { throw new Exception("Não existe configuração para emitir NF venda consumo para a empresa " + lItens[0].Cd_empresa.Trim()); } if (string.IsNullOrEmpty(rCfg.Cd_local)) { throw new Exception("Não existe local armazenagem configurado para a empresa " + lItens[0].Cd_empresa.Trim()); } //Verificar se existe servico na lista de itens List <CamadaDados.Faturamento.PDV.TRegistro_VendaRapida_Item> lItemServico = lItens.FindAll(p => new CamadaDados.Estoque.Cadastros.TCD_CadProduto().ItemServico(p.Cd_produto)); if ((lItemServico.Count > 0) && string.IsNullOrEmpty(rCfg.Cfg_pedservico)) { throw new Exception("Não existe configuração para emitir NF de serviço para a empresa " + lItens[0].Cd_empresa.Trim()); } if (lItemServico.Count > 0) { //Remover itens servico da lista de itens lItemServico.ForEach(p => lItens.Remove(p)); //Criar objeto pedido servico rPedServico = new CamadaDados.Faturamento.Pedido.TRegistro_Pedido(); rPedServico.CD_Empresa = lItemServico[0].Cd_empresa; rPedServico.CD_Clifor = Cd_clifor.Trim(); rPedServico.CD_Endereco = Cd_endereco.Trim(); rPedServico.Cd_moeda = moeda; rPedServico.Cd_vendedor = string.Empty; rPedServico.CFG_Pedido = rCfg.Cfg_pedservico; //Buscar cidade da empresa CamadaDados.Financeiro.Cadastros.TList_CadCidade lCid = new CamadaDados.Financeiro.Cadastros.TCD_CadCidade().Select( new Utils.TpBusca[] { new Utils.TpBusca() { vNM_Campo = string.Empty, vOperador = "exists", vVL_Busca = "(select 1 from tb_fin_endereco x " + "inner join tb_div_empresa y " + "on x.cd_clifor = y.cd_clifor " + "and x.cd_endereco = y.cd_endereco " + "where x.cd_cidade = a.cd_cidade " + "and y.cd_empresa = '" + rPedServico.CD_Empresa.Trim() + "')" } }, 1, string.Empty); if (lCid.Count > 0) { rPedServico.Cd_municipioexecservico = lCid[0].Cd_cidade; rPedServico.Ds_municipioexecservico = lCid[0].Ds_cidade; } rPedServico.DT_Pedido = CamadaDados.UtilData.Data_Servidor(); rPedServico.TP_Movimento = "S"; //Pedido de saida rPedServico.ST_Pedido = "F"; //Pedido fechado rPedServico.ST_Registro = "F"; //Pedido fechado //Montar itens do pedido foreach (CamadaDados.Faturamento.PDV.TRegistro_VendaRapida_Item p in lItemServico) { rPedServico.Pedido_Itens.Add(new CamadaDados.Faturamento.Pedido.TRegistro_LanPedido_Item() { Cd_Empresa = p.Cd_empresa, Cd_produto = p.Cd_produto, Ds_produto = p.Ds_produto, Cd_condfiscal_produto = p.Cd_condfiscal_produto, Cd_unidade_est = p.Cd_unidade, Cd_unidade_valor = string.Empty, Quantidade = p.Quantidade, Vl_unitario = p.Vl_unitario, Vl_subtotal = p.Vl_subtotal, Vl_descCupom = p.Vl_desconto, Vl_juroCupom = p.Vl_acrescimo }); rPedServico.Pedido_Itens[rPedServico.Pedido_Itens.Count - 1].lItemCF.Add(p); } rPedServico.Pedido_Itens.ForEach(p => { p.Cd_unidade_valor = p.Cd_unidade_est; p.Vl_juro_fin = p.Vl_juroCupom; p.Vl_desc = p.Vl_descCupom; }); } //Criar objeto pedido if (lItens.Count > 0) { rPedPproduto = new CamadaDados.Faturamento.Pedido.TRegistro_Pedido(); rPedPproduto.CD_Empresa = lItens[0].Cd_empresa; rPedPproduto.CD_Clifor = Cd_clifor.Trim(); rPedPproduto.CD_Endereco = Cd_endereco; rPedPproduto.Cd_moeda = moeda; rPedPproduto.Cd_vendedor = string.Empty; rPedPproduto.CFG_Pedido = St_nfconsumo ? rCfg.Cfg_pedvendaconsumo : rCfg.Cfg_pedido; rPedPproduto.DT_Pedido = CamadaDados.UtilData.Data_Servidor(); rPedPproduto.TP_Movimento = "S"; //Pedido de saida rPedPproduto.ST_Pedido = "F"; //Pedido fechado rPedPproduto.ST_Registro = "F"; //Pedido fechado rPedPproduto.Tp_frete = lItens.Exists(x => x.Vl_frete > decimal.Zero) ? "1" : "9"; //Montar itens do pedido foreach (CamadaDados.Faturamento.PDV.TRegistro_VendaRapida_Item p in lItens) { //Buscar Movimentacao Lote Anvisa string obs_item = string.Empty; string enter = string.Empty; CamadaNegocio.Faturamento.LoteAnvisa.TCN_MovLoteAnvisa.Buscar(p.Cd_empresa, string.Empty, p.Id_vendarapida.Value.ToString(), p.Id_lanctovenda.Value.ToString(), string.Empty, string.Empty, null).ForEach(v => { obs_item += enter + "Lote=" + v.Nr_lote.Trim() + " Qtd=" + v.Quantidade.ToString("N3", new System.Globalization.CultureInfo("pt-BR", true)) + " Fab=" + (v.Dt_fabric.HasValue ? v.Dt_fabric.Value.ToString("dd/MM/yyyy") : string.Empty) + " Val=" + (v.Dt_validade.HasValue ? v.Dt_validade.Value.ToString("dd/MM/yyyy") : "INDETERMINADO"); enter = "\r\n"; }); if (!string.IsNullOrEmpty(p.Cd_anp)) { obs_item += enter + "ANP: " + p.Cd_anp.Trim(); } if (new CamadaDados.Estoque.Cadastros.TCD_CadProduto().ProdutoCombustivel(p.Cd_produto)) { new CamadaDados.PostoCombustivel.TCD_VendaCombustivel().Select( new Utils.TpBusca[] { new Utils.TpBusca() { vNM_Campo = "a.cd_empresa", vOperador = "=", vVL_Busca = "'" + p.Cd_empresa.Trim() + "'" }, new Utils.TpBusca() { vNM_Campo = "a.id_cupom", vOperador = "=", vVL_Busca = p.Id_vendarapida.Value.ToString() }, new Utils.TpBusca() { vNM_Campo = "a.id_lancto", vOperador = "=", vVL_Busca = p.Id_lanctovenda.Value.ToString() } }, 0, string.Empty, string.Empty).ForEach(v => { obs_item += enter + "#B" + v.Ds_label.Trim() + "##EI" + (v.Encerrantebico - v.Volumeabastecido).ToString("N3", new System.Globalization.CultureInfo("en-US", true)) + "##EF" + v.Encerrantebico.ToString("N3", new System.Globalization.CultureInfo("en-US", true)); enter = "\r\n"; }); } if (rPedPproduto.Pedido_Itens.Exists(v => v.Cd_produto.Trim().Equals(p.Cd_produto.Trim())) && (CamadaNegocio.ConfigGer.TCN_CadParamGer.BuscaVL_Bool("AGRUPAR_ITENS_IGUAIS_NF_DIRETA", p.Cd_empresa, null) == "S")) { rPedPproduto.Pedido_Itens.Find(x => x.Cd_produto.Trim().Equals(p.Cd_produto.Trim())).Quantidade += p.Quantidade; rPedPproduto.Pedido_Itens.Find(x => x.Cd_produto.Trim().Equals(p.Cd_produto.Trim())).Vl_subtotal += p.Vl_subtotal; rPedPproduto.Pedido_Itens.Find(x => x.Cd_produto.Trim().Equals(p.Cd_produto.Trim())).Vl_descCupom += p.Vl_desconto; rPedPproduto.Pedido_Itens.Find(x => x.Cd_produto.Trim().Equals(p.Cd_produto.Trim())).Vl_juroCupom += p.Vl_acrescimo; rPedPproduto.Pedido_Itens.Find(x => x.Cd_produto.Trim().Equals(p.Cd_produto.Trim())).Vl_freteitem += p.Vl_frete; rPedPproduto.Pedido_Itens.Find(v => v.Cd_produto.Trim().Equals(p.Cd_produto.Trim())).lItemCF.Add(p); } else { rPedPproduto.Pedido_Itens.Add(new CamadaDados.Faturamento.Pedido.TRegistro_LanPedido_Item() { Cd_Empresa = p.Cd_empresa, Cd_local = rCfg.Cd_local, Cd_produto = p.Cd_produto, Ds_produto = p.Ds_produto, Cd_condfiscal_produto = p.Cd_condfiscal_produto, Cd_unidade_est = p.Cd_unidade, Cd_unidade_valor = string.Empty, Quantidade = p.Quantidade, Vl_unitario = p.Vl_unitario, Vl_subtotal = p.Vl_subtotal, Vl_descCupom = p.Vl_desconto, Vl_juroCupom = p.Vl_acrescimo, Vl_freteitem = p.Vl_frete, Ds_observacaoitem = obs_item }); rPedPproduto.Pedido_Itens[rPedPproduto.Pedido_Itens.Count - 1].lItemCF.Add(p); } } rPedPproduto.Pedido_Itens.ForEach(p => { p.Cd_unidade_valor = p.Cd_unidade_est; p.Vl_juro_fin = p.Vl_juroCupom; p.Vl_desc = p.Vl_descCupom; }); } } }
public static CamadaDados.Faturamento.Pedido.TRegistro_Pedido ProcessarPedido(List <CamadaDados.Faturamento.PDV.TRegistro_NFCe> lCupom, string Cd_empresa, string Cd_cliente) { if ((lCupom != null) && (!string.IsNullOrEmpty(Cd_empresa)) && (!string.IsNullOrEmpty(Cd_cliente))) { //Buscar moeda padrao string moeda = CamadaNegocio.ConfigGer.TCN_CadParamGer.BuscaVL_String_Empresa("CD_MOEDA_PADRAO", Cd_empresa); if (string.IsNullOrEmpty(moeda)) { throw new Exception("Não existe moeda padrão configurada para a empresa " + Cd_empresa); } //Buscar Endereco clifor object obj_end = new CamadaDados.Financeiro.Cadastros.TCD_CadEndereco().BuscarEscalar( new Utils.TpBusca[] { new Utils.TpBusca() { vNM_Campo = "a.cd_clifor", vOperador = "=", vVL_Busca = "'" + Cd_cliente.Trim() + "'" } }, "a.cd_endereco"); if (obj_end == null) { throw new Exception("Cliente " + Cd_cliente + " não possui endereço cadastrado."); } //Buscar Configuracao cupom CamadaDados.Faturamento.Cadastros.TList_CFGCupomFiscal lCfgCupom = CamadaNegocio.Faturamento.Cadastros.TCN_CFGCupomFiscal.Buscar(Cd_empresa, null); if (lCfgCupom.Count < 1) { throw new Exception("Não existe configuração cupom fiscal para a empresa " + Cd_empresa); } if (string.IsNullOrEmpty(lCfgCupom[0].Cfg_pedidovinculado)) { throw new Exception("Não existe tipo pedido vinculado configurado para a empresa " + Cd_empresa); } //Criar objeto pedido CamadaDados.Faturamento.Pedido.TRegistro_Pedido rPed = new CamadaDados.Faturamento.Pedido.TRegistro_Pedido(); rPed.CD_Empresa = Cd_empresa; rPed.CD_Clifor = Cd_cliente; rPed.CD_Endereco = obj_end.ToString(); rPed.Cd_moeda = moeda; rPed.CFG_Pedido = lCfgCupom[0].Cfg_pedidovinculado; rPed.DT_Pedido = CamadaDados.UtilData.Data_Servidor(); rPed.TP_Movimento = "S"; //Pedido de saida rPed.ST_Pedido = "F"; //Pedido fechado rPed.ST_Registro = "F"; //Pedido fechado //Montar itens do pedido lCupom.ForEach(p => { //Buscar itens do cupom p.lItem = CamadaNegocio.Faturamento.PDV.TCN_NFCe_Item.Buscar(p.Id_nfcestr, p.Cd_empresa, string.Empty, null); p.lItem.ForEach(v => { //Verificar se existe item no pedido if (rPed.Pedido_Itens.Exists(x => x.Cd_produto.Trim().Equals(v.Cd_produto.Trim())) && (CamadaNegocio.ConfigGer.TCN_CadParamGer.BuscaVL_Bool("AGRUPAR_ITENS_IGUAIS_NF_DIRETA", p.Cd_empresa, null) == "S")) { rPed.Pedido_Itens.Find(x => x.Cd_produto.Trim().Equals(v.Cd_produto.Trim())).Quantidade += v.Quantidade; rPed.Pedido_Itens.Find(x => x.Cd_produto.Trim().Equals(v.Cd_produto.Trim())).Vl_subtotal += v.Vl_subtotal; rPed.Pedido_Itens.Find(x => x.Cd_produto.Trim().Equals(v.Cd_produto.Trim())).Vl_descCupom += v.Vl_desconto; rPed.Pedido_Itens.Find(x => x.Cd_produto.Trim().Equals(v.Cd_produto.Trim())).Vl_juroCupom += v.Vl_acrescimo; rPed.Pedido_Itens.Find(x => x.Cd_produto.Trim().Equals(v.Cd_produto.Trim())).Vl_unitario = Math.Round(rPed.Pedido_Itens.Find(x => x.Cd_produto.Trim().Equals(v.Cd_produto.Trim())).Vl_subtotal / rPed.Pedido_Itens.Find(x => x.Cd_produto.Trim().Equals(v.Cd_produto.Trim())).Quantidade, 7); } else { rPed.Pedido_Itens.Add(new CamadaDados.Faturamento.Pedido.TRegistro_LanPedido_Item() { Cd_Empresa = p.Cd_empresa, Cd_produto = v.Cd_produto, Ds_produto = v.Ds_produto, Cd_condfiscal_produto = v.Cd_condfiscal_produto, Cd_unidade_est = v.Cd_unidade, Cd_unidade_valor = string.Empty, Quantidade = v.Quantidade, Vl_unitario = v.Vl_unitario, Vl_subtotal = v.Vl_subtotal, Vl_descCupom = v.Vl_desconto, Vl_juroCupom = v.Vl_acrescimo }); } }); }); rPed.Pedido_Itens.ForEach(p => { p.Cd_unidade_valor = p.Cd_unidade_est; p.Vl_juro_fin = p.Vl_juroCupom; p.Vl_desc = p.Vl_descCupom; }); return(rPed); } else { return(null); } }
private static CamadaDados.Faturamento.Pedido.TRegistro_Pedido GerarPedidoRemessa(CamadaDados.Servicos.TRegistro_LanServico val, bool St_nfterceiro, decimal Quantidade, decimal Vl_unitario) { if (val != null) { //Buscar configuracao para emitir pedido de remessa CamadaDados.Servicos.Cadastros.TList_OSE_ParamOS lParam = CamadaNegocio.Servicos.Cadastros.TCN_OSE_ParamOS.Buscar(val.Tp_ordemstr, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, 1, string.Empty, null); if (lParam.Count > 0) { if (!string.IsNullOrEmpty(lParam[0].Cfg_pedido_transpremessa)) { //Verificar se nao existe um pedido de remessa em aberto para este cliente CamadaDados.Faturamento.Pedido.TList_Pedido lPed = CamadaNegocio.Faturamento.Pedido.TCN_Pedido.Busca(val.Cd_empresa, string.Empty, string.Empty, val.Cd_clifor, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, lParam[0].Cfg_pedido_transpremessa, false, true, false, true, false, false, false, false, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, decimal.Zero, decimal.Zero, string.Empty, string.Empty, false, 1, string.Empty, null); if (lPed.Count > 0) { if (St_nfterceiro) { if (Vl_unitario > 0) { CamadaDados.Faturamento.Pedido.TList_RegLanPedido_Item lItem = CamadaNegocio.Faturamento.Pedido.TCN_LanPedido_Item.Busca(string.Empty, string.Empty, val.CD_ProdutoOS, lPed[0].Nr_pedido.ToString(), string.Empty, string.Empty, string.Empty, false, null); if (lItem.Count > 0) { if (Math.Round(lItem[0].Vl_unitario, 2).Equals(Math.Round(Vl_unitario))) { lItem[0].Quantidade += Quantidade; lPed[0].Pedido_Itens.Add(lItem[0]); } else { //Incluir novo item no pedido com valor unitario diferente lPed[0].Pedido_Itens.Add(new CamadaDados.Faturamento.Pedido.TRegistro_LanPedido_Item() { Cd_Empresa = val.Cd_empresa, Cd_local = string.Empty, Cd_produto = val.CD_ProdutoOS, Ds_produto = val.DS_ProdutoOS, Cd_unidade_est = val.Cd_unidOS, Cd_unidade_valor = val.Cd_unidOS, Quantidade = Quantidade, Vl_unitario = Vl_unitario, Vl_subtotal = Quantidade * Vl_unitario }); } } else { //Incluir novo item no pedido com valor unitario diferente lPed[0].Pedido_Itens.Add(new CamadaDados.Faturamento.Pedido.TRegistro_LanPedido_Item() { Cd_Empresa = val.Cd_empresa, Cd_local = string.Empty, Cd_produto = val.CD_ProdutoOS, Ds_produto = val.DS_ProdutoOS, Cd_unidade_est = val.Cd_unidOS, Cd_unidade_valor = val.Cd_unidOS, Quantidade = Quantidade, Vl_unitario = Vl_unitario, Vl_subtotal = Quantidade * Vl_unitario }); } } else { //Incluir novo item no pedido lPed[0].Pedido_Itens.Add(new CamadaDados.Faturamento.Pedido.TRegistro_LanPedido_Item() { Cd_Empresa = val.Cd_empresa, Cd_local = string.Empty, Cd_produto = val.CD_ProdutoOS, Ds_produto = val.DS_ProdutoOS, Cd_unidade_est = val.Cd_unidOS, Cd_unidade_valor = val.Cd_unidOS, Quantidade = Quantidade, Vl_unitario = Vl_unitario, Vl_subtotal = Quantidade * Vl_unitario }); } lPed[0].Tp_pedido = "RM";//Pedido de Remessa return(lPed[0]); } else { CamadaDados.Faturamento.Pedido.TList_RegLanPedido_Item lItem = CamadaNegocio.Faturamento.Pedido.TCN_LanPedido_Item.Busca(string.Empty, string.Empty, val.CD_ProdutoOS, lPed[0].Nr_pedido.ToString(), string.Empty, string.Empty, string.Empty, false, null); if (lItem.Count > 0) { lItem[0].Quantidade += Quantidade; lPed[0].Pedido_Itens.Add(lItem[0]); lPed[0].Tp_pedido = "RM";//Pedido de Remessa return(lPed[0]); } else { decimal vl_unitario = decimal.Zero; //Buscar valor medio do estoque CamadaNegocio.Estoque.TCN_LanEstoque.VlMedioEstoque(val.Cd_empresa, val.CD_ProdutoOS, ref vl_unitario, null); //Buscar valor da ultima compra if (vl_unitario.Equals(decimal.Zero)) { CamadaDados.Faturamento.NotaFiscal.TListUltimasCompras lUltimaCompra = new CamadaDados.Faturamento.NotaFiscal.TCD_LanFaturamento_Item().Select( new Utils.TpBusca[] { new Utils.TpBusca() { vNM_Campo = "a.tp_movimento", vOperador = "=", vVL_Busca = "'E'" }, new Utils.TpBusca() { vNM_Campo = "b.cd_produto", vOperador = "=", vVL_Busca = "'" + val.CD_ProdutoOS.Trim() + "'" }, new Utils.TpBusca() { vNM_Campo = "ISNULL(e.ST_Complementar, 'N')", vOperador = "=", vVL_Busca = "'N'" }, new Utils.TpBusca() { vNM_Campo = "ISNULL(e.ST_Devolucao, 'N')", vOperador = "=", vVL_Busca = "'N'" }, new Utils.TpBusca() { vNM_Campo = "ISNULL(e.ST_GeraEstoque, 'N')", vOperador = "=", vVL_Busca = "'S'" }, new Utils.TpBusca() { vNM_Campo = "ISNULL(a.ST_Registro, 'A')", vOperador = "<>", vVL_Busca = "'C'" }, }, 1); if (lUltimaCompra.Count > 0) { vl_unitario = lUltimaCompra[0].Vl_unitario; } } //Incluir novo item no pedido lPed[0].Pedido_Itens.Add(new CamadaDados.Faturamento.Pedido.TRegistro_LanPedido_Item() { Cd_Empresa = val.Cd_empresa, Cd_local = string.Empty, Cd_produto = val.CD_ProdutoOS, Ds_produto = val.DS_ProdutoOS, Cd_unidade_est = val.Cd_unidOS, Cd_unidade_valor = val.Cd_unidOS, Quantidade = Quantidade, Vl_unitario = vl_unitario, Vl_subtotal = Quantidade * vl_unitario }); lPed[0].Tp_pedido = "RM";//Pedido de Remessa return(lPed[0]); } } } else { CamadaDados.Faturamento.Pedido.TRegistro_Pedido rPed = new CamadaDados.Faturamento.Pedido.TRegistro_Pedido(); rPed.CD_Empresa = val.Cd_empresa; rPed.DT_Pedido = val.Dt_abertura; rPed.CFG_Pedido = lParam[0].Cfg_pedido_transpremessa; rPed.TP_Movimento = "E"; //Pedido de entrada rPed.ST_Pedido = "F"; //Pedido fechado rPed.ST_Registro = "F"; //Pedido fechado rPed.CD_Clifor = val.Cd_clifor; rPed.CD_Endereco = val.Cd_endereco; rPed.Cd_moeda = lParam[0].Cd_moeda; rPed.CD_TRANSPORTADORA = lParam[0].Cd_transportadora; rPed.CD_ENDERECOTRANSP = lParam[0].Cd_enderecoTransp; //Buscar valor medio do estoque if (!St_nfterceiro) { CamadaNegocio.Estoque.TCN_LanEstoque.VlMedioEstoque(val.Cd_empresa, val.CD_ProdutoOS, ref Vl_unitario, null); //Buscar valor da ultima compra if (Vl_unitario.Equals(decimal.Zero)) { CamadaDados.Faturamento.NotaFiscal.TListUltimasCompras lUltimaCompra = new CamadaDados.Faturamento.NotaFiscal.TCD_LanFaturamento_Item().Select( new Utils.TpBusca[] { new Utils.TpBusca() { vNM_Campo = "a.tp_movimento", vOperador = "=", vVL_Busca = "'E'" }, new Utils.TpBusca() { vNM_Campo = "b.cd_produto", vOperador = "=", vVL_Busca = "'" + val.CD_ProdutoOS.Trim() + "'" }, new Utils.TpBusca() { vNM_Campo = "ISNULL(e.ST_Complementar, 'N')", vOperador = "=", vVL_Busca = "'N'" }, new Utils.TpBusca() { vNM_Campo = "ISNULL(e.ST_Devolucao, 'N')", vOperador = "=", vVL_Busca = "'N'" }, new Utils.TpBusca() { vNM_Campo = "ISNULL(e.ST_GeraEstoque, 'N')", vOperador = "=", vVL_Busca = "'S'" }, new Utils.TpBusca() { vNM_Campo = "ISNULL(a.ST_Registro, 'A')", vOperador = "<>", vVL_Busca = "'C'" }, }, 1); if (lUltimaCompra.Count > 0) { Vl_unitario = lUltimaCompra[0].Vl_unitario; } } } rPed.Pedido_Itens.Add(new CamadaDados.Faturamento.Pedido.TRegistro_LanPedido_Item() { Cd_Empresa = val.Cd_empresa, Cd_local = string.Empty, Cd_produto = val.CD_ProdutoOS, Ds_produto = val.DS_ProdutoOS, Cd_unidade_est = val.Cd_unidOS, Cd_unidade_valor = val.Cd_unidOS, Quantidade = Quantidade, Vl_unitario = Vl_unitario, Vl_subtotal = Quantidade * Vl_unitario }); rPed.Tp_pedido = "RM"; //Pedido de remessa return(rPed); } } else { throw new Exception("Não existe configuração para emitir pedido de remessa para o tipo de ordem " + val.Tp_ordemstr); } } else { throw new Exception("Não existe configuração para o tipo de ordem " + val.Tp_ordemstr); } } else { return(null); } }