Beispiel #1
0
        // Save new Record
        public JsonResult SaveRecord(SalesViewModel model)
        {
            var result = false;

            try
            {
                if (model.Ps_Id > 0)
                {
                    var record = db.ProductsSolds.SingleOrDefault(x => x.Ps_Id == model.Ps_Id);
                    record.Ps_CustomerId = model.Ps_CustomerId;
                    record.Ps_ProductId  = model.Ps_ProductId;
                    record.Ps_StoreId    = model.Ps_StoreId;
                    record.DateSold      = model.DateSold;
                    db.SaveChanges();
                    result = true;
                }
                else
                {
                    var record = new ProductsSold();
                    record.Ps_CustomerId = model.Ps_CustomerId;
                    record.Ps_ProductId  = model.Ps_ProductId;
                    record.Ps_StoreId    = model.Ps_StoreId;
                    record.DateSold      = model.DateSold;
                    db.ProductsSolds.Add(record);
                    db.SaveChanges();
                    result = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public SalesOrderItem CreateOrderItem(ProductsSold productSold)
        {
            SalesOrderItem salesOrderItem = null;

            var product = db.FindProduct(productSold.ProductCode);

            if (product != null)
            {
                // Update the product pack size
                var rp = ropesDb.FindProduct(product.ProductCode);
                if (rp == null)
                {
                    LogService.WriteLog(TransType.Replenishment, productSold.StoreId, null, $"Error: Product {product.ProductCode} not found in ROPES! Using pack size of {product.PackSize}");
                }
                else
                {
                    product.PackSize = rp.MSQ;
                    db.InsertOrUpdateProduct(product, false);

                    LogService.WriteLog(TransType.Replenishment, productSold.StoreId, product.Id, $"Product {product.ProductCode} updated with pack size: {product.PackSize}");
                }

                salesOrderItem = new SalesOrderItem {
                    Brand        = "",
                    SaleDate     = DateTimeOffset.Now,
                    Number       = "",
                    StoreId      = productSold.StoreId,
                    ProductCode  = productSold.ProductCode,
                    ProductName  = productSold.ProductName,
                    Quantity     = productSold.Qty,
                    CurrencyCode = "",
                    Price        = 0,
                    Notes        = "",
                    MSQ          = (product.PackSize < 1 ? 1 : product.PackSize)
                };

                // We now apply the 'algorithm' to work out the quantity to be ordered:

                // The following method calculates: totalStock = stockOnHand - stockInTransit
                int stockOnHand    = 0,
                    stockInTransit = 0;
                ProductService.GetTotalStock(currentStore, product, ref stockOnHand, ref stockInTransit);
                var totalStock = stockOnHand + stockInTransit;

                int     sales          = productSold.Qty;
                decimal forecastFactor = (currentStore.ForecastFactor == null ? 0 : currentStore.ForecastFactor.Value);

                // Formula take from spreadsheet provided by Emma Shaw
                // =IF(CEILING(F4-(C4+D4)+(A4*B4),E4)<0,0,CEILING(F4-(C4+D4)+(A4*B4),E4))
                // =IF(CEILING(product.Mpl-(totalStock)+(sales*forecastFactor),product.PackSize)<0,0,CEILING(product.Mpl-(totalStock)+(sales*forecastFactor),product.PackSize))
                //salesOrderItem.Quantity = Math.Max(0, (int)Ceiling(product.Mpl - (totalStock) + (sales * forecastFactor), product.PackSize));
                salesOrderItem.Quantity = CalculateOrderQty(product.Mpl, totalStock, sales, forecastFactor, product.PackSize);

                LogService.WriteLog(TransType.Replenishment, productSold.StoreId, product.Id, $"Product {productSold.ProductCode} / Sales:{sales} ForecastFactor:{forecastFactor} SOH:{stockOnHand} SIT:{stockInTransit} TotalStock:{totalStock} PackSize:{product.PackSize} MPL:{product.Mpl} OrderQty:{salesOrderItem.Quantity}");
            }

            return(salesOrderItem);
        }
        public void SaveTempToProductsSoldTable(ErplyTempModel temp, int unixTimeStamp)
        {
            ProductsSold entity = new ProductsSold {
                StoreId       = temp.ErplyStoreId,
                UnixDateStamp = unixTimeStamp,
                ProductCode   = temp.ProductCode,
                ProductName   = temp.ProductName,
                //Minimum = ??
                //DFO = ??
                Qty = temp.Qty
            };

            db.InsertOrUpdateProductSold(entity);
        }
Beispiel #4
0
        public void Initialize()
        {
            StaffList = new ObservableCollection <Staff>(Database.GetAllStaffs());

            // Monthly Sales
            ProductsSold      = Database.GetAllProductsOnMonth(DateTime.Now);
            ProductsSoldShown = new ObservableCollection <Item>(ProductsSold.Select(x => new Item(x)));
            MonthlySalesDate  = DateTime.Now;
            var list = Enum.GetNames(typeof(ProductCategory));

            FilterCollection = new ObservableCollection <string>(list);

            // Product Sales
            TopProducts = Database.GetTopProductsOnMonth(DateTime.Now);
            for (int i = 0; i < TopProducts.Count; i++)
            {
                TopProducts[i].Brush = Mains.GetBrushFromList[i];
            }
            TotalTopSales = TopProducts.Sum(x => x.TotalSale);
            DrawPieChart();
        }
Beispiel #5
0
 public ActionResult BuyProduct(Products prod)
 {
     if (Session["UserID"] != null)
     {
         if (prod.isAuction == 1)
         {
             //Si aun queda tiempo de la subasta
             var subasta    = db.Auction.SqlQuery("SELECT * FROM Auction WHERE ProductID =" + prod.ProductID).First();
             var currentBid = db.BidList.SqlQuery("SELECT * FROM BidList WHERE AuctionID = " + subasta.AuctionID).ToList().Last();
             int userBid    = Convert.ToInt32(Request.Form["auctionBID"]);
             if (userBid >= currentBid.Bid + 100)
             {
                 BidList newBid = new BidList();
                 newBid.BidID     = db.BidList.Count() + 1;
                 newBid.AuctionID = currentBid.AuctionID;
                 newBid.UserID    = Convert.ToInt32(Session["UserID"]);
                 newBid.Bid       = userBid;
                 db.BidList.Add(newBid);
                 db.Products.Find(prod.ProductID).Price = userBid;
                 db.SaveChanges();
                 return(RedirectToAction("Index", "Home"));
             }
         }
         else
         {
             var    AccMoney = Convert.ToInt32(Session["AccMoney"]);
             int    quantity;
             String Squantity = Request.Form["quantity"];
             if (Squantity != null)
             {
                 quantity = Convert.ToInt32(Squantity);
                 if (quantity <= prod.Existencies && quantity != 0 && prod.Existencies != 0)
                 {
                     if (AccMoney >= prod.Price * quantity)
                     {
                         //Take money from buyer
                         Session["AccMoney"] = AccMoney - prod.Price * quantity;
                         db.Users.Find(Session["UserID"]).AccMoney = Convert.ToInt32(Session["AccMoney"]);
                         //Give money to the seller
                         db.Users.Find(prod.UserID).AccMoney = db.Users.Find(prod.UserID).AccMoney + quantity * prod.Price;
                         //Movement of money
                         Movements mov = new Movements();
                         mov.UserID      = Convert.ToInt32(Session["UserID"]);
                         mov.MovementsID = db.Movements.Count() + 1;
                         mov.Ammount     = -1 * prod.Price * quantity; //(Es * -1 porque debe restar el valor de la cuenta original))
                         mov.Type        = "Compra";
                         db.Movements.Add(mov);
                         //Adding to list of bougth products
                         ProductsSold newSell = new ProductsSold();
                         newSell.SalesID    = db.ProductsSold.Count() + 1;
                         newSell.BuyerID    = Convert.ToInt32(Session["UserID"]);
                         newSell.SellerID   = prod.UserID;
                         newSell.ProductID  = prod.ProductID;
                         newSell.BuyDate    = DateTime.Today;
                         newSell.Price      = prod.Price;
                         newSell.Quantity   = quantity;
                         newSell.ShippingID = prod.ShippingID;
                         db.ProductsSold.Add(newSell);
                         //Actualizar las existencias de un producto
                         var productList = db.Products.ToList();
                         foreach (var product in productList)
                         {
                             if (product.ProductID == prod.ProductID)
                             {
                                 product.Existencies = product.Existencies - quantity;
                                 prod.Existencies    = product.Existencies;
                                 break;
                             }
                         }
                         db.SaveChanges();
                         return(RedirectToAction("Index", "Home"));
                     }
                 }
             }
             else
             {
                 quantity = 1;
             }
         }
     }
     return(View());
 }