Example #1
0
        public ActionResult DashboardofLeaveReport(int?BranchId, int?Year, int?EmployeeId)
        {
            BranchId   = BranchId == 0 ? BRANCHID : BranchId;
            EmployeeId = EmployeeId == 0 ? null : EmployeeId;
            LeaveReportVm vm = new LeaveReportVm();

            using (var dbCntx = new HrDataContext())
            {
                vm.dtAvailed  = EMPLOYEELEAVESUMMARYYTD(BranchId, Year, 0);
                vm.dtBalance  = EMPLOYEELEAVESUMMARYYTD(BranchId, Year, 1);
                vm.consReport = LEAVEREPORTYTD(BranchId, Year, EmployeeId);
            }

            //vm.dtAvailed.Columns.Add("ANNUAL LEAVE1");
            //vm.dtAvailed.Columns.Add("MATERNITY LEAVE1");
            //vm.dtAvailed.Columns.Add("MEDICAL LEAVE1");
            for (int i = 1; i < vm.dtBalance.Columns.Count; i++)
            {
                vm.dtAvailed.Columns.Add("BALANCE " + vm.dtBalance.Columns[i]);
                for (int j = 0; j < vm.dtAvailed.Rows.Count; j++)
                {
                    vm.dtAvailed.Rows[j]["BALANCE " + vm.dtBalance.Columns[i]] = vm.dtBalance.Rows[j][vm.dtBalance.Columns[i]];
                }
            }



            vm.BranchID          = BranchId;
            vm.Year              = Year;
            vm.EmployeeID        = EmployeeId;
            ViewData["RoleCode"] = ROLECODE.ToUpper();


            return(View(vm));
        }
