Example #1
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5EM_SE_1657 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here

            ORM_CMN_Address address = new ORM_CMN_Address();
            if (Parameter.CMN_AddressID != Guid.Empty)
            {
                var result = address.Load(Connection, Transaction, Parameter.CMN_AddressID);
                if (result.Status != FR_Status.Success || address.CMN_AddressID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            address.City_Name       = Parameter.City_Name;
            address.Street_Name     = Parameter.Street_Name;
            address.Street_Number   = Parameter.Street_Number;
            address.Country_Name    = Parameter.Country_Name;
            address.Province_Name   = Parameter.Province_Name;
            address.Tenant_RefID    = securityTicket.TenantID;
            address.City_PostalCode = Parameter.City_PostalCode;
            address.Save(Connection, Transaction);
            CSV2Core.DlTrace.Trace("success address");
            ORM_CMN_PER_PersonInfo person = new ORM_CMN_PER_PersonInfo();
            if (Parameter.CMN_PER_PersonInfoID != Guid.Empty)
            {
                var result = person.Load(Connection, Transaction, Parameter.CMN_PER_PersonInfoID);
                if (result.Status != FR_Status.Success || person.CMN_PER_PersonInfoID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }

            //person.AccountImage_URL = Parameter.ProfileImage_Document_RefID;
            person.FirstName     = Parameter.FirstName;
            person.LastName      = Parameter.LastName;
            person.PrimaryEmail  = Parameter.PrimaryEmail;
            person.Tenant_RefID  = securityTicket.TenantID;
            person.Title         = Parameter.Title;
            person.Address_RefID = address.CMN_AddressID;
            person.ProfileImage_Document_RefID = Parameter.ImageID;
            person.BirthDate        = Parameter.BirthDate;
            person.NumberOfChildren = Parameter.TaxInfoParameter != null ? Parameter.TaxInfoParameter.NumberOfChildren : 0;
            person.Save(Connection, Transaction);
            CSV2Core.DlTrace.Trace("success persopm");

            var contactQuery = new ORM_CMN_PER_CommunicationContact.Query();
            contactQuery.Tenant_RefID     = securityTicket.TenantID;
            contactQuery.PersonInfo_RefID = person.CMN_PER_PersonInfoID;
            contactQuery.IsDeleted        = false;
            var deleteContacts = ORM_CMN_PER_CommunicationContact.Query.SoftDelete(Connection, Transaction, contactQuery);
            foreach (var parContact in Parameter.Contacts)
            {
                ORM_CMN_PER_CommunicationContact contact = new ORM_CMN_PER_CommunicationContact();
                if (parContact.CMN_PER_CommunicationContactID != Guid.Empty)
                {
                    var result = contact.Load(Connection, Transaction, parContact.CMN_PER_CommunicationContactID);
                    if (result.Status != FR_Status.Success || contact.CMN_PER_CommunicationContactID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                }
                contact.Content          = parContact.Content;
                contact.Contact_Type     = parContact.CMN_PER_CommunicationContact_TypeID;
                contact.Tenant_RefID     = securityTicket.TenantID;
                contact.PersonInfo_RefID = person.CMN_PER_PersonInfoID;
                contact.Save(Connection, Transaction);
                CSV2Core.DlTrace.Trace("success contact");
            }

            ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
            if (Parameter.CMN_BPT_BusinessParticipantID != Guid.Empty)
            {
                var result = bParticipant.Load(Connection, Transaction, Parameter.CMN_BPT_BusinessParticipantID);
                if (result.Status != FR_Status.Success || bParticipant.CMN_BPT_BusinessParticipantID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            bParticipant.DisplayName = Parameter.DisplayName;
            bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
            bParticipant.IsNaturalPerson = true;
            bParticipant.Tenant_RefID    = securityTicket.TenantID;
            bParticipant.Save(Connection, Transaction);
            ORM_CMN_BPT_EMP_Employee employee = new ORM_CMN_BPT_EMP_Employee();
            CSV2Core.DlTrace.Trace("success bpart");


            if (Parameter.CMN_BPT_EMP_EmployeeID != Guid.Empty)
            {
                var result = employee.Load(Connection, Transaction, Parameter.CMN_BPT_EMP_EmployeeID);
                if (result.Status != FR_Status.Success || employee.CMN_BPT_EMP_EmployeeID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            employee.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
            employee.Staff_Number     = Parameter.Staff_Number;
            employee.StandardFunction = Parameter.StandardFunction;
            employee.Tenant_RefID     = securityTicket.TenantID;
            employee.Save(Connection, Transaction);
            CSV2Core.DlTrace.Trace("success employee");


            ORM_CMN_BPT_EMP_EmploymentRelationship employmentRelationship = new ORM_CMN_BPT_EMP_EmploymentRelationship();
            if (Parameter.CMN_BPT_EMP_Employee_EmploymentRelationshipID != Guid.Empty)
            {
                var result = employmentRelationship.Load(Connection, Transaction, Parameter.CMN_BPT_EMP_Employee_EmploymentRelationshipID);
                if (result.Status != FR_Status.Success || employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            employmentRelationship.Work_StartDate = Parameter.Work_StartDate;

            bool resignationDateChanged = false;
            if (employmentRelationship.Work_EndDate != Parameter.Work_EndDate)
            {
                resignationDateChanged = true;
            }

            employmentRelationship.Work_EndDate   = Parameter.Work_EndDate;
            employmentRelationship.Tenant_RefID   = securityTicket.TenantID;
            employmentRelationship.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
            employmentRelationship.Save(Connection, Transaction);
            CSV2Core.DlTrace.Trace("success employmentRelationship");

            if (Parameter.Work_EndDate.Ticks != 0)
            {
                ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query empRelationShipToWorkingContractQuery = new ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query();
                empRelationShipToWorkingContractQuery.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                empRelationShipToWorkingContractQuery.Tenant_RefID = securityTicket.TenantID;
                empRelationShipToWorkingContractQuery.IsDeleted    = false;
                List <ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract> workingContractAssignments = ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query.Search(Connection, Transaction, empRelationShipToWorkingContractQuery);
                foreach (var workingContractAssignment in workingContractAssignments)
                {
                    ORM_CMN_BPT_EMP_WorkingContract workingContract = new ORM_CMN_BPT_EMP_WorkingContract();
                    if (workingContractAssignment.WorkingContract_RefID != Guid.Empty)
                    {
                        var result = workingContract.Load(Connection, Transaction, workingContractAssignment.WorkingContract_RefID);
                        if (result.Status != FR_Status.Success || workingContract.CMN_BPT_EMP_WorkingContractID == Guid.Empty)
                        {
                            var error = new FR_Guid();
                            error.ErrorMessage = "No Such ID";
                            error.Status       = FR_Status.Error_Internal;
                            return(error);
                        }
                    }
                    if (workingContract.Contract_EndDate.Ticks == 0 || workingContract.Contract_EndDate.Ticks > Parameter.Work_EndDate.Ticks)
                    {
                        workingContract.Contract_EndDate         = Parameter.Work_EndDate;
                        workingContract.IsContractEndDateDefined = true;
                        workingContract.Save(Connection, Transaction);
                    }
                }
            }

            var activeTimeFrame = cls_Get_Active_CalculationTimeFrame.Invoke(Connection, Transaction, securityTicket).Result;

            var timeframes   = cls_Get_CalculationTimeFramesForTenant.Invoke(Connection, Transaction, securityTicket).Result.ToList();
            var resultFrames = timeframes.Where(i => i.CalculationTimeframe_StartDate.Year == employmentRelationship.Work_StartDate.Year).ToList();
            if (resultFrames.Count == 0)
            {
                var newFrame    = new ORM_CMN_CAL_CalculationTimeframe();
                int currentYear = Parameter.Work_StartDate.Year;
                while (currentYear < activeTimeFrame.CalculationTimeframe_StartDate.Year)
                {
                    if (!timeframes.Any(i => i.CalculationTimeframe_StartDate.Year == currentYear))
                    {
                        newFrame.CalculationTimeframe_StartDate        = new DateTime(currentYear, 1, 1);
                        newFrame.CalculationTimeframe_EstimatedEndDate = new DateTime(currentYear, 12, 31);
                        newFrame.Tenant_RefID = securityTicket.TenantID;
                        newFrame.Save(Connection, Transaction);
                        newFrame = new ORM_CMN_CAL_CalculationTimeframe();
                    }
                    currentYear++;

                    ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe relationshipFrame = new ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe();
                    relationshipFrame.CalculationTimeframe_RefID   = newFrame.CMN_CAL_CalculationTimeframeID;
                    relationshipFrame.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                    relationshipFrame.Tenant_RefID = securityTicket.TenantID;
                    relationshipFrame.Save(Connection, Transaction);
                }
            }
            else
            {
                timeframes = timeframes.Where(i => i.CalculationTimeframe_StartDate.Year < activeTimeFrame.CalculationTimeframe_StartDate.Year && i.CalculationTimeframe_StartDate.Year >= employmentRelationship.Work_StartDate.Year).ToList();
                foreach (var timeframe in timeframes)
                {
                    ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe.Query relationshipFrameQuery = new ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe.Query();
                    relationshipFrameQuery.CalculationTimeframe_RefID   = timeframe.CMN_CAL_CalculationTimeframeID;
                    relationshipFrameQuery.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                    relationshipFrameQuery.Tenant_RefID = securityTicket.TenantID;
                    List <ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe> oldContractFrames = ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe.Query.Search(Connection, Transaction, relationshipFrameQuery);
                    if (oldContractFrames.Count == 0)
                    {
                        ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe relationshipFrame = new ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe();
                        relationshipFrame.CalculationTimeframe_RefID   = timeframe.CMN_CAL_CalculationTimeframeID;
                        relationshipFrame.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                        relationshipFrame.Tenant_RefID = securityTicket.TenantID;
                        relationshipFrame.Save(Connection, Transaction);
                    }
                }
            }



            P_L5EM_GAERCTFFE_1405 timeFrameParam = new P_L5EM_GAERCTFFE_1405();
            timeFrameParam.EmployeeID = employee.CMN_BPT_EMP_EmployeeID;
            L5EM_GAERCTFFE_1405 employeeTimeFrame = cls_Get_Active_EmployeeRelationshipTimeFrame_For_EmployeeID.Invoke(Connection, Transaction, timeFrameParam, securityTicket).Result;
            if (employeeTimeFrame == null)
            {
                ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe timeFrame = new ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe();
                timeFrame.CalculationTimeframe_RefID   = activeTimeFrame.CMN_CAL_CalculationTimeframeID;
                timeFrame.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                timeFrame.Tenant_RefID = securityTicket.TenantID;
                timeFrame.Save(Connection, Transaction);
                CSV2Core.DlTrace.Trace("success timeFrame");
            }

            //save employee professions
            P_L5EM_SEP_1447 saveProfessionsPar = new P_L5EM_SEP_1447();
            saveProfessionsPar.Employee_RefID    = employee.CMN_BPT_EMP_EmployeeID;
            saveProfessionsPar.FunctionHistories = Parameter.FunctionHistories;
            cls_Save_EmployeeFunctionHistory.Invoke(Connection, Transaction, saveProfessionsPar, securityTicket);
            CSV2Core.DlTrace.Trace("success employee function history");

            //save workplace histories
            P_L5EM_SWPH_1625 saveWorkplaceHistoryPar = new P_L5EM_SWPH_1625();
            saveWorkplaceHistoryPar.Employee_RefID     = employee.CMN_BPT_EMP_EmployeeID;
            saveWorkplaceHistoryPar.WorkplaceHistories = Parameter.WorkplaceHistories;
            cls_Save_WorkplaceHistories.Invoke(Connection, Transaction, saveWorkplaceHistoryPar, securityTicket);
            CSV2Core.DlTrace.Trace("success workplaceHistories");

            P_L5EM_SUED_1648 saveDocuments = new P_L5EM_SUED_1648();
            saveDocuments.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
            saveDocuments.Documents      = Parameter.Documents;
            cls_Save_Uploaded_Employee_Document.Invoke(Connection, Transaction, saveDocuments, securityTicket);
            CSV2Core.DlTrace.Trace("success documents");

            P_L5EM_SEQS_0959 saveSkillsPar = new P_L5EM_SEQS_0959();
            saveSkillsPar.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
            saveSkillsPar.Skills         = Parameter.Skills;
            cls_Save_Employee_QualificationSkills.Invoke(Connection, Transaction, saveSkillsPar, securityTicket);
            CSV2Core.DlTrace.Trace("success skills");

            CSV2Core.DlTrace.Trace("AccountID :" + Parameter.USR_AccountID);

            if (Parameter.USR_AccountID != null && Parameter.USR_AccountID != Guid.Empty)
            {
                CSV2Core.DlTrace.Trace("success param");

                ORM_USR_Account account = new ORM_USR_Account();
                if (Parameter.USR_AccountID != Guid.Empty)
                {
                    var result = account.Load(Connection, Transaction, Parameter.USR_AccountID);
                    if (account.USR_AccountID == Guid.Empty)
                    {
                        account.USR_AccountID = Guid.NewGuid();
                        account.AccountType   = 2;
                    }
                    account.Username = Parameter.username;
                    account.DefaultLanguage_RefID     = Parameter.LanguageID;
                    account.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
                    account.Tenant_RefID = securityTicket.TenantID;
                    account.Save(Connection, Transaction);


                    var personToAccountQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query();
                    personToAccountQuery.Tenant_RefID      = securityTicket.TenantID;
                    personToAccountQuery.USR_Account_RefID = account.USR_AccountID;
                    personToAccountQuery.IsDeleted         = false;
                    var personToAccounts = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, personToAccountQuery);
                    if (personToAccounts.Count != 0)
                    {
                        ORM_CMN_PER_PersonInfo_2_Account personToAccount = personToAccounts[0];
                        personToAccount.CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
                        personToAccount.USR_Account_RefID        = account.USR_AccountID;
                        personToAccount.Tenant_RefID             = securityTicket.TenantID;
                        personToAccount.Save(Connection, Transaction);
                    }
                    else
                    {
                        ORM_CMN_PER_PersonInfo_2_Account personToAccount = new ORM_CMN_PER_PersonInfo_2_Account();
                        personToAccount.CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
                        personToAccount.USR_Account_RefID        = account.USR_AccountID;
                        personToAccount.Tenant_RefID             = securityTicket.TenantID;
                        personToAccount.Save(Connection, Transaction);
                    }
                }



                if (Parameter.Rights != null)
                {
                    foreach (var rightsParam in Parameter.Rights)
                    {
                        if (rightsParam.RightAssinmentID == Guid.Empty && rightsParam.RightID != Guid.Empty)
                        {
                            var right2account = new ORM_USR_Account_2_FunctionLevelRight();
                            right2account.Account_RefID            = Parameter.USR_AccountID;
                            right2account.FunctionLevelRight_RefID = rightsParam.RightID;
                            right2account.Tenant_RefID             = securityTicket.TenantID;
                            right2account.Save(Connection, Transaction);
                            CSV2Core.DlTrace.Trace("success save right: " + right2account.FunctionLevelRight_RefID);
                        }

                        if (rightsParam.RightAssinmentID != Guid.Empty && rightsParam.RightID == Guid.Empty)
                        {
                            var right2account = new ORM_USR_Account_2_FunctionLevelRight();
                            if (rightsParam.RightAssinmentID != Guid.Empty)
                            {
                                var result = right2account.Load(Connection, Transaction, rightsParam.RightAssinmentID);
                                if (result.Status != FR_Status.Success || right2account.AssignmentID == Guid.Empty)
                                {
                                    var error = new FR_Guid();
                                    error.ErrorMessage = "No Such ID";
                                    error.Status       = FR_Status.Error_Internal;
                                    return(error);
                                }
                            }
                            right2account.IsDeleted = true;
                            right2account.Save(Connection, Transaction);
                            CSV2Core.DlTrace.Trace("success save right2Acc: " + right2account.FunctionLevelRight_RefID);
                        }
                    }
                }
            }

            CSV2Core.DlTrace.Trace("emp id wtf " + Parameter.CMN_BPT_EMP_EmployeeID);

            if (Parameter.CMN_BPT_EMP_EmployeeID == Guid.Empty || resignationDateChanged)
            {
                var enterpriseService          = InfrastructureFactory.CreateEnterpriseService();
                KeyPerformanceIndicator action = new KeyPerformanceIndicator();
                action.PerformedByAccountID     = securityTicket.AccountID;
                action.PerformedByApplicationID = Parameter.ApplicationID;
                action.PerformedOn               = DateTime.Now;
                action.PerformedByTenantID       = securityTicket.TenantID;
                action.KeyPerformanceIndicatorID = Guid.Parse("4dda967a-5399-4929-afae-7af64699895b");
                action.Value = cls_Get_Employees_For_Tenant.Invoke(Connection, Transaction, securityTicket).Result.Where(i => i.Work_EndDate.Ticks == 0 || i.Work_EndDate.Ticks > DateTime.Now.Ticks).ToArray().Length;

                var result = enterpriseService.SendMessage(action.ToPayload(), KeyPerformanceIndicator.MESSAGE_TYPE, Parameter.ApplicationID, EMessageRecipient.CUSTOMER_MANAGEMENT_PLATFORM);
                // ServerLog.Instance.Info("Enterprise message sending " + (result.Code == 200 ? "successful" : "failed"));
                CSV2Core.DlTrace.Trace("success send kpi");
            }

            Parameter.TaxInfoParameter.EmployeeID = employee.CMN_BPT_EMP_EmployeeID;
            Parameter.TaxInfoParameter.CMN_BPT_BusinessParticipantID = bParticipant.CMN_BPT_BusinessParticipantID;
            cls_Save_Employee_TaxInformation.Invoke(Connection, Transaction, Parameter.TaxInfoParameter, securityTicket);
            cls_Save_Employee_BankAccount.Invoke(Connection, Transaction, Parameter.BankAccountParameter, securityTicket);
            Parameter.SocialSecurity.CMN_PER_PersonInfoID          = person.CMN_PER_PersonInfoID;
            Parameter.SocialSecurity.CMN_BPT_EMP_EmployeeID        = employee.CMN_BPT_EMP_EmployeeID;
            Parameter.SocialSecurity.CMN_BPT_BusinessParticipantID = bParticipant.CMN_BPT_BusinessParticipantID;
            cls_Save_Employee_SocialSecurity.Invoke(Connection, Transaction, Parameter.SocialSecurity, securityTicket);

            returnValue.Result = employee.CMN_BPT_EMP_EmployeeID;
            return(returnValue);

            #endregion UserCode
        }
Example #2
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L6LR_SLR_1142 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            ORM_CMN_BPT_STA_AbsenceReason.Query selectedLeaveTypeQuery = new ORM_CMN_BPT_STA_AbsenceReason.Query();
            selectedLeaveTypeQuery.Tenant_RefID = securityTicket.TenantID;
            selectedLeaveTypeQuery.CMN_BPT_STA_AbsenceReasonID = Parameter.LeaveRequest.AbsenceReason_RefID;
            selectedLeaveTypeQuery.IsDeleted = false;

            var selectedLeaveType = ORM_CMN_BPT_STA_AbsenceReason.Query.Search(Connection, Transaction, selectedLeaveTypeQuery).FirstOrDefault();

            LeaveRequestUtils leaveRequestUtils = new LeaveRequestUtils();

            P_L5LR_SELR_255 par      = Parameter.LeaveRequest;
            L6TN_GSFT_1017  settings = cls_Get_Settings_For_Tenant.Invoke(Connection, Transaction, securityTicket).Result;
            par.NumberOfResponsiblePersonsRequiredToApprove = settings.NumberOfResponsiblePersonsRequiredToApprove;
            if (settings.NumberOfResponsiblePersonsRequiredToApprove == 0 || !Parameter.IsAuthRequired)
            {
                par.IsApprovalProcessOpened = false;
                par.IsApproved = true;
            }
            Guid leaveRequestID = cls_Save_Employee_LeaveRequest.Invoke(Connection, Transaction, par, securityTicket).Result;
            returnValue.Result = leaveRequestID;
            P_L5CT_GER2AAR_1258 getParam = new P_L5CT_GER2AAR_1258();
            getParam.AbsenceReasonID = Parameter.LeaveRequest.AbsenceReason_RefID;
            getParam.ForEmployeeID   = Parameter.LeaveRequest.RequestedFor_Employee_RefID;
            L5CT_GER2AAR_1258 wc2aar = cls_Get_EmploymentRelationships_2_AllowedAbsenceReasons.Invoke(Connection, Transaction, getParam, securityTicket).Result;
            L5EM_GEFE_1150_WorkingContract activeWorkingContract = new L5EM_GEFE_1150_WorkingContract();
            P_L5EM_GEFE_1150 param = new P_L5EM_GEFE_1150();
            param.EmployeeID = Parameter.LeaveRequest.RequestedFor_Employee_RefID;
            var employeeData = cls_Get_Employee_For_EmployeeID.Invoke(Connection, Transaction, param, securityTicket).Result;
            if (employeeData != null && employeeData.WorkingContracts != null)
            {
                activeWorkingContract = employeeData.WorkingContracts.FirstOrDefault(t => t.IsContract_Active == true);
                if (wc2aar == null)
                {
                    if (activeWorkingContract != null)
                    {
                        ORM_CMN_BPT_EMP_WorkingContract_AllowedAbsenceReason workingContractToabsenceReason = new ORM_CMN_BPT_EMP_WorkingContract_AllowedAbsenceReason();
                        workingContractToabsenceReason.ContractAllowedAbsence_per_Month = 0;
                        workingContractToabsenceReason.WorkingContract_RefID            = activeWorkingContract.CMN_BPT_EMP_WorkingContractID;
                        workingContractToabsenceReason.IsAbsenceCalculated_InDays       = activeWorkingContract.IsWorkTimeCalculated_InDays;
                        workingContractToabsenceReason.IsAbsenceCalculated_InHours      = activeWorkingContract.IsWorkTimeCalculated_InHours;
                        workingContractToabsenceReason.ContractAllowedAbsence_per_Month = 0;
                        workingContractToabsenceReason.STA_AbsenceReason_RefID          = Parameter.LeaveRequest.AbsenceReason_RefID;
                        workingContractToabsenceReason.Tenant_RefID = securityTicket.TenantID;
                        workingContractToabsenceReason.Save(Connection, Transaction);
                    }
                }
            }


            // update statistics ************************************************
            var timeFrame = cls_Get_CalculationTimeFramesForTenant.Invoke(Connection, Transaction, securityTicket).Result.Where(x => x.CalculationTimeframe_StartDate.Year == par.StartTime.Year).FirstOrDefault();
            if (timeFrame == null)
            {
                ORM_CMN_CAL_CalculationTimeframe timeFramePar = new ORM_CMN_CAL_CalculationTimeframe();
                timeFramePar.CalculationTimeframe_StartDate        = new DateTime(par.StartTime.Year, 1, 1);
                timeFramePar.CalculationTimefrate_EndDate          = new DateTime(0);
                timeFramePar.CalculationTimeframe_EstimatedEndDate = new DateTime(par.StartTime.Year, 12, 31);
                timeFramePar.IsCalculationTimeframe_Active         = false;
                timeFramePar.Tenant_RefID = securityTicket.TenantID;
                timeFramePar.Save(Connection, Transaction);
                L5EM_GEFT_0959[] employees = cls_Get_Employees_For_Tenant.Invoke(Connection, Transaction, securityTicket).Result;
                foreach (var emp in employees)
                {
                    ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe workingContactTimeFrame = new ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe();
                    workingContactTimeFrame.CalculationTimeframe_RefID = timeFramePar.CMN_CAL_CalculationTimeframeID;
                    workingContactTimeFrame.CMN_BPT_EMP_EmploymentRelationship_TimeframeID = emp.CMN_BPT_EMP_EmploymentRelationshipID;
                    workingContactTimeFrame.Tenant_RefID = securityTicket.TenantID;
                    workingContactTimeFrame.Save(Connection, Transaction);
                }

                ORM_CMN_BPT_EMP_Employee_AbsenceReason_TimeframeStatistic timeFrameStatisticsPar = new ORM_CMN_BPT_EMP_Employee_AbsenceReason_TimeframeStatistic();
                timeFrameStatisticsPar.AbsenceReason_RefID        = par.AbsenceReason_RefID;
                timeFrameStatisticsPar.CalculationTimeframe_RefID = timeFramePar.CMN_CAL_CalculationTimeframeID;
                timeFrameStatisticsPar.Employee_RefID             = par.RequestedFor_Employee_RefID;
                timeFrameStatisticsPar.R_AbsenceCarryOver_InDays  = 0;
                timeFrameStatisticsPar.R_AbsenceCarryOver_InHours = 0;
                double timeToSubtractDays  = 0;
                double timeToSubtractHours = 0;

                if (par.IsApproved)
                {
                    timeToSubtractDays  = Parameter.durationInDays;
                    timeToSubtractHours = Parameter.durationInHours;
                    timeFrameStatisticsPar.R_RequestReservedAbsence_InDays  = 0;
                    timeFrameStatisticsPar.R_RequestReservedAbsence_InHours = 0;
                    timeFrameStatisticsPar.R_AbsenceTimeUsed_InDays         = Parameter.durationInDays;
                    timeFrameStatisticsPar.R_AbsenceTimeUsed_InHours        = Parameter.durationInHours;
                }
                else
                {
                    timeFrameStatisticsPar.R_RequestReservedAbsence_InDays  = Parameter.durationInDays;
                    timeFrameStatisticsPar.R_RequestReservedAbsence_InHours = Parameter.durationInDays;
                    timeFrameStatisticsPar.R_AbsenceTimeUsed_InDays         = 0;
                    timeFrameStatisticsPar.R_AbsenceTimeUsed_InHours        = 0;
                }
                if (wc2aar != null && activeWorkingContract != null)
                {
                    if (wc2aar.IsAbsenceCalculated_InDays)
                    {
                        timeFrameStatisticsPar.R_TotalAllowedAbsenceTime_InDays  = wc2aar.ContractAllowedAbsence_per_Month - timeToSubtractDays;
                        timeFrameStatisticsPar.R_TotalAllowedAbsenceTime_InHours = WeeklyOfficeHoursUtils.DaysToHoursPeriod(leaveRequestUtils.PresiPatch(activeWorkingContract.WeeklyOfficeHours), wc2aar.ContractAllowedAbsence_per_Month - timeToSubtractHours);
                    }
                    else
                    {
                        timeFrameStatisticsPar.R_TotalAllowedAbsenceTime_InDays  = WeeklyOfficeHoursUtils.HoursToDaysPeriod(leaveRequestUtils.PresiPatch(activeWorkingContract.WeeklyOfficeHours), wc2aar.ContractAllowedAbsence_per_Month - timeToSubtractDays);
                        timeFrameStatisticsPar.R_TotalAllowedAbsenceTime_InHours = wc2aar.ContractAllowedAbsence_per_Month - timeToSubtractHours;
                    }
                }
                else
                {
                    timeFrameStatisticsPar.R_TotalAllowedAbsenceTime_InDays  = 0;
                    timeFrameStatisticsPar.R_TotalAllowedAbsenceTime_InHours = 0;
                }
                timeFrameStatisticsPar.Tenant_RefID = securityTicket.TenantID;
                timeFrameStatisticsPar.Save(Connection, Transaction);
            }
            else
            {
                P_L5EM_GEATFSbRTFE_1423 statParam = new P_L5EM_GEATFSbRTFE_1423();
                statParam.absenceReasonID = Parameter.LeaveRequest.AbsenceReason_RefID;
                statParam.employeeID      = Parameter.LeaveRequest.RequestedFor_Employee_RefID;
                statParam.timeFrameID     = timeFrame.CMN_CAL_CalculationTimeframeID;
                var statistics = cls_Get_Employee_AbsenceReason_TimeframeStatistic_byReasonTimeFrameEmployee.Invoke(Connection, Transaction, statParam, securityTicket).Result;
                if (statistics != null)
                {
                    P_L5EM_SEARTFS_1356 updateStatisticsParam = new P_L5EM_SEARTFS_1356();
                    updateStatisticsParam.CMN_BPT_EMP_Employee_AbsenceReason_TimeframeStatisticsID = statistics.CMN_BPT_EMP_Employee_AbsenceReason_TimeframeStatisticsID;
                    updateStatisticsParam.Employee_RefID             = statistics.Employee_RefID;
                    updateStatisticsParam.CalculationTimeframe_RefID = statistics.CalculationTimeframe_RefID;
                    updateStatisticsParam.AbsenceReason_RefID        = statistics.AbsenceReason_RefID;

                    updateStatisticsParam.R_AbsenceCarryOver_InDays  = statistics.R_AbsenceCarryOver_InDays;
                    updateStatisticsParam.R_AbsenceCarryOver_InHours = statistics.R_AbsenceCarryOver_InHours;

                    if (par.IsApproved)
                    {
                        updateStatisticsParam.R_TotalAllowedAbsenceTime_InDays  = statistics.R_TotalAllowedAbsenceTime_InDays - Parameter.durationInDays;
                        updateStatisticsParam.R_TotalAllowedAbsenceTime_InHours = statistics.R_TotalAllowedAbsenceTime_InHours - Parameter.durationInHours;

                        updateStatisticsParam.R_RequestReservedAbsence_InDays  = statistics.R_RequestReservedAbsence_InDays;
                        updateStatisticsParam.R_RequestReservedAbsence_InHours = statistics.R_RequestReservedAbsence_InHours;

                        updateStatisticsParam.R_AbsenceTimeUsed_InDays  = statistics.R_AbsenceTimeUsed_InDays + Parameter.durationInDays;
                        updateStatisticsParam.R_AbsenceTimeUsed_InHours = statistics.R_AbsenceTimeUsed_InHours + Parameter.durationInHours;
                    }
                    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 + Parameter.durationInDays;
                        updateStatisticsParam.R_RequestReservedAbsence_InHours = statistics.R_RequestReservedAbsence_InHours + Parameter.durationInHours;

                        updateStatisticsParam.R_AbsenceTimeUsed_InDays  = statistics.R_AbsenceTimeUsed_InDays;
                        updateStatisticsParam.R_AbsenceTimeUsed_InHours = statistics.R_AbsenceTimeUsed_InHours;
                    }
                    var res = cls_Save_Employee_AbsenceReason_TimeframeStatistic.Invoke(Connection, Transaction, updateStatisticsParam, securityTicket);
                }
                else
                {
                    ORM_CMN_BPT_EMP_Employee_AbsenceReason_TimeframeStatistic timeFrameStatisticsPar = new ORM_CMN_BPT_EMP_Employee_AbsenceReason_TimeframeStatistic();
                    timeFrameStatisticsPar.AbsenceReason_RefID        = par.AbsenceReason_RefID;
                    timeFrameStatisticsPar.CalculationTimeframe_RefID = timeFrame.CMN_CAL_CalculationTimeframeID;
                    timeFrameStatisticsPar.Employee_RefID             = par.RequestedFor_Employee_RefID;
                    timeFrameStatisticsPar.R_AbsenceCarryOver_InDays  = 0;
                    timeFrameStatisticsPar.R_AbsenceCarryOver_InHours = 0;
                    double timeToSubtractDays  = 0;
                    double timeToSubtractHours = 0;

                    if (par.IsApproved)
                    {
                        timeToSubtractDays  = Parameter.durationInDays;
                        timeToSubtractHours = Parameter.durationInHours;
                        timeFrameStatisticsPar.R_RequestReservedAbsence_InDays  = 0;
                        timeFrameStatisticsPar.R_RequestReservedAbsence_InHours = 0;
                        timeFrameStatisticsPar.R_AbsenceTimeUsed_InDays         = Parameter.durationInDays;
                        timeFrameStatisticsPar.R_AbsenceTimeUsed_InHours        = Parameter.durationInHours;
                    }
                    else
                    {
                        timeFrameStatisticsPar.R_RequestReservedAbsence_InDays  = Parameter.durationInDays;
                        timeFrameStatisticsPar.R_RequestReservedAbsence_InHours = Parameter.durationInDays;
                        timeFrameStatisticsPar.R_AbsenceTimeUsed_InDays         = 0;
                        timeFrameStatisticsPar.R_AbsenceTimeUsed_InHours        = 0;
                    }
                    if (wc2aar != null && activeWorkingContract != null)
                    {
                        timeFrameStatisticsPar.R_TotalAllowedAbsenceTime_InDays  = 0;
                        timeFrameStatisticsPar.R_TotalAllowedAbsenceTime_InHours = 0;

                        timeFrameStatisticsPar.R_TotalAllowedAbsenceTime_InDays  = 0;
                        timeFrameStatisticsPar.R_TotalAllowedAbsenceTime_InHours = 0;
                    }
                    else
                    {
                        timeFrameStatisticsPar.R_TotalAllowedAbsenceTime_InDays  = 0;
                        timeFrameStatisticsPar.R_TotalAllowedAbsenceTime_InHours = 0;
                    }
                    timeFrameStatisticsPar.Tenant_RefID = securityTicket.TenantID;
                    timeFrameStatisticsPar.Save(Connection, Transaction);
                }
            }

            //cls_get

            // statistics update end :)

            //Create daily work schedule
            DateTime startTime = Parameter.LeaveRequest.StartTime;
            while (startTime.Date <= Parameter.LeaveRequest.EndTime.Date)
            {
                ORM_CMN_STR_PPS_DailyWorkSchedule.Query scheduleQuery = new ORM_CMN_STR_PPS_DailyWorkSchedule.Query();
                scheduleQuery.Tenant_RefID    = securityTicket.TenantID;
                scheduleQuery.IsDeleted       = false;
                scheduleQuery.WorkSheduleDate = startTime.Date;
                scheduleQuery.Employee_RefID  = Parameter.LeaveRequest.RequestedFor_Employee_RefID;
                List <ORM_CMN_STR_PPS_DailyWorkSchedule> workSechedules = ORM_CMN_STR_PPS_DailyWorkSchedule.Query.Search(Connection, Transaction, scheduleQuery);

                if (workSechedules.Count == 0)
                {
                    ORM_CMN_STR_PPS_DailyWorkSchedule schedule = new ORM_CMN_STR_PPS_DailyWorkSchedule();
                    var workingTimeInHours   = 0.0;
                    var daysFromContractTerm = WeeklyOfficeHoursUtils.DaysFromContractTerm(leaveRequestUtils.PresiPatch(activeWorkingContract.WeeklyOfficeHours));
                    var dayFromContractTerm  = daysFromContractTerm.FirstOrDefault(x => x.dayOfWeek == startTime.DayOfWeek);

                    if (dayFromContractTerm != null)
                    {
                        workingTimeInHours = (double)dayFromContractTerm.hours;
                    }

                    TimeSpan workingTimeSpan = TimeSpan.FromHours(workingTimeInHours);
                    var      workingHours    = workingTimeSpan.Hours;
                    var      workingMinutes  = workingTimeSpan.Minutes;
                    var      workingSeconds  = workingTimeSpan.Seconds;


                    DateTime detailStartTime;;
                    DateTime detailEndTime;

                    if (startTime.Date == Parameter.LeaveRequest.StartTime.Date)
                    {
                        detailStartTime = startTime;
                        if (startTime.Hour + workingTimeInHours < 24)
                        {
                            var newEndTime = startTime.TimeOfDay + workingTimeSpan;
                            detailEndTime = new DateTime(startTime.Year, startTime.Month, startTime.Day, newEndTime.Hours, newEndTime.Minutes, newEndTime.Seconds);
                        }
                        else
                        {
                            detailEndTime = new DateTime(startTime.Year, startTime.Month, startTime.Day, 23, 59, 59);
                        }
                    }
                    else if (startTime.Date == Parameter.LeaveRequest.EndTime.Date)
                    {
                        if (Parameter.LeaveRequest.EndTime.TimeOfDay > workingTimeSpan)
                        {
                            var newStartTime = Parameter.LeaveRequest.EndTime.TimeOfDay - workingTimeSpan;
                            detailStartTime = new DateTime(startTime.Year, startTime.Month, startTime.Day, newStartTime.Hours, newStartTime.Minutes, newStartTime.Seconds);
                        }
                        else
                        {
                            detailStartTime = new DateTime(startTime.Year, startTime.Month, startTime.Day, 0, 0, 0);
                        }
                        detailEndTime = Parameter.LeaveRequest.EndTime;
                    }
                    else
                    {
                        int hours   = (int)Parameter.WorkTimeStart / (int)60;
                        int mintues = Parameter.WorkTimeStart - hours * 60;
                        detailStartTime = new DateTime(startTime.Year, startTime.Month, startTime.Day, hours, mintues, 0);
                        if (hours + workingTimeSpan.Hours >= 24)
                        {
                            if (mintues + workingTimeSpan.Minutes >= 60)
                            {
                                detailEndTime = new DateTime(startTime.Year, startTime.Month, startTime.Day, hours + workingTimeSpan.Hours - 24, workingTimeSpan.Minutes, workingTimeSpan.Seconds);
                            }
                            else
                            {
                                detailEndTime = new DateTime(startTime.Year, startTime.Month, startTime.Day, hours + workingTimeSpan.Hours - 24, workingTimeSpan.Minutes - 60, workingTimeSpan.Seconds);
                            }
                        }
                        else
                        {
                            if (mintues + workingTimeSpan.Minutes >= 60)
                            {
                                detailEndTime = new DateTime(startTime.Year, startTime.Month, startTime.Day, hours + workingTimeSpan.Hours, workingTimeSpan.Minutes - 60, workingTimeSpan.Seconds);
                            }
                            else
                            {
                                detailEndTime = new DateTime(startTime.Year, startTime.Month, startTime.Day, hours + workingTimeSpan.Hours, workingTimeSpan.Minutes, workingTimeSpan.Seconds);
                            }
                        }
                    }

                    schedule.Employee_RefID                         = Parameter.LeaveRequest.RequestedFor_Employee_RefID;
                    schedule.ContractWorkerText                     = "";
                    schedule.BreakDurationTime_in_sec               = 0;
                    schedule.IsBreakTimeManualySpecified            = false;
                    schedule.IsWorkShedule_Confirmed                = false;
                    schedule.R_ContractSpecified_WorkingTime_in_sec = (int)workingTimeSpan.TotalSeconds;
                    if (selectedLeaveType.IsLeaveTimeReducing_WorkingHours)
                    {
                        schedule.R_WorkDay_Duration_in_sec = (int)detailEndTime.Subtract(detailStartTime).TotalSeconds;
                    }
                    else
                    {
                        schedule.R_WorkDay_Duration_in_sec = 0;
                    }
                    schedule.R_WorkDay_Start_in_sec     = (int)new TimeSpan(detailStartTime.Hour, detailStartTime.Minute, detailStartTime.Second).TotalSeconds;
                    schedule.R_WorkDay_End_in_sec       = (int)detailEndTime.Subtract(detailStartTime).TotalSeconds;
                    schedule.SheduleBreakTemplate_RefID = Guid.Empty;
                    schedule.Tenant_RefID          = securityTicket.TenantID;
                    schedule.WorkingSheduleComment = "";
                    schedule.WorkShedule_ConfirmedBy_Account_RefID = Guid.Empty;
                    schedule.WorkSheduleDate = startTime.Date;
                    schedule.InstantiatedWithShiftTemplate_RefID = Guid.Empty;
                    schedule.Save(Connection, Transaction);



                    P_L5DWS_SDWSD_1130 detailParam = new P_L5DWS_SDWSD_1130();
                    detailParam.WorkTime_Start                          = detailStartTime;
                    detailParam.WorkTime_End                            = detailEndTime;
                    detailParam.DailyWorkSchedule_RefID                 = schedule.CMN_STR_PPS_DailyWorkScheduleID;
                    detailParam.IsWorkBreak                             = false;
                    detailParam.SheduleForWorkplace_RefID               = Guid.Empty;
                    detailParam.AbsenceReason_RefID                     = Parameter.LeaveRequest.AbsenceReason_RefID;
                    detailParam.RequestedBy_Employee_RefID              = Parameter.LeaveRequest.RequestedBy_Employee_RefID;
                    detailParam.RequestedFor_Employee_RefID             = Parameter.LeaveRequest.RequestedFor_Employee_RefID;
                    detailParam.CMN_BPT_EMP_Employee_LeaveRequest_RefID = leaveRequestID;
                    detailParam.createRequest                           = false;
                    cls_Save_Employee_DailyWorkSchedule_Detail.Invoke(Connection, Transaction, detailParam, securityTicket);
                }
                else
                {
                    var dwsParam = new P_L5DWS_GDWSWDFT_0946();
                    dwsParam.WorkSheduleDate = startTime.Date;
                    var resultDailyWorkSchedule        = cls_Get_DailyWorkSchedules_WithDetails_For_Date.Invoke(Connection, Transaction, dwsParam, securityTicket);
                    LeaveRequestUtils leaveRequestUtil = new LeaveRequestUtils();
                    var dailySchedule = resultDailyWorkSchedule.Result.FirstOrDefault(i => i.Employee_RefID == Parameter.LeaveRequest.RequestedFor_Employee_RefID);
                    foreach (var detail in dailySchedule.Details)
                    {
                        var durationInDays  = leaveRequestUtil.LeaveRequestDuration(detail.FromTime_as_DateTime, detail.ToTime_as_DateTime, Parameter.Events, Parameter.Employees.FirstOrDefault(x => x.CMN_BPT_EMP_EmployeeID == Parameter.LeaveRequest.RequestedFor_Employee_RefID), true);
                        var durationInHours = leaveRequestUtil.LeaveRequestDuration(detail.FromTime_as_DateTime, detail.ToTime_as_DateTime, Parameter.Events, Parameter.Employees.FirstOrDefault(x => x.CMN_BPT_EMP_EmployeeID == Parameter.LeaveRequest.RequestedFor_Employee_RefID), false);
                        P_L5DWS_DDWSDFIDL_1014 deleteParam = new P_L5DWS_DDWSDFIDL_1014();
                        deleteParam.DailyWorkSchedule_DetailID = detail.CMN_STR_PPS_DailyWorkSchedule_DetailID;

                        var scheduleID = cls_Delete_Employee_DailyWorkSchedule_Detail.Invoke(Connection, Transaction, deleteParam, securityTicket);
                    }
                    ORM_CMN_STR_PPS_DailyWorkSchedule schedule = new ORM_CMN_STR_PPS_DailyWorkSchedule();
                    schedule.Load(Connection, Transaction, dailySchedule.CMN_STR_PPS_DailyWorkScheduleID);

                    var workingTimeInHours   = 0;
                    var daysFromContractTerm = WeeklyOfficeHoursUtils.DaysFromContractTerm(leaveRequestUtils.PresiPatch(activeWorkingContract.WeeklyOfficeHours));
                    var dayFromContractTerm  = daysFromContractTerm.FirstOrDefault(x => x.dayOfWeek == startTime.DayOfWeek);

                    if (dayFromContractTerm != null)
                    {
                        workingTimeInHours = (int)dayFromContractTerm.hours;
                    }


                    DateTime detailStartTime;;
                    DateTime detailEndTime;

                    if (startTime.Date == Parameter.LeaveRequest.StartTime.Date)
                    {
                        detailStartTime = startTime;
                        detailEndTime   = new DateTime(startTime.Year, startTime.Month, startTime.Day, 23, 59, 59);
                    }
                    else if (startTime.Date == Parameter.LeaveRequest.EndTime.Date)
                    {
                        detailStartTime = new DateTime(startTime.Year, startTime.Month, startTime.Day, 0, 0, 0);
                        detailEndTime   = Parameter.LeaveRequest.EndTime;
                    }
                    else
                    {
                        detailStartTime = new DateTime(startTime.Year, startTime.Month, startTime.Day, 0, 0, 0);
                        detailEndTime   = new DateTime(startTime.Year, startTime.Month, startTime.Day, 23, 59, 59);
                    }

                    schedule.Employee_RefID                         = Parameter.LeaveRequest.RequestedFor_Employee_RefID;
                    schedule.ContractWorkerText                     = "";
                    schedule.BreakDurationTime_in_sec               = 0;
                    schedule.IsBreakTimeManualySpecified            = false;
                    schedule.IsWorkShedule_Confirmed                = false;
                    schedule.R_ContractSpecified_WorkingTime_in_sec = workingTimeInHours * 360;
                    if (selectedLeaveType.IsLeaveTimeReducing_WorkingHours)
                    {
                        schedule.R_WorkDay_Duration_in_sec = (int)detailEndTime.Subtract(detailStartTime).TotalSeconds;
                    }
                    else
                    {
                        schedule.R_WorkDay_Duration_in_sec = 0;
                    }
                    schedule.R_WorkDay_Start_in_sec     = (int)new TimeSpan(detailStartTime.Hour, detailStartTime.Minute, detailStartTime.Second).TotalSeconds;
                    schedule.R_WorkDay_End_in_sec       = schedule.R_WorkDay_Start_in_sec + (int)detailEndTime.Subtract(detailStartTime).TotalSeconds;
                    schedule.SheduleBreakTemplate_RefID = Guid.Empty;
                    schedule.Tenant_RefID          = securityTicket.TenantID;
                    schedule.WorkingSheduleComment = "";
                    schedule.WorkShedule_ConfirmedBy_Account_RefID = Guid.Empty;
                    schedule.WorkSheduleDate = startTime.Date;
                    schedule.InstantiatedWithShiftTemplate_RefID = Guid.Empty;
                    schedule.Save(Connection, Transaction);



                    P_L5DWS_SDWSD_1130 detailParam = new P_L5DWS_SDWSD_1130();
                    detailParam.WorkTime_Start                          = detailStartTime;
                    detailParam.WorkTime_End                            = detailEndTime;
                    detailParam.DailyWorkSchedule_RefID                 = schedule.CMN_STR_PPS_DailyWorkScheduleID;
                    detailParam.IsWorkBreak                             = false;
                    detailParam.SheduleForWorkplace_RefID               = Guid.Empty;
                    detailParam.AbsenceReason_RefID                     = Parameter.LeaveRequest.AbsenceReason_RefID;
                    detailParam.RequestedBy_Employee_RefID              = Parameter.LeaveRequest.RequestedBy_Employee_RefID;
                    detailParam.RequestedFor_Employee_RefID             = Parameter.LeaveRequest.RequestedFor_Employee_RefID;
                    detailParam.CMN_BPT_EMP_Employee_LeaveRequest_RefID = leaveRequestID;
                    detailParam.createRequest                           = false;
                    cls_Save_Employee_DailyWorkSchedule_Detail.Invoke(Connection, Transaction, detailParam, securityTicket);
                }
                startTime = startTime.AddDays(1);
            }

            return(returnValue);

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



            ORM_CMN_BPT_EMP_ContractAbsenceAdjustment adjustment = new ORM_CMN_BPT_EMP_ContractAbsenceAdjustment();
            if (Parameter.AdjustmentID != Guid.Empty)
            {
                var result = adjustment.Load(Connection, Transaction, Parameter.AdjustmentID);
                if (result.Status != FR_Status.Success || adjustment.CMN_BPT_EMP_ContractAbsenceAdjustmentID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            Guid workingContractTimeFrameID = Guid.Empty;
            var  timeFrame = cls_Get_CalculationTimeFramesForTenant.Invoke(Connection, Transaction, securityTicket).Result.Where(x => x.CalculationTimeframe_StartDate.Year == Parameter.Year).FirstOrDefault();
            if (timeFrame == null)
            {
                ORM_CMN_CAL_CalculationTimeframe timeFramePar = new ORM_CMN_CAL_CalculationTimeframe();
                timeFramePar.CalculationTimeframe_StartDate        = new DateTime(Parameter.Year, 1, 1);
                timeFramePar.CalculationTimefrate_EndDate          = new DateTime(0);
                timeFramePar.CalculationTimeframe_EstimatedEndDate = new DateTime(Parameter.Year, 12, 31);
                timeFramePar.IsCalculationTimeframe_Active         = false;
                timeFramePar.Tenant_RefID = securityTicket.TenantID;
                timeFramePar.Save(Connection, Transaction);
                L5EM_GEFT_0959[] employees = cls_Get_Employees_For_Tenant.Invoke(Connection, Transaction, securityTicket).Result;
                foreach (var emp in employees)
                {
                    ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe workingContractTimeFrame = new ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe();
                    workingContractTimeFrame.CalculationTimeframe_RefID   = timeFramePar.CMN_CAL_CalculationTimeframeID;
                    workingContractTimeFrame.EmploymentRelationship_RefID = emp.CMN_BPT_EMP_EmploymentRelationshipID;
                    workingContractTimeFrame.Tenant_RefID = securityTicket.TenantID;
                    workingContractTimeFrame.Save(Connection, Transaction);
                    if (emp.CMN_BPT_EMP_EmployeeID == Parameter.EmployeeID)
                    {
                        workingContractTimeFrameID = workingContractTimeFrame.CMN_BPT_EMP_EmploymentRelationship_TimeframeID;
                    }
                }
            }
            else
            {
                P_L5EM_GERTFFETF_1129 param = new P_L5EM_GERTFFETF_1129();
                param.EmployeeID             = Parameter.EmployeeID;
                param.CalculationTimeframeID = timeFrame.CMN_CAL_CalculationTimeframeID;
                L5EM_GERTFFETF_1129 workingContractTimeFrame = cls_Get_EmploymentRelationshipTimeFrame_For_Employee_And_TimeFrame.Invoke(Connection, Transaction, param, securityTicket).Result;
                if (workingContractTimeFrame == null)
                {
                    P_L5EM_GEFE_1150 empPar = new P_L5EM_GEFE_1150();
                    empPar.EmployeeID = Parameter.EmployeeID;
                    L5EM_GEFE_1150 employee = cls_Get_Employee_For_EmployeeID.Invoke(Connection, Transaction, empPar, securityTicket).Result;
                    ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe workingContractTimeFrameNew = new ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe();
                    workingContractTimeFrameNew.CalculationTimeframe_RefID   = timeFrame.CMN_CAL_CalculationTimeframeID;
                    workingContractTimeFrameNew.EmploymentRelationship_RefID = employee.CMN_BPT_EMP_EmploymentRelationshipID;
                    workingContractTimeFrameNew.Tenant_RefID = securityTicket.TenantID;
                    workingContractTimeFrameNew.Save(Connection, Transaction);
                    workingContractTimeFrameID = workingContractTimeFrameNew.CMN_BPT_EMP_EmploymentRelationship_TimeframeID;
                }
                else
                {
                    workingContractTimeFrameID = workingContractTimeFrame.CMN_BPT_EMP_EmploymentRelationship_TimeframeID;
                }
            }
            adjustment.AbsenceTime_InMinutes = Parameter.AbsenceTimeInMinutes;
            adjustment.AdjustmentComment     = Parameter.AdjustmentComment;
            adjustment.AbsenceReason_RefID   = Parameter.AbsenceReasonID;
            adjustment.EmploymentRelationship_Timeframe_RefID = workingContractTimeFrameID;
            adjustment.IsManual = Parameter.isManual;
            adjustment.InternalAdjustmentType  = Parameter.InternalAdjustmentType;
            adjustment.TriggeringAccount_RefID = securityTicket.AccountID;
            adjustment.AdjustmentDate          = Parameter.AdjustmentDate;
            adjustment.Tenant_RefID            = securityTicket.TenantID;
            adjustment.IsDeleted = Parameter.isDeleted;
            adjustment.Save(Connection, Transaction);
            returnValue.Result = adjustment.CMN_BPT_EMP_ContractAbsenceAdjustmentID;
            //Put your code here
            return(returnValue);

            #endregion UserCode
        }