Beispiel #1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(SalaryConfig model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update salaryconfig set ");
            strSql.Append("EMPLOYEEID=@EMPLOYEEID,");
            strSql.Append("BASESALARY=@BASESALARY,");
            strSql.Append("AGEWAGE=@AGEWAGE,");
            strSql.Append("ACCOMMODATION_ALLOWANCE=@ACCOMMODATION_ALLOWANCE,");
            strSql.Append("MEAL_ALLOWANCE=@MEAL_ALLOWANCE,");
            strSql.Append("OTHERWAGE=@OTHERWAGE,");
            strSql.Append("SOCIALSECURITY_INDIVIDUAL=@SOCIALSECURITY_INDIVIDUAL,");
            strSql.Append("SOCIALSECURITY_COMPANY=@SOCIALSECURITY_COMPANY,");
            strSql.Append("HOUSINGPROVIDENTFUND_INDIVIDUAL=@HOUSINGPROVIDENTFUND_INDIVIDUAL,");
            strSql.Append("HOUSINGPROVIDENTFUND_COMPANY=@HOUSINGPROVIDENTFUND_COMPANY,");
            strSql.Append("PAYOFF_TYPE=@PAYOFF_TYPE,");
            strSql.Append("COMMISSION=@COMMISSION");
            strSql.Append(" where ID=@ID ");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@EMPLOYEEID",                      MySqlDbType.VarChar, 40),
                new MySqlParameter("@BASESALARY",                      MySqlDbType.Decimal, 10),
                new MySqlParameter("@AGEWAGE",                         MySqlDbType.Decimal,  8),
                new MySqlParameter("@ACCOMMODATION_ALLOWANCE",         MySqlDbType.Decimal,  8),
                new MySqlParameter("@MEAL_ALLOWANCE",                  MySqlDbType.Decimal,  8),
                new MySqlParameter("@OTHERWAGE",                       MySqlDbType.Decimal,  8),
                new MySqlParameter("@SOCIALSECURITY_INDIVIDUAL",       MySqlDbType.Decimal,  8),
                new MySqlParameter("@SOCIALSECURITY_COMPANY",          MySqlDbType.Decimal,  8),
                new MySqlParameter("@HOUSINGPROVIDENTFUND_INDIVIDUAL", MySqlDbType.Decimal,  8),
                new MySqlParameter("@HOUSINGPROVIDENTFUND_COMPANY",    MySqlDbType.Decimal,  8),
                new MySqlParameter("@PAYOFF_TYPE",                     MySqlDbType.Decimal,  1),
                new MySqlParameter("@COMMISSION",                      MySqlDbType.Decimal,  3),
                new MySqlParameter("@ID",                              MySqlDbType.VarChar, 40)
            };
            parameters[0].Value  = model.EMPLOYEEID;
            parameters[1].Value  = model.BASESALARY;
            parameters[2].Value  = model.AGEWAGE;
            parameters[3].Value  = model.ACCOMMODATION_ALLOWANCE;
            parameters[4].Value  = model.MEAL_ALLOWANCE;
            parameters[5].Value  = model.OTHERWAGE;
            parameters[6].Value  = model.SOCIALSECURITY_INDIVIDUAL;
            parameters[7].Value  = model.SOCIALSECURITY_COMPANY;
            parameters[8].Value  = model.HOUSINGPROVIDENTFUND_INDIVIDUAL;
            parameters[9].Value  = model.HOUSINGPROVIDENTFUND_COMPANY;
            parameters[10].Value = model.PAYOFF_TYPE;
            parameters[11].Value = model.COMMISSION;
            parameters[12].Value = model.ID;

            int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public async Task <Result <SalaryConfig> > GetAsync()
        {
            try
            {
                var salarySetting = await _dbContext.SalarySettings.Include(x => x.SalaryCurrency)
                                    .ThenInclude(y => y.ProgressiveTaxRateSettings)
                                    .FirstOrDefaultAsync();

                if (salarySetting == null)
                {
                    _logger.LogError(Errors.SalaryConfig.GetSalaryConfigSalarySettingNotFoundError.Message);
                    return(Errors.SalaryConfig.GetSalaryConfigSalarySettingNotFoundError);
                }

                var currency = new Currency(salarySetting.SalaryCurrency.Value);

                var salaryConfig = new SalaryConfig(
                    id: salarySetting.Id,
                    commonMinimumWage: new Money(salarySetting.CommonMinimumWage, currency),
                    regionalMinimumWage: new Money(salarySetting.RegionalMinimumWage, currency),
                    coefficientSocialCare: salarySetting.CoefficientSocialCare,
                    minimumNonWorkingDay: salarySetting.MinimumNonWorkingDay,
                    employerSocialInsuranceRate: salarySetting.EmployerSocialInsuranceRate,
                    employeeSocialInsuranceRate: salarySetting.EmployeeSocialInsuranceRate,
                    healthCareInsuranceEmployeeRate: salarySetting.EmployeeHealthCareInsuranceRate,
                    healthCareInsuranceEmployerRate: salarySetting.EmployerHealthCareInsuranceRate,
                    unemploymentInsuranceEmployeeRate: salarySetting.EmployeeUnemploymentInsuranceRate,
                    unemploymentInsuranceEmployerRate: salarySetting.EmployerUnemploymentInsuranceRate,
                    foreignEmployerSocialInsuranceRate: salarySetting.ForeignEmployerSocialInsuranceRate,
                    foreignEmployeeSocialInsuranceRate: salarySetting.ForeignEmployeeSocialInsuranceRate,
                    foreignHealthCareInsuranceEmployeeRate: salarySetting.ForeignEmployeeHealthCareInsuranceRate,
                    foreignHealthCareInsuranceEmployerRate: salarySetting.ForeignEmployerHealthCareInsuranceRate,
                    foreignUnemploymentInsuranceEmployeeRate: salarySetting.ForeignEmployeeUnemploymentInsuranceRate,
                    foreignUnemploymentInsuranceEmployerRate: salarySetting.ForeignEmployerUnemploymentInsuranceRate,
                    employeeUnionFeeRate: salarySetting.EmployeeUnionFeeRate,
                    employerUnionFeeRate: salarySetting.EmployerUnionFeeRate,
                    maximumUnionFeeRate: salarySetting.MaximumUnionFeeRate,
                    personalDeduction: new Money(salarySetting.PersonalDeduction, currency),
                    dependantDeduction: new Money(salarySetting.DependantDeduction, currency),
                    progressiveTaxRateLookUpTable: new ProgressiveTaxRateLookUpTable(salarySetting.SalaryCurrency.ProgressiveTaxRateSettings
                                                                                     .Select(x => new ProgressiveTaxRate(
                                                                                                 lowerBound: new Money(x.LowerBound, currency),
                                                                                                 upperBound: new Money(x.UpperBound, currency),
                                                                                                 rate: x.Rate,
                                                                                                 progressiveTaxRateLevel: (ProgressiveTaxRateLevel)x.TaxRateLevel
                                                                                                 )).ToArray()),
                    defaultProbationTaxRate: salarySetting.DefaultProbationTaxRate,
                    isInsurancePaidFullSalary: salarySetting.IsInsurancePaidFullSalary,
                    insurancePaidAmount: new Money(salarySetting.InsurancePaidAmount, currency)
                    );

                return(Result <SalaryConfig> .Ok(salaryConfig));
            }
            catch (SqlException ex)
            {
                _logger.LogError(ex, Errors.SalaryConfig.GetSalaryConfigDatabaseError.Message);
                return(Errors.SalaryConfig.GetSalaryConfigDatabaseError);
            }
        }
