Exemplo n.º 1
0
        public static void EditSoldProduct(SoldProductViewModel model)
        {
            var existingSoldProduct = Db.SoldProducts.FirstOrDefault(sp => sp.Id == model.Id);

            if (existingSoldProduct != null)
            {
                existingSoldProduct.Id        = model.Id;
                existingSoldProduct.SoldDate  = model.SoldDate;
                existingSoldProduct.ProductId = model.ProductId;
                //existingSoldProduct.Product = new Product() {
                //    Id = model.Product.Id,
                //    Name= model.Product.Name,
                //    Price= model.Product.Price
                //};
                existingSoldProduct.CustomerId = model.CustomerId;
                //existingSoldProduct.Customer = new Customer()
                //{
                //    Id = model.Customer.Id,
                //    Name = model.Customer.Name,
                //    Address = model.Customer.Address
                //};
                existingSoldProduct.StoreId = model.StoreId;
                //existingSoldProduct.Store = new Store()
                //{
                //    Id = model.Store.Id,
                //    Name = model.Store.Name,
                //    Address = model.Store.Address
                //};
            }
            Db.SaveChanges();
        }
Exemplo n.º 2
0
 public SoldTransactionViewModel(Transaction transaction) : base(transaction)
 {
     if (Type == TranType.Sold && transaction.Product != null)
     {
         SoldProduct = new SoldProductViewModel(transaction.Product);
     }
 }
        // Get all products and the amount of them that have been sold so far
        public List <SoldProductViewModel> GetTotalSoldProducts()
        {
            List <SoldProductViewModel> soldProducts = new List <SoldProductViewModel>();
            List <ProductViewModel>     products     = _productBusinessLogic.GetAll();
            List <InvoiceViewModel>     invoices     = this.GetAll();

            foreach (var product in products)
            {
                int productCounter = 0;

                foreach (var invoice in invoices)
                {
                    List <DetailLineViewModel> detailLines = _detailLineBusinessLogic.FindByInvoice(invoice);

                    foreach (var detailLine in detailLines)
                    {
                        if (detailLine.Product.Name == product.Name)
                        {
                            productCounter += detailLine.Amount;
                        }
                    }
                }
                SoldProductViewModel soldProduct = new SoldProductViewModel()
                {
                    Product   = product,
                    TotalSold = productCounter
                };
                soldProducts.Add(soldProduct);
            }

            return(soldProducts);
        }
Exemplo n.º 4
0
        public async Task <IActionResult> DeleteSellingProduct(SoldProductViewModel pr)
        {
            var product = AutoMapperConfig.MapperInstance.Map <SoldProduct>(pr);

            await this.productService.DeleteSoldProduct(product);

            return(this.RedirectToAction("Index", "Products"));
        }
Exemplo n.º 5
0
 public ActionResult Edit(SoldProductViewModel model)
 {
     if (ModelState.IsValid)
     {
         SoldProductLogic.EditSoldProduct(model);
         return(Json(new { IsSucceeded = true }));
     }
     return(Json(new { IsSucceeded = false }));
 }
Exemplo n.º 6
0
        public IActionResult GetAllSoldItems(string type)
        {
            decimal PriceReductionPercent = 0M;
            decimal newSellingPrice       = 0M;
            decimal newCostPrice          = 0M;

            if (type == "official")
            {
                PriceReductionPercent = decimal.Parse(configuration.GetSection("ProjectSettings")["PriceReductionPercentage"]);
            }


            List <SoldProductViewModel> soldproductList = new List <SoldProductViewModel>();


            var allsolditems = soldItemRepo.GetAll();

            decimal VatPercent = decimal.Parse(configuration.GetSection("ProjectSettings")["VatPercentage"]);



            foreach (var item in allsolditems)
            {
                var product   = productRepo.GetById(item.ProductId);
                var orderDate = shopsinglerepo.GetSalesdateByCartId(item.ShoppingCartId);

                if (PriceReductionPercent != 0)
                {
                    newSellingPrice = item.AmountSold - (item.AmountSold * PriceReductionPercent);
                    newCostPrice    = product.costPrice - (product.costPrice * PriceReductionPercent);
                }
                else
                {
                    newSellingPrice = item.AmountSold;
                    newCostPrice    = product.costPrice;
                }

                var soldproduct = new SoldProductViewModel()
                {
                    Quantity          = item.quantity,
                    Name              = product.Name,
                    ProductCode       = product.prodCode,
                    ProductImageUrl   = product.productImageUrl,
                    CostPrice         = newCostPrice,
                    TotalSellingPrice = newSellingPrice * item.quantity,
                    VAT        = newSellingPrice * item.quantity * VatPercent,
                    AmountSold = newSellingPrice,
                    DateSold   = orderDate.ToShortDateString()
                };

                soldproductList.Add(soldproduct);
            }


            return(Ok(soldproductList));
        }
