From 60718b24b5cf1ac90f730b1c512985f41d0bac25 Mon Sep 17 00:00:00 2001 From: hydrant Date: Tue, 30 Jul 2019 13:30:53 +0200 Subject: [PATCH] Include rental fees in payday --- ReallifeGamemode.Server/Commands/UserCommands.cs | 1 + ReallifeGamemode.Server/Finance/Economy.cs | 13 ++++++++++++- ReallifeGamemode.Server/Finance/Paycheck.cs | 6 +++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ReallifeGamemode.Server/Commands/UserCommands.cs b/ReallifeGamemode.Server/Commands/UserCommands.cs index 2156662f..35109697 100644 --- a/ReallifeGamemode.Server/Commands/UserCommands.cs +++ b/ReallifeGamemode.Server/Commands/UserCommands.cs @@ -43,6 +43,7 @@ namespace ReallifeGamemode.Server.Commands ChatService.SendMessage(client, "~g~[PAYCHECK]~s~ Finanzhilfe : ~g~+$" + (int)Economy.Paychecks[user.Id].FinancialHelp); ChatService.SendMessage(client, "~g~[PAYCHECK]~s~ Fahrzeugsteuer : ~r~-$" + Economy.Paychecks[user.Id].VehicleTaxation); ChatService.SendMessage(client, "~g~[PAYCHECK]~s~ Grundsteuer (Haus) : ~r~-$" + Economy.Paychecks[user.Id].PropertyTaxation); + ChatService.SendMessage(client, "~g~[PAYCHECK]~s~ Mietkosten : ~r~-$" + Economy.Paychecks[user.Id].RentalFees); ChatService.SendMessage(client, "~g~[PAYCHECK]~s~ Einkommen Steuer : ~r~" + (int)(Economy.Paychecks[user.Id].FinancialInterest * 100) + " %"); ChatService.SendMessage(client, ""); ChatService.SendMessage(client, "~g~[PAYCHECK]~s~ Ausgaben : ~r~-$" + (Economy.Paychecks[user.Id].Wage - Economy.Paychecks[user.Id].Amount)); diff --git a/ReallifeGamemode.Server/Finance/Economy.cs b/ReallifeGamemode.Server/Finance/Economy.cs index e0541f8c..761fa920 100644 --- a/ReallifeGamemode.Server/Finance/Economy.cs +++ b/ReallifeGamemode.Server/Finance/Economy.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using GTANetworkAPI; +using Microsoft.EntityFrameworkCore; using ReallifeGamemode.Server.Entities; using ReallifeGamemode.Server.Extensions; using ReallifeGamemode.Server.Models; @@ -158,15 +159,25 @@ namespace ReallifeGamemode.Server.Finance (int bankAccount, float financialHelp, float financialInterest) = GetEconomyClass(client, wage); float propertyTax = GetPropertyTaxation(client); int vehicleTaxation = GetVehicleTaxation(client); + int rentalFees = GetRentalFees(client); int amount = wage - (int)(wage * financialInterest) - vehicleTaxation - (int)propertyTax + (int)financialHelp; - Paycheck paycheck = new Paycheck(financialHelp, financialInterest, vehicleTaxation, propertyTax, wage, amount); + Paycheck paycheck = new Paycheck(financialHelp, financialInterest, vehicleTaxation, propertyTax, wage, amount, rentalFees); User user = client.GetUser(); Paychecks[user.Id] = paycheck; ReleasePayDay(client, paycheck); } + private static int GetRentalFees(Client client) + { + using (var dbContext = new DatabaseContext()) + { + User user = client.GetUser(); + return dbContext.HouseRentals.Where(h => h.UserId == user.Id).Include(h => h.House).Sum(h => h.House.RentalFee); + } + } + public static void ReleasePayDay(Client client, Paycheck paycheck) { using (var dbContext = new DatabaseContext()) diff --git a/ReallifeGamemode.Server/Finance/Paycheck.cs b/ReallifeGamemode.Server/Finance/Paycheck.cs index 7eb75a83..58619e0c 100644 --- a/ReallifeGamemode.Server/Finance/Paycheck.cs +++ b/ReallifeGamemode.Server/Finance/Paycheck.cs @@ -18,8 +18,9 @@ namespace ReallifeGamemode.Server.Finance public float PropertyTaxation { get; set; } = 0; public int Wage { get; set; } = 0; public int Amount { get; set; } = 0; + public int RentalFees { get; set; } = 0; - public Paycheck(float FinancialHelp, float FinancialInterest, int VehicleTaxation, float PropertyTaxation, int Wage, int Amount) + public Paycheck(float FinancialHelp, float FinancialInterest, int VehicleTaxation, float PropertyTaxation, int Wage, int Amount, int RentalFees) { this.FinancialHelp = FinancialHelp; this.FinancialInterest = FinancialInterest; @@ -27,8 +28,7 @@ namespace ReallifeGamemode.Server.Finance this.PropertyTaxation = PropertyTaxation; this.Wage = Wage; this.Amount = Amount; + this.RentalFees = RentalFees; } - - } }