/// <summary>
        /// Save
        /// </summary>
        /// <param name="companyId">companyId</param>
        public void Save(int companyId)
        {
            EmployeeInformationTDS employeeInformationChanges = (EmployeeInformationTDS)Data.GetChanges();

            if (employeeInformationChanges.BasicInformation.Rows.Count > 0)
            {
                EmployeeInformationBasicInformationGateway employeeInformationBasicInformationGateway = new EmployeeInformationBasicInformationGateway(employeeInformationChanges);

                // Update employee
                foreach (EmployeeInformationTDS.BasicInformationRow basicInformationRow in (EmployeeInformationTDS.BasicInformationDataTable)employeeInformationChanges.BasicInformation)
                {
                    // Unchanged values
                    int employeeId = basicInformationRow.EmployeeID;
                    int? loginId = null; if(!basicInformationRow.IsLoginIDNull()) loginId =  basicInformationRow.LoginID;
                    int? contactsId = null; if (!basicInformationRow.IsContactsIDNull()) contactsId = basicInformationRow.ContactsID;
                    string middleInitial = ""; if (!basicInformationRow.IsMiddleInitialNull()) middleInitial = basicInformationRow.MiddleInitial;
                    bool deleted = basicInformationRow.Deleted;
                    decimal? bourdenFactor = null; if (!basicInformationRow.IsBourdenFactorNull()) bourdenFactor = (decimal)basicInformationRow.BourdenFactor;
                    decimal? usHealthBenefitFactor = null; if (!basicInformationRow.IsUSHealthBenefitFactorNull()) usHealthBenefitFactor = (decimal)basicInformationRow.USHealthBenefitFactor;
                    decimal? benefitFactorCad = null; if (!basicInformationRow.IsBenefitFactorCadNull()) benefitFactorCad = (decimal)basicInformationRow.BenefitFactorCad;
                    decimal? benefitFactorUsd = null; if (!basicInformationRow.IsBenefitFactorUsdNull()) benefitFactorUsd = (decimal)basicInformationRow.BenefitFactorUsd;

                    // Original values
                    string originalFirstName = employeeInformationBasicInformationGateway.GetFirstNameOriginal(employeeId);
                    string originalLastName = employeeInformationBasicInformationGateway.GetLastNameOriginal(employeeId);
                    string originalFullName = originalFirstName +  ' ' + originalLastName;
                    string originalType = employeeInformationBasicInformationGateway.GetTypeOriginal(employeeId);
                    string originalState = employeeInformationBasicInformationGateway.GetStateOriginal(employeeId);
                    bool originalIsSalessman = employeeInformationBasicInformationGateway.GetIsSalesmanOriginal(employeeId);
                    bool originalRequestProjectTime = employeeInformationBasicInformationGateway.GetRequestProjectTimeOriginal(employeeId);
                    bool originalSalaried = employeeInformationBasicInformationGateway.GetSalariedOriginal(employeeId);
                    string originalEMail = employeeInformationBasicInformationGateway.GeteMailOriginal(employeeId);
                    bool originalAssignableSrs = employeeInformationBasicInformationGateway.GetAssignableSRSOriginal(employeeId);
                    string originalJobClassType = employeeInformationBasicInformationGateway.GetJobClassTypeOriginal(employeeId);
                    string originalCategory = employeeInformationBasicInformationGateway.GetCategoryOriginal(employeeId);
                    string originalPersonalAgencyName = employeeInformationBasicInformationGateway.GetPersonalAgencyNameOriginal(employeeId);
                    bool originalIsVacationsManager = employeeInformationBasicInformationGateway.GetIsVacationsManagerOriginal(employeeId);
                    bool originalApproveTimesheets = employeeInformationBasicInformationGateway.GetApproveTimesheetsOriginal(employeeId);
                    string originalCrew = employeeInformationBasicInformationGateway.GetCrewOriginal(employeeId);

                    // New variables
                    string newFirstName = employeeInformationBasicInformationGateway.GetFirstName(employeeId);
                    string newLastName = employeeInformationBasicInformationGateway.GetLastName(employeeId);
                    string newFullName = newFirstName + ' ' + newLastName;
                    string newType = employeeInformationBasicInformationGateway.GetType(employeeId);
                    string newState = employeeInformationBasicInformationGateway.GetState(employeeId);
                    bool newIsSalessman = employeeInformationBasicInformationGateway.GetIsSalesman(employeeId);
                    bool newRequestProjectTime = employeeInformationBasicInformationGateway.GetRequestProjectTime(employeeId);
                    bool newSalaried = employeeInformationBasicInformationGateway.GetSalaried(employeeId);
                    string newEMail = employeeInformationBasicInformationGateway.GeteMail(employeeId);
                    bool newAssignableSrs = employeeInformationBasicInformationGateway.GetAssignableSRS(employeeId);
                    string newJobClassType = employeeInformationBasicInformationGateway.GetJobClassType(employeeId);
                    string newCategory = employeeInformationBasicInformationGateway.GetCategory(employeeId);
                    string newPersonalAgencyName = employeeInformationBasicInformationGateway.GetPersonalAgencyName(employeeId);
                    bool newIsVacationsManager = employeeInformationBasicInformationGateway.GetIsVacationsManager(employeeId);
                    bool newApproveTimesheets = employeeInformationBasicInformationGateway.GetApproveTimesheets(employeeId);
                    string newCrew = employeeInformationBasicInformationGateway.GetCrew(employeeId);

                    // ... Update
                    Employee employee = new Employee(null);
                    employee.UpdateDirect(employeeId, loginId, contactsId, originalFullName, originalFirstName, middleInitial, originalLastName, originalType, originalState, originalIsSalessman, originalRequestProjectTime, deleted, originalSalaried, originalEMail, originalAssignableSrs, originalJobClassType, originalCategory, originalPersonalAgencyName, originalIsVacationsManager, originalApproveTimesheets, bourdenFactor, usHealthBenefitFactor, benefitFactorCad, benefitFactorUsd, originalCrew, newFullName, newFirstName, middleInitial, newLastName, newType, newState, newIsSalessman, newRequestProjectTime, deleted, newSalaried, newEMail, newAssignableSrs, newJobClassType, newCategory, newPersonalAgencyName, newIsVacationsManager, newApproveTimesheets,  bourdenFactor, usHealthBenefitFactor, benefitFactorCad, benefitFactorUsd, newCrew);
                }
            }
        }
        /// <summary>
        /// Save
        /// </summary>
        /// <param name="companyId">companyId</param>
        public void Save(int companyId)
        {
            EmployeeStandardCostsSetupTDS employeeStandardCostsSetupChanges = (EmployeeStandardCostsSetupTDS)Data.GetChanges();

            if (employeeStandardCostsSetupChanges.StandardCostsSetup.Rows.Count > 0)
            {
                EmployeeStandardCostsSetupGateway employeeStandardCostsSetupGateway = new EmployeeStandardCostsSetupGateway(employeeStandardCostsSetupChanges);

                // Update employee
                foreach (EmployeeStandardCostsSetupTDS.StandardCostsSetupRow standardCostsSetupRow in (EmployeeStandardCostsSetupTDS.StandardCostsSetupDataTable)employeeStandardCostsSetupChanges.StandardCostsSetup)
                {
                    // Unchanged values
                    int employeeId = standardCostsSetupRow.EmployeeID;
                    int? loginId = null; if(!standardCostsSetupRow.IsLoginIDNull()) loginId =  standardCostsSetupRow.LoginID;
                    int? contactsId = null; if (!standardCostsSetupRow.IsContactsIDNull()) contactsId = standardCostsSetupRow.ContactsID;
                    string fullName = standardCostsSetupRow.FullName;
                    string firstName = standardCostsSetupRow.FirstName;
                    string middleInitial = ""; if (!standardCostsSetupRow.IsMiddleInitialNull()) middleInitial = standardCostsSetupRow.MiddleInitial;
                    string lastName = standardCostsSetupRow.LastName;
                    string type = standardCostsSetupRow.Type;
                    string state = standardCostsSetupRow.State;
                    bool isSalessman = standardCostsSetupRow.IsSalesman;
                    bool requestProjectTime = standardCostsSetupRow.RequestProjectTime;
                    bool deleted = standardCostsSetupRow.Deleted;
                    bool salaried = standardCostsSetupRow.Salaried;
                    string eMail = ""; if (!standardCostsSetupRow.IseMailNull()) eMail = standardCostsSetupRow.eMail;
                    bool assignableSrs = standardCostsSetupRow.AssignableSRS;
                    string jobClassType = ""; if (!standardCostsSetupRow.IsJobClassTypeNull()) jobClassType = standardCostsSetupRow.JobClassType;
                    string category = standardCostsSetupRow.Category;
                    string personalAgencyName = ""; if (!standardCostsSetupRow.IsPersonalAgencyNameNull()) personalAgencyName = standardCostsSetupRow.PersonalAgencyName;
                    bool isVacationsManager = standardCostsSetupRow.IsVacationsManager;
                    bool approveTimesheets = standardCostsSetupRow.ApproveTimesheets;

                    // Original values
                    decimal? originalBourdenFactor = employeeStandardCostsSetupGateway.GetBourdenFactorOriginal(employeeId);
                    decimal? originalUSHealthBenefitFactor = employeeStandardCostsSetupGateway.GetUSHealthBenefitFactorOriginal(employeeId);
                    decimal? originalBenefitFactorCad = employeeStandardCostsSetupGateway.GetBenefitFactorCadOriginal(employeeId);
                    decimal? originalBenefitFactorUsd = employeeStandardCostsSetupGateway.GetBenefitFactorUsdOriginal(employeeId);

                    // New variables
                    decimal? newBourdenFactor = employeeStandardCostsSetupGateway.GetBourdenFactor(employeeId);
                    decimal? newUSHealthBenefitFactor = employeeStandardCostsSetupGateway.GetUSHealthBenefitFactor(employeeId);
                    decimal? newBenefitFactorCad = employeeStandardCostsSetupGateway.GetBenefitFactorCad(employeeId);
                    decimal? newBenefitFactorUsd = employeeStandardCostsSetupGateway.GetBenefitFactorUsd(employeeId);
                    string crew = ""; if (!standardCostsSetupRow.IsCrewNull()) crew = standardCostsSetupRow.Crew;

                    // ... Update employee
                    Employee employee = new Employee(null);
                    employee.UpdateDirect(employeeId, loginId, contactsId, fullName, firstName, middleInitial, lastName, type, state, isSalessman, requestProjectTime, deleted, salaried, eMail, assignableSrs, jobClassType, category, personalAgencyName, isVacationsManager, approveTimesheets, originalBourdenFactor, originalUSHealthBenefitFactor, originalBenefitFactorCad, originalBenefitFactorUsd, crew, fullName, firstName, middleInitial, lastName, type, state, isSalessman, requestProjectTime, deleted, salaried, eMail, assignableSrs, jobClassType, category, personalAgencyName, isVacationsManager, approveTimesheets, newBourdenFactor, newUSHealthBenefitFactor, newBenefitFactorCad, newBenefitFactorUsd, crew);

                    // ... Update cost history table
                    // ... ... if there are new values
                    if ((newBourdenFactor.HasValue) && (newUSHealthBenefitFactor.HasValue) && (newBenefitFactorCad.HasValue) && (newBenefitFactorUsd.HasValue))
                    {
                        // ... ... verify if the new values are different from original
                        if ((originalBourdenFactor.HasValue) && (originalUSHealthBenefitFactor.HasValue) && (originalBenefitFactorCad.HasValue) && (originalBenefitFactorUsd.HasValue))
                        {
                            if (((decimal)originalBourdenFactor != (decimal)newBourdenFactor) || ((decimal)originalUSHealthBenefitFactor != (decimal)newUSHealthBenefitFactor) || ((decimal)originalBenefitFactorCad != (decimal)newBenefitFactorCad) || ((decimal)originalBenefitFactorUsd != (decimal)newBenefitFactorUsd))
                            {
                                EmployeeInformationCostInformationGateway employeeInformationCostInformationGateway = new EmployeeInformationCostInformationGateway();
                                employeeInformationCostInformationGateway.LoadLastCostByEmployeeId(employeeId, companyId);
                                if (employeeInformationCostInformationGateway.Table.Rows.Count > 0)
                                {
                                    DateTime date = DateTime.Now;
                                    int lastCostId = employeeInformationCostInformationGateway.GetCostId(employeeId);
                                    string unitOfMeasurement = employeeInformationCostInformationGateway.GetUnitOfMeasurement(lastCostId, employeeId);
                                    decimal payRateCad = employeeInformationCostInformationGateway.GetPayRateCad(lastCostId, employeeId);
                                    decimal payRateUsd = employeeInformationCostInformationGateway.GetPayRateUsd(lastCostId, employeeId);
                                    decimal benefitFactorUsd = employeeInformationCostInformationGateway.GetBenefitFactorUsd(lastCostId, employeeId);

                                    decimal boudenFactor = (decimal)newBourdenFactor / 100;

                                    decimal burdenRateCad = Decimal.Round(payRateCad * boudenFactor, 2);
                                    decimal totalCostCad = payRateCad + burdenRateCad;
                                    totalCostCad = Decimal.Round(totalCostCad, 2);

                                    decimal burdenRateUsd = Decimal.Round(payRateUsd * boudenFactor, 2);
                                    decimal totalCostUsd = payRateUsd + burdenRateUsd;
                                    totalCostUsd = Decimal.Round(totalCostUsd, 2);

                                    decimal healthBenefitFactorUsd = (decimal)newUSHealthBenefitFactor / 100;
                                    decimal healthBenefitUsd = benefitFactorUsd * healthBenefitFactorUsd;

                                    int newCostId = lastCostId + 1;

                                    EmployeeCostHistory employeeCostHistory = new EmployeeCostHistory(null);
                                    employeeCostHistory.InsertDirect(newCostId, employeeId, date, unitOfMeasurement, payRateCad, burdenRateCad, totalCostCad, payRateUsd, burdenRateUsd, totalCostUsd, false, companyId, (decimal)newBenefitFactorCad, (decimal)newBenefitFactorUsd, healthBenefitUsd);
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Save
        /// </summary>
        public void Save()
        {
            EmployeeNavigatorTDS employeeNavigatorChanges = (EmployeeNavigatorTDS)Data.GetChanges();

            if (employeeNavigatorChanges != null)
            {
                if (employeeNavigatorChanges.EmployeeNavigator.Rows.Count > 0)
                {
                    EmployeeNavigatorGateway employeeNavigatorGateway = new EmployeeNavigatorGateway(employeeNavigatorChanges);

                    // Update employees
                    foreach (EmployeeNavigatorTDS.EmployeeNavigatorRow row in (EmployeeNavigatorTDS.EmployeeNavigatorDataTable)employeeNavigatorChanges.EmployeeNavigator)
                    {
                        // Insert new employees
                        if ((!row.Deleted) && (!row.InDatabase))
                        {
                            Employee employee = new Employee(null);
                            int? loginId = null; if (!row.IsLoginIDNull()) loginId = row.LoginID;
                            int? contactsId = null; if (!row.IsContactsIDNull()) contactsId = row.ContactsID;
                            string middleInitial = ""; if (!row.IsMiddleInitialNull()) middleInitial = row.MiddleInitial;
                            string email = ""; if (!row.IseMailNull()) email = row.eMail;
                            bool assignableSrs = row.AssignableSRS;
                            string jobClassType = ""; if (!row.IsJobClassTypeNull()) jobClassType = row.JobClassType;
                            string personalAgencyName = ""; if (!row.IsPersonalAgencyNameNull()) personalAgencyName = row.PersonalAgencyName;
                            decimal? bourdenFactor = null; if (!row.IsBourdenFactorNull()) bourdenFactor = (decimal)row.BourdenFactor;
                            decimal? usHealthBenefitFactor = null; if (!row.IsUSHealthBenefitFactorNull()) usHealthBenefitFactor = (decimal)row.USHealthBenefitFactor;
                            decimal? standardBenefitFactorCad = null; if (!row.IsStandardBenefitFactorCadNull()) standardBenefitFactorCad = (decimal)row.StandardBenefitFactorCad;
                            decimal? standardBenefitFactorUsd = null; if (!row.IsStandardBenefitFactorUsdNull()) standardBenefitFactorUsd = (decimal)row.StandardBenefitFactorUsd;
                            string crew = ""; if (!row.IsCrewNull()) crew = row.Crew;
                            employee.InsertDirect(loginId, contactsId, row.FullName, row.FirstName, middleInitial, row.LastName, row.Type, row.State, row.IsSalesman, row.RequestProjectTime, row.Deleted, row.Salaried, email, assignableSrs, jobClassType, row.Category, personalAgencyName, row.IsVacationsManager, row.ApproveTimesheets, bourdenFactor, usHealthBenefitFactor, standardBenefitFactorCad, standardBenefitFactorUsd, crew);
                        }

                        // Update employees
                        if ((!row.Deleted) && (row.InDatabase))
                        {
                            // non editable values
                            int employeeId = row.EmployeeID;
                            int? originalLoginId = row.LoginID;
                            int? originalContactsId = row.ContactsID;
                            bool originalDeleted = false;
                            decimal? originalBourdenFactor = null; if (!row.IsBourdenFactorNull()) originalBourdenFactor = (decimal)row.BourdenFactor;
                            decimal? originalUSHealthBenefitFactor = null; if (!row.IsUSHealthBenefitFactorNull()) originalUSHealthBenefitFactor = (decimal)row.USHealthBenefitFactor;
                            decimal? originalStandardBenefitFactorCad = null; if (!row.IsStandardBenefitFactorCadNull()) originalStandardBenefitFactorCad = (decimal)row.StandardBenefitFactorCad;
                            decimal? originalStandardBenefitFactorUsd = null; if (!row.IsStandardBenefitFactorUsdNull()) originalStandardBenefitFactorUsd = (decimal)row.StandardBenefitFactorUsd;

                            // original values
                            string originalFullName = employeeNavigatorGateway.GetFullNameOriginal(employeeId);
                            string originalFirstName = employeeNavigatorGateway.GetFirstNameOriginal(employeeId);
                            string originalMiddleInitial = employeeNavigatorGateway.GetMiddleInitialOriginal(employeeId);
                            string originalLastName = employeeNavigatorGateway.GetLastNameOriginal(employeeId);
                            string originalType = employeeNavigatorGateway.GetTypeOriginal(employeeId);
                            string originalState = employeeNavigatorGateway.GetStateOriginal(employeeId);
                            bool originalIsSalesman = employeeNavigatorGateway.GetIsSalesmanOriginal(employeeId);
                            bool originalRequestProjectTime = employeeNavigatorGateway.GetRequestProjectTimeOriginal(employeeId);
                            bool originalSalaried = employeeNavigatorGateway.GetSalariedOriginal(employeeId);
                            string originalEMail = employeeNavigatorGateway.GetEMailOriginal(employeeId);
                            bool originalAssignableSrs = employeeNavigatorGateway.GetAssignableSRSOriginal(employeeId);
                            string originalJobClassType = employeeNavigatorGateway.GetJobClassTypeOriginal(employeeId);
                            string originalCategory = employeeNavigatorGateway.GetCategoryOriginal(employeeId);
                            string originalPersonalAgencyName = employeeNavigatorGateway.GetPersonalAgencyNameOriginal(employeeId);
                            bool originalIsVacationsManager = employeeNavigatorGateway.GetIsVacationsManagerOriginal(employeeId);
                            bool originalApproveTimesheets = employeeNavigatorGateway.GetApproveTimesheetsOriginal(employeeId);

                            // new values
                            string newFullName = employeeNavigatorGateway.GetFullName(employeeId);
                            string newFirstName = employeeNavigatorGateway.GetFirstName(employeeId);
                            string newMiddleInitial = employeeNavigatorGateway.GetMiddleInitial(employeeId);
                            string newLastName = employeeNavigatorGateway.GetLastName(employeeId);
                            string newType = employeeNavigatorGateway.GetType(employeeId);
                            string newState = employeeNavigatorGateway.GetState(employeeId);
                            bool newIsSalesman = employeeNavigatorGateway.GetIsSalesman(employeeId);
                            bool newRequestProjectTime = employeeNavigatorGateway.GetRequestProjectTime(employeeId);
                            bool newSalaried = employeeNavigatorGateway.GetSalaried(employeeId);
                            string newEMail = employeeNavigatorGateway.GetEMail(employeeId);
                            bool newAssignableSrs = employeeNavigatorGateway.GetAssignableSRS(employeeId);
                            string newJobClassType = employeeNavigatorGateway.GetJobClassType(employeeId);
                            string newCategory = employeeNavigatorGateway.GetCategory(employeeId);
                            string newPersonalAgencyName = employeeNavigatorGateway.GetPersonalAgencyName(employeeId);
                            bool newIsVacationsManager = employeeNavigatorGateway.GetIsVacationsManager(employeeId);
                            bool newApproveTimesheets = employeeNavigatorGateway.GetApproveTimesheets(employeeId);
                            string crew = ""; if (!row.IsCrewNull()) crew = row.Crew;//TODO CREW
                            Employee employee = new Employee(null);
                            employee.UpdateDirect(employeeId, originalLoginId, originalContactsId, originalFullName, originalFirstName, originalMiddleInitial, originalLastName, originalType, originalState, originalIsSalesman, originalRequestProjectTime, originalDeleted, originalSalaried, originalEMail, originalAssignableSrs, originalJobClassType, originalCategory, originalPersonalAgencyName, originalIsVacationsManager, originalApproveTimesheets, originalBourdenFactor, originalUSHealthBenefitFactor, originalStandardBenefitFactorCad, originalStandardBenefitFactorUsd, crew, newFullName, newFirstName, newMiddleInitial, newLastName, newType, newState, newIsSalesman, newRequestProjectTime, originalDeleted, newSalaried, newEMail, newAssignableSrs, newJobClassType, newCategory, newPersonalAgencyName, newIsVacationsManager, newApproveTimesheets, originalBourdenFactor, originalUSHealthBenefitFactor, originalStandardBenefitFactorCad, originalStandardBenefitFactorUsd, crew);
                        }

                        // Deleted employees
                        if ((row.Deleted) && (row.InDatabase))
                        {
                            Employee employee = new Employee(null);
                            employee.DeleteDirect(row.EmployeeID);
                        }
                    }
                }
            }
        }