Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finances: Loan Refactoring/Standardization #2782

Merged
merged 3 commits into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 trans : getAllTransactions()) {
trans.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 @@ -358,12 +358,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 @@ -375,7 +374,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 @@ -424,12 +423,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 @@ -438,7 +436,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 @@ -474,7 +472,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