Skip to content

Commit

Permalink
Merge pull request #2782 from Windchild292/dev_Windchild_Loan
Browse files Browse the repository at this point in the history
Finances: Loan Refactoring/Standardization
  • Loading branch information
Windchild292 authored Aug 6, 2021
2 parents 61ef12e + 72d54ff commit d90684b
Show file tree
Hide file tree
Showing 7 changed files with 364 additions and 376 deletions.
14 changes: 7 additions & 7 deletions MekHQ/src/mekhq/campaign/Campaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -6196,27 +6196,27 @@ public PartInventory getPartInventory(Part part) {
}

public void addLoan(Loan loan) {
addReport("You have taken out loan " + loan.getDescription()
addReport("You have taken out loan " + loan
+ ". Your account has been credited "
+ loan.getPrincipal().toAmountAndSymbolString()
+ " for the principal amount.");
finances.addLoan(loan);
MekHQ.triggerEvent(new LoanNewEvent(loan));
finances.credit(loan.getPrincipal(), Transaction.C_LOAN_PRINCIPAL,
"loan principal for " + loan.getDescription(), getLocalDate());
"loan principal for " + loan, getLocalDate());
}

public void payOffLoan(Loan loan) {
if (finances.debit(loan.getRemainingValue(),
Transaction.C_LOAN_PAYMENT, "loan payoff for " + loan.getDescription(), getLocalDate())) {
if (finances.debit(loan.determineRemainingValue(),
Transaction.C_LOAN_PAYMENT, "loan payoff for " + loan, getLocalDate())) {
addReport("You have paid off the remaining loan balance of "
+ loan.getRemainingValue().toAmountAndSymbolString()
+ "on " + loan.getDescription());
+ loan.determineRemainingValue().toAmountAndSymbolString()
+ "on " + loan);
finances.removeLoan(loan);
MekHQ.triggerEvent(new LoanPaidEvent(loan));
} else {
addReport("<font color='red'>You do not have enough funds to pay off "
+ loan.getDescription() + "</font>");
+ loan + "</font>");
}

}
Expand Down
22 changes: 10 additions & 12 deletions MekHQ/src/mekhq/campaign/finances/Finances.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public Money getBalance() {

public Money getLoanBalance() {
Money balance = Money.zero();
return balance.plus(loans.stream().map(Loan::getRemainingValue).collect(Collectors.toList()));
return balance.plus(loans.stream().map(Loan::determineRemainingValue).collect(Collectors.toList()));
}

public boolean isInDebt() {
Expand Down Expand Up @@ -186,8 +186,8 @@ public void writeToXml(PrintWriter pw1, int indent) {
for (Transaction transaction : getAllTransactions()) {
transaction.writeToXML(pw1, indent + 1);
}
for (Loan loan : getAllLoans()) {
loan.writeToXml(pw1, indent + 1);
for (final Loan loan : getAllLoans()) {
loan.writeToXML(pw1, indent + 1);
}
for (Asset asset : getAllAssets()) {
asset.writeToXML(pw1, indent + 1);
Expand Down Expand Up @@ -362,12 +362,11 @@ public void newDay(Campaign campaign) {
for (Loan loan : loans) {
if (loan.checkLoanPayment(campaign.getLocalDate())) {
if (debit(loan.getPaymentAmount(), Transaction.C_LOAN_PAYMENT,
String.format(resourceMap.getString("Loan.title"), loan.getDescription()),
String.format(resourceMap.getString("Loan.title"), loan),
campaign.getLocalDate())) {
campaign.addReport(String.format(
resourceMap.getString("Loan.text"),
loan.getPaymentAmount().toAmountAndSymbolString(),
loan.getDescription()));
loan.getPaymentAmount().toAmountAndSymbolString(), loan));
loan.paidLoan();
} else {
campaign.addReport(String.format(
Expand All @@ -379,7 +378,7 @@ public void newDay(Campaign campaign) {
if (loan.getRemainingPayments() > 0) {
newLoans.add(loan);
} else {
campaign.addReport(String.format(resourceMap.getString("Loan.paid"), loan.getDescription()));
campaign.addReport(String.format(resourceMap.getString("Loan.paid"), loan));
}
}
if ((wentIntoDebt != null) && !isInDebt()) {
Expand Down Expand Up @@ -428,12 +427,11 @@ public Money checkOverdueLoanPayments(Campaign campaign) {
for (Loan loan : loans) {
if (loan.isOverdue()) {
if (debit(loan.getPaymentAmount(), Transaction.C_LOAN_PAYMENT,
String.format(resourceMap.getString("Loan.title"), loan.getDescription()),
String.format(resourceMap.getString("Loan.title"), loan),
campaign.getLocalDate())) {
campaign.addReport(String.format(
resourceMap.getString("Loan.text"),
loan.getPaymentAmount().toAmountAndSymbolString(),
loan.getDescription()));
loan.getPaymentAmount().toAmountAndSymbolString(), loan));
loan.paidLoan();
} else {
overdueAmount = overdueAmount.plus(loan.getPaymentAmount());
Expand All @@ -442,7 +440,7 @@ public Money checkOverdueLoanPayments(Campaign campaign) {
if (loan.getRemainingPayments() > 0) {
newLoans.add(loan);
} else {
campaign.addReport(String.format(resourceMap.getString("Loan.paid"), loan.getDescription()));
campaign.addReport(String.format(resourceMap.getString("Loan.paid"), loan));
}
}
loans = newLoans;
Expand Down Expand Up @@ -478,7 +476,7 @@ public int getFailedCollateral() {

public Money getTotalLoanCollateral() {
Money amount = Money.zero();
return amount.plus(loans.stream().map(Loan::getCollateralAmount).collect(Collectors.toList()));
return amount.plus(loans.stream().map(Loan::determineCollateralAmount).collect(Collectors.toList()));
}

public Money getTotalAssetValue() {
Expand Down
Loading

0 comments on commit d90684b

Please sign in to comment.