protected void updateInvoiceComment(Data.Entities.LeadInvoice invoice, LeadInvoiceDetail invoiceDetail) { LeadComment comment = null; // retrieve comment by reference comment = LeadCommentManager.GetLeadCommentByReferenceId(invoiceDetail.InvoiceLineID); if (comment == null) { comment = new LeadComment(); } comment.InsertBy = Core.SessionHelper.getUserId(); comment.InsertDate = DateTime.Now; comment.LeadId = invoice.LeadId; comment.PolicyType = invoice.PolicyTypeID; comment.ReferenceID = invoiceDetail.InvoiceLineID; comment.Status = 1; // active comment.UserId = Core.SessionHelper.getUserId(); comment.CommentText = string.Format("<div>Invoice # {0} - {1:MM-dd-yyyy} for {2} Qty:{3:N2} Rate:{4:N2} Item Total:{5:N2}</div><div>{6}</div>", invoice.AdjusterInvoiceNumber, invoiceDetail.LineDate, invoiceDetail.LineDescription ?? "", invoiceDetail.Qty ?? 0, invoiceDetail.Rate ?? 0, invoiceDetail.LineAmount ?? 0, invoiceDetail.Comments ?? "" ); LeadCommentManager.Save(comment); }
protected void btnEmailInvoice_Click(object sender, EventArgs e) { string reportPath = null; int invoiceID = 0; Data.Entities.LeadInvoice invoice = null; int port = 0; string password = null; CRM.Data.Entities.SecUser user = null; string subject = "Invoice"; int userID = Core.SessionHelper.getUserId(); string bodyText = "Invoiced is attached."; Page.Validate("emailInvoice"); if (!Page.IsValid) { return; } try { invoiceID = Convert.ToInt32(ViewState["InvoiceID"].ToString()); reportPath = generateInvoicePDF(invoiceID); user = SecUserManager.GetByUserId(userID); if (user != null && !string.IsNullOrEmpty(reportPath)) { invoice = LeadInvoiceManager.Get(invoiceID); string[] recipient = new string[] { txtEmailTo.Text }; string[] attachments = new string[] { reportPath }; port = Convert.ToInt32(user.emailHostPort); password = Core.SecurityManager.Decrypt(user.emailPassword); Core.EmailHelper.sendEmail(user.Email, recipient, null, subject, bodyText, attachments, user.emailHost, port, user.Email, password); updateDocumentLog(reportPath, (int)invoice.PolicyTypeID); lblMessage.Text = "Invoice mailed successfully."; lblMessage.CssClass = "ok"; } } catch (Exception ex) { lblMessage.Text = "Unable to email invoice."; lblMessage.CssClass = "error"; } }
private void saveInvoice() { string[] billToValues = null; int clientID = 0; int invoiceID = 0; int InvoiceLineID = 0; Data.Entities.LeadInvoice invoice = null; CRM.Data.Entities.LeadPolicy policy = null; LeadInvoiceDetail invoiceDetailLine = null; LeadInvoiceDetail invoiceDetail = null; int nextInvoiceNumber = 0; int policyID = 0; decimal taxAmount = 0; billToValues = ddlBillTo.SelectedValue.Split(new char[] { '|' }); // get invoice id invoiceID = Convert.ToInt32(ViewState["InvoiceID"].ToString()); clientID = Core.SessionHelper.getClientId(); // current policy being edited policyID = Session["policyID"] == null ? 0 : Convert.ToInt32(Session["policyID"]); policy = LeadPolicyManager.GetByID(policyID); if (invoiceID == 0) { invoice = new Data.Entities.LeadInvoice(); // get id for current lead invoice.LeadId = Core.SessionHelper.getLeadId(); invoice.isVoid = false; // assign client invoice.ClientID = clientID; // hide print button //btnPrint.Visible = false; } else { invoice = LeadInvoiceManager.Get(invoiceID); // show print button //btnPrint.Visible = true; } invoice.PolicyID = policy.PolicyType; invoice.InvoiceDate = Convert.ToDateTime(txtInvoiceDate.Text); invoice.DueDate = Convert.ToDateTime(txtDueDate.Text); invoice.BillToName = txtBillTo.Text.Trim(); invoice.BillToAddress1 = txtBillToAddress1.Text.Trim(); invoice.BillToAddress2 = txtBillToAddress2.Text.Trim(); invoice.BillToAddress3 = txtBillToAddress3.Text.Trim(); invoice.AdjusterID = policy.AdjusterID; invoice.AdjusterInvoiceNumber = txtReferenceNumber.Text.Trim(); try { using (TransactionScope scope = new TransactionScope()) { if (invoiceID == 0) { // assign next invoice number to new invoice nextInvoiceNumber = LeadInvoiceManager.GetNextInvoiceNumber(clientID); invoice.InvoiceNumber = nextInvoiceNumber; } invoiceID = LeadInvoiceManager.Save(invoice); // save newly generated invoice id ViewState["InvoiceID"] = invoiceID.ToString(); // check for add/edit invoice detail line InvoiceLineID = ViewState["InvoiceLineID"] == null ? 0 : Convert.ToInt32(ViewState["InvoiceLineID"]); if (InvoiceLineID > 0) invoiceDetail = LeadInvoiceDetailManager.Get(InvoiceLineID); else invoiceDetail = new LeadInvoiceDetail(); // get detail line from gridview footer if (invoiceDetail != null) { invoiceDetailLine = getInvoiceDetailLine(); if (invoiceDetailLine.LineDate != null && !string.IsNullOrEmpty(invoiceDetailLine.LineDescription) && invoiceDetailLine.Qty > 0 && invoiceDetailLine.Rate > 0) { // update fields invoiceDetail.InvoiceID = invoiceID; invoiceDetail.InvoiceLineID = InvoiceLineID; invoiceDetail.ServiceTypeID = invoiceDetailLine.ServiceTypeID; invoiceDetail.Comments = invoiceDetailLine.Comments; invoiceDetail.isBillable = invoiceDetailLine.isBillable; invoiceDetail.LineAmount = invoiceDetailLine.LineAmount; invoiceDetail.LineDate = invoiceDetailLine.LineDate; invoiceDetail.LineDescription = invoiceDetailLine.LineDescription; invoiceDetail.Qty = invoiceDetailLine.Qty; invoiceDetail.Rate = invoiceDetailLine.Rate; invoiceDetail.UnitDescription = invoiceDetailLine.UnitDescription; invoiceDetail.Total = invoiceDetailLine.Total; // save invoice detail LeadInvoiceDetailManager.Save(invoiceDetail); // clear ViewState["InvoiceLineID"] = "0"; // update invoice total after adding invoice = LeadInvoiceManager.Get(invoiceID); invoice.TotalAmount = invoice.LeadInvoiceDetail.Where(x => x.isBillable == true).Sum(x => x.LineAmount); taxAmount = (invoice.TotalAmount ?? 0) * ((invoice.TaxRate ?? 0) / 100); //invoice.TotalAmount = invoice.TotalAmount + taxAmount; LeadInvoiceManager.Save(invoice); // update comment updateInvoiceComment(invoice, invoiceDetail); } } // complete transaction scope.Complete(); } // refresh invoice detail lines bindInvoiceDetails(invoiceID); clearFields(); showToolbarButtons(); } catch (Exception ex) { lblMessage.Text = "Error while saving invoice."; lblMessage.CssClass = "error"; Core.EmailHelper.emailError(ex); } }
private void saveInvoice() { string[] billToValues = null; int clientID = 0; int invoiceID = 0; int InvoiceLineID = 0; Data.Entities.LeadInvoice invoice = null; CRM.Data.Entities.LeadPolicy policy = null; LeadInvoiceDetail invoiceDetailLine = null; LeadInvoiceDetail invoiceDetail = null; int nextInvoiceNumber = 0; int policyID = 0; decimal taxAmount = 0; billToValues = ddlBillTo.SelectedValue.Split(new char[] { '|' }); // get invoice id invoiceID = Convert.ToInt32(ViewState["InvoiceID"].ToString()); clientID = Core.SessionHelper.getClientId(); // current policy being edited policyID = Session["policyID"] == null ? 0 : Convert.ToInt32(Session["policyID"]); policy = LeadPolicyManager.GetByID(policyID); if (invoiceID == 0) { invoice = new Data.Entities.LeadInvoice(); // get id for current lead invoice.LeadId = Core.SessionHelper.getLeadId(); invoice.isVoid = false; // assign client invoice.ClientID = clientID; // hide print button //btnPrint.Visible = false; } else { invoice = LeadInvoiceManager.Get(invoiceID); // show print button //btnPrint.Visible = true; } invoice.PolicyID = policy.PolicyType; invoice.InvoiceDate = Convert.ToDateTime(txtInvoiceDate.Text); invoice.DueDate = Convert.ToDateTime(txtDueDate.Text); invoice.BillToName = txtBillTo.Text.Trim(); invoice.BillToAddress1 = txtBillToAddress1.Text.Trim(); invoice.BillToAddress2 = txtBillToAddress2.Text.Trim(); invoice.BillToAddress3 = txtBillToAddress3.Text.Trim(); invoice.AdjusterID = policy.AdjusterID; invoice.AdjusterInvoiceNumber = txtReferenceNumber.Text.Trim(); try { using (TransactionScope scope = new TransactionScope()) { if (invoiceID == 0) { // assign next invoice number to new invoice nextInvoiceNumber = LeadInvoiceManager.GetNextInvoiceNumber(clientID); invoice.InvoiceNumber = nextInvoiceNumber; } invoiceID = LeadInvoiceManager.Save(invoice); // save newly generated invoice id ViewState["InvoiceID"] = invoiceID.ToString(); // check for add/edit invoice detail line InvoiceLineID = ViewState["InvoiceLineID"] == null ? 0 : Convert.ToInt32(ViewState["InvoiceLineID"]); if (InvoiceLineID > 0) { invoiceDetail = LeadInvoiceDetailManager.Get(InvoiceLineID); } else { invoiceDetail = new LeadInvoiceDetail(); } // get detail line from gridview footer if (invoiceDetail != null) { invoiceDetailLine = getInvoiceDetailLine(); if (invoiceDetailLine.LineDate != null && !string.IsNullOrEmpty(invoiceDetailLine.LineDescription) && invoiceDetailLine.Qty > 0 && invoiceDetailLine.Rate > 0) { // update fields invoiceDetail.InvoiceID = invoiceID; invoiceDetail.InvoiceLineID = InvoiceLineID; invoiceDetail.ServiceTypeID = invoiceDetailLine.ServiceTypeID; invoiceDetail.Comments = invoiceDetailLine.Comments; invoiceDetail.isBillable = invoiceDetailLine.isBillable; invoiceDetail.LineAmount = invoiceDetailLine.LineAmount; invoiceDetail.LineDate = invoiceDetailLine.LineDate; invoiceDetail.LineDescription = invoiceDetailLine.LineDescription; invoiceDetail.Qty = invoiceDetailLine.Qty; invoiceDetail.Rate = invoiceDetailLine.Rate; invoiceDetail.UnitDescription = invoiceDetailLine.UnitDescription; invoiceDetail.Total = invoiceDetailLine.Total; // save invoice detail LeadInvoiceDetailManager.Save(invoiceDetail); // clear ViewState["InvoiceLineID"] = "0"; // update invoice total after adding invoice = LeadInvoiceManager.Get(invoiceID); invoice.TotalAmount = invoice.LeadInvoiceDetail.Where(x => x.isBillable == true).Sum(x => x.LineAmount); taxAmount = (invoice.TotalAmount ?? 0) * ((invoice.TaxRate ?? 0) / 100); //invoice.TotalAmount = invoice.TotalAmount + taxAmount; LeadInvoiceManager.Save(invoice); // update comment updateInvoiceComment(invoice, invoiceDetail); } } // complete transaction scope.Complete(); } // refresh invoice detail lines bindInvoiceDetails(invoiceID); clearFields(); showToolbarButtons(); } catch (Exception ex) { lblMessage.Text = "Error while saving invoice."; lblMessage.CssClass = "error"; Core.EmailHelper.emailError(ex); } }