예제 #1
0
        public void SumUp()
        {
            List <SalesOrderLine> lines = new List <SalesOrderLine>();
            double discountPercentage   = 0;

            using (MyDbContext db = new MyDbContext())
            {
                //get the percentage of so

                SalesType salesType = db.SalesType.Where(st => st.SalesTypeId == this.SalesTypeId).SingleOrDefault();
                if (salesType != null)
                {
                    discountPercentage = salesType.DiscountPercentage;
                }

                lines         = db.SalesOrderLine.Where(x => x.SalesOrderId.Equals(this.SalesOrderId)).ToList();
                this.Amount   = lines.Sum(x => x.Amount);
                this.SubTotal = lines.Sum(x => x.SubTotal);
                this.Discount = lines.Sum(x => x.DiscountAmount);
                this.Tax      = lines.Sum(x => x.TaxAmount);
                this.Total    = this.Freight + lines.Sum(x => x.Total) * (1 - discountPercentage);
            }

            //update master data by its lines
        }
예제 #2
0
 public void SetBestDiscount()
 {
     using (MyDbContext db = new MyDbContext())
     {
         SalesType bestST = db.SalesType.Where(st => st.From < DateTime.Now && DateTime.Now < st.To).OrderByDescending(st => st.DiscountPercentage).First();
         this.SalesTypeId = bestST.SalesTypeId;
         SumUp();
         //this.OrderProgressTypeId = OrderProgressStatus.BEST_DISCOUNT_APPLIED;
     }
 }