Пример #1
0
        protected static FR_L6DWS_LPD_1451_Array Execute(DbConnection Connection, DbTransaction Transaction, P_L6DWS_LPD_1451 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L6DWS_LPD_1451_Array();

            LeaveRequestUtils leaveRequestUtil = new LeaveRequestUtils();

            var dayCount = 1;
            if (Parameter.LoadFor_Week)
            {
                dayCount = 7;
            }

            for (int i = 0; i < dayCount; i++)
            {
                var date = Parameter.WorkSheduleDate.Date.AddDays(i);
                if (Parameter.LoadFrom_LastWeek || Parameter.LoadFrom_Specific_Date_Or_Week)
                {
                    P_L5DWS_GDWSWDFT_0946 param = new P_L5DWS_GDWSWDFT_0946();
                    if (Parameter.LoadFrom_Specific_Date_Or_Week)
                    {
                        param.WorkSheduleDate = Parameter.IfLoadFrom_Specific_Date_Or_Week_DateTime.AddDays(i);
                    }
                    else
                    {
                        param.WorkSheduleDate = Parameter.WorkSheduleDate.AddDays(-7).AddDays(i);
                    }

                    var lastWeekSchedules = cls_Get_DailyWorkSchedules_WithDetails_For_Date.Invoke(Connection, Transaction, param, securityTicket).Result;

                    foreach (var lastWeekSchedule in lastWeekSchedules)
                    {
                        var empInfo = Parameter.EmployeeInformation.FirstOrDefault(x => x.EmployeeID == lastWeekSchedule.Employee_RefID);

                        ORM_CMN_STR_PPS_DailyWorkSchedule.Query dailyWorkScheduleQuery = new ORM_CMN_STR_PPS_DailyWorkSchedule.Query();
                        dailyWorkScheduleQuery.Employee_RefID  = lastWeekSchedule.Employee_RefID;
                        dailyWorkScheduleQuery.WorkSheduleDate = date;
                        dailyWorkScheduleQuery.IsDeleted       = false;
                        dailyWorkScheduleQuery.Tenant_RefID    = securityTicket.TenantID;

                        var oldDailyWorkSchedule = ORM_CMN_STR_PPS_DailyWorkSchedule.Query.Search(Connection, Transaction, dailyWorkScheduleQuery).FirstOrDefault();

                        if (oldDailyWorkSchedule != null)
                        {
                            ORM_CMN_STR_PPS_DailyWorkSchedule_Detail.Query oldDailyWorkScheduleDetailQuery = new ORM_CMN_STR_PPS_DailyWorkSchedule_Detail.Query();
                            oldDailyWorkScheduleDetailQuery.DailyWorkSchedule_RefID = oldDailyWorkSchedule.CMN_STR_PPS_DailyWorkScheduleID;
                            oldDailyWorkScheduleDetailQuery.IsDeleted    = false;
                            oldDailyWorkScheduleDetailQuery.Tenant_RefID = securityTicket.TenantID;

                            var oldDailyWorkScheduleDetails = ORM_CMN_STR_PPS_DailyWorkSchedule_Detail.Query.Search(Connection, Transaction, oldDailyWorkScheduleDetailQuery);

                            List <P_L6DWS_DDWS_1126_Details> detailsList = new List <P_L6DWS_DDWS_1126_Details>();

                            foreach (var detail in oldDailyWorkScheduleDetails)
                            {
                                ORM_CMN_CAL_Event.Query eventQuery = new ORM_CMN_CAL_Event.Query();
                                eventQuery.CMN_CAL_EventID = detail.CMN_CAL_Event_RefID;
                                eventQuery.IsDeleted       = false;
                                eventQuery.Tenant_RefID    = securityTicket.TenantID;

                                var detailEvent = ORM_CMN_CAL_Event.Query.Search(Connection, Transaction, eventQuery).FirstOrDefault();

                                if (detailEvent != null)
                                {
                                    P_L6DWS_DDWS_1126_Details detailParam = new P_L6DWS_DDWS_1126_Details();
                                    detailParam.DailyWorkSchedule_DetailID = detail.CMN_STR_PPS_DailyWorkSchedule_DetailID;
                                    detailParam.durationInDays             = leaveRequestUtil.LeaveRequestDuration(detailEvent.StartTime, detailEvent.EndTime, Parameter.Events, Parameter.Employees.FirstOrDefault(x => x.CMN_BPT_EMP_EmployeeID == lastWeekSchedule.Employee_RefID), true);
                                    detailParam.durationInHours            = leaveRequestUtil.LeaveRequestDuration(detailEvent.StartTime, detailEvent.EndTime, Parameter.Events, Parameter.Employees.FirstOrDefault(x => x.CMN_BPT_EMP_EmployeeID == lastWeekSchedule.Employee_RefID), false);
                                    detailsList.Add(detailParam);
                                }
                            }


                            P_L6DWS_DDWS_1126 deleteParam = new P_L6DWS_DDWS_1126();
                            deleteParam.CMN_STR_PPS_DailyWorkScheduleID = oldDailyWorkSchedule.CMN_STR_PPS_DailyWorkScheduleID;
                            deleteParam.Details = detailsList.ToArray();
                            cls_Delete_DailyWorkSchedule.Invoke(Connection, Transaction, deleteParam, securityTicket);
                        }

                        ORM_CMN_STR_PPS_DailyWorkSchedule dailyWorkSchedule = new ORM_CMN_STR_PPS_DailyWorkSchedule();
                        dailyWorkSchedule.BreakDurationTime_in_sec               = lastWeekSchedule.BreakDurationTime_in_sec;
                        dailyWorkSchedule.ContractWorkerText                     = lastWeekSchedule.ContractWorkerText;
                        dailyWorkSchedule.Employee_RefID                         = lastWeekSchedule.Employee_RefID;
                        dailyWorkSchedule.InstantiatedWithShiftTemplate_RefID    = lastWeekSchedule.InstantiatedWithShiftTemplate_RefID;
                        dailyWorkSchedule.IsBreakTimeManualySpecified            = lastWeekSchedule.IsBreakTimeManualySpecified;
                        dailyWorkSchedule.IsWorkShedule_Confirmed                = lastWeekSchedule.IsWorkShedule_Confirmed;
                        dailyWorkSchedule.R_ContractSpecified_WorkingTime_in_sec = empInfo.ContractInfo.FirstOrDefault(x => x.Date.Date == date.Date).ContractSpecified_WorkingTime_in_sec;
                        dailyWorkSchedule.R_WorkDay_Duration_in_sec              = lastWeekSchedule.R_WorkDay_Duration_in_sec;
                        dailyWorkSchedule.R_WorkDay_End_in_sec                   = lastWeekSchedule.R_WorkDay_End_in_sec;
                        dailyWorkSchedule.R_WorkDay_Start_in_sec                 = lastWeekSchedule.R_WorkDay_Start_in_sec;
                        dailyWorkSchedule.SheduleBreakTemplate_RefID             = lastWeekSchedule.SheduleBreakTemplate_RefID;
                        dailyWorkSchedule.Tenant_RefID          = securityTicket.TenantID;
                        dailyWorkSchedule.WorkingSheduleComment = lastWeekSchedule.WorkingSheduleComment;
                        dailyWorkSchedule.WorkShedule_ConfirmedBy_Account_RefID = lastWeekSchedule.WorkShedule_ConfirmedBy_Account_RefID;
                        dailyWorkSchedule.WorkSheduleDate = date;
                        dailyWorkSchedule.Save(Connection, Transaction);

                        foreach (var lastWeekDetail in lastWeekSchedule.Details)
                        {
                            ORM_CMN_STR_PPS_DailyWorkSchedule_Detail detail = new ORM_CMN_STR_PPS_DailyWorkSchedule_Detail();
                            detail.AbsenceReason_RefID = lastWeekDetail.AbsenceReason_RefID;
                            if (lastWeekDetail.CMN_CAL_Event_RefID != Guid.Empty)
                            {
                                ORM_CMN_CAL_Event.Query eventQuery = new ORM_CMN_CAL_Event.Query();
                                eventQuery.CMN_CAL_EventID = lastWeekDetail.CMN_CAL_Event_RefID;
                                eventQuery.Tenant_RefID    = securityTicket.TenantID;
                                eventQuery.IsDeleted       = false;

                                var eventResult            = ORM_CMN_CAL_Event.Query.Search(Connection, Transaction, eventQuery).FirstOrDefault();
                                ORM_CMN_CAL_Event newEvent = new ORM_CMN_CAL_Event();
                                newEvent.CalendarInstance_RefID = eventResult.CalendarInstance_RefID;
                                newEvent.EndTime = date.AddHours(eventResult.EndTime.TimeOfDay.TotalHours);
                                newEvent.IsCalendarEvent_Editable = eventResult.IsCalendarEvent_Editable;
                                newEvent.IsRepetitive             = eventResult.IsRepetitive;
                                newEvent.IsWholeDayEvent          = eventResult.IsWholeDayEvent;
                                newEvent.R_EventDuration_sec      = eventResult.R_EventDuration_sec;
                                newEvent.Repetition_RefID         = eventResult.Repetition_RefID;
                                newEvent.StartTime    = date.AddHours(eventResult.StartTime.TimeOfDay.TotalHours);
                                newEvent.Tenant_RefID = securityTicket.TenantID;
                                newEvent.Save(Connection, Transaction);
                                detail.CMN_CAL_Event_RefID = newEvent.CMN_CAL_EventID;
                            }
                            else
                            {
                                detail.CMN_CAL_Event_RefID = Guid.Empty;
                            }
                            detail.DailyWorkSchedule_RefID   = dailyWorkSchedule.CMN_STR_PPS_DailyWorkScheduleID;
                            detail.IsWorkBreak               = lastWeekDetail.IsWorkBreak;
                            detail.SheduleForWorkplace_RefID = lastWeekDetail.SheduleForWorkplace_RefID;
                            detail.Tenant_RefID              = securityTicket.TenantID;


                            if (detail.AbsenceReason_RefID != Guid.Empty)
                            {
                                ORM_CMN_CAL_Event leaveRequestEvent = new ORM_CMN_CAL_Event();
                                leaveRequestEvent.EndTime      = date.AddSeconds(lastWeekDetail.ToTime_as_DateTime.TimeOfDay.TotalSeconds);
                                leaveRequestEvent.StartTime    = date.AddSeconds(lastWeekDetail.FromTime_as_DateTime.TimeOfDay.TotalSeconds);
                                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;

                                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 == detail.AbsenceReason_RefID))
                                    {
                                        var reason = absenceReasons.FirstOrDefault(r => r.CMN_BPT_STA_AbsenceReasonID == detail.AbsenceReason_RefID);
                                        if (reason != null)
                                        {
                                            authRequired = reason.IsAuthorizationRequired;
                                        }
                                    }
                                }

                                L6TN_GSFT_1017 settings = cls_Get_Settings_For_Tenant.Invoke(Connection, Transaction, securityTicket).Result;
                                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);

                                var leaveRequest = new ORM_CMN_BPT_EMP_Employee_LeaveRequest();
                                leaveRequest.CMN_BPT_STA_AbsenceReason_RefID = detail.AbsenceReason_RefID;
                                leaveRequest.CMN_CAL_Event_Approval_RefID    = approvalItem.CMN_CAL_Event_ApprovalID;
                                leaveRequest.CMN_CAL_Event_RefID             = leaveRequestEvent.CMN_CAL_EventID;
                                leaveRequest.IsDeleted = false;
                                leaveRequest.RequestedBy_Employee_RefID  = Parameter.LoggedEmployeeID;
                                leaveRequest.RequestedFor_Employee_RefID = lastWeekSchedule.Employee_RefID;
                                leaveRequest.Tenant_RefID       = securityTicket.TenantID;
                                leaveRequest.Creation_Timestamp = DateTime.Now;
                                leaveRequest.Save(Connection, Transaction);
                                detail.CMN_BPT_EMP_Employee_LeaveRequest_RefID = leaveRequest.CMN_BPT_EMP_Employee_LeaveRequestID;

                                detail.Save(Connection, Transaction);

                                #region updateStatistics

                                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;

                                    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 (approvalItem.IsApproved)
                                    {
                                        updateStatisticsParam.R_TotalAllowedAbsenceTime_InDays  = statistics.R_TotalAllowedAbsenceTime_InDays - durationInDays;
                                        updateStatisticsParam.R_TotalAllowedAbsenceTime_InHours = statistics.R_TotalAllowedAbsenceTime_InHours - 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 + durationInDays;
                                        updateStatisticsParam.R_AbsenceTimeUsed_InHours = statistics.R_AbsenceTimeUsed_InHours + durationInHours;
                                    }
                                    else
                                    {
                                        updateStatisticsParam.R_TotalAllowedAbsenceTime_InDays  = statistics.R_TotalAllowedAbsenceTime_InDays;
                                        updateStatisticsParam.R_TotalAllowedAbsenceTime_InHours = statistics.R_TotalAllowedAbsenceTime_InHours;

                                        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;
                                    }


                                    var res = cls_Save_Employee_AbsenceReason_TimeframeStatistic.Invoke(Connection, Transaction, updateStatisticsParam, securityTicket);
                                }
                                #endregion
                            }
                            else
                            {
                                detail.Save(Connection, Transaction);
                            }
                        }
                    }
                }
                else if (Parameter.LoadFrom_StandardTimes)
                {
                    bool isEven = false;

                    if (CronExtender.weekNumber(date) % 2 == 0)
                    {
                        isEven = true;
                    }

                    ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query workplaceAssignementQuery = new ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query();
                    foreach (var empInfo in Parameter.EmployeeInformation)
                    {
                        var empID = empInfo.EmployeeID;
                        workplaceAssignementQuery.CMN_BPT_EMP_Employee_RefID = empID;
                        workplaceAssignementQuery.Tenant_RefID = securityTicket.TenantID;
                        workplaceAssignementQuery.IsDeleted    = false;

                        var workplaceAssignements = ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query.Search(Connection, Transaction, workplaceAssignementQuery);

                        if (workplaceAssignements != null)
                        {
                            var workplaceAssignement = workplaceAssignements.FirstOrDefault(x => x.WorkplaceAssignment_StartDate <= date && (x.WorkplaceAssignment_EndDate >= date || x.WorkplaceAssignment_EndDate == new DateTime()));

                            if (workplaceAssignement != null)
                            {
                                ORM_CMN_BPT_EMP_WorkplaceAssignments_WorkPattern.Query patternQuery = new ORM_CMN_BPT_EMP_WorkplaceAssignments_WorkPattern.Query();
                                patternQuery.BoundTo_WorkplaceAssignment_RefID = workplaceAssignement.CMN_BPT_EMP_Employee_WorkplaceAssignment;
                                patternQuery.Tenant_RefID = securityTicket.TenantID;
                                patternQuery.IsDeleted    = false;

                                var patterns = ORM_CMN_BPT_EMP_WorkplaceAssignments_WorkPattern.Query.Search(Connection, Transaction, patternQuery);
                                if (patterns != null)
                                {
                                    foreach (var pattern in patterns)
                                    {
                                        if (pattern.IsWeek_Even == isEven || !pattern.IsWeek_Even && pattern.IsWeek_Odd)
                                        {
                                            switch (date.DayOfWeek)
                                            {
                                            case DayOfWeek.Monday:
                                                if (!pattern.IsMonday)
                                                {
                                                    continue;
                                                }
                                                break;

                                            case DayOfWeek.Tuesday:
                                                if (!pattern.IsTuesday)
                                                {
                                                    continue;
                                                }
                                                break;

                                            case DayOfWeek.Wednesday:
                                                if (!pattern.IsWednesday)
                                                {
                                                    continue;
                                                }
                                                break;

                                            case DayOfWeek.Thursday:
                                                if (!pattern.IsThursday)
                                                {
                                                    continue;
                                                }
                                                break;

                                            case DayOfWeek.Friday:
                                                if (!pattern.IsFriday)
                                                {
                                                    continue;
                                                }
                                                break;

                                            case DayOfWeek.Saturday:
                                                if (!pattern.IsSaturday)
                                                {
                                                    continue;
                                                }
                                                break;

                                            case DayOfWeek.Sunday:
                                                if (!pattern.IsSunday)
                                                {
                                                    continue;
                                                }
                                                break;
                                            }


                                            if (pattern.CMN_PPS_ShiftTemplate_RefID == Guid.Empty && pattern.CMN_BPT_STA_AbsenceReason_RefID != Guid.Empty)
                                            {
                                                double   totalTime = 0;
                                                DateTime startTime = date.AddMinutes(empInfo.ContractInfo.FirstOrDefault(x => x.Date == date).startTime);
                                                DateTime endTime   = date.AddMinutes(empInfo.ContractInfo.FirstOrDefault(x => x.Date == date).endTime);


                                                double startTimeInSec = startTime.TimeOfDay.TotalSeconds;
                                                double endTimeInSec   = endTime.TimeOfDay.TotalSeconds;


                                                ORM_CMN_STR_PPS_DailyWorkSchedule.Query dailyWorkScheduleQuery = new ORM_CMN_STR_PPS_DailyWorkSchedule.Query();
                                                dailyWorkScheduleQuery.Employee_RefID  = empID;
                                                dailyWorkScheduleQuery.WorkSheduleDate = date;
                                                dailyWorkScheduleQuery.IsDeleted       = false;
                                                dailyWorkScheduleQuery.Tenant_RefID    = securityTicket.TenantID;

                                                var oldDailyWorkSchedule = ORM_CMN_STR_PPS_DailyWorkSchedule.Query.Search(Connection, Transaction, dailyWorkScheduleQuery).FirstOrDefault();

                                                if (oldDailyWorkSchedule != null)
                                                {
                                                    ORM_CMN_STR_PPS_DailyWorkSchedule_Detail.Query oldDailyWorkScheduleDetailQuery = new ORM_CMN_STR_PPS_DailyWorkSchedule_Detail.Query();
                                                    oldDailyWorkScheduleDetailQuery.DailyWorkSchedule_RefID = oldDailyWorkSchedule.CMN_STR_PPS_DailyWorkScheduleID;
                                                    oldDailyWorkScheduleDetailQuery.IsDeleted    = false;
                                                    oldDailyWorkScheduleDetailQuery.Tenant_RefID = securityTicket.TenantID;

                                                    var oldDailyWorkScheduleDetails = ORM_CMN_STR_PPS_DailyWorkSchedule_Detail.Query.Search(Connection, Transaction, oldDailyWorkScheduleDetailQuery);

                                                    List <P_L6DWS_DDWS_1126_Details> detailsList = new List <P_L6DWS_DDWS_1126_Details>();

                                                    foreach (var detail in oldDailyWorkScheduleDetails)
                                                    {
                                                        ORM_CMN_CAL_Event.Query eventQuery = new ORM_CMN_CAL_Event.Query();
                                                        eventQuery.CMN_CAL_EventID = detail.CMN_CAL_Event_RefID;
                                                        eventQuery.IsDeleted       = false;
                                                        eventQuery.Tenant_RefID    = securityTicket.TenantID;

                                                        var detailEvent = ORM_CMN_CAL_Event.Query.Search(Connection, Transaction, eventQuery).FirstOrDefault();

                                                        if (detailEvent != null)
                                                        {
                                                            P_L6DWS_DDWS_1126_Details deleteDetailParam = new P_L6DWS_DDWS_1126_Details();
                                                            deleteDetailParam.DailyWorkSchedule_DetailID = detail.CMN_STR_PPS_DailyWorkSchedule_DetailID;
                                                            deleteDetailParam.durationInDays             = leaveRequestUtil.LeaveRequestDuration(detailEvent.StartTime, detailEvent.EndTime, Parameter.Events, Parameter.Employees.FirstOrDefault(x => x.CMN_BPT_EMP_EmployeeID == empID), true);
                                                            deleteDetailParam.durationInHours            = leaveRequestUtil.LeaveRequestDuration(detailEvent.StartTime, detailEvent.EndTime, Parameter.Events, Parameter.Employees.FirstOrDefault(x => x.CMN_BPT_EMP_EmployeeID == empID), false);
                                                            detailsList.Add(deleteDetailParam);
                                                        }
                                                    }


                                                    P_L6DWS_DDWS_1126 deleteParam = new P_L6DWS_DDWS_1126();
                                                    deleteParam.CMN_STR_PPS_DailyWorkScheduleID = oldDailyWorkSchedule.CMN_STR_PPS_DailyWorkScheduleID;
                                                    deleteParam.Details = detailsList.ToArray();
                                                    cls_Delete_DailyWorkSchedule.Invoke(Connection, Transaction, deleteParam, securityTicket);
                                                }

                                                ORM_CMN_STR_PPS_DailyWorkSchedule dailyWorkSchedule = new ORM_CMN_STR_PPS_DailyWorkSchedule();
                                                dailyWorkSchedule.IsBreakTimeManualySpecified = false;
                                                dailyWorkSchedule.BreakDurationTime_in_sec    = 0;

                                                dailyWorkSchedule.R_WorkDay_Start_in_sec    = (int)startTimeInSec;
                                                dailyWorkSchedule.R_WorkDay_Duration_in_sec = (int)totalTime;
                                                dailyWorkSchedule.R_WorkDay_End_in_sec      = (int)endTimeInSec;
                                                dailyWorkSchedule.R_ContractSpecified_WorkingTime_in_sec = 0;
                                                dailyWorkSchedule.ContractWorkerText = "";
                                                dailyWorkSchedule.Employee_RefID     = empID;
                                                dailyWorkSchedule.WorkSheduleDate    = date;
                                                dailyWorkSchedule.Tenant_RefID       = securityTicket.TenantID;

                                                dailyWorkSchedule.Save(Connection, Transaction);


                                                var durationInDays  = leaveRequestUtil.LeaveRequestDuration(date.AddSeconds(startTimeInSec), date.AddSeconds(endTimeInSec), Parameter.Events, Parameter.Employees.FirstOrDefault(x => x.CMN_BPT_EMP_EmployeeID == empID), true);
                                                var durationInHours = leaveRequestUtil.LeaveRequestDuration(date.AddSeconds(startTimeInSec), date.AddSeconds(endTimeInSec), Parameter.Events, Parameter.Employees.FirstOrDefault(x => x.CMN_BPT_EMP_EmployeeID == empID), false);

                                                P_L6DWS_SDWSD_1130 detailParam = new P_L6DWS_SDWSD_1130();
                                                detailParam.WorkTime_Start              = dailyWorkSchedule.WorkSheduleDate.AddSeconds(startTimeInSec);
                                                detailParam.WorkTime_End                = dailyWorkSchedule.WorkSheduleDate.AddSeconds(endTimeInSec);
                                                detailParam.DailyWorkSchedule_RefID     = dailyWorkSchedule.CMN_STR_PPS_DailyWorkScheduleID;
                                                detailParam.IsWorkBreak                 = false;
                                                detailParam.SheduleForWorkplace_RefID   = Guid.Empty;
                                                detailParam.AbsenceReason_RefID         = pattern.CMN_BPT_STA_AbsenceReason_RefID;
                                                detailParam.RequestedBy_Employee_RefID  = Guid.Empty;
                                                detailParam.RequestedFor_Employee_RefID = empID;
                                                detailParam.durationInDays              = durationInDays;
                                                detailParam.durationInHours             = durationInHours;
                                                cls_Save_DailyWorkSchedule_Detail.Invoke(Connection, Transaction, detailParam, securityTicket);
                                            }
                                            else if (pattern.CMN_PPS_ShiftTemplate_RefID != Guid.Empty)
                                            {
                                                ORM_CMN_PPS_ShiftTemplate.Query shiftTemplateQuery = new ORM_CMN_PPS_ShiftTemplate.Query();
                                                shiftTemplateQuery.CMN_PPS_ShiftTemplateID = pattern.CMN_PPS_ShiftTemplate_RefID;
                                                shiftTemplateQuery.Tenant_RefID            = securityTicket.TenantID;
                                                shiftTemplateQuery.IsDeleted = false;


                                                var shiftTemplate = ORM_CMN_PPS_ShiftTemplate.Query.Search(Connection, Transaction, shiftTemplateQuery).FirstOrDefault();

                                                if (shiftTemplate != null)
                                                {
                                                    ORM_CMN_STR_PPS_DailyWorkSchedule.Query dailyWorkScheduleQuery = new ORM_CMN_STR_PPS_DailyWorkSchedule.Query();
                                                    dailyWorkScheduleQuery.Employee_RefID  = empID;
                                                    dailyWorkScheduleQuery.WorkSheduleDate = date;
                                                    dailyWorkScheduleQuery.IsDeleted       = false;
                                                    dailyWorkScheduleQuery.Tenant_RefID    = securityTicket.TenantID;

                                                    var oldDailyWorkSchedule = ORM_CMN_STR_PPS_DailyWorkSchedule.Query.Search(Connection, Transaction, dailyWorkScheduleQuery).FirstOrDefault();

                                                    if (oldDailyWorkSchedule != null)
                                                    {
                                                        ORM_CMN_STR_PPS_DailyWorkSchedule_Detail.Query oldDailyWorkScheduleDetailQuery = new ORM_CMN_STR_PPS_DailyWorkSchedule_Detail.Query();
                                                        oldDailyWorkScheduleDetailQuery.DailyWorkSchedule_RefID = oldDailyWorkSchedule.CMN_STR_PPS_DailyWorkScheduleID;
                                                        oldDailyWorkScheduleDetailQuery.IsDeleted    = false;
                                                        oldDailyWorkScheduleDetailQuery.Tenant_RefID = securityTicket.TenantID;

                                                        var oldDailyWorkScheduleDetails = ORM_CMN_STR_PPS_DailyWorkSchedule_Detail.Query.Search(Connection, Transaction, oldDailyWorkScheduleDetailQuery);

                                                        List <P_L6DWS_DDWS_1126_Details> detailsList = new List <P_L6DWS_DDWS_1126_Details>();

                                                        foreach (var detail in oldDailyWorkScheduleDetails)
                                                        {
                                                            ORM_CMN_CAL_Event.Query eventQuery = new ORM_CMN_CAL_Event.Query();
                                                            eventQuery.CMN_CAL_EventID = detail.CMN_CAL_Event_RefID;
                                                            eventQuery.IsDeleted       = false;
                                                            eventQuery.Tenant_RefID    = securityTicket.TenantID;

                                                            var detailEvent = ORM_CMN_CAL_Event.Query.Search(Connection, Transaction, eventQuery).FirstOrDefault();

                                                            if (detailEvent != null)
                                                            {
                                                                P_L6DWS_DDWS_1126_Details detailParam = new P_L6DWS_DDWS_1126_Details();
                                                                detailParam.DailyWorkSchedule_DetailID = detail.CMN_STR_PPS_DailyWorkSchedule_DetailID;
                                                                detailParam.durationInDays             = leaveRequestUtil.LeaveRequestDuration(detailEvent.StartTime, detailEvent.EndTime, Parameter.Events, Parameter.Employees.FirstOrDefault(x => x.CMN_BPT_EMP_EmployeeID == empID), true);
                                                                detailParam.durationInHours            = leaveRequestUtil.LeaveRequestDuration(detailEvent.StartTime, detailEvent.EndTime, Parameter.Events, Parameter.Employees.FirstOrDefault(x => x.CMN_BPT_EMP_EmployeeID == empID), false);
                                                                detailsList.Add(detailParam);
                                                            }
                                                        }


                                                        P_L6DWS_DDWS_1126 deleteParam = new P_L6DWS_DDWS_1126();
                                                        deleteParam.CMN_STR_PPS_DailyWorkScheduleID = oldDailyWorkSchedule.CMN_STR_PPS_DailyWorkScheduleID;
                                                        deleteParam.Details = detailsList.ToArray();
                                                        cls_Delete_DailyWorkSchedule.Invoke(Connection, Transaction, deleteParam, securityTicket);
                                                    }
                                                    P_L5DWS_SDWSFST_1447 param = new P_L5DWS_SDWSFST_1447();
                                                    param.Employee_RefID = empID;
                                                    param.InstantiatedWithShiftTemplate_RefID = shiftTemplate.CMN_PPS_ShiftTemplateID;
                                                    param.WorkSheduleDate = date;
                                                    param.R_ContractSpecified_WorkingTime_in_sec = empInfo.ContractInfo.FirstOrDefault(x => x.Date == date).ContractSpecified_WorkingTime_in_sec;
                                                    cls_Save_DailyWorkSchedule_For_ShiftTemplate.Invoke(Connection, Transaction, param, securityTicket);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }



            //Put your code here
            return(returnValue);

            #endregion UserCode
        }
Пример #2
0
        protected static FR_L5ST_GSTFSTI_1641 Execute(DbConnection Connection, DbTransaction Transaction, P_L5ST_GSTFSTI_1641 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5ST_GSTFSTI_1641();
            returnValue.Result = new L5ST_GSTFSTI_1641();


            ORM_CMN_PPS_ShiftTemplate.Query shiftTemplateQuery = new ORM_CMN_PPS_ShiftTemplate.Query();
            shiftTemplateQuery.Tenant_RefID            = securityTicket.TenantID;
            shiftTemplateQuery.IsDeleted               = false;
            shiftTemplateQuery.CMN_PPS_ShiftTemplateID = Parameter.ShiftTemplateID;
            List <ORM_CMN_PPS_ShiftTemplate> shiftTemplates = ORM_CMN_PPS_ShiftTemplate.Query.Search(Connection, Transaction, shiftTemplateQuery);


            ORM_CMN_PPS_ShiftTemplate shiftTemplate = shiftTemplates[0];
            L5ST_GSTFT_1610           templateItem  = new L5ST_GSTFT_1610();
            templateItem.CMN_PPS_ShiftTemplateID = shiftTemplate.CMN_PPS_ShiftTemplateID;
            templateItem.CMN_STR_Office_RefID    = shiftTemplate.CMN_STR_Office_RefID;
            templateItem.CMN_STR_Workarea_RefID  = shiftTemplate.CMN_STR_Workarea_RefID;
            templateItem.CMN_STR_Workplace_RefID = shiftTemplate.CMN_STR_Workplace_RefID;
            templateItem.ShiftTemplate_Name      = shiftTemplate.ShiftTemplate_Name;
            templateItem.ShiftTemplate_ShortName = shiftTemplate.ShiftTemplate_ShortName;

            ORM_CMN_PPS_ShiftTemplate_WorkDetail.Query workdetailsQuery = new ORM_CMN_PPS_ShiftTemplate_WorkDetail.Query();
            workdetailsQuery.IsDeleted    = false;
            workdetailsQuery.Tenant_RefID = securityTicket.TenantID;
            workdetailsQuery.CMN_PPS_ShiftTemplate_RefID = shiftTemplate.CMN_PPS_ShiftTemplateID;
            List <ORM_CMN_PPS_ShiftTemplate_WorkDetail> workDetails = ORM_CMN_PPS_ShiftTemplate_WorkDetail.Query.Search(Connection, Transaction, workdetailsQuery);
            if (workDetails != null && workDetails.Count != 0)
            {
                int    startingTime  = 0;
                int    endingTime    = 0;
                int    brakeTime     = 0;
                double totalWorkTime = 0;
                foreach (var workDetail in workDetails)
                {
                    if (startingTime == 0 || startingTime > workDetail.ShiftStart_Offset_sec)
                    {
                        startingTime = (int)workDetail.ShiftStart_Offset_sec;
                    }
                    if (endingTime < workDetail.ShiftStart_Offset_sec + workDetail.Duration_in_sec)
                    {
                        endingTime = (int)workDetail.ShiftStart_Offset_sec + (int)workDetail.Duration_in_sec;
                    }

                    totalWorkTime += workDetail.Duration_in_sec;
                }
                templateItem.BrakeTime = CronExtender.secondsToTime(brakeTime);
                templateItem.EndTime   = CronExtender.secondsToTime(endingTime);
                templateItem.StartTime = CronExtender.secondsToTime(startingTime);
                templateItem.Worktime  = CronExtender.secondsToTime(Int32.Parse(totalWorkTime.ToString()));
            }



            returnValue.Result.ShiftTemplate = templateItem;


            //Put your code here
            return(returnValue);

            #endregion UserCode
        }
Пример #3
0
        protected static FR_Base Execute(DbConnection Connection, DbTransaction Transaction, P_L5DWS_LAD_1001 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            FR_Base returnValue = new FR_Base();


            var dayCount = 1;
            if (Parameter.LoadFor_Week)
            {
                dayCount = 7;
            }

            LeaveRequestUtils leaveRequestUtil = new LeaveRequestUtils();

            for (int i = 0; i < dayCount; i++)
            {
                var date = Parameter.WorkSheduleDate.Date.AddDays(i);
                if (Parameter.LoadFrom_LastWeek || Parameter.LoadFrom_Specific_Date_Or_Week)
                {
                    DateTime loadForDate;

                    if (Parameter.LoadFrom_Specific_Date_Or_Week)
                    {
                        loadForDate = Parameter.IfLoadFrom_Specific_Date_Or_Week_DateTime.AddDays(i);
                    }
                    else
                    {
                        loadForDate = Parameter.WorkSheduleDate.AddDays(-7).AddDays(i);
                    }



                    ORM_CMN_BPT_EMP_EffectiveWorkTime_Header.Query actualsQuery = new ORM_CMN_BPT_EMP_EffectiveWorkTime_Header.Query();
                    actualsQuery.EffectiveBusinessDay = loadForDate;
                    actualsQuery.Tenant_RefID         = securityTicket.TenantID;
                    actualsQuery.IsDeleted            = false;

                    var allEffectiveWorkTimeHeadersToLoadFrom = ORM_CMN_BPT_EMP_EffectiveWorkTime_Header.Query.Search(Connection, Transaction, actualsQuery);

                    foreach (var effectiveWorkTimeHeader in allEffectiveWorkTimeHeadersToLoadFrom)
                    {
                        ORM_CMN_BPT_EMP_EffectiveWorkTime_Header.Query effectiveWorkTimeToDeleteQuery = new ORM_CMN_BPT_EMP_EffectiveWorkTime_Header.Query();
                        effectiveWorkTimeToDeleteQuery.EffectiveBusinessDay = date;
                        effectiveWorkTimeToDeleteQuery.Employee_RefID       = effectiveWorkTimeHeader.Employee_RefID;
                        effectiveWorkTimeToDeleteQuery.Tenant_RefID         = securityTicket.TenantID;
                        effectiveWorkTimeToDeleteQuery.IsDeleted            = false;

                        var effectiveWorkTimeHeaderToDeleteQueryResult = ORM_CMN_BPT_EMP_EffectiveWorkTime_Header.Query.Search(Connection, Transaction, effectiveWorkTimeToDeleteQuery);

                        if (effectiveWorkTimeHeaderToDeleteQueryResult.Count != 0)
                        {
                            var effectiveWorkTimeHeaderToDelete = effectiveWorkTimeHeaderToDeleteQueryResult.FirstOrDefault();
                            P_L5DWS_DEWTH_1126 deleteParam      = new P_L5DWS_DEWTH_1126();
                            deleteParam.CMN_STR_PPS_EffectiveWorkTime_HeaderID = effectiveWorkTimeHeaderToDelete.CMN_STR_PPS_EffectiveWorkTime_HeaderID;

                            ORM_CMN_BPT_EMP_EffectiveWorkTime_Position.Query positionsQuery = new ORM_CMN_BPT_EMP_EffectiveWorkTime_Position.Query();
                            positionsQuery.EffectiveWorkTime_Header_RefID = effectiveWorkTimeHeaderToDelete.CMN_STR_PPS_EffectiveWorkTime_HeaderID;
                            positionsQuery.Tenant_RefID = securityTicket.TenantID;
                            positionsQuery.IsDeleted    = false;

                            var positions = ORM_CMN_BPT_EMP_EffectiveWorkTime_Position.Query.Search(Connection, Transaction, positionsQuery);

                            List <P_L5DWS_DEWTH_1126_Positions> listOfPositions = new List <P_L5DWS_DEWTH_1126_Positions>();

                            foreach (var position in positions)
                            {
                                P_L5DWS_DEWTH_1126_Positions positionItem = new P_L5DWS_DEWTH_1126_Positions();
                                positionItem.CMN_BPT_EMP_EffectiveWorkTime_PositionID = position.CMN_BPT_EMP_EffectiveWorkTime_PositionID;
                                positionItem.durationInDays  = leaveRequestUtil.LeaveRequestDuration(position.WorkTime_StartTime, position.WorkTime_StartTime.AddSeconds(position.WorkTime_Duration_in_sec), Parameter.Events, Parameter.Employees.FirstOrDefault(x => x.CMN_BPT_EMP_EmployeeID == position.CMN_BPT_EMP_Employe_RefID), true);
                                positionItem.durationInHours = leaveRequestUtil.LeaveRequestDuration(position.WorkTime_StartTime, position.WorkTime_StartTime.AddSeconds(position.WorkTime_Duration_in_sec), Parameter.Events, Parameter.Employees.FirstOrDefault(x => x.CMN_BPT_EMP_EmployeeID == position.CMN_BPT_EMP_Employe_RefID), false);
                                listOfPositions.Add(positionItem);
                            }

                            deleteParam.Positions = listOfPositions.ToArray();
                            cls_Delete_EffectiveWorkTime_Header.Invoke(Connection, Transaction, deleteParam, securityTicket);
                        }

                        ORM_CMN_BPT_EMP_EffectiveWorkTime_Position.Query positionsToLoadQuery = new ORM_CMN_BPT_EMP_EffectiveWorkTime_Position.Query();
                        positionsToLoadQuery.EffectiveWorkTime_Header_RefID = effectiveWorkTimeHeader.CMN_STR_PPS_EffectiveWorkTime_HeaderID;
                        positionsToLoadQuery.Tenant_RefID = securityTicket.TenantID;
                        positionsToLoadQuery.IsDeleted    = false;

                        var positionsToLoad = ORM_CMN_BPT_EMP_EffectiveWorkTime_Position.Query.Search(Connection, Transaction, positionsToLoadQuery);

                        ORM_CMN_BPT_EMP_EffectiveWorkTime_Header newHeader = new ORM_CMN_BPT_EMP_EffectiveWorkTime_Header();
                        newHeader.ContractWorkerText          = effectiveWorkTimeHeader.ContractWorkerText;
                        newHeader.BreakDurationTime_in_sec    = effectiveWorkTimeHeader.BreakDurationTime_in_sec;
                        newHeader.EffectiveBusinessDay        = date;
                        newHeader.Employee_RefID              = effectiveWorkTimeHeader.Employee_RefID;
                        newHeader.IsBreakTimeManualySpecified = effectiveWorkTimeHeader.IsBreakTimeManualySpecified;
                        newHeader.SheduleBreakTemplate_RefID  = effectiveWorkTimeHeader.SheduleBreakTemplate_RefID;
                        newHeader.Tenant_RefID = securityTicket.TenantID;
                        newHeader.Save(Connection, Transaction);

                        foreach (var positionToLoad in positionsToLoad)
                        {
                            P_L5DWS_SEWTP_1337 positionSavePar = new P_L5DWS_SEWTP_1337();
                            if (positionToLoad.CMN_BPT_EMP_Employee_LeaveRequest_RefID != Guid.Empty)
                            {
                                ORM_CMN_BPT_EMP_Employee_LeaveRequest.Query lrQuery = new ORM_CMN_BPT_EMP_Employee_LeaveRequest.Query();
                                lrQuery.CMN_BPT_EMP_Employee_LeaveRequestID = positionToLoad.CMN_BPT_EMP_Employee_LeaveRequest_RefID;
                                lrQuery.IsDeleted    = false;
                                lrQuery.Tenant_RefID = securityTicket.TenantID;

                                var leaveRequest = ORM_CMN_BPT_EMP_Employee_LeaveRequest.Query.Search(Connection, Transaction, lrQuery).FirstOrDefault();

                                positionSavePar.AbsenceReason_RefID         = leaveRequest.CMN_BPT_STA_AbsenceReason_RefID;
                                positionSavePar.durationInDays              = leaveRequestUtil.LeaveRequestDuration(positionToLoad.WorkTime_StartTime, positionToLoad.WorkTime_StartTime.AddSeconds(positionToLoad.WorkTime_Duration_in_sec), Parameter.Events, Parameter.Employees.FirstOrDefault(x => x.CMN_BPT_EMP_EmployeeID == positionToLoad.CMN_BPT_EMP_Employe_RefID), true);
                                positionSavePar.durationInHours             = leaveRequestUtil.LeaveRequestDuration(positionToLoad.WorkTime_StartTime, positionToLoad.WorkTime_StartTime.AddSeconds(positionToLoad.WorkTime_Duration_in_sec), Parameter.Events, Parameter.Employees.FirstOrDefault(x => x.CMN_BPT_EMP_EmployeeID == positionToLoad.CMN_BPT_EMP_Employe_RefID), false);
                                positionSavePar.RequestedBy_Employee_RefID  = leaveRequest.RequestedBy_Employee_RefID;
                                positionSavePar.RequestedFor_Employee_RefID = leaveRequest.RequestedFor_Employee_RefID;
                            }
                            else
                            {
                                positionSavePar.AbsenceReason_RefID         = Guid.Empty;
                                positionSavePar.durationInDays              = 0;
                                positionSavePar.durationInHours             = 0;
                                positionSavePar.RequestedBy_Employee_RefID  = Guid.Empty;
                                positionSavePar.RequestedFor_Employee_RefID = Guid.Empty;
                            }

                            positionSavePar.CMN_BPT_EMP_Employee_LeaveRequest_RefID = Guid.Empty;
                            positionSavePar.EffectiveWorkTime_Header_RefID          = newHeader.CMN_STR_PPS_EffectiveWorkTime_HeaderID;
                            positionSavePar.Employee_RefID     = newHeader.Employee_RefID;
                            positionSavePar.OldDurationInDays  = 0;
                            positionSavePar.OldDurationInHours = 0;
                            positionSavePar.Workplace_RefID    = positionToLoad.Workplace_RefID;
                            positionSavePar.WorkTime_End       = positionToLoad.WorkTime_StartTime.AddSeconds(positionToLoad.WorkTime_Duration_in_sec);
                            positionSavePar.WorkTime_Start     = positionToLoad.WorkTime_StartTime;

                            cls_Save_EffectiveWorkTime_Position.Invoke(Connection, Transaction, positionSavePar, securityTicket);
                        }
                    }
                }
                else if (Parameter.LoadFrom_StandardTimes)
                {
                    bool isEven = false;

                    if (CronExtender.weekNumber(date) % 2 == 0)
                    {
                        isEven = true;
                    }

                    ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query workplaceAssignementQuery = new ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query();
                    foreach (var empInfo in Parameter.EmployeeInformation)
                    {
                        var empID = empInfo.EmployeeID;
                        workplaceAssignementQuery.CMN_BPT_EMP_Employee_RefID = empID;
                        workplaceAssignementQuery.Tenant_RefID = securityTicket.TenantID;
                        workplaceAssignementQuery.IsDeleted    = false;

                        var workplaceAssignements = ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query.Search(Connection, Transaction, workplaceAssignementQuery);

                        if (workplaceAssignements != null)
                        {
                            var workplaceAssignement = workplaceAssignements.FirstOrDefault(x => x.WorkplaceAssignment_StartDate <= date && (x.WorkplaceAssignment_EndDate >= date || x.WorkplaceAssignment_EndDate == new DateTime()));

                            if (workplaceAssignement != null)
                            {
                                ORM_CMN_BPT_EMP_WorkplaceAssignments_WorkPattern.Query patternQuery = new ORM_CMN_BPT_EMP_WorkplaceAssignments_WorkPattern.Query();
                                patternQuery.BoundTo_WorkplaceAssignment_RefID = workplaceAssignement.CMN_BPT_EMP_Employee_WorkplaceAssignment;
                                patternQuery.Tenant_RefID = securityTicket.TenantID;
                                patternQuery.IsDeleted    = false;

                                var patterns = ORM_CMN_BPT_EMP_WorkplaceAssignments_WorkPattern.Query.Search(Connection, Transaction, patternQuery);
                                if (patterns != null)
                                {
                                    foreach (var pattern in patterns)
                                    {
                                        if (pattern.IsWeek_Even == isEven || !pattern.IsWeek_Even && pattern.IsWeek_Odd)
                                        {
                                            switch (date.DayOfWeek)
                                            {
                                            case DayOfWeek.Monday:
                                                if (!pattern.IsMonday)
                                                {
                                                    continue;
                                                }
                                                break;

                                            case DayOfWeek.Tuesday:
                                                if (!pattern.IsTuesday)
                                                {
                                                    continue;
                                                }
                                                break;

                                            case DayOfWeek.Wednesday:
                                                if (!pattern.IsWednesday)
                                                {
                                                    continue;
                                                }
                                                break;

                                            case DayOfWeek.Thursday:
                                                if (!pattern.IsThursday)
                                                {
                                                    continue;
                                                }
                                                break;

                                            case DayOfWeek.Friday:
                                                if (!pattern.IsFriday)
                                                {
                                                    continue;
                                                }
                                                break;

                                            case DayOfWeek.Saturday:
                                                if (!pattern.IsSaturday)
                                                {
                                                    continue;
                                                }
                                                break;

                                            case DayOfWeek.Sunday:
                                                if (!pattern.IsSunday)
                                                {
                                                    continue;
                                                }
                                                break;
                                            }

                                            if (pattern.CMN_PPS_ShiftTemplate_RefID == Guid.Empty && pattern.CMN_BPT_STA_AbsenceReason_RefID != Guid.Empty)
                                            {
                                                double   totalTime = 0;
                                                DateTime startTime = date;
                                                DateTime endTime   = new DateTime(date.Year, date.Month, date.Day, 23, 59, 59);


                                                double startTimeInSec = startTime.TimeOfDay.TotalSeconds;
                                                double endTimeInSec   = endTime.TimeOfDay.TotalSeconds;


                                                ORM_CMN_BPT_EMP_EffectiveWorkTime_Header.Query effectiveWorkTimeToDeleteQuery = new ORM_CMN_BPT_EMP_EffectiveWorkTime_Header.Query();
                                                effectiveWorkTimeToDeleteQuery.EffectiveBusinessDay = date;
                                                effectiveWorkTimeToDeleteQuery.Employee_RefID       = empID;
                                                effectiveWorkTimeToDeleteQuery.Tenant_RefID         = securityTicket.TenantID;
                                                effectiveWorkTimeToDeleteQuery.IsDeleted            = false;

                                                var allEffectiveWorkTimeHeadersToDelete = ORM_CMN_BPT_EMP_EffectiveWorkTime_Header.Query.Search(Connection, Transaction, effectiveWorkTimeToDeleteQuery);

                                                foreach (var effectiveWorkTimeHeaderToDelete in allEffectiveWorkTimeHeadersToDelete)
                                                {
                                                    P_L5DWS_DEWTH_1126 deleteParam = new P_L5DWS_DEWTH_1126();
                                                    deleteParam.CMN_STR_PPS_EffectiveWorkTime_HeaderID = effectiveWorkTimeHeaderToDelete.CMN_STR_PPS_EffectiveWorkTime_HeaderID;

                                                    ORM_CMN_BPT_EMP_EffectiveWorkTime_Position.Query positionsQuery = new ORM_CMN_BPT_EMP_EffectiveWorkTime_Position.Query();
                                                    positionsQuery.EffectiveWorkTime_Header_RefID = effectiveWorkTimeHeaderToDelete.CMN_STR_PPS_EffectiveWorkTime_HeaderID;
                                                    positionsQuery.Tenant_RefID = securityTicket.TenantID;
                                                    positionsQuery.IsDeleted    = false;

                                                    var positions = ORM_CMN_BPT_EMP_EffectiveWorkTime_Position.Query.Search(Connection, Transaction, positionsQuery);

                                                    List <P_L5DWS_DEWTH_1126_Positions> listOfPositions = new List <P_L5DWS_DEWTH_1126_Positions>();

                                                    foreach (var position in positions)
                                                    {
                                                        P_L5DWS_DEWTH_1126_Positions positionItem = new P_L5DWS_DEWTH_1126_Positions();
                                                        positionItem.CMN_BPT_EMP_EffectiveWorkTime_PositionID = position.CMN_BPT_EMP_EffectiveWorkTime_PositionID;
                                                        positionItem.durationInDays  = leaveRequestUtil.LeaveRequestDuration(position.WorkTime_StartTime, position.WorkTime_StartTime.AddSeconds(position.WorkTime_Duration_in_sec), Parameter.Events, Parameter.Employees.FirstOrDefault(x => x.CMN_BPT_EMP_EmployeeID == position.CMN_BPT_EMP_Employe_RefID), true);
                                                        positionItem.durationInHours = leaveRequestUtil.LeaveRequestDuration(position.WorkTime_StartTime, position.WorkTime_StartTime.AddSeconds(position.WorkTime_Duration_in_sec), Parameter.Events, Parameter.Employees.FirstOrDefault(x => x.CMN_BPT_EMP_EmployeeID == position.CMN_BPT_EMP_Employe_RefID), false);
                                                        listOfPositions.Add(positionItem);
                                                    }

                                                    deleteParam.Positions = listOfPositions.ToArray();
                                                    cls_Delete_EffectiveWorkTime_Header.Invoke(Connection, Transaction, deleteParam, securityTicket);
                                                }

                                                ORM_CMN_BPT_EMP_EffectiveWorkTime_Header effectiveWorkTimeHeader = new ORM_CMN_BPT_EMP_EffectiveWorkTime_Header();
                                                effectiveWorkTimeHeader.IsBreakTimeManualySpecified = false;
                                                effectiveWorkTimeHeader.ContractWorkerText          = "";
                                                effectiveWorkTimeHeader.Employee_RefID       = empID;
                                                effectiveWorkTimeHeader.Tenant_RefID         = securityTicket.TenantID;
                                                effectiveWorkTimeHeader.EffectiveBusinessDay = date;
                                                effectiveWorkTimeHeader.Save(Connection, Transaction);

                                                P_L5DWS_SEWTP_1337 effectivePositionParam = new P_L5DWS_SEWTP_1337();
                                                effectivePositionParam.EffectiveWorkTime_Header_RefID = effectiveWorkTimeHeader.CMN_STR_PPS_EffectiveWorkTime_HeaderID;
                                                effectivePositionParam.WorkTime_Start              = effectiveWorkTimeHeader.EffectiveBusinessDay.AddSeconds(0);
                                                effectivePositionParam.WorkTime_End                = effectiveWorkTimeHeader.EffectiveBusinessDay.AddSeconds(86340);
                                                effectivePositionParam.Employee_RefID              = empID;
                                                effectivePositionParam.AbsenceReason_RefID         = pattern.CMN_BPT_STA_AbsenceReason_RefID;
                                                effectivePositionParam.RequestedFor_Employee_RefID = empID;
                                                cls_Save_EffectiveWorkTime_Position.Invoke(Connection, Transaction, effectivePositionParam, securityTicket);
                                            }
                                            else if (pattern.CMN_PPS_ShiftTemplate_RefID != Guid.Empty)
                                            {
                                                ORM_CMN_PPS_ShiftTemplate.Query shiftTemplateQuery = new ORM_CMN_PPS_ShiftTemplate.Query();
                                                shiftTemplateQuery.CMN_PPS_ShiftTemplateID = pattern.CMN_PPS_ShiftTemplate_RefID;
                                                shiftTemplateQuery.Tenant_RefID            = securityTicket.TenantID;
                                                shiftTemplateQuery.IsDeleted = false;

                                                var shiftTemplate = ORM_CMN_PPS_ShiftTemplate.Query.Search(Connection, Transaction, shiftTemplateQuery).FirstOrDefault();

                                                if (shiftTemplate != null)
                                                {
                                                    ORM_CMN_BPT_EMP_EffectiveWorkTime_Header.Query effectiveWorkTimeToDeleteQuery = new ORM_CMN_BPT_EMP_EffectiveWorkTime_Header.Query();
                                                    effectiveWorkTimeToDeleteQuery.EffectiveBusinessDay = date;
                                                    effectiveWorkTimeToDeleteQuery.Employee_RefID       = empID;
                                                    effectiveWorkTimeToDeleteQuery.Tenant_RefID         = securityTicket.TenantID;
                                                    effectiveWorkTimeToDeleteQuery.IsDeleted            = false;

                                                    var allEffectiveWorkTimeHeadersToDelete = ORM_CMN_BPT_EMP_EffectiveWorkTime_Header.Query.Search(Connection, Transaction, effectiveWorkTimeToDeleteQuery);

                                                    foreach (var effectiveWorkTimeHeaderToDelete in allEffectiveWorkTimeHeadersToDelete)
                                                    {
                                                        P_L5DWS_DEWTH_1126 deleteParam = new P_L5DWS_DEWTH_1126();
                                                        deleteParam.CMN_STR_PPS_EffectiveWorkTime_HeaderID = effectiveWorkTimeHeaderToDelete.CMN_STR_PPS_EffectiveWorkTime_HeaderID;

                                                        ORM_CMN_BPT_EMP_EffectiveWorkTime_Position.Query positionsQuery = new ORM_CMN_BPT_EMP_EffectiveWorkTime_Position.Query();
                                                        positionsQuery.EffectiveWorkTime_Header_RefID = effectiveWorkTimeHeaderToDelete.CMN_STR_PPS_EffectiveWorkTime_HeaderID;
                                                        positionsQuery.Tenant_RefID = securityTicket.TenantID;
                                                        positionsQuery.IsDeleted    = false;

                                                        var positions = ORM_CMN_BPT_EMP_EffectiveWorkTime_Position.Query.Search(Connection, Transaction, positionsQuery);

                                                        List <P_L5DWS_DEWTH_1126_Positions> listOfPositions = new List <P_L5DWS_DEWTH_1126_Positions>();

                                                        foreach (var position in positions)
                                                        {
                                                            P_L5DWS_DEWTH_1126_Positions positionItem = new P_L5DWS_DEWTH_1126_Positions();
                                                            positionItem.CMN_BPT_EMP_EffectiveWorkTime_PositionID = position.CMN_BPT_EMP_EffectiveWorkTime_PositionID;
                                                            positionItem.durationInDays  = leaveRequestUtil.LeaveRequestDuration(position.WorkTime_StartTime, position.WorkTime_StartTime.AddSeconds(position.WorkTime_Duration_in_sec), Parameter.Events, Parameter.Employees.FirstOrDefault(x => x.CMN_BPT_EMP_EmployeeID == position.CMN_BPT_EMP_Employe_RefID), true);
                                                            positionItem.durationInHours = leaveRequestUtil.LeaveRequestDuration(position.WorkTime_StartTime, position.WorkTime_StartTime.AddSeconds(position.WorkTime_Duration_in_sec), Parameter.Events, Parameter.Employees.FirstOrDefault(x => x.CMN_BPT_EMP_EmployeeID == position.CMN_BPT_EMP_Employe_RefID), false);
                                                            listOfPositions.Add(positionItem);
                                                        }

                                                        deleteParam.Positions = listOfPositions.ToArray();
                                                        cls_Delete_EffectiveWorkTime_Header.Invoke(Connection, Transaction, deleteParam, securityTicket);
                                                    }

                                                    P_L5DWS_SEWTFST_1141 saveParam = new P_L5DWS_SEWTFST_1141();
                                                    saveParam.EffectiveBusinessDay = date;
                                                    saveParam.Employee_RefID       = empID;
                                                    saveParam.ShiftTemplate_RefID  = shiftTemplate.CMN_PPS_ShiftTemplateID;

                                                    cls_Save_EffectiveWorkTime_For_ShiftTemplate.Invoke(Connection, Transaction, saveParam, securityTicket);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else if (Parameter.LoadFrom_PlanData)
                {
                    P_L5DWS_GDWSWDFT_0946 param = new P_L5DWS_GDWSWDFT_0946();
                    param.WorkSheduleDate = date;
                    var dailyWorkSchedules = cls_Get_DailyWorkSchedules_WithDetails_For_Date.Invoke(Connection, Transaction, param, securityTicket).Result;

                    foreach (var dailyWorkSchedule in dailyWorkSchedules)
                    {
                        ORM_CMN_BPT_EMP_EffectiveWorkTime_Header.Query effectiveWorkTimeToDeleteQuery = new ORM_CMN_BPT_EMP_EffectiveWorkTime_Header.Query();
                        effectiveWorkTimeToDeleteQuery.EffectiveBusinessDay = date;
                        effectiveWorkTimeToDeleteQuery.Employee_RefID       = dailyWorkSchedule.Employee_RefID;
                        effectiveWorkTimeToDeleteQuery.Tenant_RefID         = securityTicket.TenantID;
                        effectiveWorkTimeToDeleteQuery.IsDeleted            = false;

                        var effectiveWorkTimeHeaderToDeleteQueryResult = ORM_CMN_BPT_EMP_EffectiveWorkTime_Header.Query.Search(Connection, Transaction, effectiveWorkTimeToDeleteQuery);

                        if (effectiveWorkTimeHeaderToDeleteQueryResult.Count != 0)
                        {
                            var effectiveWorkTimeHeaderToDelete = effectiveWorkTimeHeaderToDeleteQueryResult.FirstOrDefault();
                            P_L5DWS_DEWTH_1126 deleteParam      = new P_L5DWS_DEWTH_1126();
                            deleteParam.CMN_STR_PPS_EffectiveWorkTime_HeaderID = effectiveWorkTimeHeaderToDelete.CMN_STR_PPS_EffectiveWorkTime_HeaderID;

                            ORM_CMN_BPT_EMP_EffectiveWorkTime_Position.Query positionsQuery = new ORM_CMN_BPT_EMP_EffectiveWorkTime_Position.Query();
                            positionsQuery.EffectiveWorkTime_Header_RefID = effectiveWorkTimeHeaderToDelete.CMN_STR_PPS_EffectiveWorkTime_HeaderID;
                            positionsQuery.Tenant_RefID = securityTicket.TenantID;
                            positionsQuery.IsDeleted    = false;

                            var positions = ORM_CMN_BPT_EMP_EffectiveWorkTime_Position.Query.Search(Connection, Transaction, positionsQuery);

                            List <P_L5DWS_DEWTH_1126_Positions> listOfPositions = new List <P_L5DWS_DEWTH_1126_Positions>();

                            foreach (var position in positions)
                            {
                                P_L5DWS_DEWTH_1126_Positions positionItem = new P_L5DWS_DEWTH_1126_Positions();
                                positionItem.CMN_BPT_EMP_EffectiveWorkTime_PositionID = position.CMN_BPT_EMP_EffectiveWorkTime_PositionID;
                                positionItem.durationInDays  = leaveRequestUtil.LeaveRequestDuration(position.WorkTime_StartTime, position.WorkTime_StartTime.AddSeconds(position.WorkTime_Duration_in_sec), Parameter.Events, Parameter.Employees.FirstOrDefault(x => x.CMN_BPT_EMP_EmployeeID == position.CMN_BPT_EMP_Employe_RefID), true);
                                positionItem.durationInHours = leaveRequestUtil.LeaveRequestDuration(position.WorkTime_StartTime, position.WorkTime_StartTime.AddSeconds(position.WorkTime_Duration_in_sec), Parameter.Events, Parameter.Employees.FirstOrDefault(x => x.CMN_BPT_EMP_EmployeeID == position.CMN_BPT_EMP_Employe_RefID), false);
                                listOfPositions.Add(positionItem);
                            }

                            deleteParam.Positions = listOfPositions.ToArray();
                            cls_Delete_EffectiveWorkTime_Header.Invoke(Connection, Transaction, deleteParam, securityTicket);
                        }

                        ORM_CMN_BPT_EMP_EffectiveWorkTime_Header newHeader = new ORM_CMN_BPT_EMP_EffectiveWorkTime_Header();
                        newHeader.ContractWorkerText          = dailyWorkSchedule.ContractWorkerText;
                        newHeader.BreakDurationTime_in_sec    = dailyWorkSchedule.BreakDurationTime_in_sec;
                        newHeader.EffectiveBusinessDay        = date;
                        newHeader.Employee_RefID              = dailyWorkSchedule.Employee_RefID;
                        newHeader.IsBreakTimeManualySpecified = dailyWorkSchedule.IsBreakTimeManualySpecified;
                        newHeader.SheduleBreakTemplate_RefID  = dailyWorkSchedule.SheduleBreakTemplate_RefID;
                        newHeader.Tenant_RefID = securityTicket.TenantID;
                        newHeader.Save(Connection, Transaction);

                        foreach (var dailyWorkDetail in dailyWorkSchedule.Details)
                        {
                            P_L5DWS_SEWTP_1337 positionSavePar = new P_L5DWS_SEWTP_1337();
                            if (dailyWorkDetail.LeaveRequest_RefID != Guid.Empty)
                            {
                                positionSavePar.AbsenceReason_RefID         = dailyWorkDetail.AbsenceReason_RefID;
                                positionSavePar.durationInDays              = leaveRequestUtil.LeaveRequestDuration(dailyWorkDetail.FromTime_as_DateTime, dailyWorkDetail.ToTime_as_DateTime, Parameter.Events, Parameter.Employees.FirstOrDefault(x => x.CMN_BPT_EMP_EmployeeID == dailyWorkSchedule.Employee_RefID), true);
                                positionSavePar.durationInHours             = leaveRequestUtil.LeaveRequestDuration(dailyWorkDetail.FromTime_as_DateTime, dailyWorkDetail.ToTime_as_DateTime, Parameter.Events, Parameter.Employees.FirstOrDefault(x => x.CMN_BPT_EMP_EmployeeID == dailyWorkSchedule.Employee_RefID), false);
                                positionSavePar.RequestedBy_Employee_RefID  = Guid.Empty;
                                positionSavePar.RequestedFor_Employee_RefID = dailyWorkSchedule.Employee_RefID;
                            }
                            else
                            {
                                positionSavePar.AbsenceReason_RefID         = Guid.Empty;
                                positionSavePar.durationInDays              = 0;
                                positionSavePar.durationInHours             = 0;
                                positionSavePar.RequestedBy_Employee_RefID  = Guid.Empty;
                                positionSavePar.RequestedFor_Employee_RefID = Guid.Empty;
                            }

                            positionSavePar.CMN_BPT_EMP_Employee_LeaveRequest_RefID = Guid.Empty;
                            positionSavePar.EffectiveWorkTime_Header_RefID          = newHeader.CMN_STR_PPS_EffectiveWorkTime_HeaderID;
                            positionSavePar.Employee_RefID     = newHeader.Employee_RefID;
                            positionSavePar.OldDurationInDays  = 0;
                            positionSavePar.OldDurationInHours = 0;
                            positionSavePar.Workplace_RefID    = dailyWorkDetail.SheduleForWorkplace_RefID;
                            positionSavePar.WorkTime_End       = dailyWorkDetail.ToTime_as_DateTime;
                            positionSavePar.WorkTime_Start     = dailyWorkDetail.FromTime_as_DateTime;

                            cls_Save_EffectiveWorkTime_Position.Invoke(Connection, Transaction, positionSavePar, securityTicket);
                        }
                    }
                }
            }

            //Put your code here
            return(returnValue);

            #endregion UserCode
        }
Пример #4
0
        protected static FR_Bool Execute(DbConnection Connection, DbTransaction Transaction, P_L5WA_IWAU_0954 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Bool();
            //Put your code here
            returnValue.Result = false;

            ORM_CMN_BPT_EMP_Employee_PlanGroup.Query planGroupQuery = new ORM_CMN_BPT_EMP_Employee_PlanGroup.Query();
            planGroupQuery.BoundTo_WorkArea_RefID = Parameter.WorkAreaID;
            planGroupQuery.IsDeleted    = false;
            planGroupQuery.Tenant_RefID = securityTicket.TenantID;
            if (ORM_CMN_BPT_EMP_Employee_PlanGroup.Query.Exists(Connection, Transaction, planGroupQuery))
            {
                returnValue.Result = true;
            }

            ORM_CMN_BPT_EMP_ExtraWorkCalculation_StructureBinding.Query extraWorkCalculationQuery = new ORM_CMN_BPT_EMP_ExtraWorkCalculation_StructureBinding.Query();
            extraWorkCalculationQuery.BoundTo_WorkArea_RefID = Parameter.WorkAreaID;
            extraWorkCalculationQuery.IsDeleted    = false;
            extraWorkCalculationQuery.Tenant_RefID = securityTicket.TenantID;
            if (ORM_CMN_BPT_EMP_ExtraWorkCalculation_StructureBinding.Query.Exists(Connection, Transaction, extraWorkCalculationQuery))
            {
                returnValue.Result = true;
            }

            ORM_CMN_BPT_EMP_ExtraWorkCalculation_Surcharge_StructureBinding.Query surchargeQuery = new ORM_CMN_BPT_EMP_ExtraWorkCalculation_Surcharge_StructureBinding.Query();
            surchargeQuery.BoundTo_WorkArea_RefID = Parameter.WorkAreaID;
            surchargeQuery.IsDeleted    = false;
            surchargeQuery.Tenant_RefID = securityTicket.TenantID;
            if (ORM_CMN_BPT_EMP_ExtraWorkCalculation_Surcharge_StructureBinding.Query.Exists(Connection, Transaction, surchargeQuery))
            {
                returnValue.Result = true;
            }

            ORM_CMN_BPT_EMP_Employee.Query employeeQuery = new ORM_CMN_BPT_EMP_Employee.Query();
            employeeQuery.Primary_WorkArea_RefID = Parameter.WorkAreaID;
            employeeQuery.IsDeleted    = false;
            employeeQuery.Tenant_RefID = securityTicket.TenantID;
            if (ORM_CMN_BPT_EMP_Employee.Query.Exists(Connection, Transaction, employeeQuery))
            {
                returnValue.Result = true;
            }

            ORM_CMN_PPS_ShiftTemplate.Query shiftTemplateQuery = new ORM_CMN_PPS_ShiftTemplate.Query();
            shiftTemplateQuery.CMN_STR_Workarea_RefID = Parameter.WorkAreaID;
            shiftTemplateQuery.IsDeleted    = false;
            shiftTemplateQuery.Tenant_RefID = securityTicket.TenantID;
            if (ORM_CMN_PPS_ShiftTemplate.Query.Exists(Connection, Transaction, shiftTemplateQuery))
            {
                returnValue.Result = true;
            }

            ORM_CMN_PPS_ShiftTemplate_WorkareaAssignment.Query shiftWorkareaAssignemntQuery = new ORM_CMN_PPS_ShiftTemplate_WorkareaAssignment.Query();
            shiftWorkareaAssignemntQuery.CMN_BPT_PPS_WorkArea_RefID = Parameter.WorkAreaID;
            shiftWorkareaAssignemntQuery.IsDeleted    = false;
            shiftWorkareaAssignemntQuery.Tenant_RefID = securityTicket.TenantID;
            if (ORM_CMN_PPS_ShiftTemplate_WorkareaAssignment.Query.Exists(Connection, Transaction, shiftWorkareaAssignemntQuery))
            {
                returnValue.Result = true;
            }

            ORM_CMN_PPS_BreakTime_Defaults_StructureBinding.Query defaultBreakQuery = new ORM_CMN_PPS_BreakTime_Defaults_StructureBinding.Query();
            defaultBreakQuery.BoundTo_WorkArea_RefID = Parameter.WorkAreaID;
            defaultBreakQuery.IsDeleted    = false;
            defaultBreakQuery.Tenant_RefID = securityTicket.TenantID;
            if (ORM_CMN_PPS_BreakTime_Defaults_StructureBinding.Query.Exists(Connection, Transaction, defaultBreakQuery))
            {
                returnValue.Result = true;
            }

            ORM_CMN_PPS_BreakTime_Template.Query breakTimeTemplateQuery = new ORM_CMN_PPS_BreakTime_Template.Query();
            breakTimeTemplateQuery.BoundTo_Workarea_RefID = Parameter.WorkAreaID;
            breakTimeTemplateQuery.IsDeleted    = false;
            breakTimeTemplateQuery.Tenant_RefID = securityTicket.TenantID;
            if (ORM_CMN_PPS_BreakTime_Template.Query.Exists(Connection, Transaction, breakTimeTemplateQuery))
            {
                returnValue.Result = true;
            }


            ORM_CMN_BPT_STR_Workarea_SettingsProfile.Query workareaSettingsProfileQuery = new ORM_CMN_BPT_STR_Workarea_SettingsProfile.Query();
            workareaSettingsProfileQuery.Workarea_RefID = Parameter.WorkAreaID;
            workareaSettingsProfileQuery.IsDeleted      = false;
            workareaSettingsProfileQuery.Tenant_RefID   = securityTicket.TenantID;
            if (ORM_CMN_BPT_STR_Workarea_SettingsProfile.Query.Exists(Connection, Transaction, workareaSettingsProfileQuery))
            {
                returnValue.Result = true;
            }

            return(returnValue);

            #endregion UserCode
        }
Пример #5
0
        protected static FR_Bool Execute(DbConnection Connection, DbTransaction Transaction, P_L5WP_IWPU_1503 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Bool();
            //Put your code here

            ORM_CMN_BPT_EMP_Employee_PlanGroup.Query planGroupQuery = new ORM_CMN_BPT_EMP_Employee_PlanGroup.Query();
            planGroupQuery.BoundTo_WorkPlace_RefID = Parameter.WorkplaceID;
            planGroupQuery.IsDeleted    = false;
            planGroupQuery.Tenant_RefID = securityTicket.TenantID;
            if (ORM_CMN_BPT_EMP_Employee_PlanGroup.Query.Exists(Connection, Transaction, planGroupQuery))
            {
                returnValue.Result = true;
            }

            ORM_CMN_BPT_EMP_ExtraWorkCalculation_StructureBinding.Query extraWorkCalculationQuery = new ORM_CMN_BPT_EMP_ExtraWorkCalculation_StructureBinding.Query();
            extraWorkCalculationQuery.BoundTo_Workplace_RefID = Parameter.WorkplaceID;
            extraWorkCalculationQuery.IsDeleted    = false;
            extraWorkCalculationQuery.Tenant_RefID = securityTicket.TenantID;
            if (ORM_CMN_BPT_EMP_ExtraWorkCalculation_StructureBinding.Query.Exists(Connection, Transaction, extraWorkCalculationQuery))
            {
                returnValue.Result = true;
            }

            ORM_CMN_BPT_EMP_ExtraWorkCalculation_Surcharge_StructureBinding.Query surchargeQuery = new ORM_CMN_BPT_EMP_ExtraWorkCalculation_Surcharge_StructureBinding.Query();
            surchargeQuery.BoundTo_Workplace_RefID = Parameter.WorkplaceID;
            surchargeQuery.IsDeleted    = false;
            surchargeQuery.Tenant_RefID = securityTicket.TenantID;
            if (ORM_CMN_BPT_EMP_ExtraWorkCalculation_Surcharge_StructureBinding.Query.Exists(Connection, Transaction, surchargeQuery))
            {
                returnValue.Result = true;
            }

            ORM_CMN_BPT_EMP_Employee.Query employeeQuery = new ORM_CMN_BPT_EMP_Employee.Query();
            employeeQuery.Primary_Workplace_RefID = Parameter.WorkplaceID;
            employeeQuery.IsDeleted    = false;
            employeeQuery.Tenant_RefID = securityTicket.TenantID;
            if (ORM_CMN_BPT_EMP_Employee.Query.Exists(Connection, Transaction, employeeQuery))
            {
                returnValue.Result = true;
            }

            ORM_CMN_PPS_ShiftTemplate.Query shiftTemplateQuery = new ORM_CMN_PPS_ShiftTemplate.Query();
            shiftTemplateQuery.CMN_STR_Workplace_RefID = Parameter.WorkplaceID;
            shiftTemplateQuery.IsDeleted    = false;
            shiftTemplateQuery.Tenant_RefID = securityTicket.TenantID;
            if (ORM_CMN_PPS_ShiftTemplate.Query.Exists(Connection, Transaction, shiftTemplateQuery))
            {
                returnValue.Result = true;
            }


            ORM_CMN_PPS_BreakTime_Defaults_StructureBinding.Query defaultBreakQuery = new ORM_CMN_PPS_BreakTime_Defaults_StructureBinding.Query();
            defaultBreakQuery.BoundTo_Workplace_RefID = Parameter.WorkplaceID;
            defaultBreakQuery.IsDeleted    = false;
            defaultBreakQuery.Tenant_RefID = securityTicket.TenantID;
            if (ORM_CMN_PPS_BreakTime_Defaults_StructureBinding.Query.Exists(Connection, Transaction, defaultBreakQuery))
            {
                returnValue.Result = true;
            }

            ORM_CMN_PPS_BreakTime_Template.Query breakTimeTemplateQuery = new ORM_CMN_PPS_BreakTime_Template.Query();
            breakTimeTemplateQuery.BoundTo_Workplace_RefID = Parameter.WorkplaceID;
            breakTimeTemplateQuery.IsDeleted    = false;
            breakTimeTemplateQuery.Tenant_RefID = securityTicket.TenantID;
            if (ORM_CMN_PPS_BreakTime_Template.Query.Exists(Connection, Transaction, breakTimeTemplateQuery))
            {
                returnValue.Result = true;
            }

            ORM_CMN_STR_PPS_Workplace_ResponsiblePerson.Query WorkplaceResponsiblePersonQuery = new ORM_CMN_STR_PPS_Workplace_ResponsiblePerson.Query();
            WorkplaceResponsiblePersonQuery.Workplace_RefID = Parameter.WorkplaceID;
            WorkplaceResponsiblePersonQuery.IsDeleted       = false;
            WorkplaceResponsiblePersonQuery.Tenant_RefID    = securityTicket.TenantID;
            if (ORM_CMN_STR_PPS_Workplace_ResponsiblePerson.Query.Exists(Connection, Transaction, WorkplaceResponsiblePersonQuery))
            {
                returnValue.Result = true;
            }



            ORM_CMN_BPT_EMP_EffectiveWorkTime_Position.Query WorkplaceEffectiveWorkTimePositionQuery = new ORM_CMN_BPT_EMP_EffectiveWorkTime_Position.Query();
            WorkplaceEffectiveWorkTimePositionQuery.Workplace_RefID = Parameter.WorkplaceID;
            WorkplaceEffectiveWorkTimePositionQuery.IsDeleted       = false;
            WorkplaceEffectiveWorkTimePositionQuery.Tenant_RefID    = securityTicket.TenantID;
            if (ORM_CMN_BPT_EMP_EffectiveWorkTime_Position.Query.Exists(Connection, Transaction, WorkplaceEffectiveWorkTimePositionQuery))
            {
                returnValue.Result = true;
            }

            ORM_CMN_STR_PPS_DailyWorkSchedule_Detail.Query WorkplaceDailyScheduleQuery = new ORM_CMN_STR_PPS_DailyWorkSchedule_Detail.Query();
            WorkplaceDailyScheduleQuery.SheduleForWorkplace_RefID = Parameter.WorkplaceID;
            WorkplaceDailyScheduleQuery.IsDeleted    = false;
            WorkplaceDailyScheduleQuery.Tenant_RefID = securityTicket.TenantID;
            if (ORM_CMN_STR_PPS_DailyWorkSchedule_Detail.Query.Exists(Connection, Transaction, WorkplaceDailyScheduleQuery))
            {
                returnValue.Result = true;
            }

            ORM_CMN_STR_PPS_WorkDetail_Activity.Query WorkplaceWorkDetailActivityQuery = new ORM_CMN_STR_PPS_WorkDetail_Activity.Query();
            WorkplaceWorkDetailActivityQuery.CMN_STR_PPS_Workplace_RefID = Parameter.WorkplaceID;
            WorkplaceWorkDetailActivityQuery.IsDeleted    = false;
            WorkplaceWorkDetailActivityQuery.Tenant_RefID = securityTicket.TenantID;
            if (ORM_CMN_STR_PPS_WorkDetail_Activity.Query.Exists(Connection, Transaction, WorkplaceWorkDetailActivityQuery))
            {
                returnValue.Result = true;
            }



            return(returnValue);

            #endregion UserCode
        }
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5DWS_SDWSFST_1447 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();

            ORM_CMN_PPS_ShiftTemplate.Query shiftTemplateQuery = new ORM_CMN_PPS_ShiftTemplate.Query();
            shiftTemplateQuery.CMN_PPS_ShiftTemplateID = Parameter.InstantiatedWithShiftTemplate_RefID;
            shiftTemplateQuery.Tenant_RefID            = securityTicket.TenantID;
            shiftTemplateQuery.IsDeleted = false;

            ORM_CMN_PPS_ShiftTemplate shiftTemplate = ORM_CMN_PPS_ShiftTemplate.Query.Search(Connection, Transaction, shiftTemplateQuery).FirstOrDefault();



            ORM_CMN_PPS_ShiftTemplate_WorkDetail.Query shiftTemplateWorkDetailQuery = new ORM_CMN_PPS_ShiftTemplate_WorkDetail.Query();
            shiftTemplateWorkDetailQuery.CMN_PPS_ShiftTemplate_RefID = Parameter.InstantiatedWithShiftTemplate_RefID;
            shiftTemplateWorkDetailQuery.Tenant_RefID = securityTicket.TenantID;
            shiftTemplateWorkDetailQuery.IsDeleted    = false;

            var shiftTemplateDetailsResult = ORM_CMN_PPS_ShiftTemplate_WorkDetail.Query.Search(Connection, Transaction, shiftTemplateWorkDetailQuery);

            double   totalTime = 0;
            DateTime?startTime = null;
            DateTime?endTime   = null;

            foreach (var shiftTemplateDetail in shiftTemplateDetailsResult)
            {
                DateTime detailStartTime = Parameter.WorkSheduleDate.Date.AddSeconds(shiftTemplateDetail.ShiftStart_Offset_sec);
                DateTime detailEndTime   = Parameter.WorkSheduleDate.Date.AddSeconds(shiftTemplateDetail.ShiftStart_Offset_sec + Math.Abs(shiftTemplateDetail.Duration_in_sec));

                if (startTime == null)
                {
                    startTime = detailStartTime;
                }
                if (endTime == null)
                {
                    endTime = detailEndTime;
                }

                if (detailStartTime < startTime)
                {
                    startTime = detailStartTime;
                }
                if (detailEndTime > endTime)
                {
                    endTime = detailEndTime;
                }

                totalTime += shiftTemplateDetail.Duration_in_sec;
            }

            double startTimeInSec = 0;
            double endTimeInSec   = 0;

            if (startTime.HasValue)
            {
                startTimeInSec = startTime.Value.TimeOfDay.TotalSeconds;
            }

            if (endTime.HasValue)
            {
                endTimeInSec = endTime.Value.TimeOfDay.TotalSeconds;
            }

            ORM_CMN_STR_PPS_DailyWorkSchedule dailyWorkSchedule = new ORM_CMN_STR_PPS_DailyWorkSchedule();
            dailyWorkSchedule.IsBreakTimeManualySpecified         = false;
            dailyWorkSchedule.SheduleBreakTemplate_RefID          = shiftTemplate.Default_AllowedBreakTimeTemplate_RefID;
            dailyWorkSchedule.InstantiatedWithShiftTemplate_RefID = Parameter.InstantiatedWithShiftTemplate_RefID;

            if (shiftTemplate.Default_AllowedBreakTimeTemplate_RefID != Guid.Empty && Parameter.IsBreakTimeCalculated_Planning)
            {
                ORM_CMN_PPS_BreakTime_Template_Assignment.Query breakTimeAssignmentQuery = new ORM_CMN_PPS_BreakTime_Template_Assignment.Query();
                breakTimeAssignmentQuery.BreakTime_Template_RefID = shiftTemplate.Default_AllowedBreakTimeTemplate_RefID;
                breakTimeAssignmentQuery.Tenant_RefID             = securityTicket.TenantID;
                breakTimeAssignmentQuery.IsDeleted = false;
                var breakTimeAssignments = ORM_CMN_PPS_BreakTime_Template_Assignment.Query.Search(Connection, Transaction, breakTimeAssignmentQuery);
                foreach (var breakTimeAssignment in breakTimeAssignments)
                {
                    ORM_CMN_PPS_BreakTime.Query breakTimeQuery = new ORM_CMN_PPS_BreakTime.Query();
                    breakTimeQuery.CMN_PPS_BreakTimeID = breakTimeAssignment.BreakTime_RefID;
                    breakTimeQuery.Tenant_RefID        = securityTicket.TenantID;
                    breakTimeQuery.IsDeleted           = false;
                    breakTimeQuery.IsDinnerBreak       = false;
                    breakTimeQuery.IsLunchBreak        = false;
                    breakTimeQuery.IsBreakfastBreak    = false;

                    var breakTime = ORM_CMN_PPS_BreakTime.Query.Search(Connection, Transaction, breakTimeQuery).FirstOrDefault();
                    if (breakTime != null)
                    {
                        dailyWorkSchedule.BreakDurationTime_in_sec += breakTime.Default_Duration_in_sec;
                    }
                }
            }
            else
            {
                dailyWorkSchedule.BreakDurationTime_in_sec = 0;
            }

            dailyWorkSchedule.R_WorkDay_Start_in_sec    = (int)startTimeInSec;
            dailyWorkSchedule.R_WorkDay_Duration_in_sec = (int)totalTime;
            dailyWorkSchedule.R_WorkDay_End_in_sec      = (int)endTimeInSec;
            dailyWorkSchedule.R_ContractSpecified_WorkingTime_in_sec = Parameter.R_ContractSpecified_WorkingTime_in_sec;
            dailyWorkSchedule.ContractWorkerText = "";
            dailyWorkSchedule.Employee_RefID     = Parameter.Employee_RefID;
            dailyWorkSchedule.WorkSheduleDate    = Parameter.WorkSheduleDate.Date;
            dailyWorkSchedule.Tenant_RefID       = securityTicket.TenantID;

            dailyWorkSchedule.Save(Connection, Transaction);
            returnValue.Result = dailyWorkSchedule.CMN_STR_PPS_DailyWorkScheduleID;
            foreach (var shiftTemplateDetail in shiftTemplateDetailsResult)
            {
                P_L5DWS_SDWSD_1130 detailParam = new P_L5DWS_SDWSD_1130();
                detailParam.WorkTime_Start              = dailyWorkSchedule.WorkSheduleDate.AddSeconds(shiftTemplateDetail.ShiftStart_Offset_sec);
                detailParam.WorkTime_End                = dailyWorkSchedule.WorkSheduleDate.AddSeconds(shiftTemplateDetail.ShiftStart_Offset_sec + shiftTemplateDetail.Duration_in_sec);
                detailParam.DailyWorkSchedule_RefID     = dailyWorkSchedule.CMN_STR_PPS_DailyWorkScheduleID;
                detailParam.IsWorkBreak                 = false;
                detailParam.SheduleForWorkplace_RefID   = Guid.Empty;
                detailParam.AbsenceReason_RefID         = Guid.Empty;
                detailParam.RequestedBy_Employee_RefID  = Guid.Empty;
                detailParam.RequestedFor_Employee_RefID = Parameter.Employee_RefID;
                cls_Save_Employee_DailyWorkSchedule_Detail.Invoke(Connection, Transaction, detailParam, securityTicket);
            }

            return(returnValue);

            #endregion UserCode
        }
Пример #7
0
        protected static FR_Bool Execute(DbConnection Connection, DbTransaction Transaction, P_L5OF_IOFU_1531 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Bool();

            ORM_CMN_BPT_EMP_Employee_PlanGroup.Query planGroupQuery = new ORM_CMN_BPT_EMP_Employee_PlanGroup.Query();
            planGroupQuery.BoundTo_Office_RefID = Parameter.OfficeID;
            planGroupQuery.IsDeleted            = false;
            planGroupQuery.Tenant_RefID         = securityTicket.TenantID;
            if (ORM_CMN_BPT_EMP_Employee_PlanGroup.Query.Exists(Connection, Transaction, planGroupQuery))
            {
                returnValue.Result = true;
            }

            ORM_CMN_BPT_EMP_ExtraWorkCalculation_StructureBinding.Query extraWorkCalculationQuery = new ORM_CMN_BPT_EMP_ExtraWorkCalculation_StructureBinding.Query();
            extraWorkCalculationQuery.BoundTo_Office_RefID = Parameter.OfficeID;
            extraWorkCalculationQuery.IsDeleted            = false;
            extraWorkCalculationQuery.Tenant_RefID         = securityTicket.TenantID;
            if (ORM_CMN_BPT_EMP_ExtraWorkCalculation_StructureBinding.Query.Exists(Connection, Transaction, extraWorkCalculationQuery))
            {
                returnValue.Result = true;
            }

            ORM_CMN_BPT_EMP_ExtraWorkCalculation_Surcharge_StructureBinding.Query surchargeQuery = new ORM_CMN_BPT_EMP_ExtraWorkCalculation_Surcharge_StructureBinding.Query();
            surchargeQuery.BoundTo_Office_RefID = Parameter.OfficeID;
            surchargeQuery.IsDeleted            = false;
            surchargeQuery.Tenant_RefID         = securityTicket.TenantID;
            if (ORM_CMN_BPT_EMP_ExtraWorkCalculation_Surcharge_StructureBinding.Query.Exists(Connection, Transaction, surchargeQuery))
            {
                returnValue.Result = true;
            }

            ORM_CMN_BPT_EMP_Employee.Query employeeQuery = new ORM_CMN_BPT_EMP_Employee.Query();
            employeeQuery.Primary_Office_RefID = Parameter.OfficeID;
            employeeQuery.IsDeleted            = false;
            employeeQuery.Tenant_RefID         = securityTicket.TenantID;
            if (ORM_CMN_BPT_EMP_Employee.Query.Exists(Connection, Transaction, employeeQuery))
            {
                returnValue.Result = true;
            }

            ORM_CMN_PPS_ShiftTemplate.Query shiftTemplateQuery = new ORM_CMN_PPS_ShiftTemplate.Query();
            shiftTemplateQuery.CMN_STR_Office_RefID = Parameter.OfficeID;
            shiftTemplateQuery.IsDeleted            = false;
            shiftTemplateQuery.Tenant_RefID         = securityTicket.TenantID;
            if (ORM_CMN_PPS_ShiftTemplate.Query.Exists(Connection, Transaction, shiftTemplateQuery))
            {
                returnValue.Result = true;
            }

            ORM_CMN_PPS_BreakTime_Defaults_StructureBinding.Query defaultBreakQuery = new ORM_CMN_PPS_BreakTime_Defaults_StructureBinding.Query();
            defaultBreakQuery.BoundTo_Office_RefID = Parameter.OfficeID;
            defaultBreakQuery.IsDeleted            = false;
            defaultBreakQuery.Tenant_RefID         = securityTicket.TenantID;
            if (ORM_CMN_PPS_BreakTime_Defaults_StructureBinding.Query.Exists(Connection, Transaction, defaultBreakQuery))
            {
                returnValue.Result = true;
            }

            ORM_CMN_PPS_BreakTime_Template.Query breakTimeTemplateQuery = new ORM_CMN_PPS_BreakTime_Template.Query();
            breakTimeTemplateQuery.BoundTo_Office_RefID = Parameter.OfficeID;
            breakTimeTemplateQuery.IsDeleted            = false;
            breakTimeTemplateQuery.Tenant_RefID         = securityTicket.TenantID;
            if (ORM_CMN_PPS_BreakTime_Template.Query.Exists(Connection, Transaction, breakTimeTemplateQuery))
            {
                returnValue.Result = true;
            }


            ORM_CMN_STR_PPS_WorkArea.Query workplaceQuery = new ORM_CMN_STR_PPS_WorkArea.Query();
            workplaceQuery.Office_RefID = Parameter.OfficeID;
            workplaceQuery.IsDeleted    = false;
            workplaceQuery.Tenant_RefID = securityTicket.TenantID;
            if (ORM_CMN_STR_PPS_WorkArea.Query.Exists(Connection, Transaction, workplaceQuery))
            {
                returnValue.Result = true;
            }

            ORM_CMN_BPT_STR_Office_SettingsProfile.Query OfficeSettingsProfileQuery = new ORM_CMN_BPT_STR_Office_SettingsProfile.Query();
            OfficeSettingsProfileQuery.Office_RefID = Parameter.OfficeID;
            OfficeSettingsProfileQuery.IsDeleted    = false;
            OfficeSettingsProfileQuery.Tenant_RefID = securityTicket.TenantID;
            if (ORM_CMN_BPT_STR_Office_SettingsProfile.Query.Exists(Connection, Transaction, OfficeSettingsProfileQuery))
            {
                returnValue.Result = true;
            }

            ORM_CMN_STR_Office_2_CostCenter.Query OfficeCostcenterQuery = new ORM_CMN_STR_Office_2_CostCenter.Query();
            OfficeCostcenterQuery.Office_RefID = Parameter.OfficeID;
            OfficeCostcenterQuery.IsDeleted    = false;
            OfficeCostcenterQuery.Tenant_RefID = securityTicket.TenantID;
            if (ORM_CMN_STR_Office_2_CostCenter.Query.Exists(Connection, Transaction, OfficeCostcenterQuery))
            {
                returnValue.Result = true;
            }

            ORM_CMN_STR_Office_Default_WorkRelationDefinition_Template.Query OfficeDefaultWorkRelationTemplateQuery = new ORM_CMN_STR_Office_Default_WorkRelationDefinition_Template.Query();
            OfficeDefaultWorkRelationTemplateQuery.CMN_STR_Office_RefID = Parameter.OfficeID;
            OfficeDefaultWorkRelationTemplateQuery.IsDeleted            = false;
            OfficeDefaultWorkRelationTemplateQuery.Tenant_RefID         = securityTicket.TenantID;
            if (ORM_CMN_STR_Office_Default_WorkRelationDefinition_Template.Query.Exists(Connection, Transaction, OfficeDefaultWorkRelationTemplateQuery))
            {
                returnValue.Result = true;
            }



            //Put your code here
            return(returnValue);

            #endregion UserCode
        }
        protected static FR_L5ST_GSTFT_1610_Array Execute(DbConnection Connection, DbTransaction Transaction, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5ST_GSTFT_1610_Array();

            List <L5ST_GSTFT_1610> shiftTemplatesReturn = new List <L5ST_GSTFT_1610>();

            ORM_CMN_PPS_ShiftTemplate.Query shiftTemplateQuery = new ORM_CMN_PPS_ShiftTemplate.Query();
            shiftTemplateQuery.Tenant_RefID = securityTicket.TenantID;
            shiftTemplateQuery.IsDeleted    = false;
            List <ORM_CMN_PPS_ShiftTemplate> shiftTemplates = ORM_CMN_PPS_ShiftTemplate.Query.Search(Connection, Transaction, shiftTemplateQuery);
            foreach (var shiftTemplate in shiftTemplates)
            {
                L5ST_GSTFT_1610 templateItem = new L5ST_GSTFT_1610();
                templateItem.CMN_PPS_ShiftTemplateID = shiftTemplate.CMN_PPS_ShiftTemplateID;
                templateItem.CMN_STR_Office_RefID    = shiftTemplate.CMN_STR_Office_RefID;
                templateItem.CMN_STR_Workarea_RefID  = shiftTemplate.CMN_STR_Workarea_RefID;
                templateItem.CMN_STR_Workplace_RefID = shiftTemplate.CMN_STR_Workplace_RefID;
                templateItem.ShiftTemplate_Name      = shiftTemplate.ShiftTemplate_Name;
                templateItem.ShiftTemplate_ShortName = shiftTemplate.ShiftTemplate_ShortName;
                templateItem.Default_AllowedBreakTimeTemplate_RefID = shiftTemplate.Default_AllowedBreakTimeTemplate_RefID;
                templateItem.DisplayColor = shiftTemplate.DisplayColor;

                ORM_CMN_PPS_ShiftTemplate_WorkDetail.Query workdetailsQuery = new ORM_CMN_PPS_ShiftTemplate_WorkDetail.Query();
                workdetailsQuery.IsDeleted    = false;
                workdetailsQuery.Tenant_RefID = securityTicket.TenantID;
                workdetailsQuery.CMN_PPS_ShiftTemplate_RefID = shiftTemplate.CMN_PPS_ShiftTemplateID;
                List <ORM_CMN_PPS_ShiftTemplate_WorkDetail> workDetails = ORM_CMN_PPS_ShiftTemplate_WorkDetail.Query.Search(Connection, Transaction, workdetailsQuery);
                if (workDetails != null && workDetails.Count != 0)
                {
                    int    startingTime  = 0;
                    int    endingTime    = 0;
                    double totalWorkTime = 0;
                    foreach (var workDetail in workDetails)
                    {
                        if (startingTime == 0 || (startingTime > workDetail.ShiftStart_Offset_sec && workDetail.ShiftStart_Offset_sec != 0))
                        {
                            startingTime = (int)workDetail.ShiftStart_Offset_sec;
                        }
                        if (endingTime < workDetail.ShiftStart_Offset_sec + workDetail.Duration_in_sec)
                        {
                            endingTime = (int)workDetail.ShiftStart_Offset_sec + (int)workDetail.Duration_in_sec;
                        }

                        totalWorkTime += workDetail.Duration_in_sec;
                    }

                    templateItem.EndTime   = CronExtender.secondsToTime(endingTime);
                    templateItem.StartTime = CronExtender.secondsToTime(startingTime);
                    templateItem.Worktime  = CronExtender.secondsToTime(Int32.Parse(totalWorkTime.ToString()));
                }
                else
                {
                    templateItem.EndTime   = CronExtender.secondsToTime(0);
                    templateItem.StartTime = CronExtender.secondsToTime(0);
                    templateItem.Worktime  = CronExtender.secondsToTime(0);
                }
                int brakeTime = 0;
                if (shiftTemplate.Default_AllowedBreakTimeTemplate_RefID != Guid.Empty)
                {
                    P_L5BR_GBMFTID_1537 par = new P_L5BR_GBMFTID_1537();
                    par.CMN_PPS_BreakTime_TemplateID = shiftTemplate.Default_AllowedBreakTimeTemplate_RefID;
                    L5BR_GBMFTID_1537 breakModel = cls_Get_BreakModels_For_TemplateID.Invoke(Connection, Transaction, par, securityTicket).Result;
                    brakeTime = breakModel.BreakModel.Duration;
                    templateItem.BrakeTime = CronExtender.secondsToTime(brakeTime);
                    templateItem.Worktime  = CronExtender.secondsToTime(CronExtender.timeToSeconds(templateItem.Worktime) - brakeTime);
                }
                else
                {
                    templateItem.BrakeTime = CronExtender.secondsToTime(0);
                }
                P_L5ST_GSTQFST_1516 param = new P_L5ST_GSTQFST_1516();
                param.ShiftTemplateID       = shiftTemplate.CMN_PPS_ShiftTemplateID;
                templateItem.Qualifications = cls_Get_ShiftQualifications_For_ShiftTemplateID.Invoke(Connection, Transaction, param, securityTicket).Result;

                shiftTemplatesReturn.Add(templateItem);
            }

            returnValue.Result = shiftTemplatesReturn.ToArray();



            //Put your code here
            return(returnValue);

            #endregion UserCode
        }
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5DWS_SEWTFST_1141 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here

            ORM_CMN_PPS_ShiftTemplate.Query shiftTemplateQuery = new ORM_CMN_PPS_ShiftTemplate.Query();
            shiftTemplateQuery.CMN_PPS_ShiftTemplateID = Parameter.ShiftTemplate_RefID;
            shiftTemplateQuery.Tenant_RefID            = securityTicket.TenantID;
            shiftTemplateQuery.IsDeleted = false;

            ORM_CMN_PPS_ShiftTemplate shiftTemplate = ORM_CMN_PPS_ShiftTemplate.Query.Search(Connection, Transaction, shiftTemplateQuery).FirstOrDefault();



            ORM_CMN_PPS_ShiftTemplate_WorkDetail.Query shiftTemplateWorkDetailQuery = new ORM_CMN_PPS_ShiftTemplate_WorkDetail.Query();
            shiftTemplateWorkDetailQuery.CMN_PPS_ShiftTemplate_RefID = Parameter.ShiftTemplate_RefID;
            shiftTemplateWorkDetailQuery.Tenant_RefID = securityTicket.TenantID;
            shiftTemplateWorkDetailQuery.IsDeleted    = false;

            var shiftTemplateDetailsResult = ORM_CMN_PPS_ShiftTemplate_WorkDetail.Query.Search(Connection, Transaction, shiftTemplateWorkDetailQuery);

            ORM_CMN_BPT_EMP_EffectiveWorkTime_Header effectiveWorkTimeHeader = new ORM_CMN_BPT_EMP_EffectiveWorkTime_Header();
            effectiveWorkTimeHeader.IsBreakTimeManualySpecified = false;
            effectiveWorkTimeHeader.SheduleBreakTemplate_RefID  = shiftTemplate.Default_AllowedBreakTimeTemplate_RefID;

            if (shiftTemplate.Default_AllowedBreakTimeTemplate_RefID != Guid.Empty && Parameter.IsBreakTimeCalculated_Actual)
            {
                ORM_CMN_PPS_BreakTime_Template_Assignment.Query breakTimeAssignmentQuery = new ORM_CMN_PPS_BreakTime_Template_Assignment.Query();
                breakTimeAssignmentQuery.BreakTime_Template_RefID = shiftTemplate.Default_AllowedBreakTimeTemplate_RefID;
                breakTimeAssignmentQuery.Tenant_RefID             = securityTicket.TenantID;
                breakTimeAssignmentQuery.IsDeleted = false;

                var breakTimeAssignment = ORM_CMN_PPS_BreakTime_Template_Assignment.Query.Search(Connection, Transaction, breakTimeAssignmentQuery).FirstOrDefault();

                ORM_CMN_PPS_BreakTime.Query breakTimeQuery = new ORM_CMN_PPS_BreakTime.Query();
                breakTimeQuery.CMN_PPS_BreakTimeID = breakTimeAssignment.BreakTime_RefID;
                breakTimeQuery.Tenant_RefID        = securityTicket.TenantID;
                breakTimeQuery.IsDeleted           = false;

                var breakTime = ORM_CMN_PPS_BreakTime.Query.Search(Connection, Transaction, breakTimeQuery).FirstOrDefault();

                effectiveWorkTimeHeader.BreakDurationTime_in_sec = breakTime.Default_Duration_in_sec;
            }
            else
            {
                effectiveWorkTimeHeader.BreakDurationTime_in_sec = 0;
            }

            effectiveWorkTimeHeader.EffectiveBusinessDay = Parameter.EffectiveBusinessDay;
            effectiveWorkTimeHeader.ContractWorkerText   = "";
            effectiveWorkTimeHeader.Employee_RefID       = Parameter.Employee_RefID;
            effectiveWorkTimeHeader.Tenant_RefID         = securityTicket.TenantID;
            effectiveWorkTimeHeader.Save(Connection, Transaction);

            foreach (var shiftTemplateDetail in shiftTemplateDetailsResult)
            {
                P_L5DWS_SEWTP_1337 effectivePositionParam = new P_L5DWS_SEWTP_1337();
                effectivePositionParam.EffectiveWorkTime_Header_RefID = effectiveWorkTimeHeader.CMN_STR_PPS_EffectiveWorkTime_HeaderID;
                effectivePositionParam.WorkTime_Start = effectiveWorkTimeHeader.EffectiveBusinessDay.AddSeconds(shiftTemplateDetail.ShiftStart_Offset_sec);
                effectivePositionParam.WorkTime_End   = effectiveWorkTimeHeader.EffectiveBusinessDay.AddSeconds(shiftTemplateDetail.ShiftStart_Offset_sec + shiftTemplateDetail.Duration_in_sec);
                effectivePositionParam.Employee_RefID = Parameter.Employee_RefID;
                effectivePositionParam.RequestedFor_Employee_RefID = Parameter.Employee_RefID;
                cls_Save_EffectiveWorkTime_Position.Invoke(Connection, Transaction, effectivePositionParam, securityTicket);
            }

            return(returnValue);

            #endregion UserCode
        }