Exemplo n.º 7
0
 public static void CreateNewSoldProduct(SoldProductViewModel model)
 {
     try
     {
         Db.SoldProducts.Add(new SoldProduct()
         {
             Id         = model.Id,
             CustomerId = model.CustomerId,
             StoreId    = model.StoreId,
             ProductId  = model.ProductId,
             SoldDate   = model.SoldDate,
         });
         Db.SaveChanges();
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
 public ActionResult Delete(SoldProductViewModel model)
 {
     SoldProductLogic.DeleteSoldProduct(model.Id);
     return(RedirectToAction("Index"));
 }
 public ActionResult Edit(SoldProductViewModel model)
 {
     SoldProductLogic.EditSoldProduct(model);
     return(RedirectToAction("Index"));
 }
Exemplo n.º 10
0
 public ActionResult Create(SoldProductViewModel model)
 {
     SoldProductLogic.CreateNewSoldProduct(model);
     return(RedirectToAction("Index"));
 }
Exemplo n.º 11
0
        public IActionResult GetAllSoldItemsByShop(int shopId, string type, string datefromClient)
        {
            decimal PriceReductionPercent = 0M;
            decimal newSellingPrice       = 0M;
            decimal newCostPrice          = 0M;

            if (type == "official")
            {
                PriceReductionPercent = decimal.Parse(configuration.GetSection("ProjectSettings")["PriceReductionPercentage"]);
            }


            List <SoldProductViewModel> soldproductList = new List <SoldProductViewModel>();


            DateTime date = (datefromClient == "Invalid Date" || datefromClient == "")? DateTime.Now : DateTime.Parse(datefromClient);

            // DateTime date = DateTime.Parse(datefromClient);

            var allsoldbyshop = orderRepo.GetSoldItemsByShop(shopId, date);

            decimal VatPercent = decimal.Parse(configuration.GetSection("ProjectSettings")["VatPercentage"]);

            //check null valu
            if (allsoldbyshop != null)
            {
                foreach (var item in allsoldbyshop)
                {
                    var product   = productRepo.GetById(item.ProductId);
                    var orderDate = shopsinglerepo.GetSalesdateByCartId(item.ShoppingCartId);

                    if (product != null)
                    {
                        if (PriceReductionPercent != 0)
                        {
                            newSellingPrice = item.AmountSold - (item.AmountSold * PriceReductionPercent);
                            newCostPrice    = product.costPrice - (product.costPrice * PriceReductionPercent);
                        }
                        else
                        {
                            newSellingPrice = item.AmountSold;
                            newCostPrice    = product.costPrice;
                        }

                        var soldproduct = new SoldProductViewModel()
                        {
                            Quantity          = item.quantity,
                            Name              = product.Name,
                            ProductCode       = product.prodCode,
                            ProductImageUrl   = product.productImageUrl,
                            CostPrice         = newCostPrice,
                            TotalSellingPrice = newSellingPrice * item.quantity,
                            VAT        = newSellingPrice * item.quantity * VatPercent,
                            AmountSold = newSellingPrice,
                            DateSold   = orderDate.ToShortDateString()
                        };

                        soldproductList.Add(soldproduct);
                    }
                }
            }



            return(Ok(soldproductList));
        }
Exemplo n.º 12
0
 public SoldTransactionViewModel(Transaction transaction)
     : base(transaction)
 {
     if (Type == TranType.Sold && transaction.Product != null) SoldProduct = new SoldProductViewModel(transaction.Product);
 }