Ejemplo n.º 1
0
        public ActionResult Reminder(long[] studentids)
        {
            var children =
                db.fees.Where(x => x.status == FeePaymentStatus.UNPAID.ToString() && x.duedate < DateTime.Now && studentids.Contains(x.studentid))
                .GroupBy(x => x.user);

            if (!children.Any())
            {
                return(SendJsonErrorResponse("Cannot send reminder if fee is not overdue"));
            }

            var viewmodel = new ReminderViewModel();

            foreach (var entry in children)
            {
                if (viewmodel.parents == null)
                {
                    viewmodel.parents = entry.Key.students_guardians.Select(x => new SelectListItem()
                    {
                        Value = x.user1.id.ToString(),
                        Text  = x.user1.ToName(true)
                    });
                }

                var alert = new LateFeeAlert();
                alert.studentname = entry.Key.ToName(false);
                alert.studentid   = entry.Key.id;
                alert.overdueFees = entry.Select(x => x).ToModel(auth.perms);
                viewmodel.alerts.Add(alert);
            }

            // set next due date one week from largest prev date
            var prevDate =
                viewmodel.alerts.SelectMany(x => x.overdueFees).OrderByDescending(y => y.duedate).First().duedate;

            viewmodel.nextduedate = (prevDate.HasValue? prevDate.Value: DateTime.Now).AddDays(7).ToString(Constants.DATEFORMAT_DATEPICKER);

            // init tempaltes
            viewmodel.templates = db.fees_templates.OrderBy(x => x.title).Select(x => new SelectListItem()
            {
                Value = x.id.ToString(),
                Text  = x.title
            });

            var view = this.RenderViewToString("Reminder", viewmodel);

            return(Json(view.ToJsonOKData(), JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        public ActionResult Index()
        {
            var viewmodel = new FinanceViewModel(baseviewmodel);

            viewmodel.schoolList = new[] { new SelectListItem()
                                           {
                                               Value = "", Text = "Select school ..."
                                           } }.Union(
                repository.GetSchools().Select(x => new SelectListItem()
            {
                Text  = x.name,
                Value = x.id.ToString()
            }));

            // don't care about reminders, otherwise if reminder is > today then it will not show up
            // check if they are any overdue fees. grouped by
            var overdueStudents = db.fees.Where(x => x.status == FeePaymentStatus.UNPAID.ToString() &&
                                                x.duedate < DateTime.Now)
                                  .OrderBy(x => x.duedate)
                                  .GroupBy(x => x.user);

            var alerts = new List <LateFeeAlert>();

            foreach (var entry in overdueStudents)
            {
                var rel = entry.Key.students_guardians.SingleOrDefault(x => x.type.HasValue && x.type.Value == (byte)GuardianType.FATHER);

                if (rel == null)
                {
                    rel =
                        entry.Key.students_guardians.SingleOrDefault(
                            x => x.type.HasValue && x.type.Value == (byte)GuardianType.MOTHER);
                }

                var parent = rel.user1;

                var alert = new LateFeeAlert
                {
                    parentid    = parent.id,
                    parentname  = parent.ToName(),
                    studentname = entry.Key.ToName(false),
                    studentid   = entry.Key.id,
                    overdueFees = entry.Select(x => x).ToModel(auth.perms)
                };
                alerts.Add(alert);
            }

            // group by parent
            var parentGroups = alerts.GroupBy(x => new { x.parentid, x.parentname });

            foreach (var entry in parentGroups)
            {
                var siblings = new LateFeeAlertSiblings();
                siblings.children = entry.Select(x => x);
                viewmodel.alerts.Add(siblings);
            }

            // TODO: list most overdued groups first

            // get templates
            viewmodel.templates = db.fees_templates.OrderBy(x => x.title).ToRowModel();

            return(View(viewmodel));
        }