public ArrayList GetCenterBonus(DateTime selectDate) { ArrayList list = new ArrayList(); ManagerBonusModel managerBonusModel = new ManagerBonusModel(); AreaManagerBonusModel areaManagerBonusModel = new AreaManagerBonusModel(); DateTime currentMonthWeekStartDate = ValidationUtility.MonthWeekStartDate(selectDate); DateTime currentMonthWeekEndDate = ValidationUtility.MonthWeekEndDate(selectDate); DateTime monthWeekStartDate = ValidationUtility.MonthWeekStartDate(selectDate.AddMonths(-11)); DateTime monthWeekEndDate = ValidationUtility.MonthWeekEndDate(selectDate.AddMonths(-11)); bool isRemaing = false; while (!isRemaing) { double totlEmpBonus = 0.0; double totalManagerAmount = 0; double totalAreaAmount = 0; double totalGeneralManagerBonus = 0; if (currentMonthWeekStartDate.Date.Equals(monthWeekStartDate.Date) && currentMonthWeekEndDate.Date.Equals(monthWeekEndDate.Date)) { isRemaing = true; //// Add Employee Bonus var lastDayOfMonth = DateTime.DaysInMonth(monthWeekEndDate.Year, monthWeekEndDate.Month); totlEmpBonus = GetMonthlyEmpBonus(new DateTime(monthWeekStartDate.Year, monthWeekStartDate.Month, 1), new DateTime(monthWeekEndDate.Year, monthWeekEndDate.Month, lastDayOfMonth)); //Get Manager Bonus ArrayList storeIds = GetAreamanagerAssignStoreList(2); foreach (int storeId in storeIds) { ArrayList getbonusList = new ArrayList(); ManagerBonusDTO actualBonusDTO = managerBonusModel.GetActualBounus(storeId, monthWeekStartDate, monthWeekEndDate.AddDays(6)); getbonusList.Add(actualBonusDTO); ManagerBonusDTO zeroBasisDTO = managerBonusModel.GetZeroBasisList(storeId, monthWeekStartDate, monthWeekEndDate.AddDays(6)); getbonusList.Add(zeroBasisDTO); totalManagerAmount = totalManagerAmount + areaManagerBonusModel.GetTotalBonus(getbonusList); } //Get Area Manager storeIds = GetAreamanagerAssignStoreList(5); foreach (int storeId in storeIds) { ArrayList getbonusList = new ArrayList(); ManagerBonusDTO actualBonusDTO = managerBonusModel.GetActualBounus(storeId, monthWeekStartDate, monthWeekEndDate.AddDays(6)); getbonusList.Add(actualBonusDTO); ManagerBonusDTO zeroBasisDTO = managerBonusModel.GetZeroBasisList(storeId, monthWeekStartDate, monthWeekEndDate.AddDays(6)); getbonusList.Add(zeroBasisDTO); totalAreaAmount = totalAreaAmount + areaManagerBonusModel.GetTotalBonus(getbonusList); } // Get General Manager ArrayList areaManagerIds= GetGeneralManagerAssignAreaManagerList(); foreach (int amId in areaManagerIds) { ArrayList storeList = ValidationUtility.GetAreaMngAssignStore(amId); foreach (StoreDTO storeDTO in storeList) { ArrayList getbonusList = new ArrayList(); ManagerBonusDTO actualBonusDTO = managerBonusModel.GetActualBounus(storeDTO.Id, monthWeekStartDate, monthWeekEndDate.AddDays(6)); getbonusList.Add(actualBonusDTO); ManagerBonusDTO zeroBasisDTO = managerBonusModel.GetZeroBasisList(storeDTO.Id, monthWeekStartDate, monthWeekEndDate.AddDays(6)); getbonusList.Add(zeroBasisDTO); totalGeneralManagerBonus = totalGeneralManagerBonus + areaManagerBonusModel.GetTotalBonus(getbonusList); } } } else { //// Add Employee Bonus var lastDayOfMonth = DateTime.DaysInMonth(monthWeekEndDate.Year, monthWeekEndDate.Month); totlEmpBonus = GetMonthlyEmpBonus(new DateTime(monthWeekStartDate.Year, monthWeekStartDate.Month, 1), new DateTime(monthWeekEndDate.Year, monthWeekEndDate.Month, lastDayOfMonth)); //Get Manager Bonus ArrayList storeIds = GetAreamanagerAssignStoreList(2); foreach (int storeId in storeIds) { ArrayList getbonusList = new ArrayList(); ManagerBonusDTO actualBonusDTO = managerBonusModel.GetActualBounus(storeId, monthWeekStartDate, monthWeekEndDate.AddDays(6)); getbonusList.Add(actualBonusDTO); ManagerBonusDTO zeroBasisDTO = managerBonusModel.GetZeroBasisList(storeId, monthWeekStartDate, monthWeekEndDate.AddDays(6)); getbonusList.Add(zeroBasisDTO); totalManagerAmount = totalManagerAmount + areaManagerBonusModel.GetTotalBonus(getbonusList); } //Get Area Manager storeIds = GetAreamanagerAssignStoreList(5); foreach (int storeId in storeIds) { ArrayList getbonusList = new ArrayList(); ManagerBonusDTO actualBonusDTO = managerBonusModel.GetActualBounus(storeId, monthWeekStartDate, monthWeekEndDate.AddDays(6)); getbonusList.Add(actualBonusDTO); ManagerBonusDTO zeroBasisDTO = managerBonusModel.GetZeroBasisList(storeId, monthWeekStartDate, monthWeekEndDate.AddDays(6)); getbonusList.Add(zeroBasisDTO); totalAreaAmount = totalAreaAmount + areaManagerBonusModel.GetTotalBonus(getbonusList); } // Get General Manager ArrayList areaManagerIds = GetGeneralManagerAssignAreaManagerList(); foreach (int amId in areaManagerIds) { ArrayList storeList = ValidationUtility.GetAreaMngAssignActiveStore(amId); foreach (StoreDTO storeDTO in storeList) { ArrayList getbonusList = new ArrayList(); ManagerBonusDTO actualBonusDTO = managerBonusModel.GetActualBounus(storeDTO.Id, monthWeekStartDate, monthWeekEndDate.AddDays(6)); getbonusList.Add(actualBonusDTO); ManagerBonusDTO zeroBasisDTO = managerBonusModel.GetZeroBasisList(storeDTO.Id, monthWeekStartDate, monthWeekEndDate.AddDays(6)); getbonusList.Add(zeroBasisDTO); totalGeneralManagerBonus = totalGeneralManagerBonus + areaManagerBonusModel.GetTotalBonus(getbonusList); } } } double actualAMBonus = totalAreaAmount / 3; double actualGMBonus = totalGeneralManagerBonus / 2; double monthlyTotal = totlEmpBonus + totalManagerAmount + actualAMBonus + actualGMBonus; BonusControlCenterDTO dto = new BonusControlCenterDTO { Month = monthWeekStartDate.ToString("MMM/yyyy"), EmpBonus = totlEmpBonus, ManagerBonus = totalManagerAmount, AreaManagerBonus = actualAMBonus, GeneralManagerBonus = actualGMBonus, TotalAmount = monthlyTotal }; list.Add(dto); monthWeekStartDate = ValidationUtility.MonthWeekStartDate(monthWeekStartDate.AddMonths(1)); monthWeekEndDate = ValidationUtility.MonthWeekEndDate(monthWeekEndDate.AddMonths(1)); } list.Reverse(); return list; }
public JsonResult GetAreaManagerBonus(string selectDate) { AreaManagerBonusModel areaManagerBonusModel = new AreaManagerBonusModel(); ArrayList bonusList = new ArrayList(); DateTime formatedDate; if (!ValidationUtility.IsNull(selectDate)) { formatedDate = ValidationUtility.ToDate(selectDate); } else { formatedDate = DateTime.Now; } DateTime givenMontWeekStartDate = ValidationUtility.MonthWeekStartDate(formatedDate); DateTime montEndDate = ValidationUtility.MonthWeekEndDate(formatedDate); UserContext cont = (UserContext)Session["UserContext"]; ArrayList assignStoreList = null; ManagerBonusModel managerBonusModel = new ManagerBonusModel(); if (!ValidationUtility.IsNull(cont)) { // assignStoreList = areaManagerBonusModel.GetAreaMngAssignStore(cont.Id); // assignStoreList = ValidationUtility.GetAreaMngAssignStore(cont.Id); assignStoreList = ValidationUtility.GetAreaMngAssignActiveStore(cont.Id); foreach (StoreDTO storeDTO in assignStoreList) { double totalAmount = 0; ArrayList storeList = ValidationUtility.GetActiveStoreList(true); ArrayList goalStoreList = new ArrayList(); foreach (StoreDTO storDTO in storeList) { if (storDTO.Id == storeDTO.Id) { goalStoreList.Add(storDTO); break; } } ManagerBonusDTO managerBonusDTO = managerBonusModel.CalculateManagerBonus(formatedDate, goalStoreList); ManagerBonusDTO returnManagerBonusDTO = managerBonusModel.GetActualBounus(managerBonusDTO.StoreId, managerBonusDTO.FirstDateOFMonth, managerBonusDTO.LastDateOFMonth); if (ValidationUtility.IsNull(returnManagerBonusDTO)) { // Add managerBonusModel.AddBounus(managerBonusDTO, false); } else { // update managerBonusModel.UpdateActualValue(managerBonusDTO); } ArrayList getbonusList = new ArrayList(); ManagerBonusDTO actualBonusDTO = managerBonusModel.GetActualBounus(storeDTO.Id, givenMontWeekStartDate, montEndDate.AddDays(6)); getbonusList.Add(actualBonusDTO); ManagerBonusDTO zeroBasisDTO = managerBonusModel.GetZeroBasisList(storeDTO.Id, givenMontWeekStartDate, montEndDate.AddDays(6)); getbonusList.Add(zeroBasisDTO); totalAmount = areaManagerBonusModel.GetTotalBonus(getbonusList); AreaManagerBonusDTO areaManagerBonusDTO = new AreaManagerBonusDTO { StoreId = storeDTO.Id, StoreName = storeDTO.StoreName, TotalStoreBonus = totalAmount }; bonusList.Add(areaManagerBonusDTO); } } return Json(bonusList, JsonRequestBehavior.AllowGet); }