public ActionResult AddIngredientCorrection([Bind(Include = "Id,Ingredient_Id,MovementType_Id,Warehouse_Id,Quantity,Remark,IsActive,CreatedBy,CreatedDate,ChangedBy,ChangedDate")] IngredientMovement ingredientMovement)
        {
            if (ModelState.IsValid)
            {
                //INGREDIENTMOVEMENT ELKÉSZÍTÉSE
                var identity = (ClaimsIdentity)User.Identity;
                var sid      = identity.Claims.Where(c => c.Type == ClaimTypes.Sid).Select(c => c.Value).SingleOrDefault();
                ingredientMovement.CreatedDate = DateTime.Now;
                ingredientMovement.CreatedBy   = Convert.ToInt32(sid);
                db.IngredientMovements.Add(ingredientMovement);



                //CURRENTINGREDIENTSTOCK MÓDOSÍTÁSA
                var ingredienttoupdate         = db.CurrentIngredientStocks.First(i => i.Ingredient_Id == ingredientMovement.Ingredient_Id);
                var originalingredientquantity = db.CurrentIngredientStocks.First(i => i.Ingredient_Id == ingredientMovement.Ingredient_Id).Quantity;
                ingredienttoupdate.Quantity        = originalingredientquantity + ingredientMovement.Quantity;
                ingredienttoupdate.ChangedDate     = DateTime.Now;
                ingredienttoupdate.ChangedBy       = Convert.ToInt32(sid);
                db.Entry(ingredienttoupdate).State = EntityState.Modified;


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

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

            foreach (var ai in db.Ingredients)
            {
                if (db.CurrentIngredientStocks.Any(x => x.Ingredient_Id == ai.Id))
                {
                    ai.Name = string.Format("{0} - {1} kg", ai.Name, string.Format("{0:0.##}", db.CurrentIngredientStocks.First(x => x.Ingredient_Id == ai.Id).Quantity));
                    existingIngredient.Add(ai);
                }
                ;
            }
            ViewBag.Ingredient_Id = new SelectList(existingIngredient, "Id", "Name");

            ViewBag.Warehouse_Id = new SelectList(db.Warehouses, "Id", "Name");
            return(View(ingredientMovement));
        }
Exemplo n.º 2
0
        public ActionResult Create([Bind(Include = "Id,Email,Name,Role,IsActive,CreatedBy,CreatedDate,ChangedBy,ChangedDate")] SystemUser systemUser)
        {
            if (ModelState.IsValid)
            {
                systemUser.CreatedDate = DateTime.Now;
                db.SystemUsers.Add(systemUser);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CreatedBy = new SelectList(db.SystemUsers, "Id", "Email", systemUser.CreatedBy);
            ViewBag.ChangedBy = new SelectList(db.SystemUsers, "Id", "Email", systemUser.ChangedBy);
            return(View(systemUser));
        }
Exemplo n.º 3
0
        public ActionResult Create([Bind(Include = "Id,Name,Remark,IsActive,CreatedBy,CreatedDate,ChangedBy,ChangedDate")] Recipe recipe)
        {
            if (ModelState.IsValid)
            {
                recipe.CreatedDate = DateTime.Now;
                db.Recipes.Add(recipe);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CreatedBy = new SelectList(db.SystemUsers, "Id", "Email", recipe.CreatedBy);
            ViewBag.ChangedBy = new SelectList(db.SystemUsers, "Id", "Email", recipe.ChangedBy);
            return(View(recipe));
        }
Exemplo n.º 4
0
        public ActionResult Create([Bind(Include = "Id,Name,IsActive,CreatedBy,CreatedDate,ChangedBy,ChangedDate")] Ingredient ingredient)
        {
            if (ModelState.IsValid)
            {
                ingredient.CreatedDate = DateTime.Now;
                db.Ingredients.Add(ingredient);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CreatedBy = new SelectList(db.SystemUsers, "Id", "Email", ingredient.CreatedBy);
            ViewBag.ChangedBy = new SelectList(db.SystemUsers, "Id", "Email", ingredient.ChangedBy);
            return(View(ingredient));
        }
        public ActionResult Create([Bind(Include = "Id,Warehouse_Id,Ingredient_Id,Quantity,Remark,IsActive,CreatedBy,CreatedDate,ChangedBy,ChangedDate")] CurrentIngredientStock currentIngredientStock)
        {
            if (ModelState.IsValid)
            {
                db.CurrentIngredientStocks.Add(currentIngredientStock);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Ingredient_Id = new SelectList(db.Ingredients, "Id", "Name", currentIngredientStock.Ingredient_Id);
            ViewBag.CreatedBy     = new SelectList(db.SystemUsers, "Id", "Email", currentIngredientStock.CreatedBy);
            ViewBag.ChangedBy     = new SelectList(db.SystemUsers, "Id", "Email", currentIngredientStock.ChangedBy);
            ViewBag.Warehouse_Id  = new SelectList(db.Warehouses, "Id", "Name", currentIngredientStock.Warehouse_Id);
            return(View(currentIngredientStock));
        }
Exemplo n.º 6
0
        public ActionResult Create([Bind(Include = "Id,Recipe_Id,Ingredient_Id,Ammount,Remark,IsActive,CreatedBy,CreatedDate,ChangedBy,ChangedDate")] RecipeIngredient recipeIngredient)
        {
            if (ModelState.IsValid)
            {
                recipeIngredient.CreatedDate = DateTime.Now;
                db.RecipeIngredients.Add(recipeIngredient);
                db.SaveChanges();
                return(RedirectToAction("List", new { id = recipeIngredient.Recipe_Id }));
            }

            ViewBag.Ingredient_Id = new SelectList(db.Ingredients, "Id", "Name", recipeIngredient.Ingredient_Id);
            ViewBag.Recipe_Id     = new SelectList(db.Recipes, "Id", "Name", recipeIngredient.Recipe_Id);
            ViewBag.CreatedBy     = new SelectList(db.SystemUsers, "Id", "Email", recipeIngredient.CreatedBy);
            ViewBag.ChangedBy     = new SelectList(db.SystemUsers, "Id", "Email", recipeIngredient.ChangedBy);
            return(View(recipeIngredient));
        }
Exemplo n.º 7
0
        public ActionResult Create([Bind(Include = "Id,Production_Id,Ingredient_Id,MovementType_Id,Warehouse_Id,Quantity,Remark,IsActive,CreatedBy,CreatedDate,ChangedBy,ChangedDate")] IngredientMovement ingredientMovement)
        {
            if (ModelState.IsValid)
            {
                db.IngredientMovements.Add(ingredientMovement);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Ingredient_Id   = new SelectList(db.Ingredients, "Id", "Name", ingredientMovement.Ingredient_Id);
            ViewBag.MovementType_Id = new SelectList(db.MovementTypes, "Id", "Name", ingredientMovement.MovementType_Id);
            ViewBag.Production_Id   = new SelectList(db.Productions, "Id", "Remark", ingredientMovement.Production_Id);
            ViewBag.CreatedBy       = new SelectList(db.SystemUsers, "Id", "Email", ingredientMovement.CreatedBy);
            ViewBag.ChangedBy       = new SelectList(db.SystemUsers, "Id", "Email", ingredientMovement.ChangedBy);
            ViewBag.Warehouse_Id    = new SelectList(db.Warehouses, "Id", "Name", ingredientMovement.Warehouse_Id);
            return(View(ingredientMovement));
        }
Exemplo n.º 8
0
        public ActionResult Create([Bind(Include = "Id,Name,IsSupplier,ZipCode,City,StreetAddress,ContactPerson1,Telephone1,ContactPerson2,Telephone2,Remark,IsActive,CreatedBy,CreatedDate,ChangedBy,ChangedDate")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                customer.CreatedDate = DateTime.Now;
                var identity = (ClaimsIdentity)User.Identity;
                var sid      = identity.Claims.Where(c => c.Type == ClaimTypes.Sid).Select(c => c.Value).SingleOrDefault();
                customer.CreatedBy = Convert.ToInt32(sid);
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CreatedBy = new SelectList(db.SystemUsers, "Id", "Email", customer.CreatedBy);
            ViewBag.ChangedBy = new SelectList(db.SystemUsers, "Id", "Email", customer.ChangedBy);
            return(View(customer));
        }
Exemplo n.º 9
0
        public ActionResult AddReceipt([Bind(Include = "Id,deliveryNoteItem,Customer_Id,DeliveryNote_Number,DeliveryNote_Remark,DeliveryNote_Date,MovementType_Id,Remark,IsActive,CreatedBy,CreatedDate,ChangedBy,ChangedDate")] InventoryOperationViewModel inventoryReceipt)
        {
            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 < inventoryReceipt.deliveryNoteItem.Count; x++)
                {
                    //INGREDIENTMOVEMENT ELKÉSZÍTÉSE
                    var currentIndex              = x;
                    var currentIngredientId       = inventoryReceipt.deliveryNoteItem[x].Ingredient_Id;
                    var currentIngredientQuantity = inventoryReceipt.deliveryNoteItem[currentIndex].Quantity;
                    var ingredientMovement        = new IngredientMovement
                    {
                        Ingredient_Id   = inventoryReceipt.deliveryNoteItem[currentIndex].Ingredient_Id,
                        MovementType_Id = inventoryReceipt.MovementType_Id,
                        Warehouse_Id    = inventoryReceipt.deliveryNoteItem[currentIndex].Warehouse_Id,
                        Quantity        = inventoryReceipt.deliveryNoteItem[currentIndex].Quantity,
                        Remark          = inventoryReceipt.Remark,
                        IsActive        = true,
                        CreatedDate     = DateTime.Now,
                        CreatedBy       = Convert.ToInt32(sid)
                    };
                    db.IngredientMovements.Add(ingredientMovement);


                    //CURRENTINGREDIENTSTOCK MÓDOSÍTÁSA
                    var ingredientexists = db.CurrentIngredientStocks.Where(i => i.Ingredient_Id == currentIngredientId);
                    //HA NINCS AZ ALAPANYAGBÓL, HOZZÁADJUK
                    if (!ingredientexists.Any())
                    {
                        db.CurrentIngredientStocks.Add(new CurrentIngredientStock
                        {
                            CreatedDate   = DateTime.Now,
                            CreatedBy     = Convert.ToInt32(sid),
                            IsActive      = true,
                            Warehouse_Id  = inventoryReceipt.deliveryNoteItem[currentIndex].Warehouse_Id,
                            Ingredient_Id = inventoryReceipt.deliveryNoteItem[currentIndex].Ingredient_Id,
                            Quantity      = inventoryReceipt.deliveryNoteItem[currentIndex].Quantity
                        });
                    }
                    //HA VAN AZ ALAPANYAGBÓL, UPDATE
                    else
                    {
                        var ingredienttoupdate         = db.CurrentIngredientStocks.First(i => i.Ingredient_Id == currentIngredientId);
                        var originalingredientquantity = db.CurrentIngredientStocks.First(i => i.Ingredient_Id == currentIngredientId).Quantity;
                        ingredienttoupdate.Quantity        = originalingredientquantity + currentIngredientQuantity;
                        ingredienttoupdate.ChangedDate     = DateTime.Now;
                        ingredienttoupdate.ChangedBy       = Convert.ToInt32(sid);
                        db.Entry(ingredienttoupdate).State = EntityState.Modified;
                    }

                    //SZÁLLÍTÓLEVÉL HOZZÁADÁSA
                    var existingDeliveryNoteId = 0;
                    if (deliveryNoteCreted == false)
                    {
                        var deliveryNote = new DeliveryNote
                        {
                            Customer_Id      = inventoryReceipt.Customer_Id,
                            Type             = "receipt",
                            Number           = inventoryReceipt.DeliveryNote_Number,
                            Remark           = inventoryReceipt.DeliveryNote_Remark,
                            IsActive         = true,
                            CreatedDate      = DateTime.Now,
                            CreatedBy        = Convert.ToInt32(sid),
                            DeliveryNoteDate = inventoryReceipt.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,
                            IngredientMovement = ingredientMovement
                        };
                        db.DeliveryNoteItems.Add(deliveryNoteItem);
                    }
                    else
                    {
                        //SZÁLLÍTÓLEVÉL TÉTELEK HOZZÁADÁSA
                        var deliveryNoteItem = new DeliveryNoteItem
                        {
                            DeliveryNote_Id    = existingDeliveryNoteId,
                            IngredientMovement = ingredientMovement
                        };
                        db.DeliveryNoteItems.Add(deliveryNoteItem);
                    }
                }

                if (db.SaveChanges() > 0)
                {
                    TempData["Operation"] = "success";
                }
                else
                {
                    TempData["Operation"] = "danger";
                }
                return(RedirectToAction("Index", "CurrentIngredientStocks"));
            }
            ViewBag.MovementType_Id = new SelectList(db.MovementTypes.Where(i => i.MovementKey == "receipt"), "Id", "Name");
            ViewBag.Ingredient_Id   = new SelectList(db.Ingredients, "Id", "Name");
            ViewBag.Warehouse_Id    = new SelectList(db.Warehouses, "Id", "Name");
            ViewBag.Customer_Id     = new SelectList(db.Customers.Where(i => i.IsSupplier == true).OrderBy(i => i.Name), "Id", "Name");
            return(View(inventoryReceipt));
        }
Exemplo n.º 10
0
        public ActionResult Create([Bind(Include = "Id,Recipe_Id,Customer_Id,Destination_Warehouse_Id,ProductionDate,Quantity,Remark,IsActive,CreatedBy,CreatedDate,ChangedBy,ChangedDate")] Production production)
        {
            if (ModelState.IsValid)
            {
                // ELLENŐRIZZÜK, HOGY MINDEN ALAPANYAGBÓL VAN-E ELEGENDŐ

                foreach (var ri in db.RecipeIngredients.Where(i => i.Recipe_Id == production.Recipe_Id))
                {
                    if (db.CurrentIngredientStocks.Any(e => e.Ingredient_Id == ri.Ingredient_Id) && production.Quantity * ri.Ammount <=
                        db.CurrentIngredientStocks.First(e => e.Ingredient_Id == ri.Ingredient_Id).Quantity)
                    {
                        continue;
                    }
                    TempData["Operation"]        = "danger";
                    TempData["OperationMessage"] = string.Format("Nem áll rendelkezésre elegendő a szükséges mennyiség ({0} kg) a következő alapanyagból: {1}", (production.Quantity * ri.Ammount), ri.Ingredient.Name);
                    return(RedirectToAction("Index"));
                }



                // PRODUCTION HOZZÁADÁSA
                // INGREDIENTMOVEMENT - CSAK GYÁRTÁS
                var identity = (ClaimsIdentity)User.Identity;
                var sid      = identity.Claims.Where(c => c.Type == ClaimTypes.Sid).Select(c => c.Value).SingleOrDefault();
                production.CreatedDate = DateTime.Now;
                production.CreatedBy   = Convert.ToInt32(sid);
                db.Productions.Add(production);

                //INGREDIENTMOVEMENT TÖLTÉSE
                var movement = db.MovementTypes.FirstOrDefault(i => i.MovementKey == "production");
                var loss     = db.MovementTypes.FirstOrDefault(i => i.MovementKey == "loss");
                foreach (var ri in db.RecipeIngredients.Where(i => i.Recipe_Id == production.Recipe_Id))
                {
                    db.IngredientMovements.Add(new IngredientMovement()
                    {
                        CreatedDate  = DateTime.Now,
                        CreatedBy    = Convert.ToInt32(sid),
                        Ingredient   = ri.Ingredient,
                        Production   = production,
                        MovementType = movement,
                        Warehouse_Id = production.Destination_Warehouse_Id,
                        Quantity     = production.Quantity * (-1 * ri.Ammount),
                        IsActive     = true
                    });
                    db.IngredientMovements.Add(new IngredientMovement()
                    {
                        CreatedDate  = DateTime.Now,
                        CreatedBy    = Convert.ToInt32(sid),
                        Ingredient   = ri.Ingredient,
                        Production   = production,
                        MovementType = loss,
                        Warehouse_Id = production.Destination_Warehouse_Id,
                        Quantity     = production.Quantity * (-1 * ri.Ammount) * (decimal)0.006,
                        IsActive     = true
                    });
                }

                // CURRENTPRODUCTSTOCK TÖLTÉSE
                var finalproductexists = db.CurrentProductStocks.Where(i => i.Recipe_Id == production.Recipe_Id);

                if (!finalproductexists.Any())
                {
                    //HA NINCS RAKTÁRBAN ILYEN TERMÉK, AKKOR ÚJAT HOZ LÉTRE
                    db.CurrentProductStocks.Add(new CurrentProductStock()
                    {
                        CreatedDate  = DateTime.Now,
                        CreatedBy    = Convert.ToInt32(sid),
                        IsActive     = true,
                        Warehouse_Id = production.Destination_Warehouse_Id,
                        Recipe_Id    = production.Recipe_Id,
                        Quantity     = production.Quantity
                    });
                }

                else
                {
                    //HA VAN RAKTÁRBAN ILYEN TERMÉK, AKKOR UPDATEEL
                    var finalproduct     = db.CurrentProductStocks.First(i => i.Recipe_Id == production.Recipe_Id);
                    var originalquantity = db.CurrentProductStocks.First(i => i.Recipe_Id == production.Recipe_Id).Quantity;
                    finalproduct.Quantity        = originalquantity + production.Quantity;
                    finalproduct.ChangedDate     = DateTime.Now;
                    finalproduct.ChangedBy       = Convert.ToInt32(sid);
                    db.Entry(finalproduct).State = EntityState.Modified;
                }

                // CURRENTINGREDIENTSTOCK TÖLTÉSE - GYÁRTÁS + VESZTESÉG EGYBEN
                foreach (var ri in db.RecipeIngredients.Where(i => i.Recipe_Id == production.Recipe_Id))
                {
                    var ingredienttoupdate         = db.CurrentIngredientStocks.First(i => i.Ingredient_Id == ri.Ingredient_Id);
                    var originalingredientquantity = db.CurrentIngredientStocks.First(i => i.Ingredient_Id == ri.Ingredient_Id).Quantity;
                    ingredienttoupdate.Quantity        = originalingredientquantity - (production.Quantity * ri.Ammount) - (production.Quantity * ri.Ammount * (decimal)0.006);
                    ingredienttoupdate.ChangedDate     = DateTime.Now;
                    ingredienttoupdate.ChangedBy       = Convert.ToInt32(sid);
                    db.Entry(ingredienttoupdate).State = EntityState.Modified;
                }


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

            ViewBag.Customer_Id = new SelectList(db.Customers, "Id", "Name", production.Customer_Id);
            var existingRecipe = new List <Recipe>();

            foreach (var ai in db.Recipes)
            {
                if (db.RecipeIngredients.Any(x => x.Recipe_Id == ai.Id))
                {
                    existingRecipe.Add(ai);
                }
                ;
            }
            ViewBag.Recipe_Id = new SelectList(existingRecipe, "Id", "Name");
            ViewBag.CreatedBy = new SelectList(db.SystemUsers, "Id", "Email", production.CreatedBy);
            ViewBag.ChangedBy = new SelectList(db.SystemUsers, "Id", "Email", production.ChangedBy);
            ViewBag.Destination_Warehouse_Id = new SelectList(db.Warehouses, "Id", "Name", production.Destination_Warehouse_Id);
            return(View(production));
        }