private void SetProductInventory(int productInventoryID) { var db = new BusinessEntities(); this.product_inventory_id = productInventoryID; this.ProductInventory = db.Product_Inventory.Find(productInventoryID); this.ProductInventory.CalculatePackage(); this.ProductInventory.SetProduct(); db.Dispose(); }
public void SetProduct() { var db = new BusinessEntities(); if (this.Product == null) { this.Product = db.Products.Find(this.product_id); } db.Dispose(); }
public void CalculateTotal() { // gathering lineitems info var db = new BusinessEntities(); var invoiceLIs = db.Invoice_Lineitem.Where(li => li.invoice_id == this.Id); decimal subtotal = 0m; foreach (var i in invoiceLIs) { i.CalculateTotal(i.product_inventory_id); i.ProductInventory.SetProduct(); subtotal += i.LineitemTotal; } this.Lineitems = invoiceLIs.ToList(); // gathering delivery items info var deliveryLIs = db.Delivery_Lineitem.Where(dl => dl.Invoice_Lineitem.invoice_id == this.Id && dl.Delivery_Schedule.is_delivered == true) .OrderBy(dl => dl.Delivery_Schedule.delivery_date) .ToList(); foreach (var i in deliveryLIs) { i.CalculateTotal(i.product_inventory_id); } this.DeliveryItems = deliveryLIs; // determine delivery status bool isComplete = true; foreach (var i in this.Lineitems) { var matchingDeliveryItems = this.DeliveryItems.Where(di => di.invoice_lineitem_id == i.Id).ToList(); if (matchingDeliveryItems != null) { int qty = 0; foreach (var d in matchingDeliveryItems) { qty += d.lineitem_unit_quantity; } if (i.lineitem_unit_quantity != qty) { isComplete = false; } } else { isComplete = false; } } if (isComplete == false) { this.DeliveryStatus = "Pending"; } else { this.DeliveryStatus = "Complete"; } this.Subtotal = subtotal; this.TaxAmount = subtotal * Tax; this.Total = this.Subtotal + this.TaxAmount; }