Beispiel #3
0
 public TotalDeduction(
     EmployeeMonthlyRecord employeeMonthlyRecord,
     SalaryConfig salaryConfig
     )
 {
     Amount = employeeMonthlyRecord.IsOnProbation()
                         ? Money.ZeroVND
                         : salaryConfig.PersonalDeduction +
              (employeeMonthlyRecord.NumberOfDependants * salaryConfig.DependantDeduction);
 }
        /// <summary>
        /// RowUpdating事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvData_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            TextBox txtBaseSalary = (TextBox)gvData.Rows[e.RowIndex].FindControl("txtBaseSalary");
            TextBox txtCommission = (TextBox)gvData.Rows[e.RowIndex].FindControl("txtCommission");
            TextBox txtAgeWage    = (TextBox)gvData.Rows[e.RowIndex].FindControl("txtAgeWage");
            TextBox txtZsbt       = (TextBox)gvData.Rows[e.RowIndex].FindControl("txtZsbt");
            TextBox txtHsbt       = (TextBox)gvData.Rows[e.RowIndex].FindControl("txtZsbt");
            TextBox txtQtsr       = (TextBox)gvData.Rows[e.RowIndex].FindControl("txtQtsr");
            TextBox txtGrsb       = (TextBox)gvData.Rows[e.RowIndex].FindControl("txtGrsb");
            TextBox txtQysb       = (TextBox)gvData.Rows[e.RowIndex].FindControl("txtQysb");
            TextBox txtGrgjj      = (TextBox)gvData.Rows[e.RowIndex].FindControl("txtGrgjj");
            TextBox txtQygjj      = (TextBox)gvData.Rows[e.RowIndex].FindControl("txtQygjj");

            string baseSalary                     = txtBaseSalary.Text.Trim(); //基本工资
            string commission                     = txtCommission.Text.Trim(); //提成比例
            string ageWage                        = txtAgeWage.Text.Trim();    //工龄工资
            string accommodationAlowance          = txtZsbt.Text.Trim();       //住宿补贴
            string mealAllowance                  = txtHsbt.Text.Trim();       //伙食补贴
            string otherWage                      = txtQtsr.Text.Trim();       //其他收入
            string socialsecurityIndividual       = txtGrsb.Text.Trim();       //个人社保
            string socialsecurityCompany          = txtQysb.Text.Trim();       //企业社保
            string housingprovidentfundIndividual = txtGrgjj.Text.Trim();      //个人公积金
            string housingprovidentfundCompany    = txtQygjj.Text.Trim();      //企业公积金

            string       id     = gvData.DataKeys[e.RowIndex].Value.ToString();
            SalaryConfig salary = scBll.GetModel(id);

            salary.BASESALARY = Convert.ToDecimal(baseSalary);
            salary.COMMISSION = Convert.ToDecimal(commission);
            salary.AGEWAGE    = Convert.ToDecimal(ageWage);
            salary.ACCOMMODATION_ALLOWANCE = Convert.ToDecimal(accommodationAlowance);
            salary.OTHERWAGE = Convert.ToDecimal(otherWage);
            salary.SOCIALSECURITY_INDIVIDUAL       = Convert.ToDecimal(socialsecurityIndividual);
            salary.SOCIALSECURITY_COMPANY          = Convert.ToDecimal(socialsecurityCompany);
            salary.HOUSINGPROVIDENTFUND_INDIVIDUAL = Convert.ToDecimal(housingprovidentfundIndividual);
            salary.HOUSINGPROVIDENTFUND_COMPANY    = Convert.ToDecimal(housingprovidentfundCompany);
            bool flag = scBll.Update(salary);

            if (flag)
            {
                gvData.EditIndex = -1;
                Bind();
                ClientScript.RegisterClientScriptBlock(this.GetType(), string.Empty, "alert('更新成功!')", true);
            }
            else
            {
                gvData.EditIndex = -1;
                Bind();
                ClientScript.RegisterClientScriptBlock(this.GetType(), string.Empty, "alert('更新失败!')", true);
            }
        }
