private KeyPerformanceIndicator GetKpiData(int franchiseId, string strStartDate, string strEndDate, bool force) { if (UserInfo.CurrentFranchise == null || UserInfo.CurrentFranchise.FranchiseID != franchiseId) { SetCurrentFranchise(franchiseId, UserInfo.ShowInactiveFranchises); } const string key = "KPI_DATA"; KeyPerformanceIndicator kpi = null; if (HttpContext.Session != null && HttpContext.Session[key] != null) { kpi = HttpContext.Session[key] as KeyPerformanceIndicator; } var startDate = DateTime.Parse(strStartDate).Date; var endDate = DateTime.Parse(strEndDate).Date.AddDays(1); if (kpi == null || force) { kpi = AbstractBusinessService.Create <ReportingService>(UserInfo.UserKey).GetKeyPerformanceIndicators( franchiseId, startDate, endDate); Session[key] = kpi; } return(kpi); }
protected static FR_Base Execute(DbConnection Connection, DbTransaction Transaction, P_L5EM_DE_1006 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Base(); //Put your code here P_L5EM_GEFE_1150 par = new P_L5EM_GEFE_1150(); par.EmployeeID = Parameter.CMN_BPT_EMP_EmployeeID; L5EM_GEFE_1150 employee = cls_Get_Employee_For_EmployeeID.Invoke(Connection, Transaction, par, securityTicket).Result; ORM_CMN_BPT_EMP_Employee whereInstanceEmployee = CSV2Core_MySQL.Support.SQLClassFilter.GetDefaultInstance <ORM_CMN_BPT_EMP_Employee>(); whereInstanceEmployee.CMN_BPT_EMP_EmployeeID = employee.CMN_BPT_EMP_EmployeeID; CSV2Core_MySQL.Support.SQLClassFilter.Delete(Connection, Transaction, whereInstanceEmployee); 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.Length; var result = enterpriseService.SendMessage(action.ToPayload(), KeyPerformanceIndicator.MESSAGE_TYPE, Parameter.ApplicationID, EMessageRecipient.CUSTOMER_MANAGEMENT_PLATFORM); ORM_CMN_BPT_EMP_EmploymentRelationship whereInstanceContract = CSV2Core_MySQL.Support.SQLClassFilter.GetDefaultInstance <ORM_CMN_BPT_EMP_EmploymentRelationship>(); whereInstanceContract.CMN_BPT_EMP_EmploymentRelationshipID = employee.CMN_BPT_EMP_EmploymentRelationshipID; CSV2Core_MySQL.Support.SQLClassFilter.Delete(Connection, Transaction, whereInstanceContract); ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query searchInstanceWorkingContract = new ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query(); searchInstanceWorkingContract.WorkingContract_RefID = employee.CMN_BPT_EMP_EmploymentRelationshipID; List <ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract> employmentRelationshipToWorkingContract = ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query.Search(Connection, Transaction, searchInstanceWorkingContract); if (employmentRelationshipToWorkingContract != null) { foreach (var relationShipToContract in employmentRelationshipToWorkingContract) { ORM_CMN_BPT_EMP_WorkingContract workingContractQuery = CSV2Core_MySQL.Support.SQLClassFilter.GetDefaultInstance <ORM_CMN_BPT_EMP_WorkingContract>(); workingContractQuery.CMN_BPT_EMP_WorkingContractID = relationShipToContract.WorkingContract_RefID; CSV2Core_MySQL.Support.SQLClassFilter.Delete(Connection, Transaction, workingContractQuery); ORM_CMN_BPT_EMP_WorkingContract_AllowedAbsenceReason allowedreasons = CSV2Core_MySQL.Support.SQLClassFilter.GetDefaultInstance <ORM_CMN_BPT_EMP_WorkingContract_AllowedAbsenceReason>(); allowedreasons.WorkingContract_RefID = relationShipToContract.WorkingContract_RefID; CSV2Core_MySQL.Support.SQLClassFilter.Delete(Connection, Transaction, allowedreasons); } } return(returnValue); #endregion UserCode }
/// <summary> /// Get the type of structure based on the selected KPA /// </summary> /// <param name="_action">The selected KPA</param> /// <returns>The type of template structure</returns> private TemplateTypes.Template GetTemplateStructure(KeyPerformanceIndicator _indicator) { if (_indicator.TemplateBlock is ITemplateThree) { return(TemplateTypes.Template.TemplateThree); } else if (_indicator.TemplateBlock is ITemplateFour) { return(TemplateTypes.Template.TemplateFour); } else // ITemplateFive { return(TemplateTypes.Template.TemplateFive); } }
/// <summary> /// Generates the report by applying the KPI to each filter /// </summary> /// <param name="filters">The list of filters the user wants to use in the report</param> /// <param name="_option">The KPI option to use in the report</param> public bool GenerateReport(List <string> filters, KpiOption _option) { bool result = true; Content = new Dictionary <string, KeyPerformanceIndicator>(); try { foreach (string filter in filters) { // Get the KPA the user would like to use KeyPerformanceIndicator indicator = GetIndicator(_option); // Get the structure type of the template being used. TemplateStructure = GetTemplateStructure(indicator); if (indicator != null) { // add the filter and the action to the dictionary Content.Add(filter, indicator); } else { MessageBox.Show("An error occured while trying to get the KPA", "Comparison Creation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); result = false; } } } catch (ArgumentNullException) { MessageBox.Show("Argument null exception was thrown", "Comparison Report Creation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); result = false; } catch (ArgumentException) { MessageBox.Show("Argument exception was thrown", "Comparison Report Creation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); result = false; } // Return the result of the creation return(result); }
public void AddKPIsForSalesManager3() { // KPI data #region string jobTitle = "Sales Manager"; string kPI = "New client aquisition exceeds 4 per month."; int minRating = 0; int maxRating = 5; bool makeDefaultScale = false; #endregion Home.GoTo(); Home.LoginAsAdmin(); Menu.Performance.Configure.KPIS.GoTo(); KeyPerformanceIndicator.AddKPI(jobTitle, kPI, minRating, maxRating, makeDefaultScale); Assert.IsTrue(KeyPerformanceIndicator.KPICorrectlyAdded(jobTitle, kPI, minRating, maxRating, makeDefaultScale), $"The KPI: {kPI} for Job Title: {jobTitle} was not correctly added."); }
/// <summary> /// Get the KPI that the user would like to use as the base of the report /// </summary> /// <param name="_option">The KPI Option used to get the KPI</param> /// <returns>The KPI the user wants as the base of the report</returns> private KeyPerformanceIndicator GetIndicator(KpiOption _option) { KeyPerformanceIndicator indicator = null; switch (_option) { case KpiOption.Plan_CurrentPlanDateVsPrPlanDate: indicator = new KeyPerformanceIndicators.Plan.CurrentPlanDateVsPRPlanDate(); break; case KpiOption.Plan_OrigPlanDateMinusPrFullReleaseDateVsCodedLead: indicator = new KeyPerformanceIndicators.Plan.OriginalPlanDateTo2ndLvlReleaseDateVsCodedLead(); break; case KpiOption.Plan_CurrentPlanDateMinusPrFullReleaseDateVsCodedLead: indicator = new KeyPerformanceIndicators.Plan.CurrentPlanDateTo2ndLvlReleaseDateVsCodedLead(); break; case KpiOption.Purch_InitialConfirmationDateVsPrPlanDate: indicator = new KeyPerformanceIndicators.Purch.InitialConfirmationDateVsPRPlanDate(); break; case KpiOption.FollowUp_CurrentConfirmationDateVsInitialConfirmationDate: indicator = new KeyPerformanceIndicators.FollowUp.CurrentConfirmationDateVsInitialConfirmationDate(); break; case KpiOption.FollowUp_FinalConfirmationDateVsInitialConfirmationDate: indicator = new KeyPerformanceIndicators.FollowUp.FinalConfirmationDateVsFinalPlanDate(); break; case KpiOption.FollowUp_ReceiptDateVsCurrentPlanDate: indicator = new KeyPerformanceIndicators.FollowUp.ReceiptDateVsCurrentPlanDate(); break; case KpiOption.FollowUp_ReceiptDateVsOriginalConfirmationDate: indicator = new KeyPerformanceIndicators.FollowUp.ReceiptDateVsOriginalConfirmationDate(); break; case KpiOption.FollowUp_ReceiptDateVsCurrentConfirmationDate: indicator = new KeyPerformanceIndicators.FollowUp.ReceiptDateVsCurrentConfirmationDate(); break; case KpiOption.PlanTwo_MaterialDueOriginalPlannedDate: indicator = new KeyPerformanceIndicators.PlanTwo.MaterialDueOriginalPlannedDate(); break; case KpiOption.PlanTwo_MaterialDueFinalPlannedDate: indicator = new KeyPerformanceIndicators.PlanTwo.MaterialDueFinalPlannedDate(); break; case KpiOption.PlanTwo_PrReleaseDateVsPrCreationDate: indicator = new KeyPerformanceIndicators.PlanTwo.PrReleaseVsPrCreation(); break; case KpiOption.PurchTwo_PrFullyReleaseDateVsPoCreationDate: indicator = new KeyPerformanceIndicators.PurchTwo.PR2ndLvlReleaseDateVsPOCreationDate(); break; case KpiOption.PurchTwo_PoCreationDateVsPoReleaseDate: indicator = new KeyPerformanceIndicators.PurchTwo.POCreationDateVsPOReleaseDate(); break; case KpiOption.PurchTwo_PoReleaseDateVsPoConfirmationDate: indicator = new KeyPerformanceIndicators.PurchTwo.POReleaseDateVsPOConfirmationDate(); break; case KpiOption.FollowUpTwo_PoReleaseToLastPoReceiptDate: indicator = new KeyPerformanceIndicators.FollowUpTwo.PoReleaseToLasteReceiptDate(); break; case KpiOption.PurchSub_PrReleaseVsPoReleaseDate: indicator = new KeyPerformanceIndicators.PurchSub.PRReleaseDateVsPOReleaseDate(); break; case KpiOption.PurchSub_PoCreationDateVsConfirmationEntryDate: indicator = new KeyPerformanceIndicators.PurchSub.POCreationDateVsConfirmationEntry(); break; case KpiOption.PurchTotal_PrReleaseDateToConfirmationEntryDate: indicator = new KeyPerformanceIndicators.PurchTotal.PRReleaseDateToConfirmationEntry(); break; case KpiOption.PurchPlan_PoReleaseVsPrDeliveryDate: indicator = new KeyPerformanceIndicators.PurchPlan.POReleaseVsPRDeliveryDate(); break; case KpiOption.Other_PrsCreated: indicator = new KeyPerformanceIndicators.Other.PRsCreated(); break; case KpiOption.Other_PrsReleased: indicator = new KeyPerformanceIndicators.Other.PRsReleased(); break; case KpiOption.Other_TotalSpend: indicator = new KeyPerformanceIndicators.Other.TotalSpend(); break; case KpiOption.Other_PrValueVsPoValue: indicator = new KeyPerformanceIndicators.Other.PRValueVsPOValue(); break; case KpiOption.Other_HotJobPRs: indicator = new KeyPerformanceIndicators.Other.HotJobPRs(); break; default: break; } // Return the requested indicator return(indicator); }
public OperationResult <Payroll> ProcessPayrollForWeek(DateTime date, int payrollidNotUsed, string FranchiseId, bool persistToDataBase, Guid userKey) { // The date is not getting the end date for the week right now, but we can change that while (date.DayOfWeek != DayOfWeek.Saturday) { date = date.AddDays(1.0); } // NOTE doesn't make sense to put in a payrollidNotUsed if we have the week, so ignore the variable for now. Kept there to maintain the parameter signature var result = new OperationResult <Payroll>(); int franchiseid = Convert.ToInt32(FranchiseId); DateTime startDate = date.AddDays(-7); DateTime holddate = date.AddDays(1); // Forget about what's in the database, just perform the function to generate a payroll for this week since we re-process it anyways // [Step 1] - Get everything we should need so we don't have to make anymore database calls List <tbl_Employee> employeelist = (from e in db.tbl_Employee where e.ActiveYN == true && e.FranchiseID == franchiseid select e).ToList <tbl_Employee>(); List <tbl_HR_TimeSheet> timeSheetList = (from ts in db.tbl_HR_TimeSheet join e in db.tbl_Employee on ts.EmployeeID equals e.EmployeeID where e.FranchiseID == franchiseid && ts.WeekEndingDateOn == date select ts).ToList <tbl_HR_TimeSheet>(); var reportingService = AbstractBusinessService.Create <ReportingService>(userKey); // Query Jobs within dates from our reporting layer KeyPerformanceIndicator kpiAllFranchise = reportingService.GetKeyPerformanceIndicators( franchiseid, startDate, holddate); List <Reporting.Job> jobList = kpiAllFranchise.AllJobs.ToList <Reporting.Job>(); List <Reporting.JobTask> taskList = kpiAllFranchise.AllTasks.ToList(); List <Reporting.PayrollSetup> payrollsetuplist = reportingService.GetPayrollSetupData(franchiseid).ToList <Reporting.PayrollSetup>(); // Existing Payroll List <tbl_Payroll> existingPayrollList = (from p in db.tbl_Payroll where p.PayrollDate == date select p).ToList <tbl_Payroll>(); tbl_Payroll existingPayroll = (existingPayrollList.Count == 0) ? null : existingPayrollList[0]; List <tbl_Job_Payroll> jobPayrollListForExistingPayroll = new List <tbl_Job_Payroll>(); List <tbl_PayrollDetails> payrollDetailsForExistingPayroll = new List <tbl_PayrollDetails>(); if (existingPayroll != null) { jobPayrollListForExistingPayroll = (from j in db.tbl_Job_Payroll where j.PayrollID == existingPayroll.PayrollID select j).ToList <tbl_Job_Payroll>(); payrollDetailsForExistingPayroll = (from pd in db.tbl_PayrollDetails where pd.PayrollID == existingPayroll.PayrollID select pd).ToList <tbl_PayrollDetails>(); } // [Step 2] - Process a new Payroll Payroll payrollResult = new Payroll(date, franchiseid); ProcessEmployeesForWeek(payrollResult, employeelist, timeSheetList, jobList, taskList, payrollsetuplist); // [Step 3] - Now do the database stuff tbl_Payroll payrollToUse = null; if (existingPayroll != null) // There IS an existing payroll { payrollToUse = existingPayroll; // blow away any existing JobPayrolls foreach (tbl_Job_Payroll existingJobPayroll in jobPayrollListForExistingPayroll) { db.DeleteObject(existingJobPayroll); } // Blow away any existing PayrollDetails foreach (tbl_PayrollDetails existingPayrollDetail in payrollDetailsForExistingPayroll) { db.DeleteObject(existingPayrollDetail); } } else { // Create a new payroll payrollToUse = new tbl_Payroll(); payrollToUse.LockDate = null; payrollToUse.PayrollDate = date; payrollToUse.FranchiseID = franchiseid; db.tbl_Payroll.AddObject(payrollToUse); } // add all the payroll details foreach (PayrollDetail pd in payrollResult.PayrollDetails) { tbl_PayrollDetails newPayrollDetail = new tbl_PayrollDetails() { PayrollID = payrollToUse.PayrollID, EmployeeID = pd.EmployeeID, SundayHours = (float)pd.SundayHours, MondayHours = (float)pd.MondayHours, TuesdayHours = (float)pd.TuesdayHours, WednesdayHours = (float)pd.WednesdayHours, ThursdayHours = (float)pd.ThursdayHours, FridayHours = (float)pd.FridayHours, SaturdayHours = (float)pd.SaturdayHours, OTHours = (float)pd.OTHours, OTPay = (float)pd.OTPay, OTRate = (float)pd.OTRate, RegularHours = (float)pd.RegularHours, RegularPay = (float)pd.RegularPay, RegularRate = (float)pd.RegularRate, WeeklySalary = (float)pd.WeeklySalary }; db.tbl_PayrollDetails.AddObject(newPayrollDetail); // now add the job_payroll records foreach (JobPayroll jobPayroll in pd.JobPayrolls) { tbl_Job_Payroll newJobPayroll = new tbl_Job_Payroll() { JobID = jobPayroll.JobID , ServiceProID = pd.EmployeeID // TODO: Get rid of this after we add the foreign key to Payroll Detail , JobSubTotal = (float)jobPayroll.JobSubTotal , TotalCommissionPartsAndLabor = jobPayroll.TotalCommissionPartsAndLabor , TotalCommissionSpifs = (float)jobPayroll.TotalCommissionSpifs , PayrollID = payrollToUse.PayrollID }; db.tbl_Job_Payroll.AddObject(newJobPayroll); } } db.SaveChanges(); //[Step 4] - Communicate results payrollResult.PayrollID = payrollToUse.PayrollID; // Doesn't make perfect sense but the UI needs this result.ResultData = payrollResult; result.Success = true; if (!result.Success) { result.Message = "Run Payroll Failed"; } return(result); }
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 }