コード例 #1
0
        public ActionResult SetFirstCheckIn(int id, TimeSpan value)
        {
            var Item = Attendance.Find(id);

            //if (value != null) {
            Item.FirstCheckin = Item.Date.Date.Add(value);
            Item.Modified     = DateTime.Now;
            Item.UpdateAndFlush();
            //}

            return(PartialView("_AttendanceEmployeeByDay", Item));
        }
コード例 #2
0
        public ActionResult SetFirstCheckOut(int id, TimeSpan value)
        {
            var Item = Attendance.Find(id);

            //if (value!=null)
            //{
            Item.FirstCheckout = Item.Date.Date.Add(value);
            if (value < TimeSpan.Parse(Item.ShiftIn))
            {
                Item.FirstCheckout.Value.AddDays(1);
            }
            Item.Modified = DateTime.Now;
            Item.UpdateAndFlush();
            //}

            return(PartialView("_AttendanceEmployeeByDay", Item));
        }
コード例 #3
0
ファイル: AttendanceController.cs プロジェクト: mig-amq/hris
        public ContentResult TimeIn(FormCollection form)
        {
            // time in
            JObject json = new JObject();

            json["error"]   = false;
            json["message"] = "";

            Employee emp = null;

            DBHandler db = new DBHandler();

            if (this.GetAccount() != null && this.GetAccount().Type != AccountType.Applicant)
            {
                emp = ((Employee)this.GetAccount().Profile);
            }
            else
            {
                if (form.GetValue("code") != null)
                {
                    string code = form.GetValue("code").AttemptedValue;
                    Dictionary <string, dynamic> param = new Dictionary <string, dynamic>();
                    param.Add("@Code", code);

                    using (DataTable dt = db.Execute <DataTable>(
                               CRUD.READ,
                               "SELECT EmployeeID FROM Employee E INNER JOIN Account A ON E.Profile = A.Profile WHERE E.Code = @Code AND (A.Type ="
                               + ((int)AccountType.Employee) + " OR A.Type = " + ((int)AccountType.DepartmentHead) + ")", param))
                    {
                        if (dt.Rows.Count > 0)
                        {
                            try
                            {
                                emp = new Employee(Int32.Parse(dt.Rows[0]["EmployeeID"].ToString()), byPrimary: true);
                            }
                            catch (Exception e)
                            {
                                emp = null;
                            }
                        }
                    }
                }
            }

            if (emp != null || (this.GetAccount() != null &&
                                (this.CheckLogin(AccountType.Employee) || this.CheckLogin(AccountType.DepartmentHead))))
            {
                Attendance at = new Attendance();
                try
                {
                    at = at.Find(
                        emp.EmployeeID,
                        DateTime.Now,
                        recursive: true,
                        byPrimary: false);

                    AttendanceTime aTime = new AttendanceTime();

                    try
                    {
                        aTime.Find(at.AttendanceID, DateTime.Now, recursive: false, byPrimary: false);

                        json["error"]   = true;
                        json["message"] = "You have already timed in today";
                    }
                    catch (Exception e)
                    {
                        aTime.Attendance = at;
                        aTime.TimeIn     = DateTime.Now;
                        aTime.Date       = DateTime.Now;

                        aTime.Create();

                        DateTime callTime = DateTime.ParseExact(DateTime.Now.ToString("yyyy-MM-dd") + " "
                                                                + "08:00 AM", "yyyy-MM-dd hh:mm tt", CultureInfo.InvariantCulture);
                        DateTime endTime = DateTime.ParseExact(DateTime.Now.ToString("yyyy-MM-dd") + " "
                                                               + "05:00 PM", "yyyy-MM-dd hh:mm tt", CultureInfo.InvariantCulture);
                        json["attendance"] = aTime.AttendanceTimeID;
                        json["message"]    = "Successfully Timed In today.";

                        if (DateTime.Compare(aTime.TimeIn.Value, callTime) > 0 && DateTime.Compare(aTime.TimeIn.Value, endTime) < 0)
                        {
                            at.Late += 1;
                            at.Update(false);
                            json["message"] = "Successfully Timed In today. However, you are late";
                        }
                        else if (DateTime.Compare(aTime.TimeIn.Value, endTime) >= 0)
                        {
                            at.Absent += 1;
                            at.Update(false);
                            json["message"] = "You have Timed In today. However, you are already counted as absent";
                        }
                    }
                }
                catch (Exception e)
                {
                    json["error"]   = true;
                    json["message"] =
                        "Cannot find an attendance row for your account, please consult the HR Department";
                }
            }
            else
            {
                json["error"]   = true;
                json["message"] = "You are not authorized to continue";
            }

            return(Content(json.ToString(), "application/json"));
        }