Exemple #1
0
        private decimal GetDays(DateTime start, DateTime end, LeaveDaySegment starttime, LeaveDaySegment endtime)
        {
            decimal total = (end - start).Days + 1;

            if (total != 0)
            {
                if (starttime == LeaveDaySegment.START && endtime == LeaveDaySegment.MIDDLE)
                {
                    total -= (decimal)0.5;
                }
                else if (starttime == LeaveDaySegment.START && endtime == LeaveDaySegment.END)
                {
                    // as usual
                }
                else if (starttime == LeaveDaySegment.MIDDLE && endtime == LeaveDaySegment.END)
                {
                    total -= (decimal)0.5;
                }
                else if (starttime == LeaveDaySegment.MIDDLE && endtime == LeaveDaySegment.MIDDLE)
                {
                    total -= 1;
                }
            }

            return(total);
        }
Exemple #2
0
        public ActionResult SaveIndex(long?id, int type, DateTime start, LeaveDaySegment start_time,
                                      DateTime end, LeaveDaySegment end_time, long staffid, string description)
        {
            var taken = new leaves_taken();

            if (id.HasValue)
            {
                taken = db.leaves_takens.Single(x => x.id == id.Value);
            }
            else
            {
                //taken.status = (byte) LeaveStatus.PENDING;
                taken.status = (byte)LeaveStatus.APPROVED;
            }

            var alloc = db.leaves_allocateds.Single(x => x.staffid == staffid && x.type == type);

            // check that staff has enough leave remaining
            var days = GetDays(start, end, start_time, end_time);

            if (alloc.remaining.HasValue && days > alloc.remaining)
            {
                return(Json("You do not have enough leave remaining".ToJsonFail()));
            }

            taken.allocatedid = alloc.id;
            taken.startdate   = start;
            taken.starttime   = (byte)start_time;
            taken.enddate     = end;
            taken.endtime     = (byte)end_time;
            taken.details     = description;
            taken.staffid     = staffid;
            taken.days        = days;

            // since we approve immediately, we have to decrement the remaining leave here
            if (alloc.remaining.HasValue)
            {
                alloc.remaining -= taken.days;
                Debug.Assert(alloc.remaining >= 0);
            }

            // save
            if (!id.HasValue)
            {
                db.leaves_takens.InsertOnSubmit(taken);
            }

            repository.Save();

            // send email notification

            /*
             * var applicant = repository.GetUser(staffid);
             * var emailmodel = new LeaveNotification();
             * emailmodel.applicant = applicant.ToName(false);
             * emailmodel.applicantid = applicant.id;
             *
             * // get director
             #if DEBUG
             * var director = repository.GetUsers(null, null, null, null, UserGroup.ADMIN, null, null, null, DateTime.Now.Year, null).FirstOrDefault();
             *
             #else
             * var director = repository.GetUsers(null, null, null, null, UserGroup.DIRECTOR, null, null, null, DateTime.Now.Year, null).FirstOrDefault();
             *
             #endif
             * if (director != null)
             * {
             *  emailmodel.receiver = director.ToName(false);
             *  this.SendEmailNow(
             *              EmailViewType.LEAVE_APPROVAL,
             *              emailmodel,
             *              string.Format("Leave Application by {0}", emailmodel.applicant),
             *              director.email,
             *              emailmodel.receiver);
             * }
             */
            var viewmodel = "Leave application submitted successfully".ToJsonOKMessage();

            viewmodel.data = this.RenderViewToString("IndexRows", new[] { taken }.ToModel(auth.perms.HasFlag(Permission.LEAVE_REVIEW), sessionid.Value, auth.perms));

            return(Json(viewmodel));
        }
Exemple #3
0
        public ActionResult Days(DateTime start, DateTime end, LeaveDaySegment start_time, LeaveDaySegment end_time)
        {
            var total = GetDays(start, end, start_time, end_time);

            return(Json(total.ToJsonOKData()));
        }