public ActionResult AddProductCorrection([Bind(Include = "Id,Recipe_Id,MovementType_Id,Warehouse_Id,Quantity,Remark,IsActive,CreatedBy,CreatedDate,ChangedBy,ChangedDate")] StockOperationViewModel productchange)
        {
            if (ModelState.IsValid)
            {
                //PRODUCTMOVEMENT ELKÉSZÍTÉSE
                var identity        = (ClaimsIdentity)User.Identity;
                var sid             = identity.Claims.Where(c => c.Type == ClaimTypes.Sid).Select(c => c.Value).SingleOrDefault();
                var productMovement = new ProductMovement
                {
                    Recipe_Id       = productchange.Recipe_Id,
                    MovementType_Id = productchange.MovementType_Id,
                    Warehouse_Id    = productchange.Warehouse_Id,
                    Quantity        = productchange.Quantity,
                    Remark          = productchange.Remark,
                    IsActive        = productchange.IsActive,
                    CreatedDate     = DateTime.Now,
                    CreatedBy       = Convert.ToInt32(sid)
                };
                db.ProductMovements.Add(productMovement);

                //CURRENTPRODUCTSTOCK MÓDOSÍTÁSA
                var producttoupdate            = db.CurrentProductStocks.First(i => i.Recipe_Id == productchange.Recipe_Id);
                var originalingredientquantity = db.CurrentProductStocks.First(i => i.Recipe_Id == productchange.Recipe_Id).Quantity;
                producttoupdate.Quantity        = originalingredientquantity + productchange.Quantity;
                producttoupdate.ChangedDate     = DateTime.Now;
                producttoupdate.ChangedBy       = Convert.ToInt32(sid);
                db.Entry(producttoupdate).State = EntityState.Modified;


                if (db.SaveChanges() > 0)
                {
                    TempData["Operation"] = "success";
                }
                else
                {
                    TempData["Operation"] = "danger";
                }
                return(RedirectToAction("AddProductCorrection", "StockOperations"));
            }

            ViewBag.MovementType_Id = new SelectList(db.MovementTypes.Where(i => i.MovementKey == "correction"), "Id", "Name");
            var existingProduct = new List <Recipe>();

            foreach (var ai in db.Recipes)
            {
                if (db.CurrentProductStocks.Any(x => x.Recipe_Id == ai.Id))
                {
                    ai.Name = string.Format("{0} - {1} t", ai.Name, string.Format("{0:0.##}", db.CurrentProductStocks.First(x => x.Recipe_Id == ai.Id).Quantity));
                    existingProduct.Add(ai);
                }
                ;
            }
            ViewBag.Recipe_Id    = new SelectList(existingProduct, "Id", "Name");
            ViewBag.Warehouse_Id = new SelectList(db.Warehouses, "Id", "Name");
            return(View(productchange));
        }
        public void Save()
        {
            var movement = new ProductMovement
            {
                Id           = Guid.NewGuid(),
                ProductId    = Product.Id,
                DateTime     = DateTimeOffset.Now,
                MovementType = ProductMovementType.Receipt,
                Quantity     = Quantity
            };

            ProductService.AddMovement(movement);

            Close();
        }
示例#3
0
        public void AddStockReceipt()
        {
            IProductService productService = new ProductService(new ProductManager());

            var product = productService.GetProducts().First();

            var movement = new ProductMovement
            {
                Id           = Guid.NewGuid(),
                ProductId    = product.Id,
                DateTime     = DateTimeOffset.Now,
                MovementType = ProductMovementType.Receipt, // Stock Receipt
                Quantity     = 10
            };

            productService.AddMovement(movement);

            Assert.AreEqual <int>(product.QuantityOnHand + movement.Quantity, productService.GetProduct(product.Id).QuantityOnHand);
        }
示例#4
0
        private ProductMovement InsertProductMovement(byte premiseId, int sessionId, int productId, int quantity, byte unitId,
                                                      string movementCategory, string movementType)
        {
            var productMovement = new ProductMovement
            {
                PremiseId        = premiseId,
                MovementCategory = movementCategory,
                MovementType     = movementType,
                //TODO: change to int
                ProductId = productId,
                UnitId    = unitId,
                Quantity  = quantity,
                //TODO: change to datetime
                MovementDate = DateTime.Now,
                SessionId    = sessionId
            };

            uow.ProductMovementRepository.Insert(productMovement);
            return(productMovement);
        }
