/// <summary> /// Creates a new invoice. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CmdSave_Click(object sender, EventArgs e) { VndBEDocumentoVenda invoice = new VndBEDocumentoVenda(); string avisos = string.Empty; invoice.Tipodoc = txtTipoDoc.Text; invoice.Entidade = txtEntidade.Text; invoice.TipoEntidade = "C"; invoice.Serie = txtSerie.Text; // To save the document as draft set this flag to true //invoice.Rascunho = true ; try { if (checkBox1.Checked) { // Set all the entity related information. PriEngine.Engine.Vendas.Documentos.PreencheDadosRelacionados(invoice); } if (listView1.Items.Count > 0) { foreach (ListViewItem item in listView1.Items) { VndBELinhasDocumentoVenda linhas = new VndBELinhasDocumentoVenda(); double qtd = Convert.ToDouble(item.SubItems[1].Text); // Add new line to the invoice and set all the item related information. PriEngine.Engine.Vendas.Documentos.AdicionaLinha(invoice, item.SubItems[0].Text, ref qtd); linhas = invoice.Linhas; linhas.GetEdita(1).Desconto1 = 10; linhas.GetEdita(1).DataEntrega = DateTime.Now.Date.AddDays(10); } if (txtobs.Text.Length > 0) { PriEngine.Engine.Vendas.Documentos.AdicionaLinhaEspecial(invoice, vdTipoLinhaEspecial.vdLinha_Comentario, 0, txtobs.Text); } } else { MessageBox.Show("There are no items."); } PriEngine.Engine.Vendas.Documentos.CalculaValoresTotais(invoice); // Save the document as draft. // PriEngine.Engine.Comercial.Vendas.ActualizaRascunho(invoice, ref strAvisos); PriEngine.Engine.Vendas.Documentos.Actualiza(invoice, ref avisos); // Accountig PriEngine.Engine.Base.LigacaoCBL.IntegraDocumentoLogCBL("V", invoice.Tipodoc, invoice.Serie, invoice.NumDoc, invoice.Filial, 1, ref avisos, true); // Show warning any message. if (avisos.Length > 0) { MessageBox.Show(avisos.ToString()); } // Send the invoice by email StringBuilder assunto = new StringBuilder(); string body = "<html><body><div class='count-center'><div class='top'><h1>EXEMPLO HTML</h1></div></body></html>"; assunto.Append("A new invoice was created - "); assunto.Append(invoice.Tipodoc.ToString()); assunto.Append("/"); assunto.Append(invoice.NumDoc.ToString()); PriEngine.Platform.Mail.Inicializa(); PriEngine.Platform.Mail.EnviaMailEx("*****@*****.**", null, null, assunto.ToString(), body.ToString(), null, false); } catch (Exception ex) { MessageBox.Show("Unable to save document. \n" + ex.Message); } }
/// <summary> /// Creates a new invoice. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CmdSave_Click(object sender, EventArgs e) { VndBEDocumentoVenda invoice = new VndBEDocumentoVenda(); string strAvisos = string.Empty; invoice.Tipodoc = txtTipoDoc.Text; invoice.Entidade = txtEntidade.Text; invoice.TipoEntidade = "C"; invoice.Serie = txtSerie.Text; // To save the document as draft set this flag to true //invoice.Rascunho = true ; try { if (checkBox1.Checked) { // Set all the entity related information. PriEngine.Engine.Vendas.Documentos.PreencheDadosRelacionados(invoice); } if (listView1.Items.Count > 0) { foreach (ListViewItem item in listView1.Items) { VndBELinhasDocumentoVenda linhas = new VndBELinhasDocumentoVenda(); double qtd = Convert.ToDouble(item.SubItems[1].Text); // Add new line to the invoice and set all the item related information. PriEngine.Engine.Vendas.Documentos.AdicionaLinha(invoice, item.SubItems[0].Text, ref qtd); linhas = invoice.Linhas; linhas.GetEdita(1).Desconto1 = 10; } if (txtobs.Text.Length > 0) { PriEngine.Engine.Vendas.Documentos.AdicionaLinhaEspecial(invoice, vdTipoLinhaEspecial.vdLinha_Comentario, 0, txtobs.Text); } } else { MessageBox.Show("There are no items."); } PriEngine.Engine.Vendas.Documentos.CalculaValoresTotais(invoice); // Save the document as draft. // PriEngine.Engine.Comercial.Vendas.ActualizaRascunho(invoice, ref strAvisos); PriEngine.Engine.Vendas.Documentos.Actualiza(invoice, ref strAvisos); if (strAvisos.Length > 0) { MessageBox.Show("Error writing document. \n" + strAvisos); } else { MessageBox.Show("Document saved with success."); StringBuilder strAssunto = new StringBuilder(); strAssunto.Append("A new invoice was created - "); strAssunto.Append(invoice.Tipodoc.ToString()); strAssunto.Append("/"); strAssunto.Append(invoice.NumDoc.ToString()); PriEngine.Platform.Mail.Inicializa(); PriEngine.Platform.Mail.EnviaMailEx("*****@*****.**", null, null, strAssunto.ToString(), null, null, false); } } catch (Exception ex) { MessageBox.Show("Unable to save document. \n" + ex.Message); } }