private void bb_inutilizar_Click(object sender, EventArgs e) { bool flag = false, semvalor = false; try { if (bsOrcamento.Current == null) { MessageBox.Show("Selecione um projeto!", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else if ((bsFicha.List as List <TRegistro_FichaTec>).Where(p => p.st_agregar).ToList().FindAll(c => string.IsNullOrEmpty(c.Cd_produto)).Count > 0) { MessageBox.Show("Obrigatório informar código de produto para gerar a remessa", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } (bsFicha.List as List <TRegistro_FichaTec>).Where(p => p.st_agregar && p.quantidade_agregar > decimal.Zero).ToList().ForEach(p => { flag = true; if (vTp_Fat.Equals("Normal")) { decimal saldo = BuscarSaldoLocal(vCD_Empresa, p.Cd_produto); if (saldo.Equals(decimal.Zero)) { MessageBox.Show("Não existe saldo disponivel no estoque.\r\n" + "Produto.........: " + p.Cd_produto.Trim() + "-" + p.Ds_produto.Trim() + "\r\n" + "Local Arm.......: " + vCd_Local.Trim() + "-" + vDs_Local + "\r\n" + "Saldo Disponivel: " + saldo.ToString("N3", new System.Globalization.CultureInfo("pt-BR", true)), "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information); semvalor = true; } } }); if (!semvalor) { if (flag) { if (vTp_Fat.Equals("Normal")) { List <TRegistro_FichaTec> lficha = new List <TRegistro_FichaTec>(); (bsFicha.List as List <TRegistro_FichaTec>).Where(p => p.st_agregar && p.quantidade_agregar > decimal.Zero).ToList() .ForEach(x => lficha.Add(x)); bsCFGEmpreendimento.DataSource = TCN_CadCFGEmpreendimento.Busca((bsOrcamento.Current as TRegistro_Orcamento).Cd_empresa, string.Empty, null); bsCFGEmpreendimento.ResetCurrentItem(); TList_CadCFGEmpreendimento lcfg = TCN_CadCFGEmpreendimento.Busca(string.Empty, string.Empty, null); if (lcfg[0].tp_precoitem.Trim().Equals("0")) { lficha.ForEach(p => { p.Vl_unitario = CamadaNegocio.Estoque.TCN_LanEstoque.Valor_Medio_Est_Produto(p.Cd_empresa, p.Cd_produto, null); if (p.Vl_unitario <= decimal.Zero) { throw new Exception("Produto " + p.Cd_produto.Trim() + "-" + p.Ds_produto.Trim() + " esta com valor medio negativo no estoque."); } }); } CamadaDados.Faturamento.NotaFiscal.TRegistro_LanFaturamento rNf = Proc_Commoditties.ProcessaEmpreendimento.ProcessarEmpreendimento("N", (bsOrcamento.Current as TRegistro_Orcamento).Cd_clifor, rorcamento, lficha); TCN_Orcamento.ProcessarNFEmpreendimento(rNf, bsCFGEmpreendimento.Current as TRegistro_CadCFGEmpreendimento, bsOrcamento.Current as TRegistro_Orcamento, null); if (rNf.Tp_nota.Trim().ToUpper().Equals("P") && rNf.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) { //Verificar se é nota de produto ou mista object obj = new CamadaDados.Faturamento.Cadastros.TCD_CadSerieNF().BuscarEscalar( new TpBusca[] { new TpBusca() { vNM_Campo = "a.nr_serie", vOperador = "=", vVL_Busca = "'" + rNf.Nr_serie + "'" } }, "a.tp_serie"); if (obj != null) { if (obj.ToString().Trim().ToUpper().Equals("P") || obj.ToString().Trim().ToUpper().Equals("M")) { try { using (srvNFE.TFGerenciarNFe fGerNfe = new srvNFE.TFGerenciarNFe()) { fGerNfe.rNfe = CamadaNegocio.Faturamento.NotaFiscal.TCN_LanFaturamento.BuscarNF(rNf.Cd_empresa, rNf.Nr_lanctofiscalstr, null); fGerNfe.ShowDialog(); } } catch (Exception ex) { MessageBox.Show("Erro enviar NF-e: " + ex.Message.Trim(), "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (obj.ToString().Trim().ToUpper().Equals("S")) { try { CamadaDados.Faturamento.NotaFiscal.TRegistro_LanFaturamento rNfs = CamadaNegocio.Faturamento.NotaFiscal.TCN_LanFaturamento.BuscarNF(rNf.Cd_empresa, rNf.Nr_lanctofiscalstr, null); NFES.TGerarRPS.CriarArquivoRPS(rNfs.rCfgNfe, new List <CamadaDados.Faturamento.NotaFiscal.TRegistro_LanFaturamento>() { rNfs }); MessageBox.Show("NFS-e enviada com sucesso. Aguarde alguns segundos e consulte o status do lote.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("Erro enviar NFS-e: " + ex.Message.Trim(), "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } } } DialogResult = DialogResult.OK; } else { MessageBox.Show("Para confirmar deve selecionar algum item.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception ex) { MessageBox.Show("" + ex.Message.Trim(), "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void ProcessarOs() { if (bsOrdemServico.Current != null) { if ((bsOrdemServico.Current as CamadaDados.Servicos.TRegistro_LanServico).St_os.Trim().ToUpper().Equals("FE")) { if (MessageBox.Show("Confirma processamento OS Nº" + (bsOrdemServico.Current as CamadaDados.Servicos.TRegistro_LanServico).Id_osstr + "?", "Pergunta", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes) { try { List <CamadaDados.Faturamento.Pedido.TRegistro_Pedido> lPed = Proc_Commoditties.TProcessaPedidoOS.ProcessarOS(new List <CamadaDados.Servicos.TRegistro_LanServico> { bsOrdemServico.Current as CamadaDados.Servicos.TRegistro_LanServico }); CamadaNegocio.Servicos.TCN_LanServico.ProcessarServico(new List <TRegistro_LanServico>() { bsOrdemServico.Current as CamadaDados.Servicos.TRegistro_LanServico }, lPed, null); if (MessageBox.Show("Ordem serviço processada com sucesso.\r\n" + "Deseja gerar faturamento agora?", "Pergunta", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes) { try { ////Gerar nota fiscal dos pedidos lPed.ForEach(p => { p = CamadaNegocio.Faturamento.Pedido.TCN_Pedido.Busca_Registro_Pedido(p.Nr_pedido.ToString(), null); //Buscar itens pedido CamadaNegocio.Faturamento.Pedido.TCN_Pedido.Busca_Pedido_Itens(p, false, null); //Buscar financeiro pedido p.Pedidos_DT_Vencto = CamadaNegocio.Faturamento.Pedido.TCN_LanPedido_DT_Vencto.Busca(p.Nr_pedido, null); CamadaDados.Faturamento.NotaFiscal.TRegistro_LanFaturamento rNf = Proc_Commoditties.TProcessaPedFaturar.ProcessaPedFaturar(p, false, decimal.Zero); //Gravar Nota Fiscal CamadaNegocio.Faturamento.NotaFiscal.TCN_LanFaturamento.GravarFaturamento(rNf, null, null); //Imprimir Nota Fiscal //Se for nota propria e NF-e if (rNf.Tp_nota.Trim().ToUpper().Equals("P")) { if (rNf.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) { //Verificar se é nota de produto ou mista object obj = new CamadaDados.Faturamento.Cadastros.TCD_CadSerieNF().BuscarEscalar( new Utils.TpBusca[] { new Utils.TpBusca() { vNM_Campo = "a.nr_serie", vOperador = "=", vVL_Busca = "'" + rNf.Nr_serie.Trim() + "'" } }, "a.tp_serie"); if (obj != null) { if (obj.ToString().Trim().ToUpper().Equals("P") || obj.ToString().Trim().ToUpper().Equals("M")) { try { using (srvNFE.TFGerenciarNFe fGerNfe = new srvNFE.TFGerenciarNFe()) { fGerNfe.rNfe = CamadaNegocio.Faturamento.NotaFiscal.TCN_LanFaturamento.BuscarNF(rNf.Cd_empresa, rNf.Nr_lanctofiscalstr, null); fGerNfe.ShowDialog(); } } catch (Exception ex) { MessageBox.Show("Erro enviar NF-e: " + ex.Message.Trim(), "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (obj.ToString().Trim().ToUpper().Equals("S")) { try { CamadaDados.Faturamento.NotaFiscal.TRegistro_LanFaturamento rNfs = CamadaNegocio.Faturamento.NotaFiscal.TCN_LanFaturamento.BuscarNF(rNf.Cd_empresa, rNf.Nr_lanctofiscalstr, null); NFES.TGerarRPS.CriarArquivoRPS(rNfs.rCfgNfe, new List <CamadaDados.Faturamento.NotaFiscal.TRegistro_LanFaturamento>() { rNfs }); MessageBox.Show("NFS-e enviada com sucesso. Aguarde alguns segundos e consulte o status do lote.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("Erro enviar NFS-e: " + ex.Message.Trim(), "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } } else { //Chamar tela de impressao para a nota fiscal //somente se for nota propria using (FormRelPadrao.TFGerenciadorImpressao fImp = new FormRelPadrao.TFGerenciadorImpressao()) { fImp.St_enabled_enviaremail = true; fImp.pCd_clifor = rNf.Cd_clifor; fImp.pMensagem = "NOTA FISCAL Nº" + rNf.Nr_notafiscal.ToString(); if ((fImp.ShowDialog() == DialogResult.OK) || (fImp.pSt_enviaremail)) { FormRelPadrao.LayoutNotaFiscal Relatorio = new FormRelPadrao.LayoutNotaFiscal(); Relatorio.Imprime_NF(rNf, fImp.pSt_imprimir, fImp.pSt_visualizar, fImp.pSt_enviaremail, fImp.pDestinatarios, "NOTA FISCAL Nº " + rNf.Nr_notafiscal.ToString(), fImp.pMensagem); } } } } }); } catch (Exception ex) { throw new Exception("Erro gerar Nota Fiscal.\r\n" + ex.Message.Trim() + "\r\n" + "Efetue as correções necessarias e proceda ao faturamento\r\n" + "dos pedidos gerados pelo processamento da OS"); } } this.LimparFiltros(); id_osbusca.Text = (bsOrdemServico.Current as CamadaDados.Servicos.TRegistro_LanServico).Id_osstr; this.afterBusca(); } catch (Exception ex) { MessageBox.Show(ex.Message.Trim(), "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show("Permitido processar somente OS FINALIZADA.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }