Exemple #1
0
        public Closing VIsBackToBackToPreviousClosing(Closing closing, IClosingService _closingService)
        {
            IList <Closing> closings = _closingService.GetQueryable().Where(x => x.Id != closing.Id).OrderByDescending(x => x.Id).ToList();

            if (closings.Any())
            {
                if (closings.FirstOrDefault().EndDatePeriod.AddDays(1).Date != closing.BeginningPeriod)
                {
                    closing.Errors.Add("Generic", "Tanggal Beginning Date harus " + closings.FirstOrDefault().EndDatePeriod.AddDays(1).ToLongDateString());
                }
            }
            return(closing);

            /*
             * int PreviousMonth = closing.Period == 1 ? 12 : closing.Period - 1;
             * int PreviousYear = closing.Period == 1 ? closing.YearPeriod - 1 : closing.YearPeriod;
             * Closing previousClosing = _closingService.GetObjectByPeriodAndYear(PreviousMonth, PreviousYear);
             */
        }
        public dynamic GetList(string _search, long nd, int rows, int?page, string sidx, string sord, string filters = "")
        {
            // Construct where statement
            string strWhere = GeneralFunction.ConstructWhere(filters);
            string filter   = null;

            GeneralFunction.ConstructWhereInLinq(strWhere, out filter);
            if (filter == "")
            {
                filter = "true";
            }

            // Get Data
            var q = _closingService.GetQueryable().Include("Account");

            var query = (from model in q
                         select new
            {
                model.Id,
                model.Period,
                model.YearPeriod,
                model.BeginningPeriod,
                model.EndDatePeriod,
                model.IsClosed,
                model.ClosedAt
            }).Where(filter).OrderBy(sidx + " " + sord);              //.ToList();

            var list = query.AsEnumerable();

            var pageIndex    = Convert.ToInt32(page) - 1;
            var pageSize     = rows;
            var totalRecords = query.Count();
            var totalPages   = (int)Math.Ceiling((float)totalRecords / (float)pageSize);

            // default last page
            if (totalPages > 0)
            {
                if (!page.HasValue)
                {
                    pageIndex = totalPages - 1;
                    page      = totalPages;
                }
            }

            list = list.Skip(pageIndex * pageSize).Take(pageSize);

            return(Json(new
            {
                total = totalPages,
                page = page,
                records = totalRecords,
                rows = (
                    from model in list
                    select new
                {
                    id = model.Id,
                    cell = new object[] {
                        model.Id,
                        model.Period,
                        model.YearPeriod,
                        model.BeginningPeriod,
                        model.EndDatePeriod,
                        model.IsClosed,
                        model.ClosedAt
                    }
                }).ToArray()
            }, JsonRequestBehavior.AllowGet));
        }