Beispiel #1
0
        /// <summary>
        /// Method SetAuthorize, mengatur autorisasi pengguna yang memiliki hak akses terhadap SFS
        /// </summary>
        private void SetAuthorize()
        {
            CustomAuthentication.CustomRole customeRole = new CustomRole();
            bool isPPC       = customeRole.IsUserInRole(User.Identity.Name, Constants.RoleNames.PPC);
            bool isAdmin     = customeRole.IsUserInRole(User.Identity.Name, Constants.RoleNames.Administrator);
            bool isPE        = customeRole.IsUserInRole(User.Identity.Name, Constants.RoleNames.PE);
            bool isForeman   = customeRole.IsUserInRole(User.Identity.Name, Constants.RoleNames.Foreman);
            bool isInspector = customeRole.IsUserInRole(User.Identity.Name, RoleNames.Inspector);

            Session["IsViewOnly"] = isPPC || isAdmin || isPE || isForeman || isInspector;
        }
Beispiel #2
0
        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"));
            }
        }