protected void gvInvoices_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { ImageButton btnEdit = e.Row.FindControl("btnEdit") as ImageButton; Label lblTotalAmount = e.Row.FindControl("lblTotalAmount") as Label; decimal taxRate = 0; decimal taxAmount = 0; ImageButton btnPrint = e.Row.FindControl("btnPrint") as ImageButton; CRM.Data.Entities.LeadInvoice invoice = e.Row.DataItem as CRM.Data.Entities.LeadInvoice; if (invoice != null && invoice.LeadInvoiceDetail != null) { invoice.TotalAmount = invoice.LeadInvoiceDetail.Where(x => x.isBillable == true).Sum(x => x.LineAmount); taxRate = invoice.TaxRate ?? 0; taxAmount = (invoice.TotalAmount ?? 0) * (taxRate / 100); lblTotalAmount.Text = string.Format("{0:N2}", invoice.TotalAmount + taxAmount); btnEdit.PostBackUrl = string.Format("~/Protected/LeadInvoiceLegacy.aspx?id={0}", invoice.InvoiceID); btnPrint.Attributes["onclick"] = string.Format("javascript:return printInvoiceLegacy({0});", invoice.InvoiceID); } } }
protected void gvInvoices_RowCommand(object sender, GridViewCommandEventArgs e) { int invoiceID = 0; CRM.Data.Entities.LeadInvoice invoice = null; if (e.CommandName == "DoDelete") { invoiceID = Convert.ToInt32(e.CommandArgument); invoice = LeadInvoiceManager.Get(invoiceID); if (invoice != null) { invoice.isVoid = true; LeadInvoiceManager.Save(invoice); // refresh list bindData(); } } }
protected void bindData() { int invoiceID = 0; int policyID = 0; CRM.Data.Entities.LeadInvoice invoice = null; List <LeadInvoiceDetail> invoiceDetails = null; // get id for current lead int leadID = Core.SessionHelper.getLeadId(); // get client id int clientID = Core.SessionHelper.getClientId(); // get current policy policyID = Core.SessionHelper.getPolicyID(); // check for new invoice or edit invoice ViewState["InvoiceID"] = Request.Params["id"] == null ? "0" : Request.Params["id"].ToString(); int.TryParse(ViewState["InvoiceID"].ToString(), out invoiceID); // get lead/claim Leads lead = LeadsManager.Get(leadID); if (lead != null) { bindBillTo(lead); lblClient.Text = string.Format("<b>{0} {1}<br/>{2}<br/>{3}<br/>{4}, {5} {6}</b>", lead.ClaimantFirstName ?? "", //0 lead.ClaimantLastName ?? "", //1 lead.LossAddress ?? "", //2 lead.LossAddress2 ?? "", //3 lead.CityName ?? "", //4 lead.StateName ?? "", // 5 lead.Zip ?? "" //6 ); } if (invoiceID == 0) { // new invoice txtInvoiceDate.Text = DateTime.Now.ToShortDateString(); invoiceDetails = new List <LeadInvoiceDetail>(); invoiceDetails.Add(new LeadInvoiceDetail()); gvInvoiceLines.DataSource = invoiceDetails; gvInvoiceLines.DataBind(); // hide empty row gvInvoiceLines.Rows[0].Visible = false; // hide print button //btnPrint.Visible = false; // hiden invoice number pnlInvoiceNumber.Visible = false; } else { // edit invoice invoice = LeadInvoiceManager.Get(invoiceID); // show print button //btnPrint.Visible = true; if (invoice != null && invoice.LeadInvoiceDetail != null) { txtInvoiceDate.Text = string.Format("{0:MM/dd/yyyy}", invoice.InvoiceDate); txtDueDate.Text = string.Format("{0:MM/dd/yyyy}", invoice.DueDate); txtBillTo.Text = invoice.BillToName; txtBillToAddress1.Text = invoice.BillToAddress1; txtBillToAddress2.Text = invoice.BillToAddress2; txtBillToAddress3.Text = invoice.BillToAddress3; // reference txtReferenceNumber.Text = invoice.AdjusterInvoiceNumber; // show total txtTotalAmount.Text = string.Format("{0:N2}", invoice.TotalAmount); // sort line items by date gvInvoiceLines.DataSource = invoice.LeadInvoiceDetail.OrderBy(x => x.LineDate); gvInvoiceLines.DataBind(); // show invoice numebr pnlInvoiceNumber.Visible = true; txtInvoiceNumber.Text = string.Format("{0:N0}", invoice.InvoiceNumber ?? 0); } } bindInvoiceServices(); }
public static LeadInvoice Save_bak(LeadInvoice invoice) { LeadInvoice updateInvoice = null; LeadInvoiceDetail updateinvoiceLine = null; if (invoice.InvoiceID == 0) { DbContextHelper.DbContext.Add(invoice); //DbContextHelper.DbContext.SaveChanges(); } else { updateInvoice = Get(invoice.InvoiceID); updateInvoice.InvoiceDate = invoice.InvoiceDate; updateInvoice.PolicyTypeID = invoice.PolicyTypeID; updateInvoice.BillToName = invoice.BillToName; updateInvoice.BillToAddress1 = invoice.BillToAddress1; updateInvoice.BillToAddress2 = invoice.BillToAddress2; updateInvoice.BillToAddress3 = invoice.BillToAddress3; updateInvoice.AdjusterInvoiceNumber = invoice.AdjusterInvoiceNumber; //DbContextHelper.DbContext.SaveChanges(); foreach (LeadInvoiceDetail invoiceLine in invoice.LeadInvoiceDetail) { if (invoiceLine.InvoiceLineID == 0) { updateinvoiceLine = new LeadInvoiceDetail(); updateinvoiceLine.InvoiceID = invoice.InvoiceID; DbContextHelper.DbContext.Add(updateinvoiceLine); } else updateinvoiceLine = GetInvoiceDetailLine(invoiceLine.InvoiceLineID); updateinvoiceLine.LineItemNo = invoiceLine.LineItemNo; updateinvoiceLine.LineDescription = invoiceLine.LineDescription; updateinvoiceLine.LineAmount = invoiceLine.LineAmount; } } DbContextHelper.DbContext.SaveChanges(); return invoice; }
public static int Save(LeadInvoice invoice) { if (invoice.InvoiceID == 0) DbContextHelper.DbContext.Add(invoice); DbContextHelper.DbContext.SaveChanges(); return invoice.InvoiceID; }