public ArrayList GetPerDayRecordSale(DateTime businessDate)
        {
            RecordSaleModel rsm = new RecordSaleModel();
            ArrayList list = null;

            UserContext cont = (UserContext)Session["UserContext"];
            if (!ValidationUtility.IsNull(cont))
            {

                // DateTime BusinessDate  = DateTime.Now;

              //  int storeId = rsm.GetManagetAssignStoredId(cont.Id);

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

                Dictionary<int, string> connectionString = (Dictionary<int, string>)Session["ConnectionString"];

                string storeNameConnectionString = "";

                if (connectionString.ContainsKey(storeId))
                {
                    storeNameConnectionString = connectionString[storeId];

                    double perDaySalesAmount = rsm.GetPerDaySalesAmount(storeNameConnectionString, businessDate);
                    int opId = rsm.GetCurrentDateOpeningInfoId(businessDate, storeNameConnectionString);
                    rsm.UpdatePerdaySales(perDaySalesAmount, storeId, businessDate, opId);
                    list = rsm.GetPerdaySales(cont.Id, storeNameConnectionString, businessDate);
                }

            }
            return list;
        }
        public ArrayList GetBonusEmployeeInfo(DateTime businessDate)
        {
            RecordSaleModel rsm = new RecordSaleModel();
            ArrayList list = null;

            UserContext cont = (UserContext)Session["UserContext"];
            if (!ValidationUtility.IsNull(cont))
            {

                // DateTime BusinessDate = DateTime.Now;

              //  int storeId = rsm.GetManagetAssignStoredId(cont.Id);

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

                Dictionary<int, string> connectionString = (Dictionary<int, string>)Session["ConnectionString"];

                string storeNameConnectionString = "";

                if (connectionString.ContainsKey(storeId))
                {
                    storeNameConnectionString = connectionString[storeId];

                    list = rsm.GetBonusEmpName(cont.Id, storeNameConnectionString, businessDate);
                }

            }
            return list;
        }
        public JsonResult getRecordSale(string selectedDate)
        {
            RecordSaleModel rsm = new RecordSaleModel();
            List<ArrayList> list = new List<ArrayList>();

            DateTime formatedDate;

            if (!ValidationUtility.IsNull(selectedDate))
            {
                formatedDate = ValidationUtility.ToDate(selectedDate);

            }
            else
            {
                formatedDate = DateTime.Now;
            }

            UserContext cont = (UserContext)Session["UserContext"];
            if (!ValidationUtility.IsNull(cont))
            {
                if (DateTime.Now.ToString("MM/dd/yyyy").Equals(formatedDate.ToString("MM/dd/yyyy")))
                {
                    list.Add(rsm.GetRecodSaleList(cont.Id, formatedDate));
                    list.Add(GetPerDayRecordSale(formatedDate));
                    list.Add(GetBonusEmployeeInfo(formatedDate));
                }
                else if (DateTime.Now > formatedDate)
                {

                   // int storeId = rsm.GetManagetAssignStoredId(cont.Id);

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

                    Dictionary<int, string> connectionString = (Dictionary<int, string>)Session["ConnectionString"];
                    string storeNameConnectionString = "";
                    if (connectionString.ContainsKey(storeId))
                    {
                           storeNameConnectionString = connectionString[storeId];
                            list.Add(rsm.GetSelectedDateRecordSales(formatedDate, storeNameConnectionString));
                            list.Add(rsm.GetPerdaySales(cont.Id, storeNameConnectionString, formatedDate));
                            list.Add(GetBonusEmployeeInfo(formatedDate));

                    }

                }

            }

            return Json(list, JsonRequestBehavior.AllowGet);
        }
        public void UpdateRecordSale()
        {
            try
            {
                log.Info(" UpdateRecordSale Start Time  is " + DateTime.Now);

                ArrayList weekDayList = new ArrayList();

                string weekOfDay = DateTime.Now.AddDays(-1).DayOfWeek.ToString();

                weekDayList.Add(weekOfDay);

                log.Info(" Day Of week " + DateTime.Now.AddDays(-1).DayOfWeek.ToString());

                //weekDayList.Add("Thursday");
                //weekDayList.Add("Friday");
                //weekDayList.Add("Saturday");
                //weekDayList.Add("Sunday");
                //weekDayList.Add("Monday");
                //weekDayList.Add("Tuesday");

                StoreModel sm = new StoreModel();

                // Get All Store List from local database
              //  ArrayList list = sm.GetStoreList();

                ArrayList list = ValidationUtility.GetActiveStoreList(true);

                foreach (StoreDTO dto in list)
                {
                    ArrayList recordSale = new ArrayList();

                    foreach (string s in weekDayList)
                    {
                        //Get Business day record (which is high in year)
                        DataTable dt = GetWeekDayRecord(dto.ConnectionString, s);
                        RecordSalesDTO recordSaleDto = new RecordSalesDTO();

                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            recordSaleDto.BusinessDate = (DateTime)dt.Rows[i]["BusinessDate"];
                            recordSaleDto.DayOfWeek = dt.Rows[i]["WeekOfDay"].ToString();
                            recordSaleDto.SalesAmount = ValidationUtility.ToDouble(dt.Rows[i]["PerDaySale"].ToString());
                            recordSaleDto.StoreId = dto.Id;
                        }

                        recordSale.Add(recordSaleDto);

                    }

                    // Now Update Records
                    foreach (RecordSalesDTO rsDto in recordSale)
                    {
                        UpdateStore(rsDto, dto.ConnectionString);
                    }
                }

                // UpdateLast sale
                foreach (StoreDTO dto in list)
                {

                    RecordSaleModel rsm = new RecordSaleModel();

                    log.Info("Record update for StorId " + dto.Id);

                    log.Info("Last Perday sale date " + DateTime.Now.AddDays(-1));

                    double perDaySalesAmount = GetPerDayUpdatedSalesAmount(dto.ConnectionString, DateTime.Now.AddDays(-1));

                    log.Info("Last date perday sales amount " + perDaySalesAmount);

                    int opId = rsm.GetCurrentDateOpeningInfoId(DateTime.Now.AddDays(-1), dto.ConnectionString);

                    log.Info("Opening Information Id of last per day sales " + opId);

                    rsm.UpdatePerdaySales(perDaySalesAmount, dto.Id, DateTime.Now.AddDays(-1), opId);

                    //ArrayList lastPerDaySales = GetLastDaySalesData(DateTime.Now.AddDays(-1), DateTime.Now.AddDays(-1).DayOfWeek.ToString(), dto.Id);
                    //foreach (PerdaySalesDTO perdaySalesDTO in lastPerDaySales)
                    //{
                    //    double perDaySalesAmount = GetPerDayUpdatedSalesAmount(dto.ConnectionString, perdaySalesDTO.BusinessDate);
                    //    int opId = rsm.GetCurrentDateOpeningInfoId(perdaySalesDTO.BusinessDate, dto.ConnectionString);
                    //    rsm.UpdatePerdaySales(perDaySalesAmount, perdaySalesDTO.StoreId, perdaySalesDTO.BusinessDate, opId);

                    //}

                }

                log.Info(" End  Time " + DateTime.Now);
            }
            catch (Exception ex)
            {
                log.Error("Exception in UpdateRecordSale  ", ex);
            }
        }