Ejemplo n.º 1
0
        public async Task <ActionResult> LichSuChamCongList(string employeeId)
        {
            var nhatKyLamViec = await nhatKylamViecRepository.FindByMaNhanVien(employeeId);

            var lichSuChamCongVMs = mapper.Map <IEnumerable <LichSuChamCongVM> >(nhatKyLamViec);

            var leaveRequests = (await leaveRequestRepository.FindAll())
                                .Where(q => q.RequestingEmployeeId == employeeId &&
                                       q.StartDate.CompareTo(DateTime.Now) <= 0 &&
                                       q.Approved == true
                                       );
            // nghĩa là ngày bắt đầu nhỏ hơn ngày hiện tại và đã được chấp thuận => yêu cầu nghỉ phép đã được thực thi

            var leaveRequestVMs = mapper.Map <IEnumerable <LeaveRequestVM> >(leaveRequests);

            foreach (var record in lichSuChamCongVMs)
            {
                int soPhut = (int)(record.ThoiGianKetThuc - record.ThoiGianBatDau).TotalMinutes;
                record.TongLuongCoBan = (int)((double)record.MucLuongCoBan / (6 * 4 * 8 * 60) * record.HeSoLuongCoBan * soPhut);
                record.TongTienLuong  = record.TongLuongCoBan + record.SoTienThuongThem;
            }

            var employee = mapper.Map <EmployeeVM>(await userManager.FindByIdAsync(employeeId));
            var model    = new NhatKyLamViecVM
            {
                LeaveRequestVMs   = leaveRequestVMs,
                LichSuChamCongVMs = lichSuChamCongVMs,
                NhanVien          = employee
            };



            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> ApproveRequest(int id)
        {
            try
            {
                var user = await _userManager.GetUserAsync(User);

                var leaveRequest = await _leaveRequestRepo.FindById(id);

                var employeeId = leaveRequest.RequestingEmployeeId;

                var currentUser = _userManager.GetUserAsync(User).Result;

                if (employeeId == currentUser.Id)
                {
                    return(NotFound("Bạn không thể phê duyệt yêu cầu nghỉ phép của chính mình."));
                }

                var LichSuChamCongList = await nhatKylamViecRepository.FindByMaNhanVien(employeeId);

                foreach (var item in LichSuChamCongList)
                {
                    if (leaveRequest.StartDate.CompareTo(item.ThoiGianBatDau.Date) <= 0 && leaveRequest.EndDate.CompareTo(item.ThoiGianBatDau.Date) >= 0
                        )
                    {
                        string errorMessage = "Khoảng thời gian của nghỉ phép được phê duyệt trùng với lịch biểu chấm công" +
                                              "\n Khoảng thời gian của nghỉ phép: " + leaveRequest.StartDate + " => " + leaveRequest.EndDate +
                                              "\n Lịch biểu bị trùng: " + item.ThoiGianBatDau + " => " + item.ThoiGianKetThuc;
                        return(NotFound(errorMessage));
                    }
                }

                var leaveTypeId = leaveRequest.LeaveTypeId;
                var allocation  = await _leaveAllocationRepo.GetLeaveAllocationsByEmployeeAndType(employeeId, leaveTypeId);

                int daysRequested = (int)(leaveRequest.EndDate - leaveRequest.StartDate).TotalDays;
                allocation.NumberOfDays -= daysRequested;


                leaveRequest.Approved     = true;
                leaveRequest.ApprovedById = user.Id;
                leaveRequest.DateActioned = DateTime.Now;

                await _leaveRequestRepo.Update(leaveRequest);

                await _leaveAllocationRepo.Update(allocation);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(RedirectToAction(nameof(Index)));
            }
        }
Ejemplo n.º 3
0
        public static int TinhTongTienThuongDaTichLuyTrongThang(INhatKylamViecRepository nhatKylamViecRepository, string employeeId, int year, int month)
        {
            var nhatKyLamViecs = nhatKylamViecRepository.FindByMaNhanVien(employeeId)
                                 .Result
                                 .Where(q => q.ThoiGianBatDau.Year == year && q.ThoiGianBatDau.Month == month);

            int tongSoTien = 0;

            foreach (var nhatKy in nhatKyLamViecs)
            {
                tongSoTien += nhatKy.SoTienThuongThem;
            }

            return(tongSoTien);
        }
Ejemplo n.º 4
0
        public static int TinhTongSoPhutLamDaTichLuyTrongThang(INhatKylamViecRepository nhatKylamViecRepository, string employeeId, int year, int month)
        {
            var nhatKyLamViecs = nhatKylamViecRepository.FindByMaNhanVien(employeeId)
                                 .Result
                                 .Where(q => q.ThoiGianBatDau.Year == year && q.ThoiGianBatDau.Month == month);

            int tongSoPhut = 0;

            foreach (var nhatKy in nhatKyLamViecs)
            {
                tongSoPhut += (int)(nhatKy.ThoiGianKetThuc - nhatKy.ThoiGianBatDau).TotalMinutes;
            }

            return(tongSoPhut);
        }
Ejemplo n.º 5
0
        public static int TinhTongLuongCoBanTichLuyTrongThang(INhatKylamViecRepository nhatKylamViecRepository, string employeeId, int year, int month)
        {
            //Tiền lương đã tích lũy = lương cơ bản /(6 ngày * 4 tuần *8 giờ* 60 phút)*hệ số lương * số phút của lịch biểu
            var nhatKyLamViecs = nhatKylamViecRepository.FindByMaNhanVien(employeeId)
                                 .Result
                                 .Where(q => q.ThoiGianBatDau.Year == year && q.ThoiGianBatDau.Month == month);

            int tongSoTien = 0;

            foreach (var nhatKy in nhatKyLamViecs)
            {
                int soPhut = (int)(nhatKy.ThoiGianKetThuc - nhatKy.ThoiGianBatDau).TotalMinutes;
                tongSoTien += (int)((double)nhatKy.MucLuongCoBan / (6 * 4 * 8 * 60) * nhatKy.HeSoLuongCoBan * soPhut);
            }

            return(tongSoTien);
        }