// POST: Insumo/Delete/5 public ActionResult DeleteConfirmed(int id) { USER_SUPPLIER_INSUMO iNSUMO = db.USER_SUPPLIER_INSUMO.Find(id); iNSUMO.ACTIVE = false; db.Entry(iNSUMO).State = EntityState.Modified; db.SaveChanges(); Success(String.Format("The ingredient {0} was removed correctly.", iNSUMO.NAME)); return(RedirectToAction("Index")); }
// GET: Insumo/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } USER_SUPPLIER_INSUMO iNSUMO = db.USER_SUPPLIER_INSUMO.Find(id); if (iNSUMO == null) { return(HttpNotFound()); } return(View(iNSUMO)); }
public ActionResult Edit([Bind(Include = "ID_USER_SUPPLIER,ID_USER_SUPPLIER_INSUMO,UNIT_WEIGHT,ID_MEDIDA_PACKAGE,ID_CUSTOM_UNIT,NAME,PRICE,QUANTITY_PACKAGE,IS_BOX,IS_PACKAGE,QUANTITY_BOX,QUANTITY,CODE")] USER_SUPPLIER_INSUMO iNSUMO) { if (ModelState.IsValid) { var idUser = User.Identity.GetUserId(); iNSUMO.ID_USER = idUser; iNSUMO.ACTIVE = true; if (iNSUMO.QUANTITY == null) { iNSUMO.QUANTITY = 1; } bool isBox = false; decimal individualPrice; if (iNSUMO.IS_BOX == true) { isBox = true; decimal totalQuantity = Convert.ToDecimal((iNSUMO.QUANTITY * iNSUMO.QUANTITY_BOX)); individualPrice = Convert.ToDecimal(iNSUMO.PRICE / totalQuantity); } else { individualPrice = Convert.ToDecimal(iNSUMO.PRICE / iNSUMO.QUANTITY); } iNSUMO.INDIVIDUAL_PRICE = individualPrice; db.Entry(iNSUMO).State = EntityState.Modified; db.SaveChanges(); Success(String.Format("The ingredient {0} was updated correctly.", iNSUMO.NAME)); return(RedirectToAction("Index")); } ViewBag.ID_MEDIDA_PACKAGE = new SelectList(db.MEDIDAs, "ID_MEDIDA", "NOMBRE", iNSUMO.ID_MEDIDA_PACKAGE); ViewBag.ID_CUSTOM_UNIT = new SelectList(db.CUSTOM_UNIT, "ID_CUSTOM_UNIT", "NAME", iNSUMO.ID_MEDIDA_PACKAGE); ViewBag.ID_USER_SUPPLIER = new SelectList(db.USER_SUPPLIER, "ID_USER_SUPPLIER", "NAME", iNSUMO.ID_USER_SUPPLIER); IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors); StringBuilder str = new StringBuilder(); str.AppendLine("The following error has ocurred: <br/>"); str.AppendLine("<ul>"); foreach (var it in allErrors) { str.AppendLine("<li>" + it.ErrorMessage.ToString() + "</li>"); } str.AppendLine("</ul>"); Danger(str.ToString(), true); return(View(iNSUMO)); }
public supplieListViewModel GetProductListCost(int?ID_PRODUCTO, int?quantity) { supplieListViewModel listaInsumoVM = new supplieListViewModel { listaInsumos = db.PRODUCTO_INSUMO.Include(x => x.PRODUCTO).Include(x => x.MEDIDA).Where(x => x.ID_PRODUCTO == ID_PRODUCTO && x.ACTIVE == true).ToList() }; listaInsumoVM.costoTotal = 0; foreach (PRODUCTO_INSUMO prod in listaInsumoVM.listaInsumos) { //TRAIGO DETALLE DEL INSUMO int idInsumo = prod.ID_USER_SUPPLIER_INSUMO.Value; USER_SUPPLIER_INSUMO ins = db.USER_SUPPLIER_INSUMO.Where(x => x.ID_USER_SUPPLIER_INSUMO == idInsumo).FirstOrDefault(); decimal?costo = 0; if (ins.ID_MEDIDA_PACKAGE == 6) //KILO { if (prod.quantity is null) { costo = ins.INDIVIDUAL_PRICE; } else { costo = ins.INDIVIDUAL_PRICE * Convert.ToDecimal(prod.quantity); } } else if (ins.ID_MEDIDA_PACKAGE == 5) // GRAMOS { decimal?costoperGR = ins.PRICE / 1000; if (!(prod.quantity is null)) { costo = costoperGR * prod.quantity; } } else if (ins.ID_MEDIDA_PACKAGE == 4) //LITRO { if (!(prod.quantity is null)) { costo = ins.PRICE * Convert.ToDecimal(prod.quantity); } else { costo = ins.PRICE; } }
// GET: Insumo/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } USER_SUPPLIER_INSUMO iNSUMO = db.USER_SUPPLIER_INSUMO.Find(id); if (iNSUMO == null) { return(HttpNotFound()); } ViewBag.ID_MEDIDA_PACKAGE = new SelectList(db.MEDIDAs, "ID_MEDIDA", "NOMBRE", iNSUMO.ID_MEDIDA_PACKAGE); ViewBag.ID_USER_SUPPLIER = new SelectList(db.USER_SUPPLIER, "ID_USER_SUPPLIER", "NAME", iNSUMO.ID_USER_SUPPLIER); ViewBag.ID_CUSTOM_UNIT = new SelectList(db.CUSTOM_UNIT, "ID_CUSTOM_UNIT", "NAME", iNSUMO.ID_CUSTOM_UNIT); return(View(iNSUMO)); }
public ActionResult AddIngredient(int?ID_USER_SUPPLIER_INSUMO, int?QUANTITY, int?ID_RECIPE, int?ID_PORTIONED_BY) { var idUser = User.Identity.GetUserId(); ViewBag.ID_USER_SUPPLIER_INSUMO = new SelectList(db.USER_SUPPLIER_INSUMO.Where(x => x.ID_USER == idUser && x.ACTIVE == true).ToList(), "ID_USER_SUPPLIER_INSUMO", "NAME"); ViewBag.ID_PORTIONED_BY = new SelectList(db.MEDIDAs, "ID_MEDIDA", "NOMBRE"); USER_SUPPLIER_INSUMO usi = db.USER_SUPPLIER_INSUMO.Find(ID_USER_SUPPLIER_INSUMO); decimal costoPorUnidad = Convert.ToDecimal(usi.INDIVIDUAL_PRICE); decimal quantity = Convert.ToDecimal(QUANTITY); var tipoUnidad = usi.MEDIDA.NOMBRE; decimal costo = 0; decimal unitRequired = 0; switch (ID_PORTIONED_BY) { case 1: //unit costo = quantity * costoPorUnidad; break; case 2: //ounce switch (tipoUnidad) { case "Ounce": costo = quantity * costoPorUnidad; break; case "Ml": decimal cantMl = quantity * 29; costo = (costoPorUnidad * cantMl); break; case "Liter": decimal cantMLL = quantity * 29; decimal costoporMl = costoPorUnidad / 1000; costo = cantMLL * costoporMl; break; case "Grams": decimal cantGr = quantity * 29; costo = (costoPorUnidad * cantGr); break; case "Kilo": decimal cantGRR = quantity * 29; decimal costoporGr = costoPorUnidad / 1000; costo = cantGRR * costoporGr; break; } break; case 3: //ml switch (tipoUnidad) { case "Ounce": decimal cantOz = Convert.ToDecimal(QUANTITY / 29); costo = cantOz * costoPorUnidad; break; case "Ml": costo = (quantity * costoPorUnidad); break; case "Liter": decimal costoporMl = costoPorUnidad / 1000; costo = quantity * costoporMl; break; case "Grams": costo = (quantity * costoPorUnidad); break; case "Kilo": decimal costoporGr = costoPorUnidad / 1000; costo = quantity * costoporGr; break; } break; case 4: //Liter switch (tipoUnidad) { case "Ounce": decimal cantMl = quantity * 1000; decimal cantOz = Convert.ToDecimal(cantMl / 29); costo = cantOz * costoPorUnidad; break; case "Ml": decimal costoPorLitro = costoPorUnidad * 1000; costo = (quantity * costoPorLitro); break; case "Liter": costo = quantity * costoPorUnidad; break; case "Grams": decimal costoPorGr = costoPorUnidad * 1000; costo = (quantity * costoPorGr); break; case "Kilo": costo = quantity * costoPorUnidad; break; } break; case 5: //grams switch (tipoUnidad) { case "Ounce": decimal cantOz = Convert.ToDecimal(QUANTITY / 29); costo = cantOz * costoPorUnidad; break; case "Ml": costo = (quantity * costoPorUnidad); break; case "Liter": decimal costoporMl = costoPorUnidad / 1000; costo = quantity * costoporMl; break; case "Grams": costo = (quantity * costoPorUnidad); break; case "Kilo": decimal costoporGr = costoPorUnidad / 1000; costo = quantity * costoporGr; break; } break; case 6: //Kilograms switch (tipoUnidad) { case "Ounce": decimal cantMl = quantity * 1000; decimal cantOz = Convert.ToDecimal(cantMl / 29); costo = cantOz * costoPorUnidad; break; case "Ml": decimal costoPorLitro = costoPorUnidad * 1000; costo = (quantity * costoPorLitro); break; case "Liter": costo = quantity * costoPorUnidad; break; case "Grams": decimal costoPorGr = costoPorUnidad * 1000; costo = (quantity * costoPorGr); break; case "Kilo": costo = quantity * costoPorUnidad; break; } break; } RECIPE_DETAIL rd = new RECIPE_DETAIL { COST = costo, COST_PERCENTAGE = 1, ID_RECIPE = ID_RECIPE, ID_USER_SUPPLIER_INSUMO = ID_USER_SUPPLIER_INSUMO, QUANTITY = QUANTITY, ID_PORTIONED_BY = ID_PORTIONED_BY, ACTIVE = true }; db.RECIPE_DETAIL.Add(rd); db.SaveChanges(); RecipeDetailViewModel rcd = new RecipeDetailViewModel { ID_RECIPE = Convert.ToInt32(ID_RECIPE), details = db.RECIPE_DETAIL.Where(x => x.ID_RECIPE == ID_RECIPE && x.ACTIVE == true) }; return(PartialView("_recipeDetails", rcd)); }
public ActionResult Create([Bind(Include = "ID_MEDIDA_PACKAGE,ID_USER_SUPPLIER,ID_CUSTOM_UNIT,UNIT_WEIGHT,ID_,NAME,PRICE,QUANTITY_PACKAGE,IS_BOX,IS_PACKAGE,QUANTITY_BOX,QUANTITY,CODE")] USER_SUPPLIER_INSUMO iNSUMO, string submitButton) { bool isBox = false; decimal individualPrice; if (ModelState.IsValid) { iNSUMO.ID_USER = User.Identity.GetUserId(); iNSUMO.ACTIVE = true; if (iNSUMO.QUANTITY == null) { iNSUMO.QUANTITY = 1; } if (iNSUMO.IS_BOX == true) { /* * If this option is checked it means the product is sold in a box/package with multiple items inside. For example: A box of Wine that brings 6 bottles of wine inside. * So for this case the information should be input as follows: * * NAME: BOX OF WINE. * QUANTITY: 1 ( Since it's 1 box) * QUANTITY_BOX: 6. * PRICE: $x price. * * Another example would be 1 box of burgers that contains 6 packages of 4 burgers each, with a total of 24 burgers. So the information should be input as follows: * * NAME: BOX OF BURGUER. * QUANTITY: 4 ( This is the amount that brings each package.) * QUANTITY_BOX: 6. ( It comes with 6 packages) * PRICE: $x price. * */ isBox = true; decimal totalQuantity = Convert.ToDecimal((iNSUMO.QUANTITY * iNSUMO.QUANTITY_BOX)); individualPrice = Convert.ToDecimal(iNSUMO.PRICE / totalQuantity); } else { individualPrice = Convert.ToDecimal(iNSUMO.PRICE / iNSUMO.QUANTITY); } iNSUMO.INDIVIDUAL_PRICE = individualPrice; db.USER_SUPPLIER_INSUMO.Add(iNSUMO); db.SaveChanges(); Success(string.Format(" The ingredient <b>{0}</b> was successfully added to the database.", iNSUMO.NAME), true); switch (submitButton) { case "Save and Create": return(RedirectToAction("Create")); break; case "Save": return(RedirectToAction("Index")); break; } } IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors); ViewBag.ID_MEDIDA_PACKAGE = new SelectList(db.MEDIDAs, "ID_MEDIDA", "NOMBRE", iNSUMO.ID_MEDIDA_PACKAGE); ViewBag.ID_CUSTOM_UNIT = new SelectList(db.CUSTOM_UNIT, "ID_CUSTOM_UNIT", "NAME"); return(View(iNSUMO)); }