/// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        private void Insert(DirectEventArgs e)
        {
            if (!string.IsNullOrEmpty(hdfGroupWorkShift.Text))
            {
                foreach (var itemRow in chkEmployeeRowSelection.SelectedRows)
                {
                    var model = new TimeSheetEmployeeGroupWorkShiftModel
                    {
                        RecordId         = Convert.ToInt32(itemRow.RecordID),
                        CreatedDate      = DateTime.Now,
                        CreatedBy        = CurrentUser.User.UserName,
                        EditedDate       = DateTime.Now,
                        GroupWorkShiftId = Convert.ToInt32(hdfGroupWorkShift.Text),
                    };

                    var listUserRule =
                        TimeSheetEmployeeGroupWorkShiftController.GetAll(null, null, null, Convert.ToInt32(hdfGroupWorkShift.Text), null, null);
                    var listRecordId = listUserRule.Select(d => d.RecordId).ToList();
                    if (listRecordId.Count <= 0 ||
                        (listRecordId.Count > 0 && !listRecordId.Contains(model.RecordId)))
                    {
                        //Create
                        TimeSheetEmployeeGroupWorkShiftController.Create(model);
                    }
                }
            }

            //reload grid
            gridUserRule.Reload();
            wdUserRule.Hide();
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAccept_ClickAllEmployee(object sender, DirectEventArgs e)
        {
            try
            {
                //Áp dụng phân ca cho tất cả các nhân viên
                //Lấy tất cả nhân viên trong hồ sơ
                var records = RecordController.GetAllEmployeeInOrganization(hdfDepartments.Text);
                foreach (var item in records)
                {
                    var model = new TimeSheetEmployeeGroupWorkShiftModel()
                    {
                        RecordId    = item.Id,
                        CreatedDate = DateTime.Now,
                        CreatedBy   = CurrentUser.User.UserName,
                        EditedDate  = DateTime.Now,
                    };
                    if (!string.IsNullOrEmpty(hdfGroupWorkShiftAll.Text))
                    {
                        model.GroupWorkShiftId = Convert.ToInt32(hdfGroupWorkShiftAll.Text);
                    }

                    //Create
                    TimeSheetEmployeeGroupWorkShiftController.Create(model);
                }

                gridUserRule.Reload();
            }
            catch (Exception ex)
            {
                Dialog.ShowNotification("Có lỗi xảy ra" + ex.Message);
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="directEventArgs"></param>
 protected void Delete(object sender, DirectEventArgs directEventArgs)
 {
     if (!string.IsNullOrEmpty(hdfKeyRecord.Text))
     {
         TimeSheetEmployeeGroupWorkShiftController.Delete(Convert.ToInt32(hdfKeyRecord.Text));
     }
     gridUserRule.Reload();
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void DeleteUserRule(object sender, DirectEventArgs e)
        {
            //Lấy tất cả bản ghi
            var userRules = TimeSheetEmployeeGroupWorkShiftController.GetAll(null, null, null, null, null, null);

            foreach (var item in userRules)
            {
                TimeSheetEmployeeGroupWorkShiftController.Delete(Convert.ToInt32(item.RecordId), null);
            }
            gridUserRule.Reload();
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void InitWindow(object sender, DirectEventArgs e)
 {
     if (!string.IsNullOrEmpty(hdfKeyRecord.Text))
     {
         var model = TimeSheetEmployeeGroupWorkShiftController.GetById(Convert.ToInt32(hdfKeyRecord.Text));
         if (model != null)
         {
             txtFullName.Text             = model.FullName;
             cbxUpdateGroupWorkShift.Text = model.GroupWorkShiftName;
             hdfGroupWorkShift.Text       = model.GroupWorkShiftId.ToString();
         }
         wdUpdateUserRule.Show();
     }
 }
 /// <summary>
 ///
 /// </summary>
 private void Update()
 {
     if (!string.IsNullOrEmpty(hdfKeyRecord.Text))
     {
         var model = TimeSheetEmployeeGroupWorkShiftController.GetById(Convert.ToInt32(hdfKeyRecord.Text));
         if (model != null)
         {
             if (!string.IsNullOrEmpty(hdfUpdateGroupWorkShift.Text))
             {
                 model.GroupWorkShiftId = Convert.ToInt32(hdfUpdateGroupWorkShift.Text);
                 model.EditedDate       = DateTime.Now;
                 model.EditedBy         = CurrentUser.User.UserName;
             }
             //update
             TimeSheetEmployeeGroupWorkShiftController.Update(model);
         }
         gridUserRule.Reload();
     }
 }
Пример #7
0
        public override void Excute(string args)
        {
            // create history
            var schedulerHistory = SchedulerHistoryServices.Create(Id, Name.ToUpper(), false, string.Empty, string.Empty, DateTime.Now, DateTime.MaxValue);

            // start process
            if (schedulerHistory == null)
            {
                return;
            }
            // log start
            SchedulerLogServices.Create(schedulerHistory.Id, "START");

            // Chạy 0:05 ngày 1 hàng tháng
            var month            = !string.IsNullOrEmpty(GetArgValue("-m")) ? Convert.ToInt32(GetArgValue("-m")) : DateTime.Now.Month;
            var year             = !string.IsNullOrEmpty(GetArgValue("-y")) ? Convert.ToInt32(GetArgValue("-y")) : DateTime.Now.Year;
            var groupWorkShiftId = !string.IsNullOrEmpty(GetArgValue("-groupWorkShiftId")) ? Convert.ToInt32(GetArgValue("-groupWorkShiftId")) : 0;

            //get all detail workShift
            var order        = " [StartDate] ASC ";
            var lstWorkShift =
                TimeSheetWorkShiftController.GetAll(null, false, groupWorkShiftId, null, null, null, null, month, year, order, null);
            var listWorkShiftIds = lstWorkShift.Select(ws => ws.Id).ToList();

            if (listWorkShiftIds.Count > 0)
            {
                TimeSheetEventController.DeleteByCondition(listWorkShiftIds, null, null, null, TimeSheetAdjustmentType.Default);
            }

            //get all employee in group
            var listEmployeeGroupWorkShift =
                TimeSheetEmployeeGroupWorkShiftController.GetAll(null, null, null, groupWorkShiftId, null, null);
            //list recordId
            var listRecordIds = listEmployeeGroupWorkShift.Select(gws => gws.RecordId).Distinct().ToList();

            //get symbolId undefined
            GetSymbolUndefined();

            //get symbolId unleave
            GetSymbolUnLeave();

            //create new timeSheet for employee
            foreach (var recordId in listRecordIds)
            {
                //get timeSheetCode by recordId
                var timeSheetCodeCondition = " [RecordId] = {0} ".FormatWith(recordId) +
                                             " AND [IsActive] = 1 ";
                var listTimeSheetCodes = hr_TimeSheetCodeServices.GetAll(timeSheetCodeCondition);
                if (listTimeSheetCodes.Count > 0)
                {
                    //ma cham cong
                    var timeSheetCodes   = string.Join(",", listTimeSheetCodes.Select(t => t.Code).ToList());
                    var arrTimeSheetCode = FormatList(timeSheetCodes);

                    //serial may cham cong
                    var machineIds       = listTimeSheetCodes.Select(tc => tc.MachineId).ToList();
                    var machineCondition = Constant.ConditionDefault;
                    machineCondition += " AND [Id] IN ({0})".FormatWith(string.Join(",", machineIds));
                    var machines      = hr_TimeSheetMachineService.GetAll(machineCondition);
                    var serialNumbers =
                        string.Join(",", machines.Select(t => t.SerialNumber).ToList());
                    var arrSerialNumber = FormatList(serialNumbers);

                    foreach (var workShiftModel in lstWorkShift)
                    {
                        //calculate timeSheet
                        CalculateTimeSheet(workShiftModel, recordId, string.Join(",", arrTimeSheetCode), string.Join(",", arrSerialNumber));
                    }
                }
            }

            SchedulerLogServices.Create(schedulerHistory.Id, "END");
        }
Пример #8
0
        protected void btnUpdateHL_Click(object sender, DirectEventArgs e)
        {
            try
            {
                foreach (var employee in chkEmployeeRowSelection.SelectedRows)
                {
                    var timeSheetEmployeeWorkShift =
                        TimeSheetEmployeeGroupWorkShiftController.GetById(int.Parse(employee.RecordID));
                    foreach (var workShift in chkWorkShiftRowSelection.SelectedRows)
                    {
                        // var timeSheetWorkShift = TimeSheetWorkShiftController.GetById(int.Parse(workShift.RecordID));
                        foreach (var symbol in chkSymbolRowSelection.SelectedRows)
                        {
                            // get symbol
                            var timeSheetSymbol = TimeSheetSymbolController.GetById(int.Parse(symbol.RecordID));
                            // get symbol group
                            var timeSheetGroupSymbol =
                                TimeSheetGroupSymbolController.GetById(timeSheetSymbol.GroupSymbolId);
                            // update time sheet event
                            var timeSheetEvent = new TimeSheetEventModel
                            {
                                RecordId      = timeSheetEmployeeWorkShift.RecordId,
                                SymbolId      = timeSheetSymbol.Id,
                                GroupSymbolId = timeSheetSymbol.GroupSymbolId,
                                WorkShiftId   = int.Parse(workShift.RecordID),
                                WorkConvert   = timeSheetSymbol.WorkConvert,
                                TimeConvert   = timeSheetSymbol.TimeConvert,
                                Type          = timeSheetGroupSymbol.Group == Constant.TimesheetOverTime
                                    ? TimeSheetAdjustmentType.AdjustmentOverTime
                                    : TimeSheetAdjustmentType.Adjustment,
                                Description = timeSheetGroupSymbol.Group == Constant.TimesheetOverTime
                                    ? "Thêm giờ"
                                    : "Hiệu chỉnh",
                                CreatedBy = CurrentUser.User.UserName
                            };
                            var newTimeSheetEvent = TimeSheetEventController.Create(timeSheetEvent);

                            // update annual leave
                            if (timeSheetGroupSymbol.Group == Constant.TimesheetLeave)
                            {
                                // update annual leave history
                                var annualLeaveHistory = new AnnualLeaveHistoryModel
                                {
                                    RecordId         = newTimeSheetEvent.RecordId,
                                    TimeSheetEventId = newTimeSheetEvent.Id,
                                    UsedLeaveDate    = newTimeSheetEvent.StartDate,
                                    UsedLeaveDay     = newTimeSheetEvent.WorkConvert,
                                    CreatedBy        = CurrentUser.User.UserName
                                };
                                AnnualLeaveHistoryController.Create(annualLeaveHistory);

                                // get annual leave configure by record id and year
                                var annualLeaveConfigures = AnnualLeaveConfigureController.GetAll(null, annualLeaveHistory.RecordId.ToString(), null,
                                                                                                  annualLeaveHistory.UsedLeaveDate.Year, false, null, 1);

                                if (annualLeaveConfigures == null || annualLeaveConfigures.Count == 0)
                                {
                                    continue;
                                }

                                // get first item in list
                                var annualLeaveConfigure = annualLeaveConfigures.First();

                                // calc used and remain leave day
                                annualLeaveConfigure.UsedLeaveDay += annualLeaveHistory.UsedLeaveDay;
                                if (annualLeaveConfigure.AnnualLeaveDay > 0)
                                {
                                    annualLeaveConfigure.RemainLeaveDay =
                                        annualLeaveConfigure.AnnualLeaveDay - annualLeaveConfigure.UsedLeaveDay;
                                }
                                annualLeaveConfigure.EditedBy = CurrentUser.User.UserName;

                                // update annual leave configure
                                AnnualLeaveConfigureController.Update(annualLeaveConfigure);
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Dialog.ShowError(exception);
            }
            gridTimeAdjust.Reload();
            wdAdjustment.Hide();
        }