Example #2
0
        // GET: Dashboard
        public ActionResult Index()
        {
            try
            {
                DateTime startDayOfYear = new DateTime(UTILITY.SINGAPORETIME.Year, 01, 01);
                if (ROLECODE == UTILITY.ROLE_SUPERADMIN)
                {
                    using (var dbCntx = new HrDataContext())
                    {
                        List <Branch>         branches = dbCntx.Branches.ToList();
                        List <EmployeeDataVm> superadminGenderCount = new List <EmployeeDataVm>();
                        foreach (Branch branch in branches)
                        {
                            var count = dbCntx.EmployeePersonalDetails
                                        .Where(x => x.BranchId == branch.BranchID).Count();
                            if (count > 0)
                            {
                                EmployeeDataVm employeeDataVm = new EmployeeDataVm();

                                employeeDataVm.genderCount = new List <GenderCount>();
                                employeeDataVm.branchName  = branch.BranchName;

                                GenderCount malecount = new GenderCount();
                                malecount.name = "Male";
                                malecount.y    = dbCntx.EmployeePersonalDetails
                                                 .Where(x => x.Gender == 101 && x.BranchId == branch.BranchID).Count();
                                malecount.custom = malecount.y;
                                employeeDataVm.genderCount.Add(malecount);

                                GenderCount femalecount = new GenderCount();
                                femalecount.name = "Female";
                                femalecount.y    = dbCntx.EmployeePersonalDetails
                                                   .Where(x => x.Gender == 102 && x.BranchId == branch.BranchID).Count();
                                femalecount.custom = femalecount.y;
                                employeeDataVm.genderCount.Add(femalecount);

                                superadminGenderCount.Add(employeeDataVm);
                            }
                        }
                        ViewData["BranchId"] = BRANCHID;
                        return(View("index", superadminGenderCount));
                    }
                }
                else if (ROLECODE == UTILITY.ROLE_ADMIN)
                {
                    using (var dbCntx = new HrDataContext())
                    {
                        DashBoardVm obj = new DashBoardVm();

                        /*
                         * obj.EmployeeCount = dbCntx.EmployeeHeaders
                         *                  .Where(x => x.BranchId == BRANCHID)
                         *                  .Count();*/
                        obj.EmployeeCount = dbCntx.usp_EmployeeDetail(BRANCHID, ROLECODE).Count();

                        obj.lineChartData = dbCntx.usp_EmployeeDateOfJoiningDate(UTILITY.SINGAPORETIME, BRANCHID)
                                            .ToList()
                                            .AsEnumerable();

                        Branch branch = dbCntx.Branches.Where(x => x.BranchID == BRANCHID).FirstOrDefault();
                        //List<EmployeeDataVm> employeeDataVm = new List<EmployeeDataVm>();

                        obj.employeeDataVm             = new EmployeeDataVm();
                        obj.employeeDataVm.genderCount = new List <GenderCount>();
                        obj.employeeDataVm.branchName  = branch.BranchName;

                        GenderCount malecount = new GenderCount();
                        malecount.name = "Male";
                        malecount.y    = dbCntx.EmployeePersonalDetails
                                         .Where(x => x.Gender == 101 && x.BranchId == branch.BranchID).Count();
                        malecount.custom = malecount.y;
                        obj.employeeDataVm.genderCount.Add(malecount);

                        GenderCount femalecount = new GenderCount();
                        femalecount.name = "Female";
                        femalecount.y    = dbCntx.EmployeePersonalDetails
                                           .Where(x => x.Gender == 102 && x.BranchId == branch.BranchID).Count();
                        femalecount.custom = femalecount.y;
                        obj.employeeDataVm.genderCount.Add(femalecount);



                        //var query = dbCntx.EmployeeLeaveLists
                        //                    .Where(x => x.EmployeeId == EMPLOYEEID && x.BranchId == BRANCHID);
                        //var leaveStartTransactions = dbCntx.LeaveTrans
                        //                          .Where(x => x.EmployeeId == EMPLOYEEID && x.BranchId == BRANCHID && x.CreatedOn >= startDayOfYear)
                        //                          .OrderBy(x => x.TransactionId)
                        //                          .FirstOrDefault();
                        //if (leaveStartTransactions != null)
                        //{
                        //    obj.totalPLs = leaveStartTransactions.CurrentLeaves;
                        //    obj.totalCLs = leaveStartTransactions.CurrentLeaves;
                        //    DateTime now = DateTime.Now;
                        //    var startDate = new DateTime(now.Year, now.Month, 1);
                        //    var endDate = startDate.AddMonths(1).AddDays(-1);

                        //    var SLPerMonth = dbCntx.Leaves.Where(x => x.BranchId == BRANCHID).FirstOrDefault().SickLeavesPerMonth;
                        //    var CurrentMonthSLs = query.Where(x => x.FromDate >= startDate && x.ToDate <= endDate && x.LeaveTypeId == 1031).ToList();
                        //    foreach (var item in CurrentMonthSLs)
                        //    {
                        //        obj.totalSLs += item.Days.Value;
                        //    }
                        //    obj.totalSLs = SLPerMonth.Value - obj.totalSLs;
                        //}
                        ViewData["BranchId"] = BRANCHID;
                        return(View("admindashboard", obj));
                    }
                }
                else if (ROLECODE == UTILITY.ROLE_EMPLOYEE)
                {
                    using (var dbCntx = new HrDataContext())
                    {
                        EmployeeDashBoardVm obj = new EmployeeDashBoardVm();
                        var empheader           = dbCntx.EmployeeHeaders.Where(x => x.EmployeeId == EMPLOYEEID).FirstOrDefault();
                        var managername         = dbCntx.EmployeeHeaders.Where(x => x.EmployeeId == empheader.ManagerId).FirstOrDefault();
                        if (empheader != null)
                        {
                            int managerId = empheader.ManagerId == null ? 0 : empheader.ManagerId.Value;
                            if (managerId == 0)
                            {
                                ViewData["message"] = "You Don't Have Reporting Manger";
                            }
                            else
                            {
                                ViewData["message"] = "Your Reporting manager is" + " " + managername.FirstName + " " + managername.LastName;
                            }
                        }
                        var query = dbCntx.EmployeeLeaveLists
                                    .Where(x => x.EmployeeId == EMPLOYEEID && x.BranchId == BRANCHID);
                        var empLeaveDetails = query.OrderByDescending(x => x.EmployeeLeaveID)
                                              .ThenByDescending(x => x.ApplyDate)
                                              .Take(5)
                                              .Select(x => new EmpLeaveDashBoard
                        {
                            FromDate      = x.FromDate,
                            ToDate        = x.ToDate,
                            ApplyDate     = x.ApplyDate,
                            LeaveTypeDesc = dbCntx.LookUps.Where(y => y.LookUpID == x.LeaveTypeId).FirstOrDefault().LookUpDescription,
                            Status        = x.Status,
                            Days          = x.Days.Value,
                            Reason        = x.Reason
                        })
                                              .ToList()
                                              .AsEnumerable();

                        LeaveMaster lMaster = new LeaveMaster();

                        var paidLeave = lMaster.ANNUALLEAVE(BRANCHID);
                        var sickLeave = lMaster.MEDICALLEAVE(BRANCHID);

                        LeaveReportVm vm = new LeaveReportVm();

                        vm.consReport = LEAVEREPORTYTD(BRANCHID, DateTime.Now.Year, EMPLOYEEID);

                        List <OtherLeave> leavepolicy = dbCntx.OtherLeaves.Where(x => x.BranchId == BRANCHID && x.IsActive == true).ToList();
                        if (leavepolicy.Count != 0)
                        {
                            var annualLeaves  = vm.consReport.Where(x => x.LeaveType.ToUpper() == "ANNUAL LEAVE");
                            var medicalLeaves = vm.consReport.Where(x => x.LeaveType.ToUpper() == "MEDICAL LEAVE");

                            var totalpaidleaves = annualLeaves.Sum(x => x.TotalLeaves) + (annualLeaves.FirstOrDefault() == null ? 0 : annualLeaves.FirstOrDefault().BalanceLeaves);
                            var totalsickLeaves = medicalLeaves.Sum(x => x.TotalLeaves) + (medicalLeaves.FirstOrDefault() == null ? 0 : medicalLeaves.FirstOrDefault().BalanceLeaves);


                            obj.empLeaveDashBoard = empLeaveDetails.ToList();
                            obj.totalPLs          = totalpaidleaves;
                            obj.totalSLs          = totalsickLeaves;
                            obj.currentpls        = annualLeaves.Sum(x => x.TotalLeaves);
                            obj.currentsls        = medicalLeaves.Sum(x => x.TotalLeaves);
                            obj.remainingpls      = annualLeaves.FirstOrDefault() == null ? 0 : annualLeaves.FirstOrDefault().BalanceLeaves;
                            obj.remainingsls      = medicalLeaves.FirstOrDefault() == null ? 0 : medicalLeaves.FirstOrDefault().BalanceLeaves;
                            obj.EmployeeId        = EMPLOYEEID;
                            obj.EmployeeName      = empheader.FirstName + " " + empheader.LastName;
                            ViewData["Alert"]     = "";
                        }
                        else
                        {
                            obj.empLeaveDashBoard = empLeaveDetails.ToList();
                            obj.totalPLs          = 0;
                            obj.totalSLs          = 0;
                            obj.currentpls        = 0;
                            obj.currentsls        = 0;
                            obj.EmployeeId        = EMPLOYEEID;
                            obj.EmployeeName      = empheader.FirstName + " " + empheader.LastName;
                            ViewData["Alert"]     = UTILITY.MISSINGLEAVEPOLICYALERT;
                        }

                        return(View("employeedashboard", obj));
                    }
                }
            }
            catch (Exception ex)
            {
                //Session["ErrMsg"] = ex.Message + " " +
                //                    ex.StackTrace + " " +
                //                    ex.TargetSite + " " +
                //                    ex.Source;
                throw;
            }


            return(View());
        }