private void ShowInvoice(OrganizationServiceContext serviceContext, Entity invoice) { var invoiceProducts = serviceContext.CreateQuery("invoicedetail") .Where(e => e.GetAttributeValue <EntityReference>("invoiceid") == invoice.ToEntityReference()) .Where(e => e.GetAttributeValue <decimal>("quantity") > 0) .ToArray(); var productIds = invoiceProducts .Select(e => e.GetAttributeValue <EntityReference>("productid")) .Where(product => product != null) .Select(product => product.Id); var products = serviceContext.CreateQuery("product") .WhereIn(e => e.GetAttributeValue <Guid>("productid"), productIds) .ToDictionary(e => e.Id, e => e); var items = invoiceProducts .Select(e => GetLineItemFromInvoiceProduct(e, products)) .Where(e => e != null) .OrderBy(e => e.Number) .ThenBy(e => e.Name); InvoiceItems.DataSource = items; InvoiceItems.DataBind(); InvoiceNumber.Text = invoice.GetAttributeValue <string>("invoicenumber"); var tax = invoice.GetAttributeValue <Money>("totaltax") ?? new Money(0); InvoiceTotalTax.Visible = tax.Value > 0; InvoiceTotalTaxAmount.Text = tax.Value.ToString("C2"); var shipping = invoice.GetAttributeValue <Money>("freightamount") ?? new Money(0); InvoiceTotalShipping.Visible = shipping.Value > 0; InvoiceTotalShippingAmount.Text = shipping.Value.ToString("C2"); var discount = invoice.GetAttributeValue <Money>("totaldiscountamount") ?? new Money(0); InvoiceTotalDiscount.Visible = discount.Value > 0; InvoiceTotalDiscountAmount.Text = discount.Value.ToString("C2"); var total = invoice.GetAttributeValue <Money>("totalamount") ?? new Money(0); InvoiceTotal.Visible = total.Value > 0; InvoiceTotalAmount.Text = total.Value.ToString("C2"); GeneralErrorMessage.Visible = false; Order.Visible = false; Invoice.Visible = true; }
protected void InvoiceItems_RowCommand(object sender, GridViewCommandEventArgs e) { int rowIndex = Convert.ToInt32(e.CommandArgument); List <InvoiceDetailsViewModel> invoiceProducts = GetInvoiceItemsFromGridView(); InvoiceDetailsViewModel invoiceItem = invoiceProducts[rowIndex]; if (e.CommandName == "DeleteFromInvoice") { invoiceProducts.Remove(invoiceItem); } InvoiceItems.DataSource = invoiceProducts; InvoiceItems.DataBind(); CalculateTotals(); }
protected void Quantity_TextChanged(object sender, EventArgs e) { List <InvoiceDetailsViewModel> invoiceProducts = GetInvoiceItemsFromGridView(); foreach (var row in invoiceProducts) { if (row.Quantity < 1) { row.Quantity = 1; MessageUserControl.ShowInfo("", "Quantity must be at least 1."); } if (row.Quantity * row.Price != row.Amount) { row.Amount = (decimal)(row.Quantity * row.Price); } } InvoiceItems.DataSource = invoiceProducts; InvoiceItems.DataBind(); CalculateTotals(); }
protected void AddButton_Click(object sender, EventArgs e) { if (QuantityTextBox.Text.Length < 1 || CategoryDropDown.SelectedIndex < 1) { MessageUserControl.ShowInfo("", "Please fill the necessary product details"); } else { if (QuantityTextBox.Text.ToInt() < 1) { MessageUserControl.ShowInfo("", "Please enter a minimum of 1 quantity for the item."); } else { InvoiceDetailsViewModel item = GetProductFromHiddenGridView(); List <InvoiceDetailsViewModel> invoiceItems = GetInvoiceItemsFromGridView(); bool existingItem = false; foreach (InvoiceDetailsViewModel member in invoiceItems) { if (item.ProductID == member.ProductID) { member.Quantity = member.Quantity + item.Quantity; member.Amount = member.Amount + item.Amount; existingItem = true; } } if (!existingItem) { invoiceItems.Insert(0, item); } InvoiceItems.DataSource = invoiceItems; InvoiceItems.DataBind(); CalculateTotals(); } } }