protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5LR_DLR_1746 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var item = new ORM_CMN_BPT_EMP_Employee_LeaveRequest(); if (Parameter.LeaveRequestID != Guid.Empty) { var result = item.Load(Connection, Transaction, Parameter.LeaveRequestID); if (result.Status != FR_Status.Success || item.CMN_BPT_EMP_Employee_LeaveRequestID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } } item.IsDeleted = true; item.Save(Connection, Transaction); var returnValue = new FR_Guid(); returnValue.Result = item.CMN_BPT_EMP_Employee_LeaveRequestID; //Put your code here return(returnValue); #endregion UserCode }
protected static FR_Base Execute(DbConnection Connection, DbTransaction Transaction, P_L5DWS_DEWTP_1130 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { //Leave UserCode region to enable user code saving #region UserCode var returnValue = new FR_Base(); //Put your code here ORM_CMN_BPT_EMP_EffectiveWorkTime_Position.Query positionQuery = new ORM_CMN_BPT_EMP_EffectiveWorkTime_Position.Query(); positionQuery.CMN_BPT_EMP_EffectiveWorkTime_PositionID = Parameter.CMN_BPT_EMP_EffectiveWorkTime_PositionID; positionQuery.IsDeleted = false; positionQuery.Tenant_RefID = securityTicket.TenantID; var position = ORM_CMN_BPT_EMP_EffectiveWorkTime_Position.Query.Search(Connection, Transaction, positionQuery).FirstOrDefault(); if (position == null) { return(null); } ORM_CMN_BPT_EMP_Employee_LeaveRequest leaveRequest = new ORM_CMN_BPT_EMP_Employee_LeaveRequest(); Guid leaveRequestID = Guid.Empty; if (position.CMN_BPT_EMP_Employee_LeaveRequest_RefID != Guid.Empty) { leaveRequestID = position.CMN_BPT_EMP_Employee_LeaveRequest_RefID; } if (leaveRequestID != Guid.Empty) { leaveRequest.Load(Connection, Transaction, leaveRequestID); leaveRequest.Remove(Connection, Transaction); ORM_CMN_CAL_Event leaveRequestEvent = new ORM_CMN_CAL_Event(); leaveRequestEvent.Load(Connection, Transaction, leaveRequest.CMN_CAL_Event_RefID); leaveRequestEvent.Remove(Connection, Transaction); var calQuery = new ORM_CMN_CAL_Event.Query(); calQuery.CMN_CAL_EventID = leaveRequest.CMN_CAL_Event_RefID; var calendarRes = ORM_CMN_CAL_Event.Query.Search(Connection, Transaction, calQuery); ORM_CMN_CAL_Event calendarEvent = calendarRes[0]; var timeFrame = cls_Get_CalculationTimeFramesForTenant.Invoke(Connection, Transaction, securityTicket).Result.Where(x => x.CalculationTimeframe_StartDate.Year == calendarEvent.StartTime.Year).FirstOrDefault(); P_L5EM_GEATFSbRTFE_1423 statParam = new P_L5EM_GEATFSbRTFE_1423(); statParam.absenceReasonID = leaveRequest.CMN_BPT_STA_AbsenceReason_RefID; statParam.employeeID = leaveRequest.RequestedFor_Employee_RefID; statParam.timeFrameID = timeFrame.CMN_CAL_CalculationTimeframeID; var statistics = cls_Get_Employee_AbsenceReason_TimeframeStatistic_byReasonTimeFrameEmployee.Invoke(Connection, Transaction, statParam, securityTicket).Result; if (statistics != null) { P_L5EM_SEARTFS_1356 updateStatisticsParam = new P_L5EM_SEARTFS_1356(); updateStatisticsParam.CMN_BPT_EMP_Employee_AbsenceReason_TimeframeStatisticsID = statistics.CMN_BPT_EMP_Employee_AbsenceReason_TimeframeStatisticsID; updateStatisticsParam.Employee_RefID = statistics.Employee_RefID; updateStatisticsParam.CalculationTimeframe_RefID = statistics.CalculationTimeframe_RefID; updateStatisticsParam.AbsenceReason_RefID = statistics.AbsenceReason_RefID; updateStatisticsParam.R_AbsenceCarryOver_InDays = statistics.R_AbsenceCarryOver_InDays; updateStatisticsParam.R_AbsenceCarryOver_InHours = statistics.R_AbsenceCarryOver_InHours; updateStatisticsParam.R_TotalAllowedAbsenceTime_InDays = statistics.R_TotalAllowedAbsenceTime_InDays + Parameter.durationInDays; updateStatisticsParam.R_TotalAllowedAbsenceTime_InHours = statistics.R_TotalAllowedAbsenceTime_InHours + Parameter.durationInHours; updateStatisticsParam.R_RequestReservedAbsence_InDays = statistics.R_RequestReservedAbsence_InDays; updateStatisticsParam.R_RequestReservedAbsence_InHours = statistics.R_RequestReservedAbsence_InHours; updateStatisticsParam.R_AbsenceTimeUsed_InDays = statistics.R_AbsenceTimeUsed_InDays - Parameter.durationInDays; updateStatisticsParam.R_AbsenceTimeUsed_InHours = statistics.R_AbsenceTimeUsed_InHours - Parameter.durationInHours; var res = cls_Save_Employee_AbsenceReason_TimeframeStatistic.Invoke(Connection, Transaction, updateStatisticsParam, securityTicket); } } position.IsDeleted = true; position.Save(Connection, Transaction); return(returnValue); #endregion UserCode }
protected static FR_Base Execute(DbConnection Connection, DbTransaction Transaction, P_L6DWS_DDWSDFIDL_1014 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { //Leave UserCode region to enable user code saving #region UserCode var returnValue = new FR_Base(); L6TN_GSFT_1017 settings = cls_Get_Settings_For_Tenant.Invoke(Connection, Transaction, securityTicket).Result; ORM_CMN_STR_PPS_DailyWorkSchedule_Detail scheduleDetail = new ORM_CMN_STR_PPS_DailyWorkSchedule_Detail(); var result = scheduleDetail.Load(Connection, Transaction, Parameter.DailyWorkSchedule_DetailID); if (result.Status != FR_Status.Success || scheduleDetail.CMN_STR_PPS_DailyWorkSchedule_DetailID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID."; error.Status = FR_Status.Error_Internal; return(error); } ORM_CMN_CAL_Event calEvent = new ORM_CMN_CAL_Event(); calEvent.Load(Connection, Transaction, scheduleDetail.CMN_CAL_Event_RefID); if (scheduleDetail.CMN_BPT_EMP_Employee_LeaveRequest_RefID != Guid.Empty) { ORM_CMN_BPT_EMP_Employee_LeaveRequest leaveRequest = new ORM_CMN_BPT_EMP_Employee_LeaveRequest(); leaveRequest.Load(Connection, Transaction, scheduleDetail.CMN_BPT_EMP_Employee_LeaveRequest_RefID); Guid oldLeaveRequestID = leaveRequest.CMN_BPT_EMP_Employee_LeaveRequestID; ORM_CMN_CAL_Event leaveRequestEvent = new ORM_CMN_CAL_Event(); leaveRequestEvent.Load(Connection, Transaction, leaveRequest.CMN_CAL_Event_RefID); var calQuery = new ORM_CMN_CAL_Event.Query(); calQuery.CMN_CAL_EventID = leaveRequest.CMN_CAL_Event_RefID; var calendarRes = ORM_CMN_CAL_Event.Query.Search(Connection, Transaction, calQuery); ORM_CMN_CAL_Event calendarEvent = calendarRes[0]; var timeFrame = cls_Get_CalculationTimeFramesForTenant.Invoke(Connection, Transaction, securityTicket).Result.Where(x => x.CalculationTimeframe_StartDate.Year == calendarEvent.StartTime.Year).FirstOrDefault(); if (leaveRequestEvent.StartTime.Date != leaveRequestEvent.EndTime.Date) { DateTimeRange firstRange = null; DateTimeRange secondRange = null; DateTimeRange thirdRange = null; ORM_CMN_STR_PPS_DailyWorkSchedule dailySchedule = new ORM_CMN_STR_PPS_DailyWorkSchedule(); dailySchedule.Load(Connection, Transaction, scheduleDetail.DailyWorkSchedule_RefID); if (leaveRequestEvent.StartTime.Date == dailySchedule.WorkSheduleDate) { P_L5DWS_GDWSWDFT_0946 dailyScheduleDetailsPar = new P_L5DWS_GDWSWDFT_0946(); dailyScheduleDetailsPar.WorkSheduleDate = dailySchedule.WorkSheduleDate.AddDays(1).Date; var schedule = cls_Get_DailyWorkSchedules_WithDetails_For_Date.Invoke(Connection, Transaction, dailyScheduleDetailsPar, securityTicket).Result.FirstOrDefault(i => i.Employee_RefID == dailySchedule.Employee_RefID); secondRange = new DateTimeRange(); if (schedule != null && schedule.Details.Any(i => i.LeaveRequest_RefID == leaveRequest.CMN_BPT_EMP_Employee_LeaveRequestID)) { secondRange.Start = schedule.Details.FirstOrDefault(i => i.LeaveRequest_RefID == leaveRequest.CMN_BPT_EMP_Employee_LeaveRequestID).FromTime_as_DateTime; secondRange.End = leaveRequestEvent.EndTime; } else { secondRange = null; } } else if (leaveRequestEvent.EndTime.Date == dailySchedule.WorkSheduleDate) { firstRange = new DateTimeRange(); firstRange.Start = leaveRequestEvent.StartTime; P_L5DWS_GDWSWDFT_0946 dailyScheduleDetailsPar = new P_L5DWS_GDWSWDFT_0946(); dailyScheduleDetailsPar.WorkSheduleDate = dailySchedule.WorkSheduleDate.AddDays(-1).Date; var schedule = cls_Get_DailyWorkSchedules_WithDetails_For_Date.Invoke(Connection, Transaction, dailyScheduleDetailsPar, securityTicket).Result.FirstOrDefault(i => i.Employee_RefID == dailySchedule.Employee_RefID); if (schedule != null && schedule.Details.Any(i => i.LeaveRequest_RefID == leaveRequest.CMN_BPT_EMP_Employee_LeaveRequestID)) { firstRange.End = schedule.Details.FirstOrDefault(i => i.LeaveRequest_RefID == leaveRequest.CMN_BPT_EMP_Employee_LeaveRequestID).ToTime_as_DateTime; } else { firstRange = null; } } else { firstRange = new DateTimeRange(); firstRange.Start = leaveRequestEvent.StartTime; P_L5DWS_GDWSWDFT_0946 dailyScheduleDetailsPar = new P_L5DWS_GDWSWDFT_0946(); dailyScheduleDetailsPar.WorkSheduleDate = dailySchedule.WorkSheduleDate.AddDays(-1).Date; var schedule = cls_Get_DailyWorkSchedules_WithDetails_For_Date.Invoke(Connection, Transaction, dailyScheduleDetailsPar, securityTicket).Result.FirstOrDefault(i => i.Employee_RefID == dailySchedule.Employee_RefID); if (schedule != null && schedule.Details.Any(i => i.LeaveRequest_RefID == leaveRequest.CMN_BPT_EMP_Employee_LeaveRequestID)) { firstRange.End = schedule.Details.FirstOrDefault(i => i.LeaveRequest_RefID == leaveRequest.CMN_BPT_EMP_Employee_LeaveRequestID).ToTime_as_DateTime; } else { firstRange = null; } P_L5DWS_GDWSWDFT_0946 dailyScheduleDetailsParSecond = new P_L5DWS_GDWSWDFT_0946(); dailyScheduleDetailsParSecond.WorkSheduleDate = dailySchedule.WorkSheduleDate.AddDays(1).Date; var scheduleSecond = cls_Get_DailyWorkSchedules_WithDetails_For_Date.Invoke(Connection, Transaction, dailyScheduleDetailsParSecond, securityTicket).Result.FirstOrDefault(i => i.Employee_RefID == dailySchedule.Employee_RefID); secondRange = new DateTimeRange(); if (scheduleSecond != null && scheduleSecond.Details.Any(i => i.LeaveRequest_RefID == leaveRequest.CMN_BPT_EMP_Employee_LeaveRequestID)) { secondRange.End = leaveRequestEvent.EndTime; secondRange.Start = scheduleSecond.Details.FirstOrDefault(i => i.LeaveRequest_RefID == leaveRequest.CMN_BPT_EMP_Employee_LeaveRequestID).FromTime_as_DateTime; } else { secondRange = null; } } #region cancelLeaveRequest P_L5LR_SEAA_1351 ApprovalActionParam = new P_L5LR_SEAA_1351(); ApprovalActionParam.Approval_Action_Commnet = ""; ApprovalActionParam.CMN_CAL_Event_Approval_ActionID = Guid.Empty; ApprovalActionParam.EventApproval_RefID = leaveRequest.CMN_CAL_Event_Approval_RefID; ApprovalActionParam.IsApproval = false; ApprovalActionParam.IsDenial = false; ApprovalActionParam.IsRevocation = true; cls_Save_Employee_ApprovalAction.Invoke(Connection, Transaction, ApprovalActionParam, securityTicket); var approvalItem = new ORM_CMN_CAL_Event_Approval(); if (leaveRequest.CMN_CAL_Event_Approval_RefID != Guid.Empty) { var approvalResult = approvalItem.Load(Connection, Transaction, leaveRequest.CMN_CAL_Event_Approval_RefID); if (approvalResult.Status != FR_Status.Success || approvalItem.CMN_CAL_Event_ApprovalID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } } bool isApprovedBefore = approvalItem.IsApproved; approvalItem.IsApprovalProcessDenied = false; approvalItem.IsApprovalProcessOpened = false; approvalItem.IsApprovalProcessCanceledByUser = true; approvalItem.IsApproved = false; approvalItem.Save(Connection, Transaction); P_L5EM_GEATFSbRTFE_1423 statParam = new P_L5EM_GEATFSbRTFE_1423(); statParam.absenceReasonID = leaveRequest.CMN_BPT_STA_AbsenceReason_RefID; statParam.employeeID = leaveRequest.RequestedFor_Employee_RefID; statParam.timeFrameID = timeFrame.CMN_CAL_CalculationTimeframeID; var statistics = cls_Get_Employee_AbsenceReason_TimeframeStatistic_byReasonTimeFrameEmployee.Invoke(Connection, Transaction, statParam, securityTicket).Result; if (statistics != null) { P_L5EM_SEARTFS_1356 updateStatisticsParam = new P_L5EM_SEARTFS_1356(); updateStatisticsParam.CMN_BPT_EMP_Employee_AbsenceReason_TimeframeStatisticsID = statistics.CMN_BPT_EMP_Employee_AbsenceReason_TimeframeStatisticsID; updateStatisticsParam.Employee_RefID = statistics.Employee_RefID; updateStatisticsParam.CalculationTimeframe_RefID = statistics.CalculationTimeframe_RefID; updateStatisticsParam.AbsenceReason_RefID = statistics.AbsenceReason_RefID; if (isApprovedBefore) { updateStatisticsParam.R_RequestReservedAbsence_InDays = statistics.R_RequestReservedAbsence_InDays; updateStatisticsParam.R_RequestReservedAbsence_InHours = statistics.R_RequestReservedAbsence_InHours; updateStatisticsParam.R_AbsenceTimeUsed_InDays = statistics.R_AbsenceTimeUsed_InDays - Parameter.durationInDays; updateStatisticsParam.R_AbsenceTimeUsed_InHours = statistics.R_AbsenceTimeUsed_InHours - Parameter.durationInHours; updateStatisticsParam.R_TotalAllowedAbsenceTime_InDays = statistics.R_TotalAllowedAbsenceTime_InDays + Parameter.durationInDays; updateStatisticsParam.R_TotalAllowedAbsenceTime_InHours = statistics.R_TotalAllowedAbsenceTime_InHours + Parameter.durationInHours; } else { updateStatisticsParam.R_RequestReservedAbsence_InDays = statistics.R_RequestReservedAbsence_InDays - Parameter.durationInDays; updateStatisticsParam.R_RequestReservedAbsence_InHours = statistics.R_RequestReservedAbsence_InHours - Parameter.durationInHours; updateStatisticsParam.R_AbsenceTimeUsed_InDays = statistics.R_AbsenceTimeUsed_InDays; updateStatisticsParam.R_AbsenceTimeUsed_InHours = statistics.R_AbsenceTimeUsed_InHours; updateStatisticsParam.R_TotalAllowedAbsenceTime_InDays = statistics.R_TotalAllowedAbsenceTime_InDays; updateStatisticsParam.R_TotalAllowedAbsenceTime_InHours = statistics.R_TotalAllowedAbsenceTime_InHours; } var res = cls_Save_Employee_AbsenceReason_TimeframeStatistic.Invoke(Connection, Transaction, updateStatisticsParam, securityTicket); } leaveRequest.Save(Connection, Transaction); Guid absenceReasonID = leaveRequest.CMN_BPT_STA_AbsenceReason_RefID; #endregion #region FirstRange var authRequired = true; var absenceReasons = cls_get_Active_AbsenceReason_For_TenantID.Invoke(Connection, Transaction, securityTicket).Result; if (absenceReasons != null) { if (absenceReasons.Any(r => r.CMN_BPT_STA_AbsenceReasonID == absenceReasonID)) { var reason = absenceReasons.FirstOrDefault(r => r.CMN_BPT_STA_AbsenceReasonID == absenceReasonID); if (reason != null) { authRequired = reason.IsAuthorizationRequired; } } } if (firstRange != null) { leaveRequestEvent = new ORM_CMN_CAL_Event(); leaveRequestEvent.CMN_CAL_EventID = Guid.NewGuid(); leaveRequestEvent.StartTime = firstRange.Start; leaveRequestEvent.EndTime = firstRange.End; leaveRequestEvent.R_EventDuration_sec = (int)firstRange.End.Subtract(firstRange.Start).TotalSeconds; leaveRequestEvent.IsRepetitive = false; leaveRequestEvent.IsWholeDayEvent = false; leaveRequestEvent.IsCalendarEvent_Editable = true; leaveRequestEvent.Tenant_RefID = securityTicket.TenantID; leaveRequestEvent.Save(Connection, Transaction); approvalItem = new ORM_CMN_CAL_Event_Approval(); approvalItem.CMN_CAL_Event_ApprovalID = Guid.NewGuid(); approvalItem.Event_RefID = leaveRequestEvent.CMN_CAL_EventID; approvalItem.IsApprovalProcessDenied = false; approvalItem.IsApprovalProcessOpened = false; if (settings.NumberOfResponsiblePersonsRequiredToApprove == 0 || !authRequired) { approvalItem.IsApproved = true; approvalItem.IsApprovalProcessOpened = false; } else { approvalItem.IsApproved = false; approvalItem.IsApprovalProcessOpened = true; } approvalItem.IsApprovalProcessCanceledByUser = false; approvalItem.IsDeleted = false; approvalItem.Creation_Timestamp = DateTime.Now; approvalItem.Tenant_RefID = securityTicket.TenantID; approvalItem.Save(Connection, Transaction); leaveRequest = new ORM_CMN_BPT_EMP_Employee_LeaveRequest(); leaveRequest.CMN_BPT_EMP_Employee_LeaveRequestID = Guid.NewGuid(); leaveRequest.CMN_BPT_STA_AbsenceReason_RefID = absenceReasonID; leaveRequest.CMN_CAL_Event_Approval_RefID = approvalItem.CMN_CAL_Event_ApprovalID; leaveRequest.CMN_CAL_Event_RefID = leaveRequestEvent.CMN_CAL_EventID; leaveRequest.IsDeleted = false; leaveRequest.RequestedFor_Employee_RefID = dailySchedule.Employee_RefID; leaveRequest.Tenant_RefID = securityTicket.TenantID; leaveRequest.Creation_Timestamp = DateTime.Now; leaveRequest.LeaveRequestCreationSource = "plannico.time"; leaveRequest.Save(Connection, Transaction); P_L5DWS_GDWSWDFP_1225 par = new P_L5DWS_GDWSWDFP_1225(); par.StartDate = firstRange.Start; par.EndDate = firstRange.End; var schedulesWithDetails = cls_Get_DailyWorkSchedules_WithDetails_For_Period.Invoke(Connection, Transaction, par, securityTicket).Result.DailyWorkSchedulesWithDetails; foreach (var schedule in schedulesWithDetails) { if (schedule.Details.Any(i => i.LeaveRequest_RefID == oldLeaveRequestID)) { foreach (var detailItem in schedule.Details.Where(i => i.LeaveRequest_RefID == oldLeaveRequestID).ToArray()) { ORM_CMN_STR_PPS_DailyWorkSchedule_Detail detail = new ORM_CMN_STR_PPS_DailyWorkSchedule_Detail(); detail.Load(Connection, Transaction, detailItem.CMN_STR_PPS_DailyWorkSchedule_DetailID); detail.CMN_BPT_EMP_Employee_LeaveRequest_RefID = leaveRequest.CMN_BPT_EMP_Employee_LeaveRequestID; detail.Save(Connection, Transaction); } } } } #endregion #region secondRange if (secondRange != null) { leaveRequestEvent = new ORM_CMN_CAL_Event(); leaveRequestEvent.CMN_CAL_EventID = Guid.NewGuid(); leaveRequestEvent.StartTime = secondRange.Start; leaveRequestEvent.EndTime = secondRange.End; leaveRequestEvent.R_EventDuration_sec = (int)secondRange.End.Subtract(secondRange.Start).TotalSeconds; leaveRequestEvent.IsRepetitive = false; leaveRequestEvent.IsWholeDayEvent = false; leaveRequestEvent.IsCalendarEvent_Editable = true; leaveRequestEvent.Tenant_RefID = securityTicket.TenantID; leaveRequestEvent.Save(Connection, Transaction); approvalItem = new ORM_CMN_CAL_Event_Approval(); approvalItem.CMN_CAL_Event_ApprovalID = Guid.NewGuid(); approvalItem.Event_RefID = leaveRequestEvent.CMN_CAL_EventID; approvalItem.IsApprovalProcessDenied = false; approvalItem.IsApprovalProcessOpened = false; if (settings.NumberOfResponsiblePersonsRequiredToApprove == 0 || !authRequired) { approvalItem.IsApproved = true; approvalItem.IsApprovalProcessOpened = false; } else { approvalItem.IsApprovalProcessOpened = true; approvalItem.IsApproved = false; } approvalItem.IsApprovalProcessCanceledByUser = false; approvalItem.IsDeleted = false; approvalItem.Creation_Timestamp = DateTime.Now; approvalItem.Tenant_RefID = securityTicket.TenantID; approvalItem.Save(Connection, Transaction); leaveRequest = new ORM_CMN_BPT_EMP_Employee_LeaveRequest(); leaveRequest.CMN_BPT_EMP_Employee_LeaveRequestID = Guid.NewGuid(); leaveRequest.CMN_BPT_STA_AbsenceReason_RefID = absenceReasonID; leaveRequest.CMN_CAL_Event_Approval_RefID = approvalItem.CMN_CAL_Event_ApprovalID; leaveRequest.CMN_CAL_Event_RefID = leaveRequestEvent.CMN_CAL_EventID; leaveRequest.IsDeleted = false; leaveRequest.RequestedFor_Employee_RefID = dailySchedule.Employee_RefID; leaveRequest.Tenant_RefID = securityTicket.TenantID; leaveRequest.Creation_Timestamp = DateTime.Now; leaveRequest.LeaveRequestCreationSource = "plannico.time"; leaveRequest.Save(Connection, Transaction); P_L5DWS_GDWSWDFP_1225 par = new P_L5DWS_GDWSWDFP_1225(); par.StartDate = secondRange.Start; par.EndDate = secondRange.End; var schedulesWithDetails = cls_Get_DailyWorkSchedules_WithDetails_For_Period.Invoke(Connection, Transaction, par, securityTicket).Result.DailyWorkSchedulesWithDetails; foreach (var schedule in schedulesWithDetails) { if (schedule.Details.Any(i => i.LeaveRequest_RefID == oldLeaveRequestID)) { foreach (var detailItem in schedule.Details.Where(i => i.LeaveRequest_RefID == oldLeaveRequestID).ToArray()) { ORM_CMN_STR_PPS_DailyWorkSchedule_Detail detail = new ORM_CMN_STR_PPS_DailyWorkSchedule_Detail(); detail.Load(Connection, Transaction, detailItem.CMN_STR_PPS_DailyWorkSchedule_DetailID); detail.CMN_BPT_EMP_Employee_LeaveRequest_RefID = leaveRequest.CMN_BPT_EMP_Employee_LeaveRequestID; detail.Save(Connection, Transaction); } } } } #endregion #region thirdRange if (thirdRange != null) { leaveRequestEvent = new ORM_CMN_CAL_Event(); leaveRequestEvent.CMN_CAL_EventID = Guid.NewGuid(); leaveRequestEvent.StartTime = thirdRange.Start; leaveRequestEvent.EndTime = thirdRange.End; leaveRequestEvent.R_EventDuration_sec = (int)thirdRange.End.Subtract(thirdRange.Start).TotalSeconds; leaveRequestEvent.IsRepetitive = false; leaveRequestEvent.IsWholeDayEvent = false; leaveRequestEvent.IsCalendarEvent_Editable = true; leaveRequestEvent.Tenant_RefID = securityTicket.TenantID; leaveRequestEvent.Save(Connection, Transaction); approvalItem = new ORM_CMN_CAL_Event_Approval(); approvalItem.CMN_CAL_Event_ApprovalID = Guid.NewGuid(); approvalItem.Event_RefID = leaveRequestEvent.CMN_CAL_EventID; approvalItem.IsApprovalProcessDenied = false; approvalItem.IsApprovalProcessOpened = false; if (settings.NumberOfResponsiblePersonsRequiredToApprove == 0 || !authRequired) { approvalItem.IsApprovalProcessOpened = false; approvalItem.IsApproved = true; } else { approvalItem.IsApprovalProcessOpened = true; approvalItem.IsApproved = false; } approvalItem.IsApprovalProcessCanceledByUser = false; approvalItem.IsDeleted = false; approvalItem.Creation_Timestamp = DateTime.Now; approvalItem.Tenant_RefID = securityTicket.TenantID; approvalItem.Save(Connection, Transaction); leaveRequest = new ORM_CMN_BPT_EMP_Employee_LeaveRequest(); leaveRequest.CMN_BPT_EMP_Employee_LeaveRequestID = Guid.NewGuid(); leaveRequest.CMN_BPT_STA_AbsenceReason_RefID = absenceReasonID; leaveRequest.CMN_CAL_Event_Approval_RefID = approvalItem.CMN_CAL_Event_ApprovalID; leaveRequest.CMN_CAL_Event_RefID = leaveRequestEvent.CMN_CAL_EventID; leaveRequest.IsDeleted = false; leaveRequest.RequestedFor_Employee_RefID = dailySchedule.Employee_RefID; leaveRequest.Tenant_RefID = securityTicket.TenantID; leaveRequest.Creation_Timestamp = DateTime.Now; leaveRequest.LeaveRequestCreationSource = "plannico.time"; leaveRequest.Save(Connection, Transaction); P_L5DWS_GDWSWDFP_1225 par = new P_L5DWS_GDWSWDFP_1225(); par.StartDate = thirdRange.Start; par.EndDate = thirdRange.End; var schedulesWithDetails = cls_Get_DailyWorkSchedules_WithDetails_For_Period.Invoke(Connection, Transaction, par, securityTicket).Result.DailyWorkSchedulesWithDetails; foreach (var schedule in schedulesWithDetails) { if (schedule.Details.Any(i => i.LeaveRequest_RefID == oldLeaveRequestID)) { foreach (var detailItem in schedule.Details.Where(i => i.LeaveRequest_RefID == oldLeaveRequestID).ToArray()) { ORM_CMN_STR_PPS_DailyWorkSchedule_Detail detail = new ORM_CMN_STR_PPS_DailyWorkSchedule_Detail(); detail.Load(Connection, Transaction, detailItem.CMN_STR_PPS_DailyWorkSchedule_DetailID); detail.CMN_BPT_EMP_Employee_LeaveRequest_RefID = leaveRequest.CMN_BPT_EMP_Employee_LeaveRequestID; detail.Save(Connection, Transaction); } } } } #endregion } else { leaveRequestEvent.Remove(Connection, Transaction); leaveRequest.Remove(Connection, Transaction); var approvalItem = new ORM_CMN_CAL_Event_Approval(); if (leaveRequest.CMN_CAL_Event_Approval_RefID != Guid.Empty) { var approvalResult = approvalItem.Load(Connection, Transaction, leaveRequest.CMN_CAL_Event_Approval_RefID); if (approvalResult.Status != FR_Status.Success || approvalItem.CMN_CAL_Event_ApprovalID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } } bool isApprovedBefore = approvalItem.IsApproved; P_L5EM_GEATFSbRTFE_1423 statParam = new P_L5EM_GEATFSbRTFE_1423(); statParam.absenceReasonID = leaveRequest.CMN_BPT_STA_AbsenceReason_RefID; statParam.employeeID = leaveRequest.RequestedFor_Employee_RefID; statParam.timeFrameID = timeFrame.CMN_CAL_CalculationTimeframeID; var statistics = cls_Get_Employee_AbsenceReason_TimeframeStatistic_byReasonTimeFrameEmployee.Invoke(Connection, Transaction, statParam, securityTicket).Result; if (statistics != null) { P_L5EM_SEARTFS_1356 updateStatisticsParam = new P_L5EM_SEARTFS_1356(); updateStatisticsParam.CMN_BPT_EMP_Employee_AbsenceReason_TimeframeStatisticsID = statistics.CMN_BPT_EMP_Employee_AbsenceReason_TimeframeStatisticsID; updateStatisticsParam.Employee_RefID = statistics.Employee_RefID; updateStatisticsParam.CalculationTimeframe_RefID = statistics.CalculationTimeframe_RefID; updateStatisticsParam.AbsenceReason_RefID = statistics.AbsenceReason_RefID; if (isApprovedBefore) { updateStatisticsParam.R_RequestReservedAbsence_InDays = statistics.R_RequestReservedAbsence_InDays; updateStatisticsParam.R_RequestReservedAbsence_InHours = statistics.R_RequestReservedAbsence_InHours; updateStatisticsParam.R_AbsenceTimeUsed_InDays = statistics.R_AbsenceTimeUsed_InDays - Parameter.durationInDays; updateStatisticsParam.R_AbsenceTimeUsed_InHours = statistics.R_AbsenceTimeUsed_InHours - Parameter.durationInHours; updateStatisticsParam.R_TotalAllowedAbsenceTime_InDays = statistics.R_TotalAllowedAbsenceTime_InDays + Parameter.durationInDays; updateStatisticsParam.R_TotalAllowedAbsenceTime_InHours = statistics.R_TotalAllowedAbsenceTime_InHours + Parameter.durationInHours; } else { updateStatisticsParam.R_RequestReservedAbsence_InDays = statistics.R_RequestReservedAbsence_InDays - Parameter.durationInDays; updateStatisticsParam.R_RequestReservedAbsence_InHours = statistics.R_RequestReservedAbsence_InHours - Parameter.durationInHours; updateStatisticsParam.R_AbsenceTimeUsed_InDays = statistics.R_AbsenceTimeUsed_InDays; updateStatisticsParam.R_AbsenceTimeUsed_InHours = statistics.R_AbsenceTimeUsed_InHours; updateStatisticsParam.R_TotalAllowedAbsenceTime_InDays = statistics.R_TotalAllowedAbsenceTime_InDays; updateStatisticsParam.R_TotalAllowedAbsenceTime_InHours = statistics.R_TotalAllowedAbsenceTime_InHours; } var res = cls_Save_Employee_AbsenceReason_TimeframeStatistic.Invoke(Connection, Transaction, updateStatisticsParam, securityTicket); } } } P_L5DWS_DDWSDFIDL_1014 param = new P_L5DWS_DDWSDFIDL_1014(); param.DailyWorkSchedule_DetailID = Parameter.DailyWorkSchedule_DetailID; cls_Delete_Employee_DailyWorkSchedule_Detail.Invoke(Connection, Transaction, param, securityTicket); //Put your code here return(returnValue); #endregion UserCode }
protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5DWS_SEWTP_1337 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Guid(); //Put your code here LeaveRequestUtils leaveRequestUtil = new LeaveRequestUtils(); ORM_CMN_BPT_EMP_EffectiveWorkTime_Position effectivePosition = new ORM_CMN_BPT_EMP_EffectiveWorkTime_Position(); if (Parameter.CMN_BPT_EMP_EffectiveWorkTime_PositionID != Guid.Empty) { var result = effectivePosition.Load(Connection, Transaction, Parameter.CMN_BPT_EMP_EffectiveWorkTime_PositionID); if (result.Status != FR_Status.Success || effectivePosition.CMN_BPT_EMP_EffectiveWorkTime_PositionID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID."; error.Status = FR_Status.Error_Internal; return(error); } effectivePosition.EffectiveWorkTime_Header_RefID = Parameter.EffectiveWorkTime_Header_RefID; effectivePosition.CMN_BPT_EMP_Employe_RefID = Parameter.Employee_RefID; effectivePosition.CMN_BPT_EMP_Employee_LeaveRequest_RefID = Parameter.CMN_BPT_EMP_Employee_LeaveRequest_RefID; effectivePosition.Workplace_RefID = Parameter.Workplace_RefID; effectivePosition.Tenant_RefID = securityTicket.TenantID; effectivePosition.WorkTime_StartTime = Parameter.WorkTime_Start; effectivePosition.WorkTime_Duration_in_sec = (int)Parameter.WorkTime_End.Subtract(Parameter.WorkTime_Start).TotalSeconds; effectivePosition.SourceOfEntry = Parameter.SourceOfEntry; effectivePosition.Save(Connection, Transaction); if (Parameter.AbsenceReason_RefID != Guid.Empty) { P_L5DWS_GDWSWDFPAE_1331 par = new P_L5DWS_GDWSWDFPAE_1331(); par.EmployeeID = Parameter.Employee_RefID; par.PeriodStartDate = Parameter.WorkTime_Start.Date; par.PeriodEndDate = Parameter.WorkTime_Start.Date; var planningData = cls_Get_DailyWorkSchedules_WithDetails_For_Period_And_EmployeeID.Invoke(Connection, Transaction, par, securityTicket).Result; if (planningData.DailyWorkSchedulesWithDetails.Length != 0) { var dailyWorkSchedule = planningData.DailyWorkSchedulesWithDetails[0]; foreach (var detail in dailyWorkSchedule.Details) { if (detail.LeaveRequest_RefID != Guid.Empty) { ORM_CMN_BPT_EMP_Employee_LeaveRequest leaveRequest = new ORM_CMN_BPT_EMP_Employee_LeaveRequest(); leaveRequest.Load(Connection, Transaction, detail.LeaveRequest_RefID); leaveRequest.Remove(Connection, Transaction); ORM_CMN_CAL_Event leaveRequestEvent = new ORM_CMN_CAL_Event(); leaveRequestEvent.Load(Connection, Transaction, leaveRequest.CMN_CAL_Event_RefID); leaveRequestEvent.Remove(Connection, Transaction); var calQuery = new ORM_CMN_CAL_Event.Query(); calQuery.CMN_CAL_EventID = leaveRequest.CMN_CAL_Event_RefID; var calendarRes = ORM_CMN_CAL_Event.Query.Search(Connection, Transaction, calQuery); ORM_CMN_CAL_Event calendarEvent = calendarRes[0]; P_L5TN_GCTFFTAY_1320 timeFrameParam = new P_L5TN_GCTFFTAY_1320(); timeFrameParam.Year = leaveRequestEvent.StartTime.Year; var timeFrame = cls_Get_CalculationTimeFramesForTenant_And_Year.Invoke(Connection, Transaction, timeFrameParam, securityTicket).Result.CalculationTimeFrame; var approvalItem = new ORM_CMN_CAL_Event_Approval(); if (leaveRequest.CMN_CAL_Event_Approval_RefID != Guid.Empty) { var approvalResult = approvalItem.Load(Connection, Transaction, leaveRequest.CMN_CAL_Event_Approval_RefID); if (approvalResult.Status != FR_Status.Success || approvalItem.CMN_CAL_Event_ApprovalID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } } bool isApprovedBefore = approvalItem.IsApproved; P_L5EM_GEATFSbRTFE_1423 statParam = new P_L5EM_GEATFSbRTFE_1423(); statParam.absenceReasonID = leaveRequest.CMN_BPT_STA_AbsenceReason_RefID; statParam.employeeID = leaveRequest.RequestedFor_Employee_RefID; statParam.timeFrameID = timeFrame.CMN_CAL_CalculationTimeframeID; var statistics = cls_Get_Employee_AbsenceReason_TimeframeStatistic_byReasonTimeFrameEmployee.Invoke(Connection, Transaction, statParam, securityTicket).Result; if (statistics != null) { P_L5EM_SEARTFS_1356 updateStatisticsParam = new P_L5EM_SEARTFS_1356(); updateStatisticsParam.CMN_BPT_EMP_Employee_AbsenceReason_TimeframeStatisticsID = statistics.CMN_BPT_EMP_Employee_AbsenceReason_TimeframeStatisticsID; updateStatisticsParam.Employee_RefID = statistics.Employee_RefID; updateStatisticsParam.CalculationTimeframe_RefID = statistics.CalculationTimeframe_RefID; updateStatisticsParam.AbsenceReason_RefID = statistics.AbsenceReason_RefID; updateStatisticsParam.R_AbsenceCarryOver_InDays = statistics.R_AbsenceCarryOver_InDays; updateStatisticsParam.R_AbsenceCarryOver_InHours = statistics.R_AbsenceCarryOver_InHours; var durationInDays = leaveRequestUtil.LeaveRequestDuration(leaveRequestEvent.StartTime, leaveRequestEvent.EndTime, Parameter.Events, Parameter.Employees.FirstOrDefault(x => x.CMN_BPT_EMP_EmployeeID == leaveRequest.RequestedFor_Employee_RefID), true); var durationInHours = leaveRequestUtil.LeaveRequestDuration(leaveRequestEvent.StartTime, leaveRequestEvent.EndTime, Parameter.Events, Parameter.Employees.FirstOrDefault(x => x.CMN_BPT_EMP_EmployeeID == leaveRequest.RequestedFor_Employee_RefID), false); if (!isApprovedBefore) { updateStatisticsParam.R_RequestReservedAbsence_InDays = statistics.R_RequestReservedAbsence_InDays - durationInDays; updateStatisticsParam.R_RequestReservedAbsence_InHours = statistics.R_RequestReservedAbsence_InHours - durationInHours; updateStatisticsParam.R_AbsenceTimeUsed_InDays = statistics.R_AbsenceTimeUsed_InDays; updateStatisticsParam.R_AbsenceTimeUsed_InHours = statistics.R_AbsenceTimeUsed_InHours; updateStatisticsParam.R_TotalAllowedAbsenceTime_InDays = statistics.R_TotalAllowedAbsenceTime_InDays; updateStatisticsParam.R_TotalAllowedAbsenceTime_InHours = statistics.R_TotalAllowedAbsenceTime_InHours; } var res = cls_Save_Employee_AbsenceReason_TimeframeStatistic.Invoke(Connection, Transaction, updateStatisticsParam, securityTicket); } ORM_CMN_STR_PPS_DailyWorkSchedule_Detail scheduleDetail = new ORM_CMN_STR_PPS_DailyWorkSchedule_Detail(); result = scheduleDetail.Load(Connection, Transaction, detail.CMN_STR_PPS_DailyWorkSchedule_DetailID); if (result.Status != FR_Status.Success || scheduleDetail.CMN_STR_PPS_DailyWorkSchedule_DetailID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID."; error.Status = FR_Status.Error_Internal; return(error); } scheduleDetail.CMN_BPT_EMP_Employee_LeaveRequest_RefID = Guid.Empty; scheduleDetail.Save(Connection, Transaction); } } } if (effectivePosition.CMN_BPT_EMP_Employee_LeaveRequest_RefID == Guid.Empty) { ORM_CMN_CAL_Event leaveRequestEvent = new ORM_CMN_CAL_Event(); leaveRequestEvent.StartTime = Parameter.WorkTime_Start; leaveRequestEvent.EndTime = Parameter.WorkTime_End; leaveRequestEvent.R_EventDuration_sec = (int)Parameter.WorkTime_End.Subtract(Parameter.WorkTime_Start).TotalSeconds; leaveRequestEvent.IsRepetitive = false; leaveRequestEvent.IsWholeDayEvent = false; leaveRequestEvent.IsCalendarEvent_Editable = true; leaveRequestEvent.Tenant_RefID = securityTicket.TenantID; leaveRequestEvent.Save(Connection, Transaction); var approvalItem = new ORM_CMN_CAL_Event_Approval(); approvalItem.Event_RefID = leaveRequestEvent.CMN_CAL_EventID; approvalItem.IsApprovalProcessDenied = false; approvalItem.IsApprovalProcessOpened = false; approvalItem.IsApproved = true; approvalItem.IsApprovalProcessCanceledByUser = false; approvalItem.IsDeleted = false; approvalItem.Creation_Timestamp = DateTime.Now; approvalItem.Tenant_RefID = securityTicket.TenantID; approvalItem.Save(Connection, Transaction); var requestItem = new ORM_CMN_BPT_EMP_Employee_LeaveRequest(); requestItem.CMN_BPT_STA_AbsenceReason_RefID = Parameter.AbsenceReason_RefID; requestItem.CMN_CAL_Event_Approval_RefID = approvalItem.CMN_CAL_Event_ApprovalID; requestItem.CMN_CAL_Event_RefID = leaveRequestEvent.CMN_CAL_EventID; requestItem.IsDeleted = false; requestItem.RequestedBy_Employee_RefID = Parameter.Employee_RefID; requestItem.RequestedFor_Employee_RefID = Parameter.Employee_RefID; requestItem.Tenant_RefID = securityTicket.TenantID; requestItem.Creation_Timestamp = DateTime.Now; requestItem.LeaveRequestCreationSource = "plannico.time"; requestItem.Save(Connection, Transaction); effectivePosition.CMN_BPT_EMP_Employee_LeaveRequest_RefID = requestItem.CMN_BPT_EMP_Employee_LeaveRequestID; effectivePosition.Save(Connection, Transaction); P_L5TN_GCTFFTAY_1320 timeFrameParam = new P_L5TN_GCTFFTAY_1320(); timeFrameParam.Year = leaveRequestEvent.StartTime.Year; var timeFrame = cls_Get_CalculationTimeFramesForTenant_And_Year.Invoke(Connection, Transaction, timeFrameParam, securityTicket).Result.CalculationTimeFrame; P_L5EM_GEATFSbRTFE_1423 statParam = new P_L5EM_GEATFSbRTFE_1423(); statParam.absenceReasonID = requestItem.CMN_BPT_STA_AbsenceReason_RefID; statParam.employeeID = requestItem.RequestedFor_Employee_RefID; statParam.timeFrameID = timeFrame.CMN_CAL_CalculationTimeframeID; var statistics = cls_Get_Employee_AbsenceReason_TimeframeStatistic_byReasonTimeFrameEmployee.Invoke(Connection, Transaction, statParam, securityTicket).Result; if (statistics != null) { P_L5EM_SEARTFS_1356 updateStatisticsParam = new P_L5EM_SEARTFS_1356(); updateStatisticsParam.CMN_BPT_EMP_Employee_AbsenceReason_TimeframeStatisticsID = statistics.CMN_BPT_EMP_Employee_AbsenceReason_TimeframeStatisticsID; updateStatisticsParam.Employee_RefID = statistics.Employee_RefID; updateStatisticsParam.CalculationTimeframe_RefID = statistics.CalculationTimeframe_RefID; updateStatisticsParam.AbsenceReason_RefID = statistics.AbsenceReason_RefID; updateStatisticsParam.R_RequestReservedAbsence_InDays = statistics.R_RequestReservedAbsence_InDays; updateStatisticsParam.R_RequestReservedAbsence_InHours = statistics.R_RequestReservedAbsence_InHours; updateStatisticsParam.R_AbsenceCarryOver_InDays = statistics.R_AbsenceCarryOver_InDays; updateStatisticsParam.R_AbsenceCarryOver_InHours = statistics.R_AbsenceCarryOver_InHours; updateStatisticsParam.R_TotalAllowedAbsenceTime_InDays = statistics.R_TotalAllowedAbsenceTime_InDays - Parameter.durationInDays; updateStatisticsParam.R_TotalAllowedAbsenceTime_InHours = statistics.R_TotalAllowedAbsenceTime_InHours - Parameter.durationInHours; updateStatisticsParam.R_AbsenceTimeUsed_InDays = statistics.R_AbsenceTimeUsed_InDays + Parameter.durationInDays; updateStatisticsParam.R_AbsenceTimeUsed_InHours = statistics.R_AbsenceTimeUsed_InHours + Parameter.durationInHours; var res = cls_Save_Employee_AbsenceReason_TimeframeStatistic.Invoke(Connection, Transaction, updateStatisticsParam, securityTicket); } } else { ORM_CMN_BPT_EMP_Employee_LeaveRequest leaveRequest = new ORM_CMN_BPT_EMP_Employee_LeaveRequest(); leaveRequest.Load(Connection, Transaction, effectivePosition.CMN_BPT_EMP_Employee_LeaveRequest_RefID); ORM_CMN_CAL_Event leaveRequestEvent = new ORM_CMN_CAL_Event(); leaveRequestEvent.Load(Connection, Transaction, leaveRequest.CMN_CAL_Event_RefID); if (leaveRequest.CMN_BPT_STA_AbsenceReason_RefID != Parameter.AbsenceReason_RefID || Parameter.OldDurationInHours != Parameter.durationInHours || Parameter.OldDurationInDays != Parameter.durationInDays) { var calQuery = new ORM_CMN_CAL_Event.Query(); calQuery.CMN_CAL_EventID = leaveRequest.CMN_CAL_Event_RefID; var calendarRes = ORM_CMN_CAL_Event.Query.Search(Connection, Transaction, calQuery); ORM_CMN_CAL_Event calendarEvent = calendarRes[0]; P_L5TN_GCTFFTAY_1320 timeFrameParam = new P_L5TN_GCTFFTAY_1320(); timeFrameParam.Year = leaveRequestEvent.StartTime.Year; var timeFrame = cls_Get_CalculationTimeFramesForTenant_And_Year.Invoke(Connection, Transaction, timeFrameParam, securityTicket).Result.CalculationTimeFrame; P_L5EM_GEATFSbRTFE_1423 statParam = new P_L5EM_GEATFSbRTFE_1423(); statParam.absenceReasonID = leaveRequest.CMN_BPT_STA_AbsenceReason_RefID; statParam.employeeID = leaveRequest.RequestedFor_Employee_RefID; statParam.timeFrameID = timeFrame.CMN_CAL_CalculationTimeframeID; var statistics = cls_Get_Employee_AbsenceReason_TimeframeStatistic_byReasonTimeFrameEmployee.Invoke(Connection, Transaction, statParam, securityTicket).Result; if (statistics != null) { P_L5EM_SEARTFS_1356 updateStatisticsParam = new P_L5EM_SEARTFS_1356(); updateStatisticsParam.CMN_BPT_EMP_Employee_AbsenceReason_TimeframeStatisticsID = statistics.CMN_BPT_EMP_Employee_AbsenceReason_TimeframeStatisticsID; updateStatisticsParam.Employee_RefID = statistics.Employee_RefID; updateStatisticsParam.CalculationTimeframe_RefID = statistics.CalculationTimeframe_RefID; updateStatisticsParam.AbsenceReason_RefID = statistics.AbsenceReason_RefID; updateStatisticsParam.R_AbsenceCarryOver_InDays = statistics.R_AbsenceCarryOver_InDays; updateStatisticsParam.R_AbsenceCarryOver_InHours = statistics.R_AbsenceCarryOver_InHours; updateStatisticsParam.R_TotalAllowedAbsenceTime_InDays = statistics.R_TotalAllowedAbsenceTime_InDays + Parameter.OldDurationInDays - Parameter.durationInDays; updateStatisticsParam.R_TotalAllowedAbsenceTime_InHours = statistics.R_TotalAllowedAbsenceTime_InHours + Parameter.OldDurationInHours - Parameter.durationInHours; updateStatisticsParam.R_RequestReservedAbsence_InDays = statistics.R_RequestReservedAbsence_InDays; updateStatisticsParam.R_RequestReservedAbsence_InHours = statistics.R_RequestReservedAbsence_InHours; updateStatisticsParam.R_AbsenceTimeUsed_InDays = statistics.R_AbsenceTimeUsed_InDays - Parameter.OldDurationInDays + Parameter.durationInDays; updateStatisticsParam.R_AbsenceTimeUsed_InHours = statistics.R_AbsenceTimeUsed_InHours - Parameter.OldDurationInHours + Parameter.durationInHours; var res = cls_Save_Employee_AbsenceReason_TimeframeStatistic.Invoke(Connection, Transaction, updateStatisticsParam, securityTicket); } leaveRequest.CMN_BPT_STA_AbsenceReason_RefID = Parameter.AbsenceReason_RefID; leaveRequest.Save(Connection, Transaction); } leaveRequestEvent.StartTime = Parameter.WorkTime_Start; leaveRequestEvent.EndTime = Parameter.WorkTime_End; leaveRequestEvent.R_EventDuration_sec = (int)Parameter.WorkTime_End.Subtract(Parameter.WorkTime_Start).TotalSeconds; leaveRequestEvent.Save(Connection, Transaction); } } else { if (effectivePosition.CMN_BPT_EMP_Employee_LeaveRequest_RefID != Guid.Empty) { ORM_CMN_BPT_EMP_Employee_LeaveRequest leaveRequest = new ORM_CMN_BPT_EMP_Employee_LeaveRequest(); leaveRequest.Load(Connection, Transaction, effectivePosition.CMN_BPT_EMP_Employee_LeaveRequest_RefID); leaveRequest.Remove(Connection, Transaction); ORM_CMN_CAL_Event_Approval.Query calEventApprovalQuery = new ORM_CMN_CAL_Event_Approval.Query(); calEventApprovalQuery.Event_RefID = leaveRequest.CMN_CAL_Event_RefID; calEventApprovalQuery.IsDeleted = false; calEventApprovalQuery.Tenant_RefID = securityTicket.TenantID; ORM_CMN_CAL_Event_Approval calEventApproval = ORM_CMN_CAL_Event_Approval.Query.Search(Connection, Transaction, calEventApprovalQuery).FirstOrDefault(); calEventApproval.Remove(Connection, Transaction); ORM_CMN_CAL_Event leaveRequestEvent = new ORM_CMN_CAL_Event(); leaveRequestEvent.Load(Connection, Transaction, leaveRequest.CMN_CAL_Event_RefID); leaveRequestEvent.Remove(Connection, Transaction); effectivePosition.CMN_BPT_EMP_Employee_LeaveRequest_RefID = Guid.Empty; effectivePosition.Save(Connection, Transaction); P_L5TN_GCTFFTAY_1320 timeFrameParam = new P_L5TN_GCTFFTAY_1320(); timeFrameParam.Year = leaveRequestEvent.StartTime.Year; var timeFrame = cls_Get_CalculationTimeFramesForTenant_And_Year.Invoke(Connection, Transaction, timeFrameParam, securityTicket).Result.CalculationTimeFrame; P_L5EM_GEATFSbRTFE_1423 statParam = new P_L5EM_GEATFSbRTFE_1423(); statParam.absenceReasonID = leaveRequest.CMN_BPT_STA_AbsenceReason_RefID; statParam.employeeID = leaveRequest.RequestedFor_Employee_RefID; statParam.timeFrameID = timeFrame.CMN_CAL_CalculationTimeframeID; var statistics = cls_Get_Employee_AbsenceReason_TimeframeStatistic_byReasonTimeFrameEmployee.Invoke(Connection, Transaction, statParam, securityTicket).Result; if (statistics != null) { P_L5EM_SEARTFS_1356 updateStatisticsParam = new P_L5EM_SEARTFS_1356(); updateStatisticsParam.CMN_BPT_EMP_Employee_AbsenceReason_TimeframeStatisticsID = statistics.CMN_BPT_EMP_Employee_AbsenceReason_TimeframeStatisticsID; updateStatisticsParam.Employee_RefID = statistics.Employee_RefID; updateStatisticsParam.CalculationTimeframe_RefID = statistics.CalculationTimeframe_RefID; updateStatisticsParam.AbsenceReason_RefID = statistics.AbsenceReason_RefID; updateStatisticsParam.R_AbsenceCarryOver_InDays = statistics.R_AbsenceCarryOver_InDays; updateStatisticsParam.R_AbsenceCarryOver_InHours = statistics.R_AbsenceCarryOver_InHours; updateStatisticsParam.R_TotalAllowedAbsenceTime_InDays = statistics.R_TotalAllowedAbsenceTime_InDays + Parameter.OldDurationInDays; updateStatisticsParam.R_TotalAllowedAbsenceTime_InHours = statistics.R_TotalAllowedAbsenceTime_InHours + Parameter.OldDurationInHours; updateStatisticsParam.R_RequestReservedAbsence_InDays = statistics.R_RequestReservedAbsence_InDays; updateStatisticsParam.R_RequestReservedAbsence_InHours = statistics.R_RequestReservedAbsence_InHours; updateStatisticsParam.R_AbsenceTimeUsed_InDays = statistics.R_AbsenceTimeUsed_InDays - Parameter.OldDurationInDays; updateStatisticsParam.R_AbsenceTimeUsed_InHours = statistics.R_AbsenceTimeUsed_InHours - Parameter.OldDurationInHours; var res = cls_Save_Employee_AbsenceReason_TimeframeStatistic.Invoke(Connection, Transaction, updateStatisticsParam, securityTicket); } } } } else { effectivePosition.EffectiveWorkTime_Header_RefID = Parameter.EffectiveWorkTime_Header_RefID; effectivePosition.CMN_BPT_EMP_Employe_RefID = Parameter.Employee_RefID; effectivePosition.CMN_BPT_EMP_Employee_LeaveRequest_RefID = Parameter.CMN_BPT_EMP_Employee_LeaveRequest_RefID; effectivePosition.Workplace_RefID = Parameter.Workplace_RefID; effectivePosition.Tenant_RefID = securityTicket.TenantID; effectivePosition.WorkTime_StartTime = Parameter.WorkTime_Start; effectivePosition.WorkTime_Duration_in_sec = (int)Parameter.WorkTime_End.Subtract(Parameter.WorkTime_Start).TotalSeconds; effectivePosition.SourceOfEntry = Parameter.SourceOfEntry; effectivePosition.Save(Connection, Transaction); if (Parameter.AbsenceReason_RefID != Guid.Empty) { ORM_CMN_CAL_Event leaveRequestEvent = new ORM_CMN_CAL_Event(); leaveRequestEvent.StartTime = Parameter.WorkTime_Start; leaveRequestEvent.EndTime = Parameter.WorkTime_End; leaveRequestEvent.R_EventDuration_sec = (int)Parameter.WorkTime_End.Subtract(Parameter.WorkTime_Start).TotalSeconds; leaveRequestEvent.IsRepetitive = false; leaveRequestEvent.IsWholeDayEvent = false; leaveRequestEvent.IsCalendarEvent_Editable = true; leaveRequestEvent.Tenant_RefID = securityTicket.TenantID; leaveRequestEvent.Save(Connection, Transaction); var approvalItem = new ORM_CMN_CAL_Event_Approval(); approvalItem.Event_RefID = leaveRequestEvent.CMN_CAL_EventID; approvalItem.IsApprovalProcessDenied = false; approvalItem.IsApprovalProcessOpened = false; approvalItem.IsApproved = true; approvalItem.IsApprovalProcessCanceledByUser = false; approvalItem.IsDeleted = false; approvalItem.Creation_Timestamp = DateTime.Now; approvalItem.Tenant_RefID = securityTicket.TenantID; approvalItem.Save(Connection, Transaction); var requestItem = new ORM_CMN_BPT_EMP_Employee_LeaveRequest(); requestItem.CMN_BPT_STA_AbsenceReason_RefID = Parameter.AbsenceReason_RefID; requestItem.CMN_CAL_Event_Approval_RefID = approvalItem.CMN_CAL_Event_ApprovalID; requestItem.CMN_CAL_Event_RefID = leaveRequestEvent.CMN_CAL_EventID; requestItem.IsDeleted = false; requestItem.RequestedBy_Employee_RefID = Parameter.RequestedBy_Employee_RefID; requestItem.RequestedFor_Employee_RefID = Parameter.RequestedFor_Employee_RefID; requestItem.Tenant_RefID = securityTicket.TenantID; requestItem.Creation_Timestamp = DateTime.Now; requestItem.LeaveRequestCreationSource = "plannico.time"; requestItem.Save(Connection, Transaction); effectivePosition.CMN_BPT_EMP_Employee_LeaveRequest_RefID = requestItem.CMN_BPT_EMP_Employee_LeaveRequestID; effectivePosition.Save(Connection, Transaction); P_L5TN_GCTFFTAY_1320 timeFrameParam = new P_L5TN_GCTFFTAY_1320(); timeFrameParam.Year = leaveRequestEvent.StartTime.Year; var timeFrame = cls_Get_CalculationTimeFramesForTenant_And_Year.Invoke(Connection, Transaction, timeFrameParam, securityTicket).Result.CalculationTimeFrame; P_L5EM_GEATFSbRTFE_1423 statParam = new P_L5EM_GEATFSbRTFE_1423(); statParam.absenceReasonID = requestItem.CMN_BPT_STA_AbsenceReason_RefID; statParam.employeeID = requestItem.RequestedFor_Employee_RefID; statParam.timeFrameID = timeFrame.CMN_CAL_CalculationTimeframeID; var statistics = cls_Get_Employee_AbsenceReason_TimeframeStatistic_byReasonTimeFrameEmployee.Invoke(Connection, Transaction, statParam, securityTicket).Result; if (statistics != null) { P_L5EM_SEARTFS_1356 updateStatisticsParam = new P_L5EM_SEARTFS_1356(); updateStatisticsParam.CMN_BPT_EMP_Employee_AbsenceReason_TimeframeStatisticsID = statistics.CMN_BPT_EMP_Employee_AbsenceReason_TimeframeStatisticsID; updateStatisticsParam.Employee_RefID = statistics.Employee_RefID; updateStatisticsParam.CalculationTimeframe_RefID = statistics.CalculationTimeframe_RefID; updateStatisticsParam.AbsenceReason_RefID = statistics.AbsenceReason_RefID; updateStatisticsParam.R_AbsenceCarryOver_InDays = statistics.R_AbsenceCarryOver_InDays; updateStatisticsParam.R_AbsenceCarryOver_InHours = statistics.R_AbsenceCarryOver_InHours; updateStatisticsParam.R_TotalAllowedAbsenceTime_InDays = statistics.R_TotalAllowedAbsenceTime_InDays - Parameter.durationInDays; updateStatisticsParam.R_TotalAllowedAbsenceTime_InHours = statistics.R_TotalAllowedAbsenceTime_InHours - Parameter.durationInHours; updateStatisticsParam.R_AbsenceTimeUsed_InDays = statistics.R_AbsenceTimeUsed_InDays + Parameter.durationInDays; updateStatisticsParam.R_AbsenceTimeUsed_InHours = statistics.R_AbsenceTimeUsed_InHours + Parameter.durationInHours; var res = cls_Save_Employee_AbsenceReason_TimeframeStatistic.Invoke(Connection, Transaction, updateStatisticsParam, securityTicket); } } } returnValue.Result = effectivePosition.CMN_BPT_EMP_EffectiveWorkTime_PositionID; return(returnValue); #endregion UserCode }
protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5LR_SELR_255 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Guid(); var eventItem = new ORM_CMN_CAL_Event(); if (Parameter.EventID != Guid.Empty) { var result = eventItem.Load(Connection, Transaction, Parameter.EventID); if (result.Status != FR_Status.Success || eventItem.CMN_CAL_EventID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } } eventItem.CalendarInstance_RefID = Parameter.CalendarInstance_RefID; eventItem.EndTime = Parameter.EndTime; eventItem.IsDeleted = false; eventItem.IsRepetitive = Parameter.IsRepetitive; eventItem.Repetition_RefID = Parameter.Repetition_RefID; eventItem.StartTime = Parameter.StartTime; eventItem.Tenant_RefID = securityTicket.TenantID; eventItem.Creation_Timestamp = DateTime.Now; eventItem.Save(Connection, Transaction); var approvalItem = new ORM_CMN_CAL_Event_Approval(); if (Parameter.Event_Approval_RefID != Guid.Empty) { var result = approvalItem.Load(Connection, Transaction, Parameter.Event_Approval_RefID); if (result.Status != FR_Status.Success || approvalItem.CMN_CAL_Event_ApprovalID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } } approvalItem.Event_RefID = eventItem.CMN_CAL_EventID; approvalItem.IsApprovalProcessDenied = Parameter.IsApprovalProcessDenied; approvalItem.IsApprovalProcessOpened = Parameter.IsApprovalProcessOpened; approvalItem.IsApproved = Parameter.IsApproved; approvalItem.IsApprovalProcessCanceledByUser = Parameter.IsApprovalProcessCanceledByUser; approvalItem.IsDeleted = false; approvalItem.Creation_Timestamp = DateTime.Now; approvalItem.Tenant_RefID = securityTicket.TenantID; approvalItem.ApprovalProcess_Type_RefID = Parameter.ApprovalProcessTypeID; approvalItem.Save(Connection, Transaction); var requestItem = new ORM_CMN_BPT_EMP_Employee_LeaveRequest(); if (Parameter.Employee_LeaveRequestID != Guid.Empty) { var result = requestItem.Load(Connection, Transaction, Parameter.Employee_LeaveRequestID); if (result.Status != FR_Status.Success || requestItem.CMN_BPT_EMP_Employee_LeaveRequestID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } } requestItem.CMN_BPT_STA_AbsenceReason_RefID = Parameter.AbsenceReason_RefID; requestItem.CMN_CAL_Event_Approval_RefID = approvalItem.CMN_CAL_Event_ApprovalID; requestItem.CMN_CAL_Event_RefID = eventItem.CMN_CAL_EventID; requestItem.Comment = Parameter.Comment; requestItem.IsDeleted = false; requestItem.RequestedBy_Employee_RefID = Parameter.RequestedBy_Employee_RefID; requestItem.RequestedFor_Employee_RefID = Parameter.RequestedFor_Employee_RefID; requestItem.Tenant_RefID = securityTicket.TenantID; requestItem.Creation_Timestamp = DateTime.Now; requestItem.LeaveRequestCreationSource = Parameter.LeaveRequestCreationSource; requestItem.Save(Connection, Transaction); if (Parameter.EmployeeCover_RefID != Guid.Empty) { var coverItem = new ORM_CMN_BPT_EMP_Employee_LeaveRequest_EmployeeCover(); if (Parameter.Employee_LeaveRequest_EmployeeCoverID != Guid.Empty) { var result = coverItem.Load(Connection, Transaction, Parameter.Employee_LeaveRequest_EmployeeCoverID); if (result.Status != FR_Status.Success || coverItem.CMN_BPT_EMP_Employee_LeaveRequest_EmployeeCoverID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } } coverItem.CMN_BPT_EMP_Employee_LeaveRequests = requestItem.CMN_BPT_EMP_Employee_LeaveRequestID; coverItem.EmployeeCover_RefID = Parameter.EmployeeCover_RefID; coverItem.IsDeleted = false; coverItem.SequenceNumber = Parameter.SequenceNumber; coverItem.Tenant_RefID = securityTicket.TenantID; coverItem.Creation_Timestamp = DateTime.Now; coverItem.Save(Connection, Transaction); } returnValue.Result = requestItem.CMN_BPT_EMP_Employee_LeaveRequestID; return(returnValue); #endregion UserCode }