Beispiel #5
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(SalaryConfig model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into salaryconfig(");
            strSql.Append("ID,EMPLOYEEID,BASESALARY,AGEWAGE,ACCOMMODATION_ALLOWANCE,MEAL_ALLOWANCE,OTHERWAGE,SOCIALSECURITY_INDIVIDUAL,SOCIALSECURITY_COMPANY,HOUSINGPROVIDENTFUND_INDIVIDUAL,HOUSINGPROVIDENTFUND_COMPANY,PAYOFF_TYPE,COMMISSION)");
            strSql.Append(" values (");
            strSql.Append("@ID,@EMPLOYEEID,@BASESALARY,@AGEWAGE,@ACCOMMODATION_ALLOWANCE,@MEAL_ALLOWANCE,@OTHERWAGE,@SOCIALSECURITY_INDIVIDUAL,@SOCIALSECURITY_COMPANY,@HOUSINGPROVIDENTFUND_INDIVIDUAL,@HOUSINGPROVIDENTFUND_COMPANY,@PAYOFF_TYPE,@COMMISSION)");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@ID",                              MySqlDbType.VarChar, 40),
                new MySqlParameter("@EMPLOYEEID",                      MySqlDbType.VarChar, 40),
                new MySqlParameter("@BASESALARY",                      MySqlDbType.Decimal, 10),
                new MySqlParameter("@AGEWAGE",                         MySqlDbType.Decimal,  8),
                new MySqlParameter("@ACCOMMODATION_ALLOWANCE",         MySqlDbType.Decimal,  8),
                new MySqlParameter("@MEAL_ALLOWANCE",                  MySqlDbType.Decimal,  8),
                new MySqlParameter("@OTHERWAGE",                       MySqlDbType.Decimal,  8),
                new MySqlParameter("@SOCIALSECURITY_INDIVIDUAL",       MySqlDbType.Decimal,  8),
                new MySqlParameter("@SOCIALSECURITY_COMPANY",          MySqlDbType.Decimal,  8),
                new MySqlParameter("@HOUSINGPROVIDENTFUND_INDIVIDUAL", MySqlDbType.Decimal,  8),
                new MySqlParameter("@HOUSINGPROVIDENTFUND_COMPANY",    MySqlDbType.Decimal,  8),
                new MySqlParameter("@PAYOFF_TYPE",                     MySqlDbType.Decimal,  1),
                new MySqlParameter("@COMMISSION",                      MySqlDbType.Decimal, 3)
            };
            parameters[0].Value  = model.ID;
            parameters[1].Value  = model.EMPLOYEEID;
            parameters[2].Value  = model.BASESALARY;
            parameters[3].Value  = model.AGEWAGE;
            parameters[4].Value  = model.ACCOMMODATION_ALLOWANCE;
            parameters[5].Value  = model.MEAL_ALLOWANCE;
            parameters[6].Value  = model.OTHERWAGE;
            parameters[7].Value  = model.SOCIALSECURITY_INDIVIDUAL;
            parameters[8].Value  = model.SOCIALSECURITY_COMPANY;
            parameters[9].Value  = model.HOUSINGPROVIDENTFUND_INDIVIDUAL;
            parameters[10].Value = model.HOUSINGPROVIDENTFUND_COMPANY;
            parameters[11].Value = model.PAYOFF_TYPE;
            parameters[12].Value = model.COMMISSION;

            int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #6
0
        public async Task <byte[]> CreateCsvByteArrayAsync(
            IEnumerable <ExportEmpMonthlySalary> records,
            SalaryConfig salaryConfig,
            string yearMonth)
        {
            using (var memoryStream = new MemoryStream())
                using (var streamWriter = new StreamWriter(memoryStream, Encoding.UTF8))
                    using (var csvWriter = new CsvWriter(streamWriter, CultureInfo.InvariantCulture))
                    {
                        csvWriter.Configuration.RegisterClassMap <ExportEmpMonthlySalaryMap>();
                        WriteHeader(csvWriter, records);
                        csvWriter.WriteRecords(records);

                        await streamWriter.FlushAsync();

                        return(memoryStream.ToArray());
                    }
        }
Beispiel #7
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public SalaryConfig GetModel(string ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select ID,EMPLOYEEID,BASESALARY,AGEWAGE,ACCOMMODATION_ALLOWANCE,MEAL_ALLOWANCE,OTHERWAGE,SOCIALSECURITY_INDIVIDUAL,SOCIALSECURITY_COMPANY,HOUSINGPROVIDENTFUND_INDIVIDUAL,HOUSINGPROVIDENTFUND_COMPANY,PAYOFF_TYPE,COMMISSION from salaryconfig ");
            strSql.Append(" where ID=@ID ");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@ID", MySqlDbType.VarChar, 40)
            };
            parameters[0].Value = ID;

            SalaryConfig model = new SalaryConfig();
            DataSet      ds    = DbHelperMySQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
        private static CrewDetails ReadRoninTags(PilotDef roninDef)
        {
            //CrewDetails crewDetails = new CrewDetails(); BAD, SERIALIZATION ONLY!
            Mod.Log.Debug?.Write($"Building CrewDetails for Ronin: {roninDef.Description.Name}_{roninDef.GUID}");

            CrewType     type = CrewType.MechWarrior;
            FactionValue favored = null, hated = null;
            int          skill = 0, size = 0;
            SalaryConfig salaryCfg = new SalaryConfig();
            bool         isFounder = false;

            foreach (string tag in roninDef.PilotTags)
            {
                // Check types
                if (tag.Equals(ModTags.Tag_CrewType_Aerospace, StringComparison.InvariantCultureIgnoreCase))
                {
                    Mod.Log.Debug?.Write($" -- found type == Aerospace");
                    type = CrewType.AerospaceWing;
                }
                if (tag.Equals(ModTags.Tag_CrewType_MechTech, StringComparison.InvariantCultureIgnoreCase))
                {
                    Mod.Log.Debug?.Write($" -- found type == MechTech");
                    type = CrewType.MechTechCrew;
                }
                if (tag.Equals(ModTags.Tag_CrewType_MedTech, StringComparison.InvariantCultureIgnoreCase))
                {
                    Mod.Log.Debug?.Write($" -- found type == MedTech");
                    type = CrewType.MedTechCrew;
                }
                if (tag.Equals(ModTags.Tag_CU_Vehicle_Crew, StringComparison.InvariantCultureIgnoreCase))
                {
                    Mod.Log.Debug?.Write($" -- found type == Vehicle");
                    type = CrewType.VehicleCrew;
                }

                // Check factions
                if (tag.StartsWith(ModTags.Tag_Prefix_Ronin_Faction_Favored, StringComparison.InvariantCultureIgnoreCase))
                {
                    string factionDefId = tag.Substring(ModTags.Tag_Prefix_Ronin_Faction_Favored.Length);
                    Mod.Log.Debug?.Write($" -- found favored faction defId: {factionDefId}");

                    foreach (FactionValue factionVal in Mod.Config.Attitude.FavoredFactionCandidates)
                    {
                        if (factionVal.FactionDefID.Equals(factionDefId, StringComparison.InvariantCultureIgnoreCase))
                        {
                            favored = factionVal;
                        }
                    }

                    if (favored == null)
                    {
                        Mod.Log.Warn?.Write($"Could not map favored factionDefId: {factionDefId} to a configured faction! Skipping!");
                    }
                }

                if (tag.StartsWith(ModTags.Tag_Prefix_Ronin_Faction_Hated, StringComparison.InvariantCultureIgnoreCase))
                {
                    string factionDefId = tag.Substring(ModTags.Tag_Prefix_Ronin_Faction_Hated.Length);
                    Mod.Log.Debug?.Write($" -- found hated faction defId: {factionDefId}");

                    foreach (FactionValue factionVal in Mod.Config.Attitude.HatedFactionCandidates)
                    {
                        if (factionVal.FactionDefID.Equals(factionDefId, StringComparison.InvariantCultureIgnoreCase))
                        {
                            hated = factionVal;
                        }
                    }

                    if (hated == null)
                    {
                        Mod.Log.Warn?.Write($"Could not map hated factionDefId: {factionDefId} to a configured faction! Skipping!");
                    }
                }

                // Check size and skill tags
                if (tag.StartsWith(ModTags.Tag_Prefix_Ronin_Support_Size, StringComparison.InvariantCultureIgnoreCase))
                {
                    string tagS = tag.Substring(ModTags.Tag_Prefix_Ronin_Support_Size.Length);
                    try
                    {
                        size = Int32.Parse(tagS, CultureInfo.InvariantCulture);
                        Mod.Log.Debug?.Write($" -- found size: {size}");
                    }
                    catch (Exception e)
                    {
                        Mod.Log.Warn?.Write(e, $"Failed to read size: {tagS} as an integer value, skipping!");
                    }
                }
                if (tag.StartsWith(ModTags.Tag_Prefix_Ronin_Support_Skill, StringComparison.InvariantCultureIgnoreCase))
                {
                    string tagS = tag.Substring(ModTags.Tag_Prefix_Ronin_Support_Skill.Length);
                    try
                    {
                        skill = Int32.Parse(tagS, CultureInfo.InvariantCulture);
                        Mod.Log.Debug?.Write($" -- found skill: {skill}");
                    }
                    catch (Exception e)
                    {
                        Mod.Log.Warn?.Write(e, $"Failed to read skill: {tagS} as an integer value, skipping!");
                    }
                }

                // Check salary & bonus values
                if (tag.StartsWith(ModTags.Tag_Prefix_Ronin_Salary_Multi, StringComparison.InvariantCultureIgnoreCase))
                {
                    string tagS = tag.Substring(ModTags.Tag_Prefix_Ronin_Salary_Multi.Length);
                    try
                    {
                        salaryCfg.Multi = Int32.Parse(tagS, CultureInfo.InvariantCulture);
                        Mod.Log.Debug?.Write($" -- found salaryMulti: {salaryCfg.Multi}");
                    }
                    catch (Exception e)
                    {
                        Mod.Log.Warn?.Write(e, $"Failed to read salaryMulti: {tagS} as an integer value, skipping!");
                    }
                }

                if (tag.StartsWith(ModTags.Tag_Prefix_Ronin_Salary_Exp, StringComparison.InvariantCultureIgnoreCase))
                {
                    string tagS = tag.Substring(ModTags.Tag_Prefix_Ronin_Salary_Exp.Length);
                    try
                    {
                        salaryCfg.Exponent = float.Parse(tagS, CultureInfo.InvariantCulture);
                        Mod.Log.Debug?.Write($" -- found salaryExp: {salaryCfg.Exponent}");
                    }
                    catch (Exception e)
                    {
                        Mod.Log.Warn?.Write(e, $"Failed to read salaryExp: {tagS} as an integer value, skipping!");
                    }
                }

                if (tag.StartsWith(ModTags.Tag_Prefix_Ronin_Salary_Variance, StringComparison.InvariantCultureIgnoreCase))
                {
                    string tagS = tag.Substring(ModTags.Tag_Prefix_Ronin_Salary_Variance.Length);
                    try
                    {
                        salaryCfg.Variance = float.Parse(tagS, CultureInfo.InvariantCulture);
                        Mod.Log.Debug?.Write($" -- found salaryVariance: {salaryCfg.Variance}");
                    }
                    catch (Exception e)
                    {
                        Mod.Log.Warn?.Write(e, $"Failed to read salaryVariance: {tagS} as an integer value, skipping!");
                    }
                }

                if (tag.StartsWith(ModTags.Tag_Prefix_Ronin_Bonus_Variance, StringComparison.InvariantCultureIgnoreCase))
                {
                    string tagS = tag.Substring(ModTags.Tag_Prefix_Ronin_Bonus_Variance.Length);
                    try
                    {
                        salaryCfg.BonusVariance = float.Parse(tagS, CultureInfo.InvariantCulture);
                        Mod.Log.Debug?.Write($" -- found bonusVariance: {salaryCfg.BonusVariance}");
                    }
                    catch (Exception e)
                    {
                        Mod.Log.Warn?.Write(e, $"Failed to read bonusVariance: {tagS} as an integer value, skipping!");
                    }
                }

                // Check founder
                if (tag.Equals(ModTags.Tag_Founder, StringComparison.InvariantCultureIgnoreCase))
                {
                    Mod.Log.Debug?.Write($" -- found founder tag");
                    isFounder = true;
                }
            }

            // Normalize size and skill to index values
            CrewDetails details = new CrewDetails(roninDef, type, favored, hated, size - 1, skill - 1, isFounder,
                                                  salaryCfg.IsDefault() ? null : salaryCfg);

            return(details);
        }
        public CrewDetails(PilotDef pilotDef, CrewType type,
                           FactionValue favoredFaction, FactionValue hatedFaction,
                           int sizeIdx            = 0, int skillIdx = 0, bool isFounder = false,
                           SalaryConfig salaryCfg = null)
        {
            this.Type  = type;
            this.Size  = sizeIdx + 1;
            this.Skill = skillIdx + 1;

            this.Attitude = 0;

            // Calculate value and set required tags
            CrewOpts config = null;

            if (IsAerospaceCrew)
            {
                Value  = Mod.Config.HiringHall.PointsBySkillAndSize.Aerospace[skillIdx][sizeIdx];
                config = Mod.Config.HiringHall.AerospaceWings;
                pilotDef.PilotTags.Add(ModTags.Tag_CrewType_Aerospace);
            }
            else if (IsMechTechCrew)
            {
                Value  = Mod.Config.HiringHall.PointsBySkillAndSize.MechTech[skillIdx][sizeIdx];
                config = Mod.Config.HiringHall.MechTechCrews;
                pilotDef.PilotTags.Add(ModTags.Tag_CrewType_MechTech);
            }
            else if (IsMedTechCrew)
            {
                Value  = Mod.Config.HiringHall.PointsBySkillAndSize.MedTech[skillIdx][sizeIdx];
                config = Mod.Config.HiringHall.MedTechCrews;
                pilotDef.PilotTags.Add(ModTags.Tag_CrewType_MedTech);
            }
            else if (IsMechWarrior)
            {
                Value  = pilotDef.BaseGunnery + pilotDef.BasePiloting + pilotDef.BaseGuts + pilotDef.BaseTactics;
                config = Mod.Config.HiringHall.MechWarriors;
            }
            else if (IsVehicleCrew)
            {
                Value  = pilotDef.BaseGunnery + pilotDef.BasePiloting + pilotDef.BaseGuts + pilotDef.BaseTactics;
                config = Mod.Config.HiringHall.VehicleCrews;

                // Required tags
                pilotDef.PilotTags.Add(ModTags.Tag_CU_NoMech_Crew);
                pilotDef.PilotTags.Add(ModTags.Tag_CU_Vehicle_Crew);
            }

            if (salaryCfg == null)
            {
                this.SalaryConfig = SalaryConfig.FromModConfig(config);
            }
            else
            {
                this.SalaryConfig = salaryCfg;
            }


            // Calculate salary and bonus
            SalaryHelper.CalcSalary(Value, this.SalaryConfig, out int salary, out int bonus);
            this.Salary      = salary;
            this.HiringBonus = bonus;

            // Determine contract length
            if (pilotDef.IsFree && pilotDef.IsImmortal)
            {
                IsPlayer = true;
                Mod.Log.Debug?.Write("Setting expiration and contract term to 0 for player character.");
                this.ContractTerm  = 0; // Free and Immortal = player character
                this.ExpirationDay = 0;
            }
            else if (isFounder)
            {
                IsFounder = true;
                Mod.Log.Debug?.Write("Setting expiration and contract term to 0 for founding member.");
                this.ContractTerm  = 0; // Free overhead, not immortal
                this.ExpirationDay = 0;
            }
            else
            {
                IsPlayer = false;
                Mod.Log.Debug?.Write("Generating contract length, new expiration day");
                this.ContractTerm  = CrewHelper.RandomContractLength(config);
                this.ExpirationDay = ModState.SimGameState.DaysPassed + ContractTerm;
            }

            if (favoredFaction != null)
            {
                this.FavoredFactionId = (int)favoredFaction.FactionID;
            }
            if (hatedFaction != null)
            {
                this.HatedFactionId = (int)hatedFaction.FactionID;
            }

            this.NextHeadHuntingDay = ModState.SimGameState.DaysPassed;
        }
Beispiel #10
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public SalaryConfig DataRowToModel(DataRow row)
        {
            SalaryConfig model = new SalaryConfig();

            if (row != null)
            {
                if (row["ID"] != null)
                {
                    model.ID = row["ID"].ToString();
                }
                if (row["EMPLOYEEID"] != null)
                {
                    model.EMPLOYEEID = row["EMPLOYEEID"].ToString();
                }
                if (row["BASESALARY"] != null && row["BASESALARY"].ToString() != "")
                {
                    model.BASESALARY = decimal.Parse(row["BASESALARY"].ToString());
                }
                if (row["AGEWAGE"] != null && row["AGEWAGE"].ToString() != "")
                {
                    model.AGEWAGE = decimal.Parse(row["AGEWAGE"].ToString());
                }
                if (row["ACCOMMODATION_ALLOWANCE"] != null && row["ACCOMMODATION_ALLOWANCE"].ToString() != "")
                {
                    model.ACCOMMODATION_ALLOWANCE = decimal.Parse(row["ACCOMMODATION_ALLOWANCE"].ToString());
                }
                if (row["MEAL_ALLOWANCE"] != null && row["MEAL_ALLOWANCE"].ToString() != "")
                {
                    model.MEAL_ALLOWANCE = decimal.Parse(row["MEAL_ALLOWANCE"].ToString());
                }
                if (row["OTHERWAGE"] != null && row["OTHERWAGE"].ToString() != "")
                {
                    model.OTHERWAGE = decimal.Parse(row["OTHERWAGE"].ToString());
                }
                if (row["SOCIALSECURITY_INDIVIDUAL"] != null && row["SOCIALSECURITY_INDIVIDUAL"].ToString() != "")
                {
                    model.SOCIALSECURITY_INDIVIDUAL = decimal.Parse(row["SOCIALSECURITY_INDIVIDUAL"].ToString());
                }
                if (row["SOCIALSECURITY_COMPANY"] != null && row["SOCIALSECURITY_COMPANY"].ToString() != "")
                {
                    model.SOCIALSECURITY_COMPANY = decimal.Parse(row["SOCIALSECURITY_COMPANY"].ToString());
                }
                if (row["HOUSINGPROVIDENTFUND_INDIVIDUAL"] != null && row["HOUSINGPROVIDENTFUND_INDIVIDUAL"].ToString() != "")
                {
                    model.HOUSINGPROVIDENTFUND_INDIVIDUAL = decimal.Parse(row["HOUSINGPROVIDENTFUND_INDIVIDUAL"].ToString());
                }
                if (row["HOUSINGPROVIDENTFUND_COMPANY"] != null && row["HOUSINGPROVIDENTFUND_COMPANY"].ToString() != "")
                {
                    model.HOUSINGPROVIDENTFUND_COMPANY = decimal.Parse(row["HOUSINGPROVIDENTFUND_COMPANY"].ToString());
                }
                if (row["PAYOFF_TYPE"] != null && row["PAYOFF_TYPE"].ToString() != "")
                {
                    model.PAYOFF_TYPE = decimal.Parse(row["PAYOFF_TYPE"].ToString());
                }
                if (row["COMMISSION"] != null && row["COMMISSION"].ToString() != "")
                {
                    model.COMMISSION = decimal.Parse(row["COMMISSION"].ToString());
                }
            }
            return(model);
        }
        public async Task <Result <Nothing> > SaveAsync(SalaryConfig salaryConfig)
        {
            //var metadata = new Dictionary<string, string>();
            //metadata.Add("Id", salaryConfig.Id.ToString());
            //metadata.Add("CoefficientSocialCare", salaryConfig.CoefficientSocialCare.ToString());
            //metadata.Add("CommonMinimumWage", salaryConfig.CommonMinimumWage.Value.ToString());
            //metadata.Add("RegionalMinimumWage", salaryConfig.RegionalMinimumWage.Value.ToString());
            //metadata.Add("EmployeeSocialInsuranceRate", salaryConfig.EmployeeSocialInsuranceRate.ToString());
            //metadata.Add("EmployeeHealthCareInsuranceRate", salaryConfig.EmployeeHealthCareInsuranceRate.ToString());
            //metadata.Add("EmployeeUnemploymentInsuranceRate", salaryConfig.EmployeeUnemploymentInsuranceRate.ToString());
            //metadata.Add("EmployeeUnionFeeRate", salaryConfig.EmployeeUnionFeeRate.ToString());
            //metadata.Add("EmployerHealthCareInsuranceRate", salaryConfig.EmployerHealthCareInsuranceRate.ToString());
            //metadata.Add("EmployerSocialInsuranceRate", salaryConfig.EmployerSocialInsuranceRate.ToString());
            //metadata.Add("EmployerUnemploymentInsuranceRate", salaryConfig.EmployerUnemploymentInsuranceRate.ToString());
            //metadata.Add("EmployerUnionFeeRate", salaryConfig.EmployerUnionFeeRate.ToString());
            //metadata.Add("MaximumUnionFeeRate", salaryConfig.MaximumUnionFeeRate.ToString());
            //metadata.Add("MinimumNonWorkingDay", salaryConfig.MinimumNonWorkingDay.ToString());
            //metadata.Add("Currency", salaryConfig.CommonMinimumWage.Currency.Value.ToString());
            //metadata.Add("DefaultProbationTaxRate", salaryConfig.DefaultProbationTaxRate.ToString());
            //metadata.Add("DependantDeduction", salaryConfig.DependantDeduction.Value.ToString());
            //metadata.Add("PersonalDeduction", salaryConfig.PersonalDeduction.Value.ToString());
            //metadata.Add("IsInsurancePaidFullSalary", salaryConfig.IsInsurancePaidFullSalary.ToString());
            //metadata.Add("InsurancePaidAmount", salaryConfig.InsurancePaidAmount.Value.ToString());
            //metadata.Add("ProgressiveTaxRates", salaryConfig.ProgressiveTaxRateLookUpTable.ToString());
            //_logger.LogInformation(Errors.SalaryConfig.SaveSalaryConfigCurrencyNotFoundError.Message
            //+ " - params: {metadata}", metadata);
            try
            {
                var currency = await
                               _dbContext.SalaryCurrencies.FirstOrDefaultAsync(x =>
                                                                               x.Value == salaryConfig.CommonMinimumWage.Currency.Value);

                if (currency == null)
                {
                    _logger.LogError(Errors.SalaryConfig.SaveSalaryConfigCurrencyNotFoundError.Message);
                    return(Errors.SalaryConfig.SaveSalaryConfigCurrencyNotFoundError);
                }

                _dbContext.SalarySettings.Update(new SalarySetting()
                {
                    Id = salaryConfig.Id,
                    CoefficientSocialCare                    = salaryConfig.CoefficientSocialCare,
                    CommonMinimumWage                        = salaryConfig.CommonMinimumWage,
                    RegionalMinimumWage                      = salaryConfig.RegionalMinimumWage,
                    EmployeeSocialInsuranceRate              = salaryConfig.EmployeeSocialInsuranceRate * 100,
                    EmployeeHealthCareInsuranceRate          = salaryConfig.EmployeeHealthCareInsuranceRate * 100,
                    EmployeeUnemploymentInsuranceRate        = salaryConfig.EmployeeUnemploymentInsuranceRate * 100,
                    EmployerHealthCareInsuranceRate          = salaryConfig.EmployerHealthCareInsuranceRate * 100,
                    EmployerSocialInsuranceRate              = salaryConfig.EmployerSocialInsuranceRate * 100,
                    EmployerUnemploymentInsuranceRate        = salaryConfig.EmployerUnemploymentInsuranceRate * 100,
                    ForeignEmployeeSocialInsuranceRate       = salaryConfig.ForeignEmployeeSocialInsuranceRate * 100,
                    ForeignEmployeeHealthCareInsuranceRate   = salaryConfig.ForeignEmployeeHealthCareInsuranceRate * 100,
                    ForeignEmployeeUnemploymentInsuranceRate = salaryConfig.ForeignEmployeeUnemploymentInsuranceRate * 100,
                    ForeignEmployerHealthCareInsuranceRate   = salaryConfig.ForeignEmployerHealthCareInsuranceRate * 100,
                    ForeignEmployerSocialInsuranceRate       = salaryConfig.ForeignEmployerSocialInsuranceRate * 100,
                    ForeignEmployerUnemploymentInsuranceRate = salaryConfig.ForeignEmployerUnemploymentInsuranceRate * 100,
                    EmployeeUnionFeeRate                     = salaryConfig.EmployeeUnionFeeRate * 100,
                    EmployerUnionFeeRate                     = salaryConfig.EmployerUnionFeeRate * 100,
                    MaximumUnionFeeRate                      = salaryConfig.MaximumUnionFeeRate * 100,
                    MinimumNonWorkingDay                     = salaryConfig.MinimumNonWorkingDay,
                    CurrencyId = currency.Id,
                    DefaultProbationTaxRate   = salaryConfig.DefaultProbationTaxRate * 100,
                    DependantDeduction        = salaryConfig.DependantDeduction,
                    PersonalDeduction         = salaryConfig.PersonalDeduction,
                    IsInsurancePaidFullSalary = salaryConfig.IsInsurancePaidFullSalary,
                    InsurancePaidAmount       = salaryConfig.IsInsurancePaidFullSalary ? 0 : salaryConfig.InsurancePaidAmount.Value
                });

                var existingTaxRates = await _dbContext.ProgressiveTaxRateSettings.ToListAsync();

                var newTaxRates = salaryConfig.ProgressiveTaxRateLookUpTable.AsReadOnlyCollection().ToList();

                newTaxRates.ForEach(x =>
                {
                    var existingTaxRate = existingTaxRates.FirstOrDefault(y =>
                                                                          y.TaxRateLevel == (int)x.ProgressiveTaxRateLevel);

                    if (existingTaxRate != null)
                    {
                        existingTaxRate.CurrencyId = currency.Id;
                        existingTaxRate.LowerBound = x.LowerBound;
                        existingTaxRate.UpperBound = x.UpperBound;
                        existingTaxRate.Rate       = x.Rate * 100;
                    }
                });

                _dbContext.ProgressiveTaxRateSettings.UpdateRange(existingTaxRates);

                await _dbContext.SaveChangesAsync();

                return(Result <Nothing> .Ok(Nothing.Value));
            }
            catch (SqlException ex)
            {
                _logger.LogError(ex, Errors.SalaryConfig.SaveSalaryConfigDatabaseError.Message);
                return(Errors.SalaryConfig.SaveSalaryConfigDatabaseError);
            }
        }
Beispiel #12
0
        public static PayrollReportRecord[] GeneratePayRollRecord(
            EmployeeMonthlyRecord[] employeeMonthlyRecords,
            SalaryConfig salaryConfig)
        {
            return(employeeMonthlyRecords.Select(employeeMonthlyRecord =>
            {
                var insuranceSalary = InsuranceCalculator.CalculateInsuranceSalary(
                    salaryConfig: salaryConfig,
                    employeeMonthlyRecord: employeeMonthlyRecord);

                var actualGrossSalary = new ActualGrossSalary(
                    grossContractedSalary: employeeMonthlyRecord.GrossContractedSalary,
                    standardWorkingDays: employeeMonthlyRecord.StandardWorkingDays,
                    probationWorkingDays: employeeMonthlyRecord.ProbationWorkingDays,
                    workingDays: employeeMonthlyRecord.WorkingDays);

                var employeeSocialInsurance = InsuranceCalculator.CalculateEmployeeSocialInsurance(
                    salaryConfig: salaryConfig,
                    employeeMonthlyRecord: employeeMonthlyRecord,
                    insuranceSalary: insuranceSalary);
                var employeeUnemploymentInsurance = InsuranceCalculator.CalculateEmployeeUnemploymentInsurance(
                    salaryConfig: salaryConfig,
                    employeeMonthlyRecord: employeeMonthlyRecord,
                    insuranceSalary: insuranceSalary);
                var employeeHealthcareInsurance = InsuranceCalculator.CalculateEmployeeHealthCareInsurance(
                    salaryConfig: salaryConfig,
                    employeeMonthlyRecord: employeeMonthlyRecord,
                    insuranceSalary: insuranceSalary);
                var employeeUnionFee = InsuranceCalculator.CalculateEmployeeUnionFee(salaryConfig: salaryConfig,
                                                                                     employeeMonthlyRecord: employeeMonthlyRecord,
                                                                                     insuranceSalary: insuranceSalary);

                var employerSocialInsurance = InsuranceCalculator.CalculateEmployerSocialInsurance(
                    salaryConfig: salaryConfig,
                    employeeMonthlyRecord: employeeMonthlyRecord,
                    insuranceSalary: insuranceSalary);
                var employerUnemploymentInsurance = InsuranceCalculator.CalculateEmployerUnemploymentInsurance(
                    salaryConfig: salaryConfig,
                    employeeMonthlyRecord: employeeMonthlyRecord,
                    insuranceSalary: insuranceSalary);
                var employerHealthcareInsurance = InsuranceCalculator.CalculateEmployerHealthCareInsurance(
                    salaryConfig: salaryConfig,
                    employeeMonthlyRecord: employeeMonthlyRecord,
                    insuranceSalary: insuranceSalary);
                var employerUnionFee = InsuranceCalculator.CalculateEmployerUnionFee(salaryConfig: salaryConfig,
                                                                                     employeeMonthlyRecord: employeeMonthlyRecord,
                                                                                     insuranceSalary: insuranceSalary);

                var taxableIncome = new TaxableIncome(actualGrossSalary, employeeMonthlyRecord.TaxableAllowances);

                var assessableIncome = new AssessableIncome(
                    taxableIncome,
                    employeeSocialInsurance: employeeSocialInsurance,
                    employeeHealthCareInsurance: employeeHealthcareInsurance,
                    employeeUnemploymentInsurance: employeeUnemploymentInsurance,
                    employeeUnionFee: employeeUnionFee,
                    totalDeduction: new TotalDeduction(employeeMonthlyRecord: employeeMonthlyRecord,
                                                       salaryConfig: salaryConfig));

                var pit = employeeMonthlyRecord.IsOnProbation()
                                        ? new PersonalIncomeTax((assessableIncome.Amount * salaryConfig.DefaultProbationTaxRate).Round())
                                        : salaryConfig.ProgressiveTaxRateLookUpTable[assessableIncome];

                var totalMonthlyIncome = new TotalMonthlyIncome(
                    actualGrossSalary: actualGrossSalary,
                    taxableAllowances: employeeMonthlyRecord.TaxableAllowances,
                    nonTaxableAllowances: employeeMonthlyRecord.NonTaxableAllowances);

                var netIncome = new NetIncome(
                    totalMonthlyIncome: totalMonthlyIncome,
                    employeeHealthcareInsurance: employeeHealthcareInsurance,
                    employeeSocialInsurance: employeeSocialInsurance,
                    employeeUnemploymentInsurance: employeeUnemploymentInsurance,
                    employeeUnionFee: employeeUnionFee,
                    pit: pit);

                return new PayrollReportRecord(
                    employeeMonthlyRecord: employeeMonthlyRecord,
                    insuranceSalary: insuranceSalary.Amount,
                    actualGrossSalary: actualGrossSalary.Amount,
                    totalMonthlyIncome: totalMonthlyIncome.Amount,
                    taxableIncome: taxableIncome.Amount,
                    employeeSocialInsurance: employeeSocialInsurance.Amount,
                    employeeHealthcareInsurance: employeeHealthcareInsurance.Amount,
                    employeeUnemploymentInsurance: employeeUnemploymentInsurance.Amount,
                    employeeUnionFee: employeeUnionFee.Amount,
                    employerSocialInsurance: employerSocialInsurance.Amount,
                    employerHealthcareInsurance: employerHealthcareInsurance.Amount,
                    employerUnemploymentInsurance: employerUnemploymentInsurance.Amount,
                    employerUnionFee: employerUnionFee.Amount,
                    personalDeduction: salaryConfig.PersonalDeduction,
                    dependantDeduction: salaryConfig.DependantDeduction * employeeMonthlyRecord.NumberOfDependants,
                    assessableIncome: assessableIncome.Amount,
                    netIncome: netIncome.Amount,
                    pit: pit.Amount,
                    totalSalaryCost: new TotalSalaryCost(
                        totalMonthlyIncome: totalMonthlyIncome,
                        employerSocialInsurance: employerSocialInsurance,
                        employerHealthcareInsurance: employerHealthcareInsurance,
                        employerUnemploymentInsurance: employerUnemploymentInsurance,
                        employerUnionFee: employerUnionFee).Amount,
                    netPayment: new NetPayment(
                        netIncome: netIncome,
                        paymentAdvance: employeeMonthlyRecord.PaymentAdvance,
                        adjustmentAdditions: employeeMonthlyRecord.AdjustmentAdditions,
                        adjustmentDeductions: employeeMonthlyRecord.AdjustmentDeduction
                        ).Amount);
            }).ToArray());
        }
Beispiel #13
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(SalaryConfig model)
 {
     return(dal.Update(model));
 }
Beispiel #14
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public bool Add(SalaryConfig model)
 {
     return(dal.Add(model));
 }