public ActionResult Create([Bind(Include = "Payment_ID,Product_ID,STUDENT_ID,Date,Quantity,Total")] ProductPayment productPayment)
        {
            if (ModelState.IsValid)
            {
                var count = db.ProductPayments.ToList().Count();
                productPayment.Payment_ID = (count + 1).ToString();
                productPayment.Date       = DateTime.Now.ToShortDateString();
                //Logic
                //Get Product price from Product Table using ProductID
                //Calculate Total Cash paid: productPrice * Quantity
                var product  = db.Products.SingleOrDefault(b => b.Product_ID == productPayment.Product_ID);
                var price    = Convert.ToDecimal(product.SellingPrice);
                var quantity = Convert.ToDecimal(productPayment.Quantity);
                productPayment.Total = (quantity * price).ToString();
                //Update QuantityInStock in Product table : product.Quantityinstock - payment.Quantity
                //Update QuantitySold in Product table : QuantitySold + payment.Quantity
                var quantityInStock = Convert.ToDecimal(product.QuantityInStock);
                var quantitySold    = Convert.ToDecimal(product.QuantitySold);
                product.QuantityInStock = (quantityInStock - quantity).ToString();
                product.QuantitySold    = (quantitySold + quantity).ToString();

                //Calculate Profit from product
                var selling = Convert.ToDecimal(product.SellingPrice);
                var cost    = Convert.ToDecimal(product.CostPrice);
                product.Profit = ((selling - cost) * Convert.ToDecimal(product.QuantitySold)).ToString();

                db.ProductPayments.Add(productPayment);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Product_ID = new SelectList(db.Products, "Product_ID", "ProductName", productPayment.Product_ID);
            ViewBag.STUDENT_ID = new SelectList(db.Students, "STUDENT_ID", "STUDENT_Fname", productPayment.STUDENT_ID);
            return(View(productPayment));
        }
Beispiel #2
0
        public IPayment CreatePayment(Product pProduct)
        {
            IPayment payment = null;

            switch (pProduct.Category)
            {
            case (Int16)enmCategory.Physical:
                if (pProduct.ProductType == "Books")
                {
                    payment = new BookPayment(_commission);
                }
                else
                {
                    payment = new ProductPayment(_commission);
                }
                break;

            case (Int16)enmCategory.Membership:
                if (pProduct.ProductType == "New")
                {
                    payment = new NewMembershipPayment(_membership, _notification);
                }
                else
                {
                    payment = new UpgradeMembershipPayment(_membership, _notification);
                }
                break;

            case (Int16)enmCategory.Video:
                payment = new VideoPayment();
                break;
            }
            return(payment);
        }
        public ActionResult DeleteConfirmed(string id)
        {
            ProductPayment productPayment = db.ProductPayments.Find(id);

            db.ProductPayments.Remove(productPayment);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "Payment_ID,Product_ID,STUDENT_ID,Date,Quantity,Total")] ProductPayment productPayment)
 {
     if (ModelState.IsValid)
     {
         db.Entry(productPayment).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Product_ID = new SelectList(db.Products, "Product_ID", "ProductName", productPayment.Product_ID);
     ViewBag.STUDENT_ID = new SelectList(db.Students, "STUDENT_ID", "STUDENT_Fname", productPayment.STUDENT_ID);
     return(View(productPayment));
 }
        // GET: ProductPayments/Details/5
        public ActionResult Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProductPayment productPayment = db.ProductPayments.Find(id);

            if (productPayment == null)
            {
                return(HttpNotFound());
            }
            return(View(productPayment));
        }
        // GET: ProductPayments/Edit/5
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProductPayment productPayment = db.ProductPayments.Find(id);

            if (productPayment == null)
            {
                return(HttpNotFound());
            }
            ViewBag.Product_ID = new SelectList(db.Products, "Product_ID", "ProductName", productPayment.Product_ID);
            ViewBag.STUDENT_ID = new SelectList(db.Students, "STUDENT_ID", "STUDENT_Fname", productPayment.STUDENT_ID);
            return(View(productPayment));
        }
        private async Task <int> UpdateProductPayment(IEnumerable <int> projectIds)
        {
            if (projectIds == null)
            {
                projectIds = (from project in _context.Project
                              where project.StatusId == (int)StatusProject.Active
                              select project.Id).ToList();
            }

            var tmpItems = from product in _context.Product
                           join project in _context.Project on product.ProjectId equals project.Id
                           where projectIds.Contains(product.ProjectId) && project.StatusId == (int)StatusProject.Active
                           select new
            {
                product.Id,
                product.ValueDate,
                project.PayTypeId,
                project.Deadline
            };

            var paymentList = new List <ProductPayment>();

            foreach (var item in tmpItems.ToList())
            {
                var payment = new ProductPayment();
                payment.ProductId   = item.Id;
                payment.NextPayment = item.ValueDate;
                payment.LastUpdate  = DateTime.Now;

                var dateDue = item.ValueDate.AddMonths(TypeParser.GetInt32Value(item.Deadline * 12));
                switch ((PaymentType)item.PayTypeId)
                {
                case PaymentType.Annual:
                    payment.FreqTotal = TypeParser.GetInt32Value(item.Deadline);
                    while (payment.NextPayment < DateTime.Now)
                    {
                        payment.NextPayment = payment.NextPayment.AddMonths(12);
                        payment.FreqCurrent++;
                    }
                    break;

                case PaymentType.AnnualHalf:
                    payment.FreqTotal = TypeParser.GetInt32Value(item.Deadline * 2);
                    while (payment.NextPayment < DateTime.Now)
                    {
                        payment.NextPayment = payment.NextPayment.AddMonths(6);
                        payment.FreqCurrent++;
                    }
                    break;

                case PaymentType.Quater:
                    payment.FreqTotal = TypeParser.GetInt32Value(item.Deadline * 4);
                    while (payment.NextPayment < DateTime.Now)
                    {
                        payment.NextPayment = payment.NextPayment.AddMonths(3);
                        payment.FreqCurrent++;
                    }
                    break;

                case PaymentType.Month:
                    payment.FreqTotal = TypeParser.GetInt32Value(item.Deadline * 12);
                    while (payment.NextPayment < DateTime.Now)
                    {
                        payment.NextPayment = payment.NextPayment.AddMonths(1);
                        payment.FreqCurrent++;
                    }
                    break;

                case PaymentType.Day:
                    payment.FreqTotal = TypeParser.GetInt32Value(item.Deadline * 365);
                    while (payment.NextPayment < DateTime.Now)
                    {
                        payment.NextPayment = payment.NextPayment.AddDays(1);
                        payment.FreqCurrent++;
                    }
                    break;

                default:
                    break;
                }

                if (payment.NextPayment <= dateDue)
                {
                    paymentList.Add(payment);
                }
            }

            _context.ProductPayment.RemoveRange(from p in _context.ProductPayment select p);
            await _context.SaveChangesAsync();

            await _context.ProductPayment.AddRangeAsync(paymentList);

            return(await _context.SaveChangesAsync());
        }