protected void bindInvoiceDetails(int invoiceID) { List <LeadInvoiceDetail> invoiceDetailLines = null; decimal?totalAmount = 0; invoiceDetailLines = LeadInvoiceDetailManager.GetInvoiceDetails(invoiceID); gvInvoiceLines.DataSource = invoiceDetailLines.OrderBy(x => x.LineDate); gvInvoiceLines.DataBind(); // total invoice lines if (invoiceDetailLines != null && invoiceDetailLines.Count > 0) { totalAmount = invoiceDetailLines.Where(x => x.isBillable == true).Sum(x => x.LineAmount); txtTotalAmount.Text = string.Format("{0:N2}", totalAmount); } }
//protected void bindInvoiceLines() { // int invoiceID = 0; // List<LeadInvoiceDetail> invoiceDetailLines = null; // invoiceID = Convert.ToInt32(hf_invoiceID.Value); // invoiceDetailLines = LeadInvoiceDetailManager.GetInvoiceDetails(invoiceID); // gvInvoiceLines.DataSource = invoiceDetailLines; // gvInvoiceLines.DataBind(); //} private void calculateLineTotal() { int invoiceID = 0; decimal qty = 0; decimal rate = 0; decimal totalAmount = 0; decimal taxableTotal = 0; string unitDescription = null; List <LeadInvoiceDetail> invoiceDetails = null; // get service unit type Label lblUnitDescription = gvInvoiceLines.FooterRow.FindControl("lblUnitDescription") as Label; if (lblUnitDescription != null) { unitDescription = lblUnitDescription.Text; } // get quantity WebNumericEditor txtQty = gvInvoiceLines.FooterRow.FindControl("txtQty") as WebNumericEditor; if (txtQty != null) { qty = txtQty.Value == null ? 0 : Convert.ToDecimal(txtQty.Value); } // rate WebNumericEditor txtRate = gvInvoiceLines.FooterRow.FindControl("txtRate") as WebNumericEditor; // remove any % symbol if (txtRate != null) { rate = txtRate.Value == null ? 0 : Convert.ToDecimal(txtRate.Value); } if (!string.IsNullOrEmpty(unitDescription) && unitDescriptions.Contains(unitDescription.ToLower())) { rate /= 100; // make it a percent for "percentage, sales tax" } totalAmount = rate * qty; if (!string.IsNullOrEmpty(unitDescription) && unitDescription.ToLower().Equals("sales tax")) { int.TryParse(ViewState["InvoiceID"].ToString(), out invoiceID); invoiceDetails = LeadInvoiceDetailManager.GetInvoiceDetails(invoiceID); taxableTotal = (decimal)invoiceDetails.Where(x => x.isBillable == true && x.InvoiceServiceType.InvoiceServiceUnit.UnitID != SALES_TAX_ID) .Sum(x => x.LineAmount); totalAmount = taxableTotal * rate; } TextBox txtLineAmount = gvInvoiceLines.FooterRow.FindControl("txtLineAmount") as TextBox; if (txtLineAmount != null) { txtLineAmount.Text = totalAmount.ToString("N2"); } }