public JsonResult GetManagerWeeklyInfo(string selectedDate)
        {
            List<ArrayList> weeklyInfoList = new List<ArrayList>();
            DateTime formatedDate;
            if (!ValidationUtility.IsNull(selectedDate))
            {
                formatedDate = ValidationUtility.ToDate(selectedDate);
            }
            else
            {
                formatedDate = DateTime.Now;
            }

            //   AddPreviousYearInfoModel previouseYear = new AddPreviousYearInfoModel();
            GoalsModel goalsModel = new GoalsModel();
            ManagerWeeklyInfoModel managerWeeklyInfoModel = new ManagerWeeklyInfoModel();
            UserContext cont = (UserContext)Session["UserContext"];
            if (!ValidationUtility.IsNull(cont))
            {
               // int sId = ValidationUtility.GetStoredId(cont.Id);

                int sId = ValidationUtility.GetActiveStoredId(cont.Id);

                ArrayList storeList = ValidationUtility.GetStoreList(true);

                ArrayList goalStoreList = new ArrayList();

                foreach (StoreDTO storDTO in storeList)
                {
                    if (storDTO.Id == sId)
                    {
                        goalStoreList.Add(storDTO);
                        break;
                    }
                }

                DateTime actualWeekStartDate = ValidationUtility.GetActualWeekStartDate(formatedDate);

                if (!goalsModel.IsGoalsYTDCurrentYearRecordExist(actualWeekStartDate, goalStoreList))
                {
                    ArrayList currentYTDList = goalsModel.GetCurrentWeekGoalsYTD(actualWeekStartDate, goalStoreList);
                    goalsModel.AddGoalYTD(currentYTDList);
                }
                else if (ValidationUtility.GetActualWeekStartDate(DateTime.Now).Date.Equals(actualWeekStartDate.Date))
                {
                    ArrayList currentYTDList = goalsModel.GetCurrentWeekGoalsYTD(actualWeekStartDate, goalStoreList);
                    goalsModel.UpdateCurrentYTD(currentYTDList);
                }

                weeklyInfoList.Add(managerWeeklyInfoModel.GetWeeklyInfo(goalStoreList, actualWeekStartDate));

                weeklyInfoList.Add(managerWeeklyInfoModel.GetManagerMonthlyInfo(goalStoreList, actualWeekStartDate));

            }
            return Json(weeklyInfoList, JsonRequestBehavior.AllowGet);
        }
        public ArrayList GetstoreGoalList(int storeId)
        {
            ArrayList goalList = new ArrayList();

            WeeklyPaperworkModel weekPaperModel = new WeeklyPaperworkModel();

            //  int storeId = ValidationUtility.ToInteger(sId);

            AddPreviousYearInfoModel previouseYear = new AddPreviousYearInfoModel();
            GoalsModel goalsModel = new GoalsModel();

             //   ArrayList storeList = ValidationUtility.GetStoreList(true);

            ArrayList storeList = ValidationUtility.GetActiveStoreList(true);

            ArrayList goalStoreList = new ArrayList();

            foreach (StoreDTO storDTO in storeList)
            {
                if (storDTO.Id == storeId)
                {
                    goalStoreList.Add(storDTO);
                    break;
                }
            }

            DateTime previousYearWeekStartDate = ValidationUtility.YearWeekStartDate(new DateTime(DateTime.Now.AddYears(-1).Year, 1, 1));

            DateTime currentYearWeekStartDate = ValidationUtility.YearWeekStartDate(new DateTime(DateTime.Now.Year, 1, 1));

            if (!weekPaperModel.IsAllWeeklyPaperYearWeekRecordExsist(goalStoreList, DateTime.Now))
            {
                previouseYear.AddLastYearWeeklyPaperwork(new DateTime(DateTime.Now.AddYears(-1).Year, 1, 1), goalStoreList);
            }

            if (!goalsModel.IsAllYearWeekRecordExsist(goalStoreList, DateTime.Now))
            {
                goalsModel.AddPreviousYearYTD(previousYearWeekStartDate, goalStoreList);
            }

            goalsModel.AddCurrentYearYTD(new DateTime(DateTime.Now.Year, 1, 1), goalStoreList);

            ArrayList currentYTDList = goalsModel.GetCurrentWeekGoalsYTD(DateTime.Now, goalStoreList);
            goalsModel.UpdateCurrentYTD(currentYTDList);

            GoalYTDDTO previousYearYtd = goalsModel.GetPreviousGoalYTDList(storeId, currentYearWeekStartDate);

            goalList.Add(previousYearYtd);

            goalList.Add(goalsModel.GetCurrentYearGoalsList(storeId, DateTime.Now.Year));

            goalList.Add(goalsModel.GetCurrrentYTDList(storeId, currentYearWeekStartDate, previousYearYtd));

            goalList.Add(goalsModel.GetPreviousYTDList(storeId, previousYearWeekStartDate));

            //if (!goalsModel.IsCurrentYearGoalsExist(storeId, DateTime.Now.AddYears(-1).Year))
            //{

            //    ArrayList PreviousYearDataList = previouseYear.GetControlSheetDataOfYear(new DateTime(DateTime.Now.AddYears(-1).Year, 1, 1), goalStoreList);

            //    goalsModel.AddControlSheetData(PreviousYearDataList, storeId, new DateTime(DateTime.Now.AddYears(-2).Year, 1, 1));
            //}

            //if (!goalsModel.IsGoalsYTDPreviousYearRecordExist(previousYearWeekStartDate, goalStoreList))
            //{
            //    goalsModel.AddPreviousYearYTD(previousYearWeekStartDate, goalStoreList);
            //}

            //DateTime currentYearWeekStartDate = ValidationUtility.YearWeekStartDate(new DateTime(DateTime.Now.Year, 1, 1));

            //if (!goalsModel.IsGoalsYTDCurrentYearRecordExist(currentYearWeekStartDate, goalStoreList))
            //{
            //    goalsModel.AddCurrentYearYTD(new DateTime(DateTime.Now.Year, 1, 1), goalStoreList);

            //}
            //else
            //{
            //    ArrayList currentYTDList = goalsModel.GetCurrentWeekGoalsYTD(currentYearWeekStartDate, goalStoreList);
            //    goalsModel.UpdateCurrentYTD(currentYTDList);
            //}
            //DateTime everyWeekStarDate = currentYearWeekStartDate;

            //bool isWeekExsist = false;

            //while (!isWeekExsist)
            //{
            //    everyWeekStarDate = everyWeekStarDate.AddDays(7);

            //    DateTime currenWeekStartDate = ValidationUtility.GetActualWeekStartDate(DateTime.Now);

            //    if (!goalsModel.IsGoalsYTDCurrentYearRecordExist(everyWeekStarDate, goalStoreList))
            //    {
            //        ArrayList currentYTDList = goalsModel.GetCurrentWeekGoalsYTD(everyWeekStarDate, goalStoreList);
            //        goalsModel.AddGoalYTD(currentYTDList);
            //    }

            //    if (currenWeekStartDate.Date.Equals(everyWeekStarDate.Date))
            //    {
            //        isWeekExsist = true;
            //        ArrayList currentYTDList = goalsModel.GetCurrentWeekGoalsYTD(everyWeekStarDate, goalStoreList);
            //        goalsModel.UpdateCurrentYTD(currentYTDList);
            //    }

            //}

            //DateTime currenWeekStartDate = ValidationUtility.GetActualWeekStartDate(DateTime.Now);

            //ArrayList currentYTDList = goalsModel.GetCurrentWeekGoalsYTD(currenWeekStartDate, goalStoreList);

            //if (!goalsModel.IsGoalsYTDCurrentYearRecordExist(currenWeekStartDate, goalStoreList))
            //{
            //    goalsModel.AddGoalYTD(currentYTDList);
            //}
            //else
            //{
            //    goalsModel.UpdateCurrentYTD(currentYTDList);
            //}

            //  ArrayList goalList = goalsModel.GetAllGoalsList(storeId);

            //goalList.Add(goalsModel.GetAllGoalsList(storeId));

            ////Get CurrentYearYTD
            //goalList.Add(goalsModel.GetCurrrentYTDList(storeId, currentYearWeekStartDate));

            ////GetPreviousYear YTD
            //goalList.Add(goalsModel.GetPreviousYTDList(storeId, previousYearWeekStartDate));

            //  return Json(goalList, JsonRequestBehavior.AllowGet);

            return goalList;
        }
        public JsonResult UpdatePaperworkList(string id, string ar, string paidOuts, string pettyExpense, string storeTransfer, string pfg1, string pfg2, string coke, string laborCost, string taxPercent, string nonTaxableSale)
        {
            WeeklyPaperworkModel weeklyPaperworkModel = new WeeklyPaperworkModel();

            GoalsModel goalsModel = new GoalsModel();

            string error = "";
            string msg = "";

            try
            {
                WeeklyPaperworkDTO weeklyPaperworkDTO = new WeeklyPaperworkDTO();
                weeklyPaperworkDTO.Id = ValidationUtility.ToInteger(id);

                weeklyPaperworkDTO.Ar = ValidationUtility.ToDouble(ar);
                weeklyPaperworkDTO.PaidOuts = ValidationUtility.ToDouble(paidOuts);
                weeklyPaperworkDTO.PettyExpense = ValidationUtility.ToDouble(pettyExpense);
                weeklyPaperworkDTO.StoreTransfer = ValidationUtility.ToDouble(storeTransfer);

                weeklyPaperworkDTO.Pfg1 = ValidationUtility.ToDouble(pfg1);
                weeklyPaperworkDTO.Pfg2 = ValidationUtility.ToDouble(pfg2);
                weeklyPaperworkDTO.Coke = ValidationUtility.ToDouble(coke);
                weeklyPaperworkDTO.LaborCost = ValidationUtility.ToDouble(laborCost);
                weeklyPaperworkDTO.TaxPercent = ValidationUtility.ToDouble(taxPercent);
                weeklyPaperworkDTO.NonTaxableSale = ValidationUtility.ToDouble(nonTaxableSale);

                weeklyPaperworkModel.UpdateWeeklyPaperSales(weeklyPaperworkDTO);

                weeklyPaperworkDTO = weeklyPaperworkModel.GetWeeklyPaperWorkOfWeek(ValidationUtility.ToInteger(id));

                ArrayList goalStoreList = new ArrayList();

               // ArrayList storeList = ValidationUtility.GetStoreList(true);

                ArrayList storeList = ValidationUtility.GetActiveStoreList(true);

                foreach (StoreDTO storDTO in storeList)
                {
                    if (storDTO.Id == weeklyPaperworkDTO.StoreId)
                    {
                        goalStoreList.Add(storDTO);
                        break;
                    }
                }

                if (!goalsModel.IsGoalsYTDCurrentYearRecordExist(weeklyPaperworkDTO.WeekStartDate, goalStoreList))
                {

                    ArrayList currentYTDList = goalsModel.GetCurrentWeekGoalsYTD(weeklyPaperworkDTO.WeekStartDate, goalStoreList);
                    goalsModel.AddGoalYTD(currentYTDList);
                }
                else
                {
                    goalsModel.UpdateCurrentYTD(weeklyPaperworkDTO);
                }

                error = "Success";
                msg = "Update Successfully";
            }
            catch (Exception ex)
            {
                error = "Error";
                msg = " Not Update ";
                log.Error("Exception in UpdatePaperworkList ", ex);

            }

            ResponseDTO resDTO = new ResponseDTO { Error = error, Message = msg };
            return Json(resDTO, JsonRequestBehavior.AllowGet);
        }