Beispiel #1
0
        public JsonResult CreatePayroll(string fromDate, string toDate, int idEmployee)
        {
            DateTime FromDate = new DateTime();
            DateTime ToDate   = new DateTime();
            int      result   = CompareDate(fromDate, toDate, ref ToDate, ref FromDate);

            if (result < 0)
            {
                return(Json(new { stt = false, mess = "Ngày bắt đầu không thể lớn hơn ngày kết thúc.", }, JsonRequestBehavior.AllowGet));
            }
            if (ToDate.Subtract(FromDate).TotalDays > 31)
            {
                return(Json(new { stt = false, mess = "Ngày kết thúc và ngày bắt đầu cách nhau không quá 31 ngày.", }, JsonRequestBehavior.AllowGet));
            }
            if (_iplEmployeePayroll.CheckPayroll(FromDate, ToDate, idEmployee) != null && _iplEmployeePayroll.CheckPayroll(FromDate, ToDate, idEmployee).Count() > 0)
            {
                return(Json(new { stt = false, mess = "Đã tạo bảng lương trong khoảng thời gian này." }, JsonRequestBehavior.AllowGet));
            }

            var lst1 = _iplAttendanceTracking.ListAll(FromDate, ToDate, idEmployee);

            if (lst1 == null || lst1.Count == 0)
            {
                return(Json(new { stt = false, mess = "Không có dữ liệu tạo bảng lương." }, JsonRequestBehavior.AllowGet));
            }
            var entity = ComputePayroll(idEmployee, lst1, FromDate, ToDate);

            _iplEmployeePayroll.Insert(entity);
            return(Json(new { stt = true }, JsonRequestBehavior.AllowGet));
        }
        public JsonResult ExportAttendance(string fromDate, string toDate, int idEmployee)
        {
            DateTime FromDate;
            DateTime ToDate;

            if (string.IsNullOrWhiteSpace(fromDate))
            {
                var a = DateTime.Now.AddDays(-30).ToString("yyyy-MM-dd");
                FromDate = DateTime.ParseExact(a, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
            }
            else
            {
                FromDate = DateTime.ParseExact(fromDate, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
            }
            if (string.IsNullOrWhiteSpace(toDate))
            {
                ToDate = DateTime.ParseExact(DateTime.Now.ToString("yyyy-MM-dd"), "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
            }
            else
            {
                ToDate = DateTime.ParseExact(toDate, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
            }
            var    lst1                     = _iplAttendanceTracking.ListAll(FromDate, ToDate, idEmployee);
            double totalAbsent              = 0;
            int    totalTimeLate            = 0;
            int    totalTimesLate           = 0;
            int    totalTimeEarly           = 0;
            int    totalTimesEarly          = 0;
            int    totalMinutesOverTime     = 0;
            int    forgetTracking           = 0;
            double work                     = 0;
            double NumberDaysOfficialSalary = 0;
            double ProbationaryDate         = 0;
            double OfficialDate             = 0;
            var    lst2                     = _iplAttendanceTracking.AttendanceTracking(lst1, ref totalAbsent, ref totalTimeLate, ref totalTimesLate, ref totalTimeEarly, ref totalTimesEarly, ref totalMinutesOverTime, ref forgetTracking, ref work, ref NumberDaysOfficialSalary, ref ProbationaryDate, ref OfficialDate);

            if (lst2 == null || lst2.Count < 1)
            {
                return(Json(new
                {
                    status = false,
                }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                var fileName = ExportExcel(lst2, totalAbsent, totalTimeLate, totalTimesLate, totalTimeEarly, totalTimesEarly, totalMinutesOverTime, forgetTracking, work, FromDate.ToString("dd/MM/yyyy"), ToDate.ToString("dd/MM/yyyy"));

                return(Json(new
                {
                    status = true,
                    FileLink = @"/Download/" + fileName,
                    FileName = fileName,
                }, JsonRequestBehavior.AllowGet));
            }
        }