示例#5
0
        public void AddMovement(ProductMovement movement)
        {
            using (var transaction = new TransactionScope())
                using (var connection = new ConnectionScope())
                {
                    var product = GetProduct(movement.ProductId);
                    if (product == null)
                    {
                        throw new Exception("Product not found");
                    }

                    if (product.QuantityOnHand + movement.Quantity < 0)
                    {
                        throw new Exception("Quantity on hand cannot become negative.");
                    }

                    movement.Insert();
                    product.QuantityOnHand += movement.Quantity;
                    product.Update();

                    transaction.Complete();
                }
        }
示例#6
0
        public ActionResult EditIssue(DTOEditIssue r)
        {
            if (ModelState.IsValid)
            {
                var identity = (ClaimsIdentity)User.Identity;
                var sid      = identity.Claims.Where(c => c.Type == ClaimTypes.Sid).Select(c => c.Value).SingleOrDefault();
                //var deliveryNoteCreted = false;

                var existingDeliveryNote = db.DeliveryNotes.Find(r.Id);

                //DELIVERYNOTE UPDATE
                existingDeliveryNote.DeliveryNoteDate = (DateTime)r.DeliveryNote.DeliveryNoteDate;
                existingDeliveryNote.Customer_Id      = r.DeliveryNote.Customer_Id;
                existingDeliveryNote.Number           = r.DeliveryNote.Number;
                existingDeliveryNote.Remark           = r.DeliveryNote.Remark;
                existingDeliveryNote.IsActive         = r.DeliveryNote.IsActive;
                existingDeliveryNote.ChangedBy        = Convert.ToInt32(sid);
                existingDeliveryNote.ChangedDate      = DateTime.Now;

                db.Entry(existingDeliveryNote).State = EntityState.Modified;


                for (int x = 0; x < r.DeliveryNote.DeliveryNoteItems.Count; x++)
                {
                    //PRODUCTMOVEMENT UPDATE
                    var currentIndex           = x;
                    var currentRecipeId        = r.DeliveryNote.DeliveryNoteItems[currentIndex].Recipe_Id;
                    var currentWarehouseId     = r.DeliveryNote.DeliveryNoteItems[currentIndex].Warehouse_Id;
                    var currentProductQuantity = r.DeliveryNote.DeliveryNoteItems[currentIndex].Quantity;

                    if (r.DeliveryNote.DeliveryNoteItems[currentIndex].ProductMovementIsActive || r.DeliveryNote.DeliveryNoteItems[currentIndex].Id == 0)
                    {
                        //HA VAN MÁR PRODUCTMOVEMENT -- UPDATE
                        if (r.DeliveryNote.DeliveryNoteItems[currentIndex].ProductMovement_Id != null)
                        {
                            var existingProductMovement =
                                db.ProductMovements.Find(r.DeliveryNote.DeliveryNoteItems[currentIndex].ProductMovement_Id);
                            var originalQuantity = existingProductMovement.Quantity;
                            //HA NEM EGYEZNEK A MENNYISÉGEK VAGY A RAKTÁR, UPDATE
                            if (
                                existingProductMovement.Quantity != r.DeliveryNote.DeliveryNoteItems[currentIndex].Quantity ||
                                existingProductMovement.Warehouse_Id != r.DeliveryNote.DeliveryNoteItems[currentIndex].Warehouse_Id
                                )
                            {
                                existingProductMovement.Quantity =
                                    (decimal)r.DeliveryNote.DeliveryNoteItems[currentIndex].Quantity;
                                existingProductMovement.Warehouse_Id = (int)r.DeliveryNote.DeliveryNoteItems[currentIndex].Warehouse_Id;
                                existingProductMovement.IsActive     = r.DeliveryNote.DeliveryNoteItems[currentIndex]
                                                                       .ProductMovementIsActive;
                                existingProductMovement.ChangedBy       = Convert.ToInt32(sid);
                                existingProductMovement.ChangedDate     = DateTime.Now;
                                db.Entry(existingProductMovement).State = EntityState.Modified;

                                var quantityDifference = originalQuantity -
                                                         (decimal)r.DeliveryNote.DeliveryNoteItems[currentIndex].Quantity;

                                //HA VAN MENNYISÉG VÁLTOZÁS, PRODUCTSTOCK MÓDOSÍTÁSA
                                if (quantityDifference != 0)
                                {
                                    var currentProductStock = db.CurrentProductStocks.SingleOrDefault(c => c.Recipe_Id == currentRecipeId && c.Warehouse_Id == currentWarehouseId);
                                    currentProductStock.Quantity        = currentProductStock.Quantity + quantityDifference;
                                    currentProductStock.ChangedBy       = Convert.ToInt32(sid);
                                    currentProductStock.ChangedDate     = DateTime.Now;
                                    db.Entry(currentProductStock).State = EntityState.Modified;
                                }
                            }
                        }
                        //HA MÉG NINCS PRODUCTMOVEMENT -- CREATE
                        else
                        {
                            var productMovement = new ProductMovement
                            {
                                Recipe_Id       = (int)r.DeliveryNote.DeliveryNoteItems[currentIndex].Recipe_Id,
                                MovementType_Id = db.MovementTypes.SingleOrDefault(c => c.MovementKey == "issue").Id,
                                Warehouse_Id    = (int)r.DeliveryNote.DeliveryNoteItems[currentIndex].Warehouse_Id,
                                Quantity        = (decimal)r.DeliveryNote.DeliveryNoteItems[currentIndex].Quantity,
                                Remark          = r.DeliveryNote.Remark,
                                IsActive        = true,
                                CreatedDate     = DateTime.Now,
                                CreatedBy       = Convert.ToInt32(sid)
                            };
                            db.ProductMovements.Add(productMovement);

                            //CURRENTPRODUCTSTOCK MÓDOSÍTÁSA
                            var productexists = db.CurrentProductStocks.Where(i => i.Recipe_Id == currentRecipeId);
                            //HA NINCS A TERMÉKBŐL, HOZZÁADJUK
                            if (!productexists.Any())
                            {
                                db.CurrentProductStocks.Add(new CurrentProductStock
                                {
                                    CreatedDate  = DateTime.Now,
                                    CreatedBy    = Convert.ToInt32(sid),
                                    IsActive     = true,
                                    Recipe_Id    = (int)r.DeliveryNote.DeliveryNoteItems[currentIndex].Recipe_Id,
                                    Warehouse_Id = (int)r.DeliveryNote.DeliveryNoteItems[currentIndex].Warehouse_Id,
                                    Quantity     = -(decimal)r.DeliveryNote.DeliveryNoteItems[currentIndex].Quantity,
                                });
                            }
                            //HA VAN A TERMÉKBŐL, UPDATE
                            else
                            {
                                var producttoupdate         = db.CurrentProductStocks.First(i => i.Recipe_Id == currentRecipeId && i.Warehouse_Id == currentWarehouseId);
                                var originalproductquantity = db.CurrentProductStocks.First(i => i.Recipe_Id == currentRecipeId && i.Warehouse_Id == currentWarehouseId).Quantity;
                                var quantityDifference      = originalproductquantity -
                                                              (decimal)r.DeliveryNote.DeliveryNoteItems[currentIndex].Quantity;
                                producttoupdate.Quantity        = (decimal)(originalproductquantity + quantityDifference);
                                producttoupdate.ChangedDate     = DateTime.Now;
                                producttoupdate.ChangedBy       = Convert.ToInt32(sid);
                                db.Entry(producttoupdate).State = EntityState.Modified;
                            }

                            //SZÁLLÍTÓLEVÉL TÉTELEK HOZZÁADÁSA
                            var existingDeliveryNoteId = r.DeliveryNote.Id;
                            var deliveryNoteItem       = new DeliveryNoteItem
                            {
                                DeliveryNote_Id = existingDeliveryNoteId,
                                ProductMovement = productMovement
                            };
                            db.DeliveryNoteItems.Add(deliveryNoteItem);
                        }
                    }
                    else
                    {
                        //HA TÖRÖLTEK SORT A SZÁLLÍTÓLEVÉLRŐL

                        //DELIVERYNOTEITEM TÖRLÉSE
                        var deliveryNoteItemToDelete  = db.DeliveryNoteItems.Find(r.DeliveryNote.DeliveryNoteItems[currentIndex].Id);
                        var affectedProductMovementId = deliveryNoteItemToDelete.ProductMovement_Id;

                        db.Entry(deliveryNoteItemToDelete).State = EntityState.Deleted;

                        //PRODUCTMOVEMENT ISACTIVE=0
                        var productMovementToDelete = db.ProductMovements.Find(affectedProductMovementId);
                        var affectedRecipeId        = productMovementToDelete.Recipe_Id;
                        productMovementToDelete.IsActive    = false;
                        productMovementToDelete.ChangedBy   = Convert.ToInt32(sid);
                        productMovementToDelete.ChangedDate = DateTime.Now;

                        db.Entry(productMovementToDelete).State = EntityState.Modified;

                        //CURRENTPRODUCTSTOCK MÓDOSÍTÁSA
                        var affectedCurrentProductStock = db.CurrentProductStocks.First(i => i.Recipe_Id == affectedRecipeId && i.Warehouse_Id == currentWarehouseId);
                        var originalproductquantity     = db.CurrentProductStocks.First(i => i.Recipe_Id == affectedRecipeId && i.Warehouse_Id == currentWarehouseId).Quantity;
                        affectedCurrentProductStock.Quantity    = (decimal)(originalproductquantity + (decimal)r.DeliveryNote.DeliveryNoteItems[currentIndex].Quantity);
                        affectedCurrentProductStock.ChangedBy   = Convert.ToInt32(sid);
                        affectedCurrentProductStock.ChangedDate = DateTime.Now;

                        db.Entry(affectedCurrentProductStock).State = EntityState.Modified;
                    }
                }

                if (db.SaveChanges() > 0)
                {
                    TempData["Operation"] = "success";
                }
                else
                {
                    TempData["Operation"] = "danger";
                }
                return(RedirectToAction("Index", "CurrentProductStocks"));
            }
            return(View(r));
        }
示例#7
0
        public ActionResult AddIssue([Bind(Include = "Id,deliveryNoteItem,Customer_Id,DeliveryNote_Number,DeliveryNote_Remark,DeliveryNote_Date,MovementType_Id,Remark,IsActive,CreatedBy,CreatedDate,ChangedBy,ChangedDate")] InventoryOperationViewModel inventoryIssue)
        {
            if (ModelState.IsValid)
            {
                var identity           = (ClaimsIdentity)User.Identity;
                var sid                = identity.Claims.Where(c => c.Type == ClaimTypes.Sid).Select(c => c.Value).SingleOrDefault();
                var deliveryNoteCreted = false;

                for (int x = 0; x < inventoryIssue.deliveryNoteItem.Count; x++)
                {
                    //PRODUCTMOVEMENT ELKÉSZÍTÉSE
                    var currentIndex           = x;
                    var currentProductId       = inventoryIssue.deliveryNoteItem[currentIndex].Recipe_Id;
                    var currentProductQuantity = inventoryIssue.deliveryNoteItem[currentIndex].Quantity;
                    var productMovement        = new ProductMovement
                    {
                        Recipe_Id       = inventoryIssue.deliveryNoteItem[currentIndex].Recipe_Id,
                        MovementType_Id = inventoryIssue.MovementType_Id,
                        Warehouse_Id    = inventoryIssue.deliveryNoteItem[currentIndex].Warehouse_Id,
                        Quantity        = inventoryIssue.deliveryNoteItem[currentIndex].Quantity,
                        Remark          = inventoryIssue.Remark,
                        IsActive        = true,
                        CreatedDate     = DateTime.Now,
                        CreatedBy       = Convert.ToInt32(sid)
                    };
                    db.ProductMovements.Add(productMovement);


                    //CURRENTPRODUCTSTOCK MÓDOSÍTÁSA
                    var productexists = db.CurrentProductStocks.Where(i => i.Recipe_Id == currentProductId);

                    //HA NINCS A TERMÉKBŐL, VAGY KEVESEBB, MINT AMENNYIT KI AKAR ADNI, HIBA
                    if (!productexists.Any())
                    {
                        TempData["Operation"]        = "danger";
                        TempData["OperationMessage"] = string.Format("A következő termék nincs raktáron: {0}",
                                                                     db.Recipes.First(i => i.Id == currentProductId).Name);
                        return(RedirectToAction("AddIssue", "InventoryOperations"));
                    }
                    if (currentProductQuantity > productexists.First().Quantity)
                    {
                        TempData["Operation"]        = "danger";
                        TempData["OperationMessage"] = string.Format("Nem áll rendelkezésre a szükséges mennyiség ({0} t) a következő termékből: {1}",
                                                                     currentProductQuantity, productexists.First().Recipe.Name);
                        return(RedirectToAction("AddIssue", "InventoryOperations"));
                    }
                    //HA VAN A TERMÉKBŐL ÉS ELEGENDŐ IS, UPDATE
                    else
                    {
                        var producttoupdate         = db.CurrentProductStocks.First(i => i.Recipe_Id == currentProductId);
                        var originalproductquantity = db.CurrentProductStocks.First(i => i.Recipe_Id == currentProductId).Quantity;
                        producttoupdate.Quantity        = originalproductquantity - currentProductQuantity;
                        producttoupdate.ChangedDate     = DateTime.Now;
                        producttoupdate.ChangedBy       = Convert.ToInt32(sid);
                        db.Entry(producttoupdate).State = EntityState.Modified;
                    }

                    //SZÁLLÍTÓLEVÉL HOZZÁADÁSA
                    var existingDeliveryNoteId = 0;
                    if (deliveryNoteCreted == false)
                    {
                        var deliveryNote = new DeliveryNote
                        {
                            Customer_Id      = inventoryIssue.Customer_Id,
                            Type             = "issue",
                            Number           = inventoryIssue.DeliveryNote_Number,
                            Remark           = inventoryIssue.DeliveryNote_Remark,
                            IsActive         = true,
                            CreatedDate      = DateTime.Now,
                            CreatedBy        = Convert.ToInt32(sid),
                            DeliveryNoteDate = inventoryIssue.DeliveryNote_Date
                        };
                        db.DeliveryNotes.Add(deliveryNote);
                        deliveryNoteCreted     = true;
                        existingDeliveryNoteId = deliveryNote.Id;
                        //SZÁLLÍTÓLEVÉL TÉTELEK HOZZÁADÁSA
                        var deliveryNoteItem = new DeliveryNoteItem
                        {
                            DeliveryNote    = deliveryNote,
                            ProductMovement = productMovement
                        };
                        db.DeliveryNoteItems.Add(deliveryNoteItem);
                    }
                    else
                    {
                        //SZÁLLÍTÓLEVÉL TÉTELEK HOZZÁADÁSA
                        var deliveryNoteItem = new DeliveryNoteItem
                        {
                            DeliveryNote_Id = existingDeliveryNoteId,
                            ProductMovement = productMovement
                        };
                        db.DeliveryNoteItems.Add(deliveryNoteItem);
                    }
                }

                if (db.SaveChanges() > 0)
                {
                    TempData["Operation"] = "success";
                }
                else
                {
                    TempData["Operation"] = "danger";
                }
                return(RedirectToAction("Index", "CurrentProductStocks"));
            }
            ViewBag.MovementType_Id = new SelectList(db.MovementTypes.Where(i => i.MovementKey == "issue"), "Id", "Name");
            ViewBag.Recipe_Id       = new SelectList(db.Recipes, "Id", "Name");
            ViewBag.Warehouse_Id    = new SelectList(db.Warehouses, "Id", "Name");
            ViewBag.Customer_Id     = new SelectList(db.Customers.OrderBy(i => i.Name), "Id", "Name");
            return(View(inventoryIssue));
        }
示例#8
0
 public void AddMovement(ProductMovement movement)
 {
     Invoke(s => s.AddMovement(movement));
 }
示例#9
0
 public void AddMovement(ProductMovement movement)
 {
     Manager.AddMovement(movement);
 }
示例#10
0
 public ProductMovementViewModel(ProductMovement movement)
 {
     Movement = movement;
 }