/// <summary> /// Method Edit berfungsi untuk mengubah capacity permonth atau start month /// </summary> /// <param name="productGroupCapacity">Parameter productGroupCapacity merupakan parameter model dari product group capacity</param> /// <returns>Data berhasil dirubah</returns> public ActionResult Edit(ProductGroupCapacity productGroupCapacity) { try { var username = User.Identity.Name; var productGroupCapactityData = db.ProductGroupCapacities.Find(productGroupCapacity.ID); var startMonth = Convert.ToDateTime(productGroupCapacity.StartMonth); var curentDate = DateTime.Now; var existingCapacityDesign = db.ProductGroupCapacities.Where(x => x.ID == productGroupCapactityData.ID && (x.StartMonth.Month == startMonth.Month && x.StartMonth.Year == startMonth.Year)).SingleOrDefault(); if (startMonth.Month < curentDate.Month && startMonth.Year == curentDate.Year) { return(Json(new { success = false, responseText = "Capacity can't be updated because start month less than current month" }, JsonRequestBehavior.AllowGet)); } else if (startMonth.Month == curentDate.Month && startMonth.Year == curentDate.Year) { return(Json(new { success = false, responseText = "Capacity can't be updated because start month same with current month" }, JsonRequestBehavior.AllowGet)); } else if (existingCapacityDesign != null) { productGroupCapactityData.Capacity = productGroupCapacity.Capacity; productGroupCapactityData.StartMonth = new DateTime(productGroupCapacity.StartMonth.Year, productGroupCapacity.StartMonth.Month, 1); db.SaveChanges(); return(Json(new { success = true, responseText = "Capacity setting successfully updated" }, JsonRequestBehavior.AllowGet)); } else { var newCapacityDesign = new ProductGroupCapacity { ProductGroupID = productGroupCapactityData.ProductGroupID, Capacity = productGroupCapacity.Capacity, StartMonth = new DateTime(productGroupCapacity.StartMonth.Year, productGroupCapacity.StartMonth.Month, 1), Created = DateTime.Now, CreatedBy = username, LastModified = DateTime.Now, LastModifiedBy = username }; db.ProductGroupCapacities.Add(newCapacityDesign); db.SaveChanges(); return(Json(new { success = true, responseText = "Capacity setting successfully added" }, JsonRequestBehavior.AllowGet)); } } catch { } return(View("Error")); }
public ActionResult Create(int productGroupId, ProductGroupCapacity productGroupCapacity, FormCollection collection) { ViewBag.ProductGroupID = Convert.ToString(productGroupId); var username = User.Identity.Name; var startMonth = productGroupCapacity.StartMonth; var groupProductCurrentPage = collection.GetValues("currentPage"); ViewBag.CurrentPage = groupProductCurrentPage[0]; try { var currentMonth = DateTime.Now.Month; var currentYear = DateTime.Now.Year; if (currentMonth == productGroupCapacity.StartMonth.Month && productGroupCapacity.StartMonth.Year == currentYear) { ViewBag.SameMonth = "Start month can't be same as current month"; } else if (productGroupCapacity.Capacity < 0) { ViewBag.Capacity = "Capacity can't be less than 0"; } else { // TODO: Add product group capacity productGroupCapacity.ProductGroupID = productGroupId; productGroupCapacity.StartMonth = new DateTime(productGroupCapacity.StartMonth.Year, productGroupCapacity.StartMonth.Month, 1); productGroupCapacity.Created = DateTime.Now; productGroupCapacity.CreatedBy = username; productGroupCapacity.LastModified = DateTime.Now; productGroupCapacity.LastModifiedBy = username; db.ProductGroupCapacities.Add(productGroupCapacity); db.SaveChanges(); ViewBag.Message = "success"; return(View()); } } catch (Exception ex) { ViewBag.Exception = ex; } return(View()); }
public ActionResult Edit(int id, ProductGroupCapacity productGroupCapacity) { var productGroupCapacityData = db.ProductGroupCapacities.Find(id); ViewBag.ProductGroupID = Convert.ToString(productGroupCapacityData.ProductGroupID); try { var username = User.Identity.Name; var currentMonth = DateTime.Now.Month; // TODO: Edit product group capacity if (currentMonth == productGroupCapacity.StartMonth.Month) { ViewBag.SameMonth = "Start month can't be same as current month"; return(View(productGroupCapacityData)); } else if (productGroupCapacity.Capacity < 0) { ViewBag.Capacity = "Capacity can't be less than 0"; return(View(productGroupCapacityData)); } else { productGroupCapacityData.Capacity = productGroupCapacity.Capacity; productGroupCapacityData.StartMonth = new DateTime(productGroupCapacity.StartMonth.Year, productGroupCapacity.StartMonth.Month, 1); productGroupCapacityData.LastModified = DateTime.Now; productGroupCapacityData.LastModifiedBy = username; db.SaveChanges(); ViewBag.Message = "success"; return(View(productGroupCapacityData)); } } catch (Exception ex) { ViewBag.Exception = ex; } return(View()); }
public ActionResult Details(int?id) { if (id != null) { ViewBag.canCRUD = false; CustomRole customeRole = new CustomRole(); ViewBag.canCRUD = customeRole.IsUserInRole(User.Identity.Name, RoleNames.PPC) || customeRole.IsUserInRole(User.Identity.Name, RoleNames.SuperAdmin);//canCRUD; DateTime startDate = DateTime.Now.AddMonths(-1); startDate = startDate.AddMilliseconds(0 - startDate.Millisecond); startDate = startDate.AddSeconds(0 - startDate.Second); startDate = startDate.AddMinutes(0 - startDate.Minute); startDate = startDate.AddHours(0 - startDate.Hour); startDate = startDate.AddDays(1 - startDate.Day); DateTime endDate = DateTime.Now.AddMonths(4); MPSViewModel mpsData = new MPSViewModel(); List <PRO> listPRO = new List <PRO>(); ProductGroup groupProductData = db.ProductGroups.Find(id); ViewBag.GroupProductName = groupProductData.Name; ViewBag.week = 0; ViewBag.tanggal = DateTime.Now; ViewBag.ReasonIssue = new SelectList(db.ReasonIssues, "ID", "Name"); #region CountHolidayTotalInRange List <DateTime> holidayDateList = db.HolidayDetails.Where(x => startDate >= x.HolidayDate && endDate <= x.HolidayDate).Select(x => x.HolidayDate).Distinct().ToList(); int totalHoliday = 0; foreach (DateTime item in holidayDateList) { if (item.DayOfWeek != DayOfWeek.Saturday && item.DayOfWeek != DayOfWeek.Sunday) { totalHoliday++; } } #endregion #region SetWeekNumberDataHeaderForEachMonth CultureInfo ci = new CultureInfo("en-US"); DateTime incDateTime = startDate; do { MonthRange monthRangeData = new MonthRange(); //int? currentCapacity ProductGroupCapacity productGroupCapacity = groupProductData.ProductGroupCapacities.Where(x => x.StartMonth.AddDays(1 - x.StartMonth.Day).Date <= incDateTime.Date).OrderByDescending(o => o.StartMonth).FirstOrDefault(); monthRangeData.Month = incDateTime.Month; monthRangeData.Year = incDateTime.Year; monthRangeData.MonthDisplayText = incDateTime.ToString("MMMM", ci) + " " + incDateTime.Year.ToString(); monthRangeData.WeekNumberList.AddRange(GetWeekNumberListofMonths(incDateTime.Month, incDateTime.Year)); monthRangeData.Capacity = null; if (productGroupCapacity != null) { monthRangeData.Capacity = productGroupCapacity.Capacity; } mpsData.MonthRangeList.Add(monthRangeData); incDateTime = incDateTime.AddMonths(1); } while (incDateTime <= endDate); #endregion listPRO = db.Pros.Where(x => x.Products.ProductSubGroups.ProductGroup.ID == id).ToList(); listPRO = listPRO.Where(x => x.DueDate.Date >= startDate.Date).OrderBy(x => x.Products.Name).ThenBy(x => x.DueDate).ToList(); #region setPROMinimunDueDate foreach (PRO item in listPRO) { int processDay = 0; int pbDays = 0; if (item.Products.ProductComposition.Count() > 0) { pbDays = 10; } DateTime currentDateTime = DateTime.Now; if (item.Products.TotalDay != null) { processDay = (int)item.Products.TotalDay + pbDays; } int totalWeek = (processDay / 5); int sisaHari = processDay % 5; currentDateTime = currentDateTime.AddDays(processDay + (totalWeek * 2) + totalHoliday); item.MinimumDueDate = currentDateTime; DateTime currentMonthFirstDate = startDate.AddMonths(1); int totalActualUnitUntilCurrentMonth = item.Units.Where(x => x.ActualDeliveryDate < currentMonthFirstDate).Count(); int totalActualUnitUntilLastMonth = item.Units.Where(x => x.ActualDeliveryDate < startDate).Count(); List <MasterPlanSchedule> listMPSUntilCurrentMonth = item.MasterPlanSchedules.Where(x => x.EndWorkingDate < currentMonthFirstDate).ToList(); List <MasterPlanSchedule> listMPSUntilLastMonth = listMPSUntilCurrentMonth.Where(x => x.EndWorkingDate < startDate).ToList(); int totalPlanUntilCurrentMonth = listMPSUntilCurrentMonth.Sum(x => x.CurrentPlannedQuantity); int totalPlanUntilLastMonth = listMPSUntilLastMonth.Sum(x => x.CurrentPlannedQuantity); item.CurrentMonthCarryOver = totalPlanUntilCurrentMonth - totalActualUnitUntilCurrentMonth; item.LastMonthCarryOver = totalPlanUntilLastMonth - totalActualUnitUntilLastMonth; item.MaximumPlanQuantity = item.UnHoldUnitCount - item.Units.Where(x => x.MPSDueDate < startDate && x.IsHold == false).Count(); } #endregion //listPRO = listPRO.OrderBy(x => x.Product.Name).ThenBy(x => x.DueDate).ToList(); mpsData.PROList = listPRO; ViewBag.TotalCarryOver = listPRO.Sum(x => x.LastMonthCarryOver); ViewBag.TestPesan = debugViewMessage; return(View(mpsData)); } else { return(RedirectToAction("Index")); } }