Beispiel #1
0
        public ActionResult ReturnPurchase(string purchaseItems)
        {
            var            result     = JsonConvert.DeserializeObject <List <ReturnViewModel> >(purchaseItems);
            ReturnPurchase temp       = new ReturnPurchase();
            StockInventry  stock      = new StockInventry();
            int            errorCount = 0;

            foreach (var pItems in result)
            {
                //Adding Product data in Purchase with DateWise
                Product p = ProductsService.Instance.GetProductInfo(pItems.ProductID);
                temp.ProductId   = p.Id;
                temp.Qty         = pItems.Quantity;
                temp.Date        = DateTime.Now;
                temp.BatchNo     = pItems.BatchNo;
                temp.TotalAmount = pItems.TotalAmount;
                ProductsService.Instance.ReturnPurchase(temp);
                if (ProductsService.Instance.CheckStockForProductReturn(temp))
                {
                    //Retruning Products from Stock
                    stock.ProductId   = pItems.ProductID;
                    stock.Price       = ProductsService.Instance.ProductPrice(pItems.ProductID);
                    stock.Stock       = pItems.Quantity;
                    stock.BatchNo     = pItems.BatchNo;
                    stock.TotalAmount = pItems.TotalAmount;
                    stock.Return      = pItems.Quantity;
                    StockService.Instance.ReturnStock(stock);
                }
                else
                {
                    errorCount++;
                }
            }
            return(Json(errorCount));
        }
 public void SaleProductsDeductedFromStock(StockInventry stock)
 {
     using (var context = new CBContext())
     {
         if (context.StockInventries.Any(x => x.ProductId == stock.ProductId && x.BatchNo == stock.BatchNo && x.Stock > stock.Stock))
         {
             var data = context.StockInventries.Where(x => x.ProductId == stock.ProductId && x.BatchNo == stock.BatchNo).FirstOrDefault();
             data.Stock       = (data.Stock - stock.Stock);
             data.TotalAmount = (data.TotalAmount - stock.TotalAmount);
             data.Sale        = (data.Sale + stock.Sale);
             data.LooseSale   = (data.LooseSale + stock.LooseSale);
             //code to minus the pack if loose sale is equal to pack size
             var temp = context.Products.Where(x => x.Id == stock.ProductId && x.BatchNo == stock.BatchNo).FirstOrDefault();
             if (data.LooseSale >= temp.PackSize)
             {
                 data.Stock     = data.Stock - 1;
                 data.Sale      = data.Sale + 1;
                 data.LooseSale = (int)(data.LooseSale - temp.PackSize);
             }
             //ends here
             context.Entry(data).State = System.Data.Entity.EntityState.Modified;
             context.SaveChanges();
         }
     }
 }
 public void ReturnStock(StockInventry stock)
 {
     using (var context = new CBContext())
     {
         if (context.StockInventries.Any(x => x.ProductId == stock.ProductId && x.BatchNo == stock.BatchNo && x.Stock > stock.Stock))
         {
             var data = context.StockInventries.Where(x => x.ProductId == stock.ProductId && x.BatchNo == stock.BatchNo).FirstOrDefault();
             data.Stock                = (data.Stock - stock.Stock);
             data.Return               = (data.Return + stock.Return);
             data.TotalAmount          = (data.TotalAmount - stock.TotalAmount);
             context.Entry(data).State = System.Data.Entity.EntityState.Modified;
             context.SaveChanges();
         }
     }
 }
 public void updateStock(StockInventry temp)
 {
     using (var context = new CBContext())
     {
         //code to minus the pack if loose sale is equal to pack size
         var productRecord = context.Products.Where(x => x.Id == temp.ProductId && x.BatchNo == temp.BatchNo).FirstOrDefault();
         if (temp.LooseSale >= productRecord.PackSize)
         {
             temp.Stock     = temp.Stock + 1;
             temp.Sale      = temp.Sale - 1;
             temp.LooseSale = (int)(temp.LooseSale - productRecord.PackSize);
         }
         //ends here
         context.Entry(temp).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Beispiel #5
0
        public ActionResult SavePurchase(string purchaseItems)
        {
            var result             = JsonConvert.DeserializeObject <List <PurchaseViewModel> >(purchaseItems);
            PurchaseProducts temp  = new PurchaseProducts();
            StockInventry    stock = new StockInventry();
            int transactionId      = PurchaseService.Instance.PurchaseProductMasterMaxID() + 1;

            int totolAmount = 0;

            foreach (var pItems in result)
            {
                //Adding Product data in Purchase with DateWise


                Product p = ProductsService.Instance.GetProductInfo(pItems.ProductID);
                temp.ProductId     = p.Id;
                temp.Qty           = pItems.Quantity;
                temp.Date          = DateTime.Now;
                temp.TotalAmount   = pItems.TotalAmount;
                temp.TransactionId = transactionId;
                temp.BatchNo       = pItems.BatchNo;
                ProductsService.Instance.PurchaseProduct(temp);
                totolAmount = totolAmount + pItems.TotalAmount;
                //Adding Products data in stock
                stock.ProductId   = pItems.ProductID;
                stock.Price       = ProductsService.Instance.ProductPrice(pItems.ProductID);
                stock.Received    = stock.Received + pItems.Quantity;
                stock.Stock       = pItems.Quantity;
                stock.BatchNo     = pItems.BatchNo;
                stock.TotalAmount = stock.TotalAmount + pItems.TotalAmount;

                StockService.Instance.AddStock(stock);
            }
            PurchaseProductsMaster ob = new PurchaseProductsMaster();

            ob.Date          = DateTime.Now;
            ob.CreatedBy     = "Admin";
            ob.TotalAmount   = totolAmount;
            ob.TransactionId = transactionId;
            PurchaseService.Instance.AddTransaction(ob);
            return(Json("Success"));
        }
 public void AddStock(StockInventry stock)
 {
     using (var context = new CBContext())
     {
         if (context.StockInventries.Any(x => x.ProductId == stock.ProductId && x.BatchNo == stock.BatchNo))
         {
             var data = context.StockInventries.Where(x => x.ProductId == stock.ProductId && x.BatchNo == stock.BatchNo).FirstOrDefault();
             data.Stock                = data.Stock + stock.Stock;
             data.Received             = (data.Received + stock.Received);
             data.TotalAmount          = (data.TotalAmount + stock.TotalAmount);
             context.Entry(data).State = System.Data.Entity.EntityState.Modified;
             context.SaveChanges();
         }
         else
         {
             context.StockInventries.Add(stock);
             context.SaveChanges();
         }
     }
 }
Beispiel #7
0
        public ActionResult SaveSaleProducts(string saleItems, string CustomerName)
        {
            var       result = JsonConvert.DeserializeObject <List <SaleViewModel> >(saleItems);
            OrderItem temp   = new OrderItem();
            Order     order  = new Order();
            decimal   total  = 0;

            foreach (var item in result)
            {
                total = total + Convert.ToDecimal(item.Amount);
            }
            order.TotalAmount  = total;
            order.Date         = DateTime.Now;
            order.CustomerName = CustomerName;
            SaleService.Instance.SaveOrder(order);
            foreach (var item in result)
            {
                temp.OrderID   = SaleService.Instance.OrderMaxID();
                temp.ProductID = item.ProductID;
                temp.BatchNo   = item.BatchNo;
                try
                {
                    if (item.Quantity != "")
                    {
                        temp.Quantity = int.Parse(item.Quantity);
                    }
                }
                catch (Exception)
                {
                    temp.Quantity = 0;
                }
                try
                {
                    if (item.Loose != "")
                    {
                        temp.Loose = int.Parse(item.Loose);
                    }
                }
                catch (Exception)
                {
                    temp.Loose = 0;
                }

                temp.Price      = Convert.ToDecimal(item.Price);
                temp.ExpiryDate = DateTime.Parse(item.ExpiryDate);
                try
                {
                    if (item.Discount != "")
                    {
                        temp.Discount = int.Parse(item.Discount);
                    }
                }
                catch (Exception)
                {
                    temp.Discount = 0;
                }
                temp.Amount = Convert.ToDecimal(item.Amount);
                SaleService.Instance.SaveSale(temp);
            }

            StockInventry stock = new StockInventry();

            //Minus the product from stock which are saled.
            foreach (var item in result)
            {
                stock.ProductId = item.ProductID;
                stock.BatchNo   = item.BatchNo;
                try
                {
                    if (item.Amount != "")
                    {
                        //stock.TotalAmount = int.Parse(item.Amount);
                        stock.TotalAmount = (int)Convert.ToInt64(Math.Floor(Convert.ToDouble(item.Amount)));
                    }
                }
                catch (Exception)
                {
                    stock.TotalAmount = 0;
                }

                try
                {
                    if (item.Quantity != "")
                    {
                        stock.Stock = int.Parse(item.Quantity);
                        stock.Sale  = int.Parse(item.Quantity);
                    }
                }
                catch (Exception)
                {
                    stock.Stock = 0;
                }

                try
                {
                    if (item.Loose != "")
                    {
                        stock.LooseSale = int.Parse(item.Loose);
                    }
                }
                catch (Exception)
                {
                    stock.LooseSale = 0;
                }



                StockService.Instance.SaleProductsDeductedFromStock(stock);
            }
            int orderId = PurchaseService.Instance.OrdersMaxID();

            return(Json(orderId));
        }