protected void lnkCompleteSale_Click(object sender, EventArgs e) { //get all the invoiceitem list InvoiceLineItemList lineItemList = Session["lineItemList"] as InvoiceLineItemList; //create an invoice Invoice newInvoice = new Invoice(); BuildNewInvoice(lineItemList, newInvoice); newInvoice.InvoiceID = InvoiceManager.Save(newInvoice); _invoiceID = newInvoice.InvoiceID; //save each line item from the line item list foreach (InvoiceLineItem lineItem in lineItemList) { lineItem.InvoiceID = newInvoice.InvoiceID; //save line items InvoiceLineItemManager.Save(lineItem); //Update the stock quantity after the lineItem has been saved ProductManager.UpdateUnitsOnHand(lineItem, "subtract"); //check if a lineitem is a Prepaid Water Pkg HandlePrepaidWaterPackages(newInvoice, lineItem); } //reset the account id _accountID = -1; //clean up session variables Session["productID"] = null; Session["lineItemList"] = null; Session["accountID"] = null; }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if ((Session["accountID"] == null)) { dViewAccountInfo.DataSource = null; dViewAccountInfo.DataBind(); } else { _accountID = Convert.ToInt32(Session["accountID"]); //populate details view dViewAccountInfo.DataSource = AccountManager.GetAccountWithAddress(_accountID); dViewAccountInfo.DataBind(); } if (Session["productID"] != null) // add the item to the gridview { lnkCompleteSale.CssClass = "linkStyle"; lnkCompleteSale.Enabled = true; _productID = Convert.ToInt32(Session["productID"]); InvoiceLineItem lineItem = GetProduct(); //clear the product id session Session["productID"] = null; if (Session["lineItemList"] == null) { //add the invoice line item to the new invoice line item list InvoiceLineItemList lineItemList = new InvoiceLineItemList(); lineItemList.Add(lineItem); //save this list into a session variable Session["lineItemList"] = lineItemList; PopulateGridviewProductsOnOrder(lineItemList); } else { InvoiceLineItemList existingLineItems = Session["lineItemList"] as InvoiceLineItemList; //add new items to the session existingLineItems.Add(lineItem); //display items in the gridview PopulateGridviewProductsOnOrder(existingLineItems); } } else { //get the existing items from the session and display it InvoiceLineItemList existingLineItems = Session["lineItemList"] as InvoiceLineItemList; //display items in the gridview PopulateGridviewProductsOnOrder(existingLineItems); } } }
public static double CalculateTotalTaxes(InvoiceLineItemList lineItems) { double totalTaxes = 0; foreach (InvoiceLineItem item in lineItems) { totalTaxes += item.TaxCharged; } return(totalTaxes); }
private void BuildNewInvoice(InvoiceLineItemList lineItemList, Invoice newInvoice) { newInvoice.AccountID = _accountID; newInvoice.InvoiceDate = DateTime.Now.ToLocalTime(); newInvoice.CreatedDate = DateTime.Now.ToLocalTime(); newInvoice.ModifiedDate = DateTime.Now.ToLocalTime(); newInvoice.CreatedBy = User.Identity.Name.ToString(); newInvoice.SubTotal = Invoice.CalculateSubTotal(lineItemList); newInvoice.TotalTaxCharged = Invoice.CalculateTotalTaxes(lineItemList); newInvoice.TotalAmount = newInvoice.SubTotal + newInvoice.TotalTaxCharged; }
public static double CalculateSubTotal(InvoiceLineItemList lineItems) { double subTotal = 0; foreach (InvoiceLineItem item in lineItems) { subTotal += item.ItemTotal; } return(subTotal); }
protected void gviewProductsOrdered_RowDeleting(object sender, GridViewDeleteEventArgs e) { int index = e.RowIndex; if (Session["lineItemList"] != null) { InvoiceLineItemList myList = Session["lineItemList"] as InvoiceLineItemList; myList.RemoveAt(index); gviewProductsOrdered.DataSource = myList; gviewProductsOrdered.DataBind(); } }
protected void gviewProductsOrdered_RowUpdating(object sender, GridViewUpdateEventArgs e) { lblMessage.Text = ""; int index = e.RowIndex; //get the Item qty of the item to be updated int itemQuantity = Convert.ToInt32((gviewProductsOrdered.Rows[index].FindControl("txtItemQuantity") as TextBox).Text); int prodID = Convert.ToInt32((gviewProductsOrdered.Rows[index].FindControl("hdnProductID") as HiddenField).Value.ToString()); //get the session InvoiceLineItemList lineItemList = Session["lineItemList"] as InvoiceLineItemList; Product myProduct = ProductManager.GetProductByID(prodID); //get the current in stock qty of the product if ((itemQuantity <= myProduct.UnitsOnHand) || (myProduct.UnitsOnHand == null)) //products with null units on hand are Prepaid water packages where unit qty is not stored { //allow the update if (Session["lineItemList"] != null) { InvoiceLineItem lineItem = lineItemList.ElementAt(index); lineItem.Quantity = itemQuantity; lineItem.TaxCharged = lineItem.CalculateTaxCharged(taxPercentage); //save the invoiceItemList back into the session //clear the session first Session["lineItemList"] = null; Session["lineItemList"] = lineItemList; //re-bind the gridview PopulateGridviewProductsOnOrder(lineItemList); } } else { //inform the user the item quantity is greater than the units on hand lblMessage.Text = "Cannot update quantity. There are only " + myProduct.UnitsOnHand + " units left for this item."; //re-bind the gridview PopulateGridviewProductsOnOrder(lineItemList); //set the focus on the qty text box (gviewProductsOrdered.Rows[index].FindControl("txtItemQuantity") as TextBox).Focus(); } }
private void PopulateGridviewProductsOnOrder(InvoiceLineItemList lineItemList) { gviewProductsOrdered.DataSource = lineItemList; gviewProductsOrdered.DataBind(); }