diff --git a/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/data/loanproduct/DefaultLoanProduct.java b/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/data/loanproduct/DefaultLoanProduct.java index 031e8cc5c..331dba020 100644 --- a/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/data/loanproduct/DefaultLoanProduct.java +++ b/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/data/loanproduct/DefaultLoanProduct.java @@ -190,6 +190,7 @@ public enum DefaultLoanProduct implements LoanProduct { LP2_ADV_PYMNT_INT_DAILY_EMI_360_30_INT_RECALC_DAILY_MULTIDISB_FULL_TERM_TRANCHE_CHARGEBACK, // LP2_ADV_PYMNT_INT_DAILY_EMI_360_30_INT_RECALC_DAILY_MULTIDISB_FULL_TERM_TRANCHE_ZERO_INT_CHARGE_OFF, // LP2_ADV_PYMNT_INT_DAILY_EMI_360_30_INT_RECALC_DAILY_MULTIDISB_FULL_TERM_TRANCHE_ACCELERATE_MATURITY, // + LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME, // ; @Override diff --git a/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/factory/LoanProductsRequestFactory.java b/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/factory/LoanProductsRequestFactory.java index 9759148ad..ba11f3a75 100644 --- a/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/factory/LoanProductsRequestFactory.java +++ b/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/factory/LoanProductsRequestFactory.java @@ -1770,6 +1770,11 @@ public class LoanProductsRequestFactory { .incomeFromBuyDownAccountId(accountTypeResolver.resolve(DefaultAccountType.INCOME_FROM_BUY_DOWN));// } + public PostLoanProductsRequest defaultLoanProductsRequestLP2BuyDownFeesFeeIncome() { + return defaultLoanProductsRequestLP2BuyDownFees()// + .buyDownFeeIncomeType(PostLoanProductsRequest.BuyDownFeeIncomeTypeEnum.FEE);// + } + public PostLoanProductsRequest defaultLoanProductsRequestLP2ChargeOffReasonToExpenseAccountMappingsWithBuyDownFee() { Long chargeOffReasonId = codeHelper.retrieveCodeByName(CHARGE_OFF_REASONS).getId(); diff --git a/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/common/ClientStepDef.java b/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/common/ClientStepDef.java index 1ed200139..4ada2c030 100644 --- a/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/common/ClientStepDef.java +++ b/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/common/ClientStepDef.java @@ -24,26 +24,23 @@ import static org.assertj.core.api.Assertions.assertThat; import io.cucumber.java.en.Then; import io.cucumber.java.en.When; import java.util.Collections; +import lombok.RequiredArgsConstructor; import org.apache.fineract.client.feign.FineractFeignClient; import org.apache.fineract.client.models.ClientAddressRequest; import org.apache.fineract.client.models.PostClientsRequest; import org.apache.fineract.client.models.PostClientsResponse; +import org.apache.fineract.client.models.PostOfficesResponse; import org.apache.fineract.test.factory.ClientRequestFactory; import org.apache.fineract.test.messaging.event.EventCheckHelper; import org.apache.fineract.test.stepdef.AbstractStepDef; import org.apache.fineract.test.support.TestContextKey; -import org.springframework.beans.factory.annotation.Autowired; +@RequiredArgsConstructor public class ClientStepDef extends AbstractStepDef { - @Autowired - private FineractFeignClient fineractClient; - - @Autowired - private ClientRequestFactory clientRequestFactory; - - @Autowired - private EventCheckHelper eventCheckHelper; + private final FineractFeignClient fineractClient; + private final ClientRequestFactory clientRequestFactory; + private final EventCheckHelper eventCheckHelper; @When("Admin creates a client with random data") public void createClientRandomFirstNameLastName() { @@ -55,6 +52,19 @@ public class ClientStepDef extends AbstractStepDef { eventCheckHelper.clientEventCheck(response); } + @When("Admin creates a client with random data in the last created office") + public void createClientInLastCreatedOffice() { + final PostOfficesResponse officeResponse = testContext().get(TestContextKey.OFFICE_CREATE_RESPONSE); + assertThat(officeResponse).as("No office was created. Use 'Admin creates a new office' step first.").isNotNull(); + final PostClientsRequest clientsRequest = clientRequestFactory.defaultClientCreationRequest()// + .officeId(officeResponse.getOfficeId()); + + final PostClientsResponse response = ok(() -> fineractClient.clients().create6(clientsRequest)); + testContext().set(TestContextKey.CLIENT_CREATE_RESPONSE, response); + + eventCheckHelper.clientEventCheck(response); + } + @When("Admin creates a second client with random data") public void createSecondClientRandomFirstNameLastName() { PostClientsRequest clientsRequest = clientRequestFactory.defaultClientCreationRequest(); diff --git a/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/common/OfficeStepDef.java b/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/common/OfficeStepDef.java new file mode 100644 index 000000000..94215d5a4 --- /dev/null +++ b/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/common/OfficeStepDef.java @@ -0,0 +1,50 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.test.stepdef.common; + +import static org.apache.fineract.client.feign.util.FeignCalls.ok; + +import io.cucumber.java.en.When; +import java.time.LocalDate; +import lombok.RequiredArgsConstructor; +import org.apache.fineract.client.feign.FineractFeignClient; +import org.apache.fineract.client.models.PostOfficesRequest; +import org.apache.fineract.client.models.PostOfficesResponse; +import org.apache.fineract.test.helper.Utils; +import org.apache.fineract.test.stepdef.AbstractStepDef; +import org.apache.fineract.test.support.TestContextKey; + +@RequiredArgsConstructor +public class OfficeStepDef extends AbstractStepDef { + + private final FineractFeignClient fineractClient; + + @When("Admin creates a new office") + public void createNewOffice() { + final PostOfficesRequest request = new PostOfficesRequest()// + .name(Utils.randomStringGenerator("Office_", 5))// + .parentId(1L)// + .openingDate(LocalDate.of(2000, 1, 1))// + .dateFormat("yyyy-MM-dd")// + .locale("en");// + + final PostOfficesResponse response = ok(() -> fineractClient.offices().createOffice(request)); + testContext().set(TestContextKey.OFFICE_CREATE_RESPONSE, response); + } +} diff --git a/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/reporting/ReportingStepDef.java b/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/reporting/ReportingStepDef.java new file mode 100644 index 000000000..e7b26a075 --- /dev/null +++ b/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/reporting/ReportingStepDef.java @@ -0,0 +1,136 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.test.stepdef.reporting; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + +import io.cucumber.datatable.DataTable; +import io.cucumber.java.en.Then; +import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Objects; +import java.util.stream.IntStream; +import lombok.RequiredArgsConstructor; +import org.apache.fineract.client.feign.FineractFeignClient; +import org.apache.fineract.client.models.PostOfficesResponse; +import org.apache.fineract.client.models.ResultsetColumnHeaderData; +import org.apache.fineract.client.models.RunReportsResponse; +import org.apache.fineract.test.stepdef.AbstractStepDef; +import org.apache.fineract.test.support.TestContextKey; + +@RequiredArgsConstructor +public class ReportingStepDef extends AbstractStepDef { + + private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("dd MMMM yyyy", Locale.ENGLISH); + + private final FineractFeignClient fineractClient; + + @Then("Transaction Summary Report for date {string} has the following data:") + public void transactionSummaryReportHasData(final String dateStr, final DataTable dataTable) { + verifyReportData("Transaction Summary Report", dateStr, dataTable); + } + + @Then("Transaction Summary Report with Asset Owner for date {string} has the following data:") + public void transactionSummaryReportWithAssetOwnerHasData(final String dateStr, final DataTable dataTable) { + verifyReportData("Transaction Summary Report with Asset Owner", dateStr, dataTable); + } + + private void verifyReportData(final String reportName, final String dateStr, final DataTable dataTable) { + final PostOfficesResponse officeResponse = testContext().get(TestContextKey.OFFICE_CREATE_RESPONSE); + assertThat(officeResponse).as("No office was created. Use 'Admin creates a new office' step first.").isNotNull(); + + final String date = LocalDate.parse(dateStr, FORMATTER).toString(); + final RunReportsResponse response = fineractClient.runReports().runReportGetData(reportName, Map.of("R_endDate", date, "R_officeId", + String.valueOf(officeResponse.getOfficeId()), "locale", "en", "dateFormat", "yyyy-MM-dd")); + assertThat(response.getData()).as("Report '%s' returned no data", reportName).isNotNull(); + + final List> expected = dataTable.asLists(); + final List headers = expected.getFirst(); + + assertThat(response.getColumnHeaders()).isNotNull(); + final int[] colIdx = headers.stream().mapToInt(h -> findColumnIndex(response.getColumnHeaders(), h)).toArray(); + + final List> actual = response.getData().stream().map(row -> { + assertThat(row.getRow()).as("Report '%s' returned a row with null cell list", reportName).isNotNull(); + return IntStream.of(colIdx).mapToObj(i -> { + assertThat(i).as("Report '%s': column index %d is out of bounds (row size: %d)", reportName, i, row.getRow().size()) + .isLessThan(row.getRow().size()); + return stringify(row.getRow().get(i)); + }).toList(); + }).toList(); + + assertThat(actual).as("Report '%s' row count mismatch.\nActual rows:\n%s", reportName, formatRows(actual)) + .hasSize(expected.size() - 1); + + for (int i = 1; i < expected.size(); i++) { + final List expRow = expected.get(i).stream().map(v -> v == null ? "" : v).toList(); + final List actRow = actual.get(i - 1); + for (int j = 0; j < headers.size(); j++) { + if (expRow.get(j).isEmpty()) { + continue; + } + if (!valuesMatch(expRow.get(j), actRow.get(j))) { + fail("Report '%s', row %d, column '%s': expected='%s', actual='%s'\nAll actual rows:\n%s", reportName, i, + headers.get(j), expRow.get(j), actRow.get(j), formatRows(actual)); + } + } + } + } + + private boolean valuesMatch(final String expected, final String actual) { + if (Objects.equals(expected, actual)) { + return true; + } + if (isBooleanMatch(expected, actual)) { + return true; + } + try { + return new BigDecimal(expected).compareTo(new BigDecimal(actual)) == 0; + } catch (NumberFormatException e) { + return false; + } + } + + private boolean isBooleanMatch(final String expected, final String actual) { + return ("0".equals(expected) && "false".equals(actual)) || ("false".equals(expected) && "0".equals(actual)) + || ("1".equals(expected) && "true".equals(actual)) || ("true".equals(expected) && "1".equals(actual)); + } + + private String stringify(final Object val) { + return val == null ? "null" : String.valueOf(val); + } + + private String formatRows(final List> rows) { + final StringBuilder sb = new StringBuilder(); + for (int i = 0; i < rows.size(); i++) { + sb.append(String.format(" [%d] %s%n", i + 1, String.join(" | ", rows.get(i)))); + } + return sb.toString(); + } + + private int findColumnIndex(final List headers, final String name) { + return IntStream.range(0, headers.size()).filter(i -> name.equalsIgnoreCase(headers.get(i).getColumnName())).findFirst() + .orElseThrow(() -> new IllegalArgumentException("Column '" + name + "' not found in report")); + } +} diff --git a/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/support/TestContextKey.java b/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/support/TestContextKey.java index 8a3fb94a6..af71aeeef 100644 --- a/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/support/TestContextKey.java +++ b/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/support/TestContextKey.java @@ -169,6 +169,7 @@ public abstract class TestContextKey { public static final String DEFAULT_LOAN_PRODUCT_CREATE_RESPONSE_LP2_PROGRESSIVE_ADV_PYMNT_BUYDOWN_FEES_NON_MERCHANT = "loanProductCreateResponseLP2ProgressiveAdvancedPaymentBuyDownFeesNonMerchant"; public static final String DEFAULT_LOAN_PRODUCT_CREATE_RESPONSE_LP2_PROGRESSIVE_ADV_PYMNT_BUYDOWN_FEES_NON_MERCHANT_CHARGE_OFF_REASON = "loanProductCreateResponseLP2ProgressiveAdvancedPaymentBuyDownFeesNonMerchantWithChargeOffReason"; public static final String DEFAULT_LOAN_PRODUCT_CREATE_RESPONSE_LP2_PROGRESSIVE_ADV_PYMNT_BUYDOWN_FEES_CLASSIFICATION_INCOME_MAP = "loanProductCreateResponseLP2ProgressiveAdvancedPaymentBuyDownFeesClassificationIncomeMap"; + public static final String DEFAULT_LOAN_PRODUCT_CREATE_RESPONSE_LP2_PROGRESSIVE_ADV_PYMNT_BUYDOWN_FEES_FEE_INCOME = "loanProductCreateResponseLP2ProgressiveAdvancedPaymentBuyDownFeesFeeIncome"; public static final String DEFAULT_LOAN_PRODUCT_CREATE_RESPONSE_LP2_ADV_PYMNT_INTEREST_DAILY_EMI_360_30_INTEREST_RECALC_DAILY_CAPITALIZED_INCOME_ADJ_CUSTOM_ALLOC = "loanProductCreateResponseLP2AdvancedPaymentInterestDailyEmi36030InterestRecalculationDailyCapitalizedIncomeAdjCustomAlloc"; public static final String DEFAULT_LOAN_PRODUCT_CREATE_RESPONSE_LP2_PROGRESSIVE_ADV_PMNT_ALLOCATION_CAPITALIZED_INCOME_ADJ_CUSTOM_ALLOC_CLASSIFICATION_INCOME_MAP = "loanProductCreateResponseLP2AdvancedPaymentCapitalizedIncomeAdjCustomAllocClassificationIncomeMao"; public static final String DEFAULT_LOAN_PRODUCT_CREATE_RESPONSE_LP2_ADV_PYMNT_INTEREST_DAILY_RECALC_EMI_360_30_MULTIDISB_OVER_APPLIED_PERCENTAGE_CAPITALIZED_INCOME = "loanProductCreateResponseLP2AdvancedPaymentInterestDailyEmi36030InterestRecalculationDailyMultidisbursalApprovedOVerAppliedPercentageCapitalizedIncome"; @@ -311,4 +312,5 @@ public abstract class TestContextKey { public static final String DEFAULT_LOAN_PRODUCT_CREATE_RESPONSE_LP2_ADV_PYMNT_INT_DAILY_EMI_360_30_INT_RECALC_DAILY_MULTIDISB_FULL_TERM_TRANCHE_CHARGEBACK = "loanProductCreateResponseLP2AdvancedPaymentInterestDailyEmi36030InterestRecalculationDailyMultidisburseFullTermTrancheChargeback"; public static final String DEFAULT_LOAN_PRODUCT_CREATE_RESPONSE_LP2_ADV_PYMNT_INT_DAILY_EMI_360_30_INT_RECALC_DAILY_MULTIDISB_FULL_TERM_TRANCHE_ZERO_CHARGE_OFF = "loanProductCreateResponseLP2AdvancedPaymentInterestDailyEmi36030InterestRecalculationDailyMultidisburseFullTermTrancheZeroIntChargeOff"; public static final String DEFAULT_LOAN_PRODUCT_CREATE_RESPONSE_LP2_ADV_PYMNT_INT_DAILY_EMI_360_30_INT_RECALC_DAILY_MULTIDISB_FULL_TERM_TRANCHE_ACCELERATE_MATURITY = "loanProductCreateResponseLP2AdvancedPaymentInterestDailyEmi36030InterestRecalculationDailyMultidisburseFullTermTrancheAccelerateMaturity"; + public static final String OFFICE_CREATE_RESPONSE = "officeCreateResponse"; } diff --git a/fineract-e2e-tests-runner/src/test/java/org/apache/fineract/test/initializer/global/LoanProductGlobalInitializerStep.java b/fineract-e2e-tests-runner/src/test/java/org/apache/fineract/test/initializer/global/LoanProductGlobalInitializerStep.java index 83ad9bdf2..04fdb78c4 100644 --- a/fineract-e2e-tests-runner/src/test/java/org/apache/fineract/test/initializer/global/LoanProductGlobalInitializerStep.java +++ b/fineract-e2e-tests-runner/src/test/java/org/apache/fineract/test/initializer/global/LoanProductGlobalInitializerStep.java @@ -4585,6 +4585,30 @@ public class LoanProductGlobalInitializerStep implements FineractGlobalInitializ TestContext.INSTANCE.set( TestContextKey.DEFAULT_LOAN_PRODUCT_CREATE_RESPONSE_LP2_ADV_PYMNT_INT_DAILY_EMI_360_30_INT_RECALC_DAILY_MULTIDISB_FULL_TERM_TRANCHE_ACCELERATE_MATURITY, responseLoanProductsRequestLP2AdvancedpaymentInterestEmi36030InterestRecalcDailyMultiDisburseFullTermTrancheAccelerateMaturity); + + // LP2 with progressive loan schedule + horizontal + interest EMI + 360/30 + // + interest recalculation, buy down fees enabled, FEE income type + final String name178 = DefaultLoanProduct.LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME.getName(); + final PostLoanProductsRequest loanProductsRequestLP2ProgressiveAdvPaymentBuyDownFeesFeeIncome = loanProductsRequestFactory + .defaultLoanProductsRequestLP2BuyDownFeesFeeIncome()// + .name(name178)// + .transactionProcessingStrategyCode(ADVANCED_PAYMENT_ALLOCATION.getValue())// + .loanScheduleType("PROGRESSIVE") // + .isInterestRecalculationEnabled(true)// + .preClosureInterestCalculationStrategy(1)// + .rescheduleStrategyMethod(4)// + .interestRecalculationCompoundingMethod(0)// + .recalculationRestFrequencyType(2)// + .recalculationRestFrequencyInterval(1)// + .paymentAllocation(List.of(// + createPaymentAllocation("DEFAULT", "NEXT_INSTALLMENT"), // + createPaymentAllocation("GOODWILL_CREDIT", "LAST_INSTALLMENT"), // + createPaymentAllocation("MERCHANT_ISSUED_REFUND", "REAMORTIZATION"), // + createPaymentAllocation("PAYOUT_REFUND", "NEXT_INSTALLMENT")));// + final PostLoanProductsResponse responseLoanProductsRequestLP2ProgressiveAdvPaymentBuyDownFeesFeeIncome = createLoanProductIdempotent( + loanProductsRequestLP2ProgressiveAdvPaymentBuyDownFeesFeeIncome); + TestContext.INSTANCE.set(TestContextKey.DEFAULT_LOAN_PRODUCT_CREATE_RESPONSE_LP2_PROGRESSIVE_ADV_PYMNT_BUYDOWN_FEES_FEE_INCOME, + responseLoanProductsRequestLP2ProgressiveAdvPaymentBuyDownFeesFeeIncome); } public static AdvancedPaymentData createPaymentAllocation(String transactionType, String futureInstallmentAllocationRule, diff --git a/fineract-e2e-tests-runner/src/test/resources/features/Reporting.feature b/fineract-e2e-tests-runner/src/test/resources/features/Reporting.feature new file mode 100644 index 000000000..e2874102e --- /dev/null +++ b/fineract-e2e-tests-runner/src/test/resources/features/Reporting.feature @@ -0,0 +1,172 @@ +@ReportingFeature +Feature: Reporting + + Scenario: Verify Transaction Summary Reports contain all buydown fee transaction types + When Admin sets the business date to "01 January 2024" + And Admin creates a new office + And Admin creates a client with random data in the last created office + And Admin creates a fully customized loan with the following data: + | LoanProduct | submitted on date | with Principal | ANNUAL interest rate % | interest type | interest calculation period | amortization type | loanTermFrequency | loanTermFrequencyType | repaymentEvery | repaymentFrequencyType | numberOfRepayments | graceOnPrincipalPayment | graceOnInterestPayment | interest free period | Payment strategy | + | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | 01 January 2024 | 100 | 7 | DECLINING_BALANCE | DAILY | EQUAL_INSTALLMENTS | 3 | MONTHS | 1 | MONTHS | 3 | 0 | 0 | 0 | ADVANCED_PAYMENT_ALLOCATION | + And Admin successfully approves the loan on "01 January 2024" with "100" amount and expected disbursement date on "01 January 2024" + And Admin successfully disburse the loan on "01 January 2024" with "100" EUR transaction amount + When Admin adds buy down fee with "AUTOPAY" payment type to the loan on "01 January 2024" with "50" EUR transaction amount + When Admin sets the business date to "31 January 2024" + When Admin runs inline COB job for Loan + When Admin sets the business date to "01 February 2024" + When Admin runs inline COB job for Loan + And Admin adds buy down fee adjustment with "AUTOPAY" payment type to the loan on "01 February 2024" with "10" EUR transaction amount + When Admin sets the business date to "02 February 2024" + And Admin adds buy down fee adjustment of buy down fee transaction made on "01 January 2024" with "AUTOPAY" payment type to the loan on "10 January 2024" with "25" EUR transaction amount + When Admin runs inline COB job for Loan + Then Transaction Summary Report for date "01 January 2024" has the following data: + | TransactionDate | Product | TransactionType_Name | PaymentType_Name | chargetype | Reversed | Allocation_Type | Chargeoff_ReasonCode | Transaction_Amount | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee | AUTOPAY | | 0 | Fees | | 0.0 | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee | AUTOPAY | | 0 | Interest | | 0.0 | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee | AUTOPAY | | 0 | Penalty | | 0.0 | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee | AUTOPAY | | 0 | Principal | | 50.0 | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee | AUTOPAY | | 0 | Unallocated Credit (UNC) | | 0.0 | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Disbursement | | | 0 | Fees | | 0.0 | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Disbursement | | | 0 | Interest | | 0.0 | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Disbursement | | | 0 | Penalty | | 0.0 | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Disbursement | | | 0 | Principal | | 100.0 | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Disbursement | | | 0 | Unallocated Credit (UNC) | | 0.0 | + Then Transaction Summary Report for date "31 January 2024" has the following data: + | TransactionDate | Product | TransactionType_Name | PaymentType_Name | chargetype | Reversed | Allocation_Type | Chargeoff_ReasonCode | Transaction_Amount | + | 2024-01-31 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Apply Charges | | | 0 | Interest | | | + | 2024-01-31 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee Amortization | | | 0 | Fees | | 0.0 | + | 2024-01-31 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee Amortization | | | 0 | Interest | | 0.55 | + | 2024-01-31 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee Amortization | | | 0 | Penalty | | 0.0 | + | 2024-01-31 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee Amortization | | | 0 | Principal | | 0.0 | + | 2024-01-31 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee Amortization | | | 0 | Unallocated Credit (UNC) | | 0.0 | + Then Transaction Summary Report for date "01 February 2024" has the following data: + | TransactionDate | Product | TransactionType_Name | PaymentType_Name | chargetype | Reversed | Allocation_Type | Chargeoff_ReasonCode | Transaction_Amount | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Apply Charges | | | 0 | Interest | | | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee Adjustment | AUTOPAY | | 0 | Fees | | 0.0 | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee Adjustment | AUTOPAY | | 0 | Interest | | 0.0 | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee Adjustment | AUTOPAY | | 0 | Penalty | | 0.0 | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee Adjustment | AUTOPAY | | 0 | Principal | | -10.0 | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee Adjustment | AUTOPAY | | 0 | Unallocated Credit (UNC) | | 0.0 | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee Amortization Adjustment | | | 0 | Fees | | 0.0 | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee Amortization Adjustment | | | 0 | Interest | | -6.63 | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee Amortization Adjustment | | | 0 | Penalty | | 0.0 | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee Amortization Adjustment | | | 0 | Principal | | 0.0 | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee Amortization Adjustment | | | 0 | Unallocated Credit (UNC) | | 0.0 | + Then Transaction Summary Report with Asset Owner for date "01 January 2024" has the following data: + | TransactionDate | Product | TransactionType_Name | PaymentType_Name | chargetype | Reversed | Allocation_Type | Chargeoff_ReasonCode | Transaction_Amount | Asset_owner_id | From_asset_owner_id | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee | AUTOPAY | | 0 | Fees | | 0.0 | | | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee | AUTOPAY | | 0 | Interest | | 0.0 | | | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee | AUTOPAY | | 0 | Penalty | | 0.0 | | | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee | AUTOPAY | | 0 | Principal | | 50.0 | | | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee | AUTOPAY | | 0 | Unallocated Credit (UNC) | | 0.0 | | | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Disbursement | | | 0 | Fees | | 0.0 | | | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Disbursement | | | 0 | Interest | | 0.0 | | | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Disbursement | | | 0 | Penalty | | 0.0 | | | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Disbursement | | | 0 | Principal | | 100.0 | | | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Disbursement | | | 0 | Unallocated Credit (UNC) | | 0.0 | | | + Then Transaction Summary Report with Asset Owner for date "31 January 2024" has the following data: + | TransactionDate | Product | TransactionType_Name | PaymentType_Name | chargetype | Reversed | Allocation_Type | Chargeoff_ReasonCode | Transaction_Amount | Asset_owner_id | From_asset_owner_id | + | 2024-01-31 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Apply Charges | | | 0 | Interest | | | | | + | 2024-01-31 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee Amortization | | | 0 | Fees | | 0.0 | | | + | 2024-01-31 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee Amortization | | | 0 | Interest | | 0.55 | | | + | 2024-01-31 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee Amortization | | | 0 | Penalty | | 0.0 | | | + | 2024-01-31 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee Amortization | | | 0 | Principal | | 0.0 | | | + | 2024-01-31 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee Amortization | | | 0 | Unallocated Credit (UNC) | | 0.0 | | | + Then Transaction Summary Report with Asset Owner for date "01 February 2024" has the following data: + | TransactionDate | Product | TransactionType_Name | PaymentType_Name | chargetype | Reversed | Allocation_Type | Chargeoff_ReasonCode | Transaction_Amount | Asset_owner_id | From_asset_owner_id | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Apply Charges | | | 0 | Interest | | | | | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee Adjustment | AUTOPAY | | 0 | Fees | | 0.0 | | | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee Adjustment | AUTOPAY | | 0 | Interest | | 0.0 | | | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee Adjustment | AUTOPAY | | 0 | Penalty | | 0.0 | | | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee Adjustment | AUTOPAY | | 0 | Principal | | -10.0 | | | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee Adjustment | AUTOPAY | | 0 | Unallocated Credit (UNC) | | 0.0 | | | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee Amortization Adjustment | | | 0 | Fees | | 0.0 | | | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee Amortization Adjustment | | | 0 | Interest | | -6.63 | | | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee Amortization Adjustment | | | 0 | Penalty | | 0.0 | | | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee Amortization Adjustment | | | 0 | Principal | | 0.0 | | | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES | Buy Down Fee Amortization Adjustment | | | 0 | Unallocated Credit (UNC) | | 0.0 | | | + + Scenario: Verify Transaction Summary Reports with buyDownFeeIncomeType = FEE + When Admin sets the business date to "01 January 2024" + And Admin creates a new office + And Admin creates a client with random data in the last created office + And Admin creates a fully customized loan with the following data: + | LoanProduct | submitted on date | with Principal | ANNUAL interest rate % | interest type | interest calculation period | amortization type | loanTermFrequency | loanTermFrequencyType | repaymentEvery | repaymentFrequencyType | numberOfRepayments | graceOnPrincipalPayment | graceOnInterestPayment | interest free period | Payment strategy | + | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | 01 January 2024 | 100 | 7 | DECLINING_BALANCE | DAILY | EQUAL_INSTALLMENTS | 3 | MONTHS | 1 | MONTHS | 3 | 0 | 0 | 0 | ADVANCED_PAYMENT_ALLOCATION | + And Admin successfully approves the loan on "01 January 2024" with "100" amount and expected disbursement date on "01 January 2024" + And Admin successfully disburse the loan on "01 January 2024" with "100" EUR transaction amount + When Admin adds buy down fee with "AUTOPAY" payment type to the loan on "01 January 2024" with "50" EUR transaction amount + When Admin sets the business date to "31 January 2024" + When Admin runs inline COB job for Loan + When Admin sets the business date to "01 February 2024" + When Admin runs inline COB job for Loan + And Admin adds buy down fee adjustment with "AUTOPAY" payment type to the loan on "01 February 2024" with "10" EUR transaction amount + When Admin sets the business date to "02 February 2024" + And Admin adds buy down fee adjustment of buy down fee transaction made on "01 January 2024" with "AUTOPAY" payment type to the loan on "10 January 2024" with "25" EUR transaction amount + When Admin runs inline COB job for Loan + Then Transaction Summary Report for date "01 January 2024" has the following data: + | TransactionDate | Product | TransactionType_Name | PaymentType_Name | chargetype | Reversed | Allocation_Type | Chargeoff_ReasonCode | Transaction_Amount | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee | AUTOPAY | | 0 | Fees | | 0.0 | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee | AUTOPAY | | 0 | Interest | | 0.0 | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee | AUTOPAY | | 0 | Penalty | | 0.0 | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee | AUTOPAY | | 0 | Principal | | 50.0 | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee | AUTOPAY | | 0 | Unallocated Credit (UNC) | | 0.0 | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Disbursement | | | 0 | Fees | | 0.0 | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Disbursement | | | 0 | Interest | | 0.0 | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Disbursement | | | 0 | Penalty | | 0.0 | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Disbursement | | | 0 | Principal | | 100.0 | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Disbursement | | | 0 | Unallocated Credit (UNC) | | 0.0 | + Then Transaction Summary Report for date "31 January 2024" has the following data: + | TransactionDate | Product | TransactionType_Name | PaymentType_Name | chargetype | Reversed | Allocation_Type | Chargeoff_ReasonCode | Transaction_Amount | + | 2024-01-31 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Apply Charges | | | 0 | Interest | | | + | 2024-01-31 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee Amortization | | | 0 | Fees | | 0.55 | + | 2024-01-31 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee Amortization | | | 0 | Interest | | 0.0 | + | 2024-01-31 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee Amortization | | | 0 | Penalty | | 0.0 | + | 2024-01-31 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee Amortization | | | 0 | Principal | | 0.0 | + | 2024-01-31 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee Amortization | | | 0 | Unallocated Credit (UNC) | | 0.0 | + Then Transaction Summary Report for date "01 February 2024" has the following data: + | TransactionDate | Product | TransactionType_Name | PaymentType_Name | chargetype | Reversed | Allocation_Type | Chargeoff_ReasonCode | Transaction_Amount | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Apply Charges | | | 0 | Interest | | | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee Adjustment | AUTOPAY | | 0 | Fees | | 0.0 | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee Adjustment | AUTOPAY | | 0 | Interest | | 0.0 | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee Adjustment | AUTOPAY | | 0 | Penalty | | 0.0 | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee Adjustment | AUTOPAY | | 0 | Principal | | -10.0 | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee Adjustment | AUTOPAY | | 0 | Unallocated Credit (UNC) | | 0.0 | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee Amortization Adjustment | | | 0 | Fees | | -6.63 | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee Amortization Adjustment | | | 0 | Interest | | 0.0 | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee Amortization Adjustment | | | 0 | Penalty | | 0.0 | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee Amortization Adjustment | | | 0 | Principal | | 0.0 | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee Amortization Adjustment | | | 0 | Unallocated Credit (UNC) | | 0.0 | + Then Transaction Summary Report with Asset Owner for date "01 January 2024" has the following data: + | TransactionDate | Product | TransactionType_Name | PaymentType_Name | chargetype | Reversed | Allocation_Type | Chargeoff_ReasonCode | Transaction_Amount | Asset_owner_id | From_asset_owner_id | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee | AUTOPAY | | 0 | Fees | | 0.0 | | | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee | AUTOPAY | | 0 | Interest | | 0.0 | | | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee | AUTOPAY | | 0 | Penalty | | 0.0 | | | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee | AUTOPAY | | 0 | Principal | | 50.0 | | | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee | AUTOPAY | | 0 | Unallocated Credit (UNC) | | 0.0 | | | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Disbursement | | | 0 | Fees | | 0.0 | | | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Disbursement | | | 0 | Interest | | 0.0 | | | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Disbursement | | | 0 | Penalty | | 0.0 | | | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Disbursement | | | 0 | Principal | | 100.0 | | | + | 2024-01-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Disbursement | | | 0 | Unallocated Credit (UNC) | | 0.0 | | | + Then Transaction Summary Report with Asset Owner for date "31 January 2024" has the following data: + | TransactionDate | Product | TransactionType_Name | PaymentType_Name | chargetype | Reversed | Allocation_Type | Chargeoff_ReasonCode | Transaction_Amount | Asset_owner_id | From_asset_owner_id | + | 2024-01-31 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Apply Charges | | | 0 | Interest | | | | | + | 2024-01-31 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee Amortization | | | 0 | Fees | | 0.55 | | | + | 2024-01-31 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee Amortization | | | 0 | Interest | | 0.0 | | | + | 2024-01-31 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee Amortization | | | 0 | Penalty | | 0.0 | | | + | 2024-01-31 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee Amortization | | | 0 | Principal | | 0.0 | | | + | 2024-01-31 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee Amortization | | | 0 | Unallocated Credit (UNC) | | 0.0 | | | + Then Transaction Summary Report with Asset Owner for date "01 February 2024" has the following data: + | TransactionDate | Product | TransactionType_Name | PaymentType_Name | chargetype | Reversed | Allocation_Type | Chargeoff_ReasonCode | Transaction_Amount | Asset_owner_id | From_asset_owner_id | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Apply Charges | | | 0 | Interest | | | | | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee Adjustment | AUTOPAY | | 0 | Fees | | 0.0 | | | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee Adjustment | AUTOPAY | | 0 | Interest | | 0.0 | | | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee Adjustment | AUTOPAY | | 0 | Penalty | | 0.0 | | | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee Adjustment | AUTOPAY | | 0 | Principal | | -10.0 | | | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee Adjustment | AUTOPAY | | 0 | Unallocated Credit (UNC) | | 0.0 | | | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee Amortization Adjustment | | | 0 | Fees | | -6.63 | | | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee Amortization Adjustment | | | 0 | Interest | | 0.0 | | | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee Amortization Adjustment | | | 0 | Penalty | | 0.0 | | | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee Amortization Adjustment | | | 0 | Principal | | 0.0 | | | + | 2024-02-01 | LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_BUYDOWN_FEES_FEE_INCOME | Buy Down Fee Amortization Adjustment | | | 0 | Unallocated Credit (UNC) | | 0.0 | | | diff --git a/fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml b/fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml index 8ae46ba69..e3892d613 100644 --- a/fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml +++ b/fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml @@ -233,4 +233,5 @@ + diff --git a/fineract-provider/src/main/resources/db/changelog/tenant/parts/0215_transaction_summary_reports_add_buydown_fee_types.xml b/fineract-provider/src/main/resources/db/changelog/tenant/parts/0215_transaction_summary_reports_add_buydown_fee_types.xml new file mode 100644 index 000000000..ac81793cc --- /dev/null +++ b/fineract-provider/src/main/resources/db/changelog/tenant/parts/0215_transaction_summary_reports_add_buydown_fee_types.xml @@ -0,0 +1,3263 @@ + + + + + + = '${endDate}' + LEFT JOIN loan_originators lo ON lo.loan_id = t.loan_id + WHERE t.submitted_on_date = '${endDate}' + AND t.transaction_type_enum not in (10, 26, 32, 34, 36, 39, 42, 43) + AND (t.office_id = ${officeId})), + slt_charge_adj AS (SELECT '${endDate}' AS transactiondate, + t.id, + l.name, + t.transaction_type_enum, + d.payment_type_id, + t.overpayment_portion_derived, + t.principal_portion_derived, + t.interest_portion_derived, + t.fee_charges_portion_derived, + t.penalty_charges_portion_derived, + t.amount, + e.status, + e.settlement_date, + e.owner_id, + m.charged_off_on_date, + t.transaction_date, + m.charge_off_reason_cv_id, + lo.originator_external_ids + FROM m_loan_transaction t + JOIN m_loan m ON m.id = t.loan_id + JOIN m_product_loan l ON l.id = m.product_id + LEFT JOIN m_payment_detail d ON d.id = t.payment_detail_id + LEFT JOIN m_external_asset_owner_transfer e + ON e.loan_id = t.loan_id AND e.settlement_date < '${endDate}' AND + e.effective_date_to >= '${endDate}' + LEFT JOIN loan_originators lo ON lo.loan_id = t.loan_id + WHERE t.submitted_on_date = '${endDate}' + AND t.transaction_type_enum = 26 + AND (t.office_id = ${officeId})), + rlt_except_charge_adj_and_accrual AS (SELECT '${endDate}' AS transactiondate, + t.id, + l.name, + t.transaction_type_enum, + d.payment_type_id, + CASE + WHEN d.payment_type_id IS NULL AND t.classification_cv_id IS NOT NULL + THEN (SELECT code_value FROM m_code_value WHERE id = t.classification_cv_id) + ELSE NULL END AS classification_name, + t.overpayment_portion_derived, + t.principal_portion_derived, + t.interest_portion_derived, + t.fee_charges_portion_derived, + t.penalty_charges_portion_derived, + t.amount, + e.status, + e.settlement_date, + e.owner_id, + m.charged_off_on_date, + t.transaction_date, + m.charge_off_reason_cv_id, + lo.originator_external_ids + FROM m_loan_transaction t + JOIN m_loan m ON m.id = t.loan_id + JOIN m_product_loan l ON l.id = m.product_id + LEFT JOIN m_payment_detail d ON d.id = t.payment_detail_id + LEFT JOIN m_external_asset_owner_transfer e + ON e.loan_id = t.loan_id AND + e.settlement_date < '${endDate}' AND + e.effective_date_to >= '${endDate}' + LEFT JOIN loan_originators lo ON lo.loan_id = t.loan_id + WHERE t.reversed_on_date = '${endDate}' + AND t.transaction_type_enum not in (10, 26, 32, 34, 36, 39, 42, 43) + AND (t.office_id = ${officeId})), + rlt_charge_adj AS (SELECT '${endDate}' AS transactiondate, + t.id, + l.name, + t.transaction_type_enum, + d.payment_type_id, + t.overpayment_portion_derived, + t.principal_portion_derived, + t.interest_portion_derived, + t.fee_charges_portion_derived, + t.penalty_charges_portion_derived, + t.amount, + e.status, + e.settlement_date, + e.owner_id, + m.charged_off_on_date, + t.transaction_date, + m.charge_off_reason_cv_id, + lo.originator_external_ids + FROM m_loan_transaction t + JOIN m_loan m ON m.id = t.loan_id + JOIN m_product_loan l ON l.id = m.product_id + LEFT JOIN m_payment_detail d ON d.id = t.payment_detail_id + LEFT JOIN m_external_asset_owner_transfer e + ON e.loan_id = t.loan_id AND e.settlement_date < '${endDate}' AND + e.effective_date_to >= '${endDate}' + LEFT JOIN loan_originators lo ON lo.loan_id = t.loan_id + WHERE t.reversed_on_date = '${endDate}' + AND t.transaction_type_enum = 26 + AND (t.office_id = ${officeId})), + slt_cap_income_amortization AS (SELECT '${endDate}' AS transactiondate, + t.id, + l.name, + t.transaction_type_enum, + d.payment_type_id, + CASE + WHEN d.payment_type_id IS NULL AND bt.classification_cv_id IS NOT NULL + THEN (SELECT code_value FROM m_code_value WHERE id = bt.classification_cv_id) + ELSE NULL END AS classification_name, + t.overpayment_portion_derived, + t.principal_portion_derived, + t.interest_portion_derived, + t.fee_charges_portion_derived, + t.penalty_charges_portion_derived, + t.amount, + e.status, + e.settlement_date, + e.owner_id, + m.charged_off_on_date, + t.transaction_date, + m.charge_off_reason_cv_id, + lo.originator_external_ids + FROM m_loan_transaction t + JOIN m_loan m ON m.id = t.loan_id + JOIN m_product_loan l ON l.id = m.product_id + LEFT JOIN m_payment_detail d ON d.id = t.payment_detail_id + JOIN m_loan_amortization_allocation_mapping map + ON map.amortization_loan_transaction_id = t.id + JOIN m_loan_transaction bt ON bt.id = map.base_loan_transaction_id + LEFT JOIN m_external_asset_owner_transfer e ON e.loan_id = t.loan_id AND + e.settlement_date < + '${endDate}' AND + e.effective_date_to >= + '${endDate}' + LEFT JOIN loan_originators lo ON lo.loan_id = t.loan_id + WHERE t.submitted_on_date = '${endDate}' + AND t.is_reversed = false + AND t.transaction_type_enum IN (36, 39, 42, 43) + AND (t.office_id = ${officeId})), + rlt_cap_income_amortization AS (SELECT '${endDate}' AS transactiondate, + t.id, + l.name, + t.transaction_type_enum, + d.payment_type_id, + CASE + WHEN d.payment_type_id IS NULL AND bt.classification_cv_id IS NOT NULL + THEN (SELECT code_value FROM m_code_value WHERE id = bt.classification_cv_id) + ELSE NULL END AS classification_name, + t.overpayment_portion_derived, + t.principal_portion_derived, + t.interest_portion_derived, + t.fee_charges_portion_derived, + t.penalty_charges_portion_derived, + t.amount, + e.status, + e.settlement_date, + e.owner_id, + m.charged_off_on_date, + t.transaction_date, + m.charge_off_reason_cv_id, + lo.originator_external_ids + FROM m_loan_transaction t + JOIN m_loan m ON m.id = t.loan_id + JOIN m_product_loan l ON l.id = m.product_id + LEFT JOIN m_payment_detail d ON d.id = t.payment_detail_id + JOIN m_loan_amortization_allocation_mapping map + ON map.amortization_loan_transaction_id = t.id + JOIN m_loan_transaction bt ON bt.id = map.base_loan_transaction_id + LEFT JOIN m_external_asset_owner_transfer e ON e.loan_id = t.loan_id AND + e.settlement_date < + '${endDate}' AND + e.effective_date_to >= + '${endDate}' + LEFT JOIN loan_originators lo ON lo.loan_id = t.loan_id + WHERE t.reversed_on_date = '${endDate}' + AND t.is_reversed = true + AND t.transaction_type_enum IN (36, 39, 42, 43) + AND (t.office_id = ${officeId})), + active_external_asset_owner_transfers AS (SELECT '${endDate}' AS transactiondate, + t.id, + p.name, + t.owner_id, + dt.principal_outstanding_derived, + dt.interest_outstanding_derived, + dt.fee_charges_outstanding_derived, + dt.penalty_charges_outstanding_derived, + dt.total_overpaid_derived, + l.charged_off_on_date, + t.settlement_date, + l.charge_off_reason_cv_id, + lo.originator_external_ids + FROM m_external_asset_owner_transfer t + JOIN m_loan l ON l.id = t.loan_id + JOIN m_client c ON c.id = l.client_id + JOIN m_product_loan p ON p.id = l.product_id + JOIN m_external_asset_owner_transfer_details dt + ON dt.asset_owner_transfer_id = t.id + LEFT JOIN loan_originators lo ON lo.loan_id = t.loan_id + WHERE t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') + AND c.office_id = ${officeId} + AND t.settlement_date = '${endDate}'), + buyback_external_asset_owner_transfers AS (SELECT '${endDate}' AS transactiondate, + t.id, + p.name, + dt.principal_outstanding_derived, + dt.interest_outstanding_derived, + dt.fee_charges_outstanding_derived, + dt.penalty_charges_outstanding_derived, + dt.total_overpaid_derived, + l.charged_off_on_date, + t.settlement_date, + l.charge_off_reason_cv_id, + t.owner_id, + lo.originator_external_ids + FROM m_external_asset_owner_transfer t + JOIN m_loan l ON l.id = t.loan_id + JOIN m_client c ON c.id = l.client_id + JOIN m_product_loan p ON p.id = l.product_id + JOIN m_external_asset_owner_transfer_details dt + ON dt.asset_owner_transfer_id = t.id + LEFT JOIN loan_originators lo ON lo.loan_id = t.loan_id + WHERE t.status in ('BUYBACK', 'BUYBACK_INTERMEDIATE') + AND c.office_id = ${officeId} + AND t.settlement_date = '${endDate}') +SELECT '${endDate}' AS TransactionDate, + a.product AS Product, + CASE + WHEN a.transaction_type = 9999 THEN 'Asset Transfer' + WHEN a.transaction_type = 99999 THEN 'Asset Buyback' + ELSE (SELECT enum_message_property + FROM r_enum_value + WHERE enum_name = 'transaction_type_enum' + AND enum_id = a.transaction_type) END AS TransactionType_Name, + COALESCE((SELECT value FROM m_payment_type WHERE id = a.payment_type_id), + a.classification_name) AS PaymentType_Name, + a.chargetype AS chargetype, + a.reversal_indicator AS Reversed, + a.Allocation_Type AS Allocation_Type, + (SELECT code_value FROM m_code_value WHERE id = a.charge_off_reason_id) AS Chargeoff_ReasonCode, + CASE + WHEN a.transaction_type = 9999 THEN sum(a.amount) * + 1 + WHEN a.transaction_type = 99999 THEN sum(a.amount) * - 1 + WHEN a.transaction_type IN (2, 23, 21, 22, 24, 4, 5, 8, 6, 27, 9, 26, 28, 31, 33, 34, 37, 39, 41, 43) AND + a.reversal_indicator = false THEN sum(a.amount) * -1 + WHEN a.transaction_type IN (2, 23, 21, 22, 24, 4, 5, 8, 6, 27, 9, 26, 28, 31, 33, 34, 37, 39, 41, 43) AND + a.reversal_indicator = true THEN sum(a.amount) * + 1 + WHEN a.transaction_type IN (1, 10, 25, 20, 35, 36, 40, 42) AND a.reversal_indicator = false THEN sum(a.amount) * + 1 + WHEN a.transaction_type IN (1, 10, 25, 20, 35, 36, 40, 42) AND a.reversal_indicator = true + THEN sum(a.amount) * -1 END AS Transaction_Amount, + (SELECT external_id + FROM m_external_asset_owner + WHERE id = a.asset_owner_id) AS Asset_owner_id, + (SELECT external_id + FROM m_external_asset_owner + WHERE id = a.from_asset_owner_id) AS From_asset_owner_id, + a.originator_external_ids +FROM (SELECT t.transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Principal' AS Allocation_Type, + CASE + WHEN t.transaction_type_enum in (1, 40, 41) THEN (CASE + WHEN t.amount is null THEN 0 + WHEN t.overpayment_portion_derived is null THEN t.amount + WHEN t.overpayment_portion_derived is not null + THEN t.amount - t.overpayment_portion_derived + ELSE t.amount END) + ELSE (CASE + WHEN t.principal_portion_derived is null THEN 0 + ELSE t.principal_portion_derived end) END amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM slt_except_charge_adj_and_accrual AS t + UNION ALL + SELECT t.transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Interest' AS Allocation_Type, + CASE WHEN t.interest_portion_derived is null THEN 0 ELSE t.interest_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM slt_except_charge_adj_and_accrual AS t + UNION ALL + SELECT t.transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Fees' AS Allocation_Type, + CASE WHEN t.fee_charges_portion_derived is null THEN 0 ELSE t.fee_charges_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM slt_except_charge_adj_and_accrual AS t + UNION ALL + SELECT t.transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Penalty' AS Allocation_Type, + CASE + WHEN t.penalty_charges_portion_derived is null THEN 0 + ELSE t.penalty_charges_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM slt_except_charge_adj_and_accrual AS t + UNION ALL + SELECT t.transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Unallocated Credit (UNC)' AS Allocation_Type, + CASE WHEN t.overpayment_portion_derived is null THEN 0 ELSE t.overpayment_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM slt_except_charge_adj_and_accrual AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Fees' AS Allocation_Type, + CASE WHEN t.fee_charges_portion_derived is null THEN 0 ELSE t.fee_charges_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.transaction_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM slt_cap_income_amortization AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Penalty' AS Allocation_Type, + CASE + WHEN t.penalty_charges_portion_derived is null THEN 0 + ELSE t.penalty_charges_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.transaction_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM slt_cap_income_amortization AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Interest' AS Allocation_Type, + CASE WHEN t.interest_portion_derived is null THEN 0 ELSE t.interest_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.transaction_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM slt_cap_income_amortization AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Principal' AS Allocation_Type, + CASE WHEN t.principal_portion_derived is null THEN 0 ELSE t.principal_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.transaction_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM slt_cap_income_amortization AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Unallocated Credit (UNC)' AS Allocation_Type, + CASE WHEN t.overpayment_portion_derived is null THEN 0 ELSE t.overpayment_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.transaction_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM slt_cap_income_amortization AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Fees' AS Allocation_Type, + CASE WHEN t.fee_charges_portion_derived is null THEN 0 ELSE t.fee_charges_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.transaction_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM rlt_cap_income_amortization AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Penalty' AS Allocation_Type, + CASE + WHEN t.penalty_charges_portion_derived is null THEN 0 + ELSE t.penalty_charges_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.transaction_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM rlt_cap_income_amortization AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Interest' AS Allocation_Type, + CASE WHEN t.interest_portion_derived is null THEN 0 ELSE t.interest_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.transaction_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM rlt_cap_income_amortization AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Principal' AS Allocation_Type, + CASE WHEN t.principal_portion_derived is null THEN 0 ELSE t.principal_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.transaction_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM rlt_cap_income_amortization AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Unallocated Credit (UNC)' AS Allocation_Type, + CASE WHEN t.overpayment_portion_derived is null THEN 0 ELSE t.overpayment_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.transaction_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM rlt_cap_income_amortization AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + l.name AS product, + t.transaction_type_enum AS transaction_type, + null AS payment_type_id, + null AS classification_name, + mc.name AS chargetype, + false AS reversal_indicator, + 'Fees' AS Allocation_Type, + CASE WHEN pd.amount is null THEN 0 ELSE pd.amount END AS amount, + CASE + WHEN e.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND e.settlement_date < '${endDate}' + THEN e.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (m.charged_off_on_date <= t.transaction_date) + THEN m.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + lo.originator_external_ids + FROM m_loan_transaction t + JOIN m_loan m ON m.id = t.loan_id + JOIN m_product_loan l ON l.id = m.product_id + JOIN m_loan_charge_paid_by pd ON pd.loan_transaction_id = t.id + JOIN m_loan_charge c ON c.id = pd.loan_charge_id + JOIN m_charge mc ON mc.id = c.charge_id AND mc.is_penalty = false + LEFT JOIN m_external_asset_owner_transfer e + ON e.loan_id = t.loan_id AND e.settlement_date < '${endDate}' AND + e.effective_date_to >= '${endDate}' + LEFT JOIN loan_originators lo ON lo.loan_id = t.loan_id + WHERE t.submitted_on_date = '${endDate}' + AND t.transaction_type_enum = 10 + AND t.is_reversed = false + AND (t.office_id = ${officeId}) + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + l.name AS product, + t.transaction_type_enum AS transaction_type, + null AS payment_type_id, + null AS classification_name, + mc.name AS chargetype, + false AS reversal_indicator, + 'Penalty' AS Allocation_Type, + CASE WHEN pd.amount is null THEN 0 ELSE pd.amount END AS amount, + CASE + WHEN e.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND e.settlement_date < '${endDate}' + THEN e.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (m.charged_off_on_date <= t.transaction_date) + THEN m.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + lo.originator_external_ids + FROM m_loan_transaction t + JOIN m_loan m ON m.id = t.loan_id + JOIN m_product_loan l ON l.id = m.product_id + JOIN m_loan_charge_paid_by pd ON pd.loan_transaction_id = t.id + JOIN m_loan_charge c ON c.id = pd.loan_charge_id + JOIN m_charge mc ON mc.id = c.charge_id AND mc.is_penalty = true + LEFT JOIN m_external_asset_owner_transfer e + ON e.loan_id = t.loan_id AND e.settlement_date < '${endDate}' AND + e.effective_date_to >= '${endDate}' + LEFT JOIN loan_originators lo ON lo.loan_id = t.loan_id + WHERE t.submitted_on_date = '${endDate}' + AND t.transaction_type_enum = 10 + AND t.is_reversed = false + AND (t.office_id = ${officeId}) + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + l.name AS product, + t.transaction_type_enum AS transaction_type, + null AS payment_type_id, + null AS classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Interest' AS Allocation_Type, + CASE WHEN t.interest_portion_derived is null THEN 0 ELSE t.interest_portion_derived END AS amount, + CASE + WHEN e.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND e.settlement_date < '${endDate}' + THEN e.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (m.charged_off_on_date <= t.transaction_date) + THEN m.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + lo.originator_external_ids + FROM m_loan_transaction t + JOIN m_loan m ON m.id = t.loan_id + JOIN m_product_loan l ON l.id = m.product_id + LEFT JOIN m_external_asset_owner_transfer e + ON e.loan_id = t.loan_id AND e.settlement_date < '${endDate}' AND + e.effective_date_to >= '${endDate}' + LEFT JOIN loan_originators lo ON lo.loan_id = t.loan_id + WHERE t.submitted_on_date = '${endDate}' + AND t.transaction_type_enum in (10, 34) + AND t.is_reversed = false + AND (t.office_id = ${officeId}) + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + null AS classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Fees' AS Allocation_Type, + CASE WHEN t.fee_charges_portion_derived is null THEN 0 ELSE t.fee_charges_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM slt_charge_adj AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + null AS classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Penalty' AS Allocation_Type, + CASE + WHEN t.penalty_charges_portion_derived is null THEN 0 + ELSE t.penalty_charges_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM slt_charge_adj AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + null AS classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Interest' AS Allocation_Type, + CASE WHEN t.interest_portion_derived is null THEN 0 ELSE t.interest_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM slt_charge_adj AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + null AS classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Principal' AS Allocation_Type, + CASE WHEN t.principal_portion_derived is null THEN 0 ELSE t.principal_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM slt_charge_adj AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + null AS classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Unallocated Credit (UNC)' AS Allocation_Type, + CASE WHEN t.overpayment_portion_derived is null THEN 0 ELSE t.overpayment_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM slt_charge_adj AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + true AS reversal_indicator, + 'Principal' AS Allocation_Type, + CASE + WHEN t.transaction_type_enum in (1, 40, 41) THEN (CASE + WHEN t.amount is null THEN 0 + WHEN t.overpayment_portion_derived is null THEN t.amount + WHEN t.overpayment_portion_derived is not null + THEN t.amount - t.overpayment_portion_derived + ELSE t.amount END) + ELSE (CASE + WHEN t.principal_portion_derived is null THEN 0 + ELSE t.principal_portion_derived end) END amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM rlt_except_charge_adj_and_accrual AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + true AS reversal_indicator, + 'Interest' AS Allocation_Type, + CASE WHEN t.interest_portion_derived is null THEN 0 ELSE t.interest_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM rlt_except_charge_adj_and_accrual AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + true AS reversal_indicator, + 'Fees' AS Allocation_Type, + CASE WHEN t.fee_charges_portion_derived is null THEN 0 ELSE t.fee_charges_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM rlt_except_charge_adj_and_accrual AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + true AS reversal_indicator, + 'Penalty' AS Allocation_Type, + CASE + WHEN t.penalty_charges_portion_derived is null THEN 0 + ELSE t.penalty_charges_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM rlt_except_charge_adj_and_accrual AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + true AS reversal_indicator, + 'Unallocated Credit (UNC)' AS Allocation_Type, + CASE WHEN t.overpayment_portion_derived is null THEN 0 ELSE t.overpayment_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM rlt_except_charge_adj_and_accrual AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + l.name AS product, + t.transaction_type_enum AS transaction_type, + null AS payment_type_id, + null AS classification_name, + mc.name AS chargetype, + true AS reversal_indicator, + 'Fees' AS Allocation_Type, + CASE WHEN pd.amount is null THEN 0 ELSE pd.amount END AS amount, + CASE + WHEN e.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND e.settlement_date < '${endDate}' + THEN e.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (m.charged_off_on_date <= t.transaction_date) + THEN m.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + lo.originator_external_ids + FROM m_loan_transaction t + JOIN m_loan m ON m.id = t.loan_id + JOIN m_product_loan l ON l.id = m.product_id + JOIN m_loan_charge_paid_by pd ON pd.loan_transaction_id = t.id + JOIN m_loan_charge c ON c.id = pd.loan_charge_id + JOIN m_charge mc ON mc.id = c.charge_id AND mc.is_penalty = false + LEFT JOIN m_external_asset_owner_transfer e + ON e.loan_id = t.loan_id AND e.settlement_date < '${endDate}' AND + e.effective_date_to >= '${endDate}' + LEFT JOIN loan_originators lo ON lo.loan_id = t.loan_id + WHERE t.reversed_on_date = '${endDate}' + AND t.transaction_type_enum = 10 + AND t.is_reversed = true + AND (t.office_id = ${officeId}) + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + l.name AS product, + t.transaction_type_enum AS transaction_type, + null AS payment_type_id, + null AS classification_name, + mc.name AS chargetype, + true AS reversal_indicator, + 'Penalty' AS Allocation_Type, + CASE WHEN pd.amount is null THEN 0 ELSE pd.amount END AS amount, + CASE + WHEN e.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND e.settlement_date < '${endDate}' + THEN e.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (m.charged_off_on_date <= t.transaction_date) + THEN m.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + lo.originator_external_ids + FROM m_loan_transaction t + JOIN m_loan m ON m.id = t.loan_id + JOIN m_product_loan l ON l.id = m.product_id + JOIN m_loan_charge_paid_by pd ON pd.loan_transaction_id = t.id + JOIN m_loan_charge c ON c.id = pd.loan_charge_id + JOIN m_charge mc ON mc.id = c.charge_id AND mc.is_penalty = true + LEFT JOIN m_external_asset_owner_transfer e + ON e.loan_id = t.loan_id AND e.settlement_date < '${endDate}' AND + e.effective_date_to >= '${endDate}' + LEFT JOIN loan_originators lo ON lo.loan_id = t.loan_id + WHERE t.reversed_on_date = '${endDate}' + AND t.transaction_type_enum = 10 + AND t.is_reversed = true + AND (t.office_id = ${officeId}) + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + l.name AS product, + t.transaction_type_enum AS transaction_type, + null AS payment_type_id, + null AS classification_name, + '' AS chargetype, + true AS reversal_indicator, + 'Interest' AS Allocation_Type, + CASE WHEN t.interest_portion_derived is null THEN 0 ELSE t.interest_portion_derived END AS amount, + CASE + WHEN e.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND e.settlement_date < '${endDate}' + THEN e.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (m.charged_off_on_date <= t.transaction_date) + THEN m.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + lo.originator_external_ids + FROM m_loan_transaction t + JOIN m_loan m ON m.id = t.loan_id + JOIN m_product_loan l ON l.id = m.product_id + LEFT JOIN m_external_asset_owner_transfer e + ON e.loan_id = t.loan_id AND e.settlement_date < '${endDate}' AND + e.effective_date_to >= '${endDate}' + LEFT JOIN loan_originators lo ON lo.loan_id = t.loan_id + WHERE t.reversed_on_date = '${endDate}' + AND t.transaction_type_enum = 10 + AND t.is_reversed = true + AND (t.office_id = ${officeId}) + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + null AS classification_name, + '' AS chargetype, + true AS reversal_indicator, + 'Fees' AS Allocation_Type, + CASE WHEN t.fee_charges_portion_derived is null THEN 0 ELSE t.fee_charges_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM rlt_charge_adj AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + null AS classification_name, + '' AS chargetype, + true AS reversal_indicator, + 'Penalty' AS Allocation_Type, + CASE + WHEN t.penalty_charges_portion_derived is null THEN 0 + ELSE t.penalty_charges_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM rlt_charge_adj AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + null AS classification_name, + '' AS chargetype, + true AS reversal_indicator, + 'Interest' AS Allocation_Type, + CASE WHEN t.interest_portion_derived is null THEN 0 ELSE t.interest_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM rlt_charge_adj AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + null AS classification_name, + '' AS chargetype, + true AS reversal_indicator, + 'Principal' AS Allocation_Type, + CASE WHEN t.principal_portion_derived is null THEN 0 ELSE t.principal_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM rlt_charge_adj AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + null AS classification_name, + '' AS chargetype, + true AS reversal_indicator, + 'Unallocated Credit (UNC)' AS Allocation_Type, + CASE WHEN t.overpayment_portion_derived is null THEN 0 ELSE t.overpayment_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM rlt_charge_adj AS t + UNION ALL + SELECT t.transactiondate, + t.id, + t.name AS product, + 9999 AS transaction_type, + null AS payment_type_id, + null AS classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Principal' AS Allocation_type, + t.principal_outstanding_derived AS amount, + t.owner_id AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.settlement_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM active_external_asset_owner_transfers AS t + WHERE t.principal_outstanding_derived > 0 + UNION ALL + SELECT t.transactiondate, + t.id, + t.name AS product, + 9999 AS transaction_type, + null AS payment_type_id, + null AS classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Interest' AS Allocation_type, + t.interest_outstanding_derived AS amount, + t.owner_id AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.settlement_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM active_external_asset_owner_transfers AS t + WHERE t.interest_outstanding_derived > 0 + UNION ALL + SELECT t.transactiondate, + t.id, + t.name AS product, + 9999 AS transaction_type, + null AS payment_type_id, + null AS classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Fees' AS Allocation_type, + t.fee_charges_outstanding_derived AS amount, + t.owner_id AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.settlement_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM active_external_asset_owner_transfers AS t + WHERE t.fee_charges_outstanding_derived > 0 + UNION ALL + SELECT t.transactiondate, + t.id, + t.name AS product, + 9999 AS transaction_type, + null AS payment_type_id, + null AS classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Penalty' AS Allocation_type, + t.penalty_charges_outstanding_derived AS amount, + t.owner_id AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.settlement_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM active_external_asset_owner_transfers AS t + WHERE t.penalty_charges_outstanding_derived > 0 + UNION ALL + SELECT t.transactiondate, + t.id, + t.name AS product, + 9999 AS transaction_type, + null AS payment_type_id, + null AS classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Unallocated Credit (UNC)' AS Allocation_type, + t.total_overpaid_derived AS amount, + t.owner_id AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.settlement_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null::bigint AS from_asset_owner_id, + t.originator_external_ids + FROM active_external_asset_owner_transfers AS t + WHERE t.total_overpaid_derived > 0 + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + 99999 AS transaction_type, + null AS payment_type_id, + null AS classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Principal' AS Allocation_type, + t.principal_outstanding_derived AS amount, + null AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.settlement_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + t.owner_id AS from_asset_owner_id, + t.originator_external_ids + FROM buyback_external_asset_owner_transfers AS t + WHERE t.principal_outstanding_derived > 0 + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + 99999 AS transaction_type, + null AS payment_type_id, + null AS classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Interest' AS Allocation_type, + t.interest_outstanding_derived AS amount, + null AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.settlement_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + t.owner_id AS from_asset_owner_id, + t.originator_external_ids + FROM buyback_external_asset_owner_transfers AS t + WHERE t.interest_outstanding_derived > 0 + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + 99999 AS transaction_type, + null AS payment_type_id, + null AS classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Fees' AS Allocation_type, + t.fee_charges_outstanding_derived AS amount, + null AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.settlement_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + t.owner_id AS from_asset_owner_id, + t.originator_external_ids + FROM buyback_external_asset_owner_transfers AS t + WHERE t.fee_charges_outstanding_derived > 0 + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + 99999 AS transaction_type, + null AS payment_type_id, + null AS classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Penalty' AS Allocation_type, + t.penalty_charges_outstanding_derived AS amount, + null AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.settlement_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + t.owner_id AS from_asset_owner_id, + t.originator_external_ids + FROM buyback_external_asset_owner_transfers AS t + WHERE t.penalty_charges_outstanding_derived > 0 + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + 99999 AS transaction_type, + null AS payment_type_id, + null AS classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Unallocated Credit (UNC)' AS Allocation_type, + t.total_overpaid_derived * -1 AS amount, + null AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.settlement_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + t.owner_id AS from_asset_owner_id, + t.originator_external_ids + FROM buyback_external_asset_owner_transfers AS t + WHERE t.total_overpaid_derived > 0) a +GROUP BY a.transactiondate, a.product, a.transaction_type, a.payment_type_id, a.classification_name, a.chargetype, + a.reversal_indicator, a.Allocation_Type, a.asset_owner_id, a.charge_off_reason_id, a.from_asset_owner_id, + a.originator_external_ids +ORDER BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 + + ]]> + + report_name='Transaction Summary Report with Asset Owner' + + + + + = '${endDate}' + LEFT JOIN loan_originators lo ON lo.loan_id = t.loan_id + WHERE t.submitted_on_date = '${endDate}' + AND t.transaction_type_enum not in (10, 26, 32, 34, 36, 39, 42, 43) + AND (t.office_id = ${officeId})), + slt_charge_adj AS (SELECT '${endDate}' AS transactiondate, + t.id, + l.name, + t.transaction_type_enum, + d.payment_type_id, + t.overpayment_portion_derived, + t.principal_portion_derived, + t.interest_portion_derived, + t.fee_charges_portion_derived, + t.penalty_charges_portion_derived, + t.amount, + e.status, + e.settlement_date, + e.owner_id, + m.charged_off_on_date, + t.transaction_date, + m.charge_off_reason_cv_id, + lo.originator_external_ids + FROM m_loan_transaction t + JOIN m_loan m ON m.id = t.loan_id + JOIN m_product_loan l ON l.id = m.product_id + LEFT JOIN m_payment_detail d ON d.id = t.payment_detail_id + LEFT JOIN m_external_asset_owner_transfer e + ON e.loan_id = t.loan_id AND e.settlement_date < '${endDate}' AND + e.effective_date_to >= '${endDate}' + LEFT JOIN loan_originators lo ON lo.loan_id = t.loan_id + WHERE t.submitted_on_date = '${endDate}' + AND t.transaction_type_enum = 26 + AND (t.office_id = ${officeId})), + rlt_except_charge_adj_and_accrual AS (SELECT '${endDate}' AS transactiondate, + t.id, + l.name, + t.transaction_type_enum, + d.payment_type_id, + CASE + WHEN d.payment_type_id IS NULL AND t.classification_cv_id IS NOT NULL + THEN (SELECT code_value FROM m_code_value WHERE id = t.classification_cv_id) + ELSE NULL END AS classification_name, + t.overpayment_portion_derived, + t.principal_portion_derived, + t.interest_portion_derived, + t.fee_charges_portion_derived, + t.penalty_charges_portion_derived, + t.amount, + e.status, + e.settlement_date, + e.owner_id, + m.charged_off_on_date, + t.transaction_date, + m.charge_off_reason_cv_id, + lo.originator_external_ids + FROM m_loan_transaction t + JOIN m_loan m ON m.id = t.loan_id + JOIN m_product_loan l ON l.id = m.product_id + LEFT JOIN m_payment_detail d ON d.id = t.payment_detail_id + LEFT JOIN m_external_asset_owner_transfer e + ON e.loan_id = t.loan_id AND + e.settlement_date < '${endDate}' AND + e.effective_date_to >= '${endDate}' + LEFT JOIN loan_originators lo ON lo.loan_id = t.loan_id + WHERE t.reversed_on_date = '${endDate}' + AND t.transaction_type_enum not in (10, 26, 32, 34, 36, 39, 42, 43) + AND (t.office_id = ${officeId})), + rlt_charge_adj AS (SELECT '${endDate}' AS transactiondate, + t.id, + l.name, + t.transaction_type_enum, + d.payment_type_id, + t.overpayment_portion_derived, + t.principal_portion_derived, + t.interest_portion_derived, + t.fee_charges_portion_derived, + t.penalty_charges_portion_derived, + t.amount, + e.status, + e.settlement_date, + e.owner_id, + m.charged_off_on_date, + t.transaction_date, + m.charge_off_reason_cv_id, + lo.originator_external_ids + FROM m_loan_transaction t + JOIN m_loan m ON m.id = t.loan_id + JOIN m_product_loan l ON l.id = m.product_id + LEFT JOIN m_payment_detail d ON d.id = t.payment_detail_id + LEFT JOIN m_external_asset_owner_transfer e + ON e.loan_id = t.loan_id AND e.settlement_date < '${endDate}' AND + e.effective_date_to >= '${endDate}' + LEFT JOIN loan_originators lo ON lo.loan_id = t.loan_id + WHERE t.reversed_on_date = '${endDate}' + AND t.transaction_type_enum = 26 + AND (t.office_id = ${officeId})), + slt_cap_income_amortization AS (SELECT '${endDate}' AS transactiondate, + t.id, + l.name, + t.transaction_type_enum, + d.payment_type_id, + CASE + WHEN d.payment_type_id IS NULL AND bt.classification_cv_id IS NOT NULL + THEN (SELECT code_value FROM m_code_value WHERE id = bt.classification_cv_id) + ELSE NULL END AS classification_name, + t.overpayment_portion_derived, + t.principal_portion_derived, + t.interest_portion_derived, + t.fee_charges_portion_derived, + t.penalty_charges_portion_derived, + t.amount, + e.status, + e.settlement_date, + e.owner_id, + m.charged_off_on_date, + t.transaction_date, + m.charge_off_reason_cv_id, + lo.originator_external_ids + FROM m_loan_transaction t + JOIN m_loan m ON m.id = t.loan_id + JOIN m_product_loan l ON l.id = m.product_id + LEFT JOIN m_payment_detail d ON d.id = t.payment_detail_id + JOIN m_loan_amortization_allocation_mapping map + ON map.amortization_loan_transaction_id = t.id + JOIN m_loan_transaction bt ON bt.id = map.base_loan_transaction_id + LEFT JOIN m_external_asset_owner_transfer e ON e.loan_id = t.loan_id AND + e.settlement_date < + '${endDate}' AND + e.effective_date_to >= + '${endDate}' + LEFT JOIN loan_originators lo ON lo.loan_id = t.loan_id + WHERE t.submitted_on_date = '${endDate}' + AND t.is_reversed = false + AND t.transaction_type_enum IN (36, 39, 42, 43) + AND (t.office_id = ${officeId})), + rlt_cap_income_amortization AS (SELECT '${endDate}' AS transactiondate, + t.id, + l.name, + t.transaction_type_enum, + d.payment_type_id, + CASE + WHEN d.payment_type_id IS NULL AND bt.classification_cv_id IS NOT NULL + THEN (SELECT code_value FROM m_code_value WHERE id = bt.classification_cv_id) + ELSE NULL END AS classification_name, + t.overpayment_portion_derived, + t.principal_portion_derived, + t.interest_portion_derived, + t.fee_charges_portion_derived, + t.penalty_charges_portion_derived, + t.amount, + e.status, + e.settlement_date, + e.owner_id, + m.charged_off_on_date, + t.transaction_date, + m.charge_off_reason_cv_id, + lo.originator_external_ids + FROM m_loan_transaction t + JOIN m_loan m ON m.id = t.loan_id + JOIN m_product_loan l ON l.id = m.product_id + LEFT JOIN m_payment_detail d ON d.id = t.payment_detail_id + JOIN m_loan_amortization_allocation_mapping map + ON map.amortization_loan_transaction_id = t.id + JOIN m_loan_transaction bt ON bt.id = map.base_loan_transaction_id + LEFT JOIN m_external_asset_owner_transfer e ON e.loan_id = t.loan_id AND + e.settlement_date < + '${endDate}' AND + e.effective_date_to >= + '${endDate}' + LEFT JOIN loan_originators lo ON lo.loan_id = t.loan_id + WHERE t.reversed_on_date = '${endDate}' + AND t.is_reversed = true + AND t.transaction_type_enum IN (36, 39, 42, 43) + AND (t.office_id = ${officeId})), + active_external_asset_owner_transfers AS (SELECT '${endDate}' AS transactiondate, + t.id, + p.name, + t.owner_id, + t.previous_owner_id, + dt.principal_outstanding_derived, + dt.interest_outstanding_derived, + dt.fee_charges_outstanding_derived, + dt.penalty_charges_outstanding_derived, + dt.total_overpaid_derived, + l.charged_off_on_date, + t.settlement_date, + l.charge_off_reason_cv_id, + lo.originator_external_ids + FROM m_external_asset_owner_transfer t + JOIN m_loan l ON l.id = t.loan_id + JOIN m_client c ON c.id = l.client_id + JOIN m_product_loan p ON p.id = l.product_id + JOIN m_external_asset_owner_transfer_details dt + ON dt.asset_owner_transfer_id = t.id + LEFT JOIN loan_originators lo ON lo.loan_id = t.loan_id + WHERE t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') + AND c.office_id = ${officeId} + AND t.settlement_date = '${endDate}'), + buyback_external_asset_owner_transfers AS (SELECT '${endDate}' AS transactiondate, + t.id, + p.name, + dt.principal_outstanding_derived, + dt.interest_outstanding_derived, + dt.fee_charges_outstanding_derived, + dt.penalty_charges_outstanding_derived, + dt.total_overpaid_derived, + l.charged_off_on_date, + t.settlement_date, + l.charge_off_reason_cv_id, + t.owner_id, + lo.originator_external_ids + FROM m_external_asset_owner_transfer t + JOIN m_loan l ON l.id = t.loan_id + JOIN m_client c ON c.id = l.client_id + JOIN m_product_loan p ON p.id = l.product_id + JOIN m_external_asset_owner_transfer_details dt + ON dt.asset_owner_transfer_id = t.id + LEFT JOIN loan_originators lo ON lo.loan_id = t.loan_id + WHERE t.status in ('BUYBACK', 'BUYBACK_INTERMEDIATE') + AND c.office_id = ${officeId} + AND t.settlement_date = '${endDate}') +SELECT '${endDate}' AS TransactionDate, + a.product AS Product, + CASE + WHEN a.transaction_type = 9999 THEN 'Asset Transfer' + WHEN a.transaction_type = 99999 THEN 'Asset Buyback' + ELSE (SELECT enum_message_property + FROM r_enum_value + WHERE enum_name = 'transaction_type_enum' + AND enum_id = a.transaction_type) END AS TransactionType_Name, + COALESCE((SELECT value FROM m_payment_type WHERE id = a.payment_type_id), + a.classification_name) AS PaymentType_Name, + a.chargetype AS chargetype, + a.reversal_indicator AS Reversed, + a.Allocation_Type AS Allocation_Type, + (SELECT code_value FROM m_code_value WHERE id = a.charge_off_reason_id) AS Chargeoff_ReasonCode, + CASE + WHEN a.transaction_type = 9999 THEN sum(a.amount) * + 1 + WHEN a.transaction_type = 99999 THEN sum(a.amount) * - 1 + WHEN a.transaction_type IN (2, 23, 21, 22, 24, 4, 5, 8, 6, 27, 9, 26, 28, 31, 33, 34, 37, 39, 41, 43) AND + a.reversal_indicator = false THEN sum(a.amount) * -1 + WHEN a.transaction_type IN (2, 23, 21, 22, 24, 4, 5, 8, 6, 27, 9, 26, 28, 31, 33, 34, 37, 39, 41, 43) AND + a.reversal_indicator = true THEN sum(a.amount) * + 1 + WHEN a.transaction_type IN (1, 10, 25, 20, 35, 36, 40, 42) AND a.reversal_indicator = false THEN sum(a.amount) * + 1 + WHEN a.transaction_type IN (1, 10, 25, 20, 35, 36, 40, 42) AND a.reversal_indicator = true + THEN sum(a.amount) * -1 END AS Transaction_Amount, + (SELECT external_id + FROM m_external_asset_owner + WHERE id = a.asset_owner_id) AS Asset_owner_id, + (SELECT external_id + FROM m_external_asset_owner + WHERE id = a.from_asset_owner_id) AS From_asset_owner_id, + a.originator_external_ids AS Originator_External_Ids +FROM (SELECT t.transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Principal' AS Allocation_Type, + CASE + WHEN t.transaction_type_enum in (1, 40, 41) THEN (CASE + WHEN t.amount is null THEN 0 + WHEN t.overpayment_portion_derived is null THEN t.amount + WHEN t.overpayment_portion_derived is not null + THEN t.amount - t.overpayment_portion_derived + ELSE t.amount END) + ELSE (CASE + WHEN t.principal_portion_derived is null THEN 0 + ELSE t.principal_portion_derived end) END amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null AS from_asset_owner_id, + t.originator_external_ids + FROM slt_except_charge_adj_and_accrual AS t + UNION ALL + SELECT t.transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Interest' AS Allocation_Type, + CASE WHEN t.interest_portion_derived is null THEN 0 ELSE t.interest_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null, + t.originator_external_ids AS from_asset_owner_id + FROM slt_except_charge_adj_and_accrual AS t + UNION ALL + SELECT t.transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Fees' AS Allocation_Type, + CASE WHEN t.fee_charges_portion_derived is null THEN 0 ELSE t.fee_charges_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null, + t.originator_external_ids AS from_asset_owner_id + FROM slt_except_charge_adj_and_accrual AS t + UNION ALL + SELECT t.transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Penalty' AS Allocation_Type, + CASE + WHEN t.penalty_charges_portion_derived is null THEN 0 + ELSE t.penalty_charges_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null, + t.originator_external_ids AS from_asset_owner_id + FROM slt_except_charge_adj_and_accrual AS t + UNION ALL + SELECT t.transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Unallocated Credit (UNC)' AS Allocation_Type, + CASE WHEN t.overpayment_portion_derived is null THEN 0 ELSE t.overpayment_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null, + t.originator_external_ids AS from_asset_owner_id + FROM slt_except_charge_adj_and_accrual AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Fees' AS Allocation_Type, + CASE WHEN t.fee_charges_portion_derived is null THEN 0 ELSE t.fee_charges_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.transaction_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null, + t.originator_external_ids AS from_asset_owner_id + FROM slt_cap_income_amortization AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Penalty' AS Allocation_Type, + CASE + WHEN t.penalty_charges_portion_derived is null THEN 0 + ELSE t.penalty_charges_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.transaction_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null, + t.originator_external_ids AS from_asset_owner_id + FROM slt_cap_income_amortization AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Interest' AS Allocation_Type, + CASE WHEN t.interest_portion_derived is null THEN 0 ELSE t.interest_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.transaction_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null, + t.originator_external_ids AS from_asset_owner_id + FROM slt_cap_income_amortization AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Principal' AS Allocation_Type, + CASE WHEN t.principal_portion_derived is null THEN 0 ELSE t.principal_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.transaction_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null, + t.originator_external_ids AS from_asset_owner_id + FROM slt_cap_income_amortization AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Unallocated Credit (UNC)' AS Allocation_Type, + CASE WHEN t.overpayment_portion_derived is null THEN 0 ELSE t.overpayment_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.transaction_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null, + t.originator_external_ids AS from_asset_owner_id + FROM slt_cap_income_amortization AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Fees' AS Allocation_Type, + CASE WHEN t.fee_charges_portion_derived is null THEN 0 ELSE t.fee_charges_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.transaction_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null, + t.originator_external_ids AS from_asset_owner_id + FROM rlt_cap_income_amortization AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Penalty' AS Allocation_Type, + CASE + WHEN t.penalty_charges_portion_derived is null THEN 0 + ELSE t.penalty_charges_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.transaction_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null, + t.originator_external_ids AS from_asset_owner_id + FROM rlt_cap_income_amortization AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Interest' AS Allocation_Type, + CASE WHEN t.interest_portion_derived is null THEN 0 ELSE t.interest_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.transaction_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null, + t.originator_external_ids AS from_asset_owner_id + FROM rlt_cap_income_amortization AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Principal' AS Allocation_Type, + CASE WHEN t.principal_portion_derived is null THEN 0 ELSE t.principal_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.transaction_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null, + t.originator_external_ids AS from_asset_owner_id + FROM rlt_cap_income_amortization AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Unallocated Credit (UNC)' AS Allocation_Type, + CASE WHEN t.overpayment_portion_derived is null THEN 0 ELSE t.overpayment_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.transaction_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null, + t.originator_external_ids AS from_asset_owner_id + FROM rlt_cap_income_amortization AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + l.name AS product, + t.transaction_type_enum AS transaction_type, + null AS payment_type_id, + null AS classification_name, + mc.name AS chargetype, + false AS reversal_indicator, + 'Fees' AS Allocation_Type, + CASE WHEN pd.amount is null THEN 0 ELSE pd.amount END AS amount, + CASE + WHEN e.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND e.settlement_date < '${endDate}' + THEN e.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (m.charged_off_on_date <= t.transaction_date) + THEN m.charge_off_reason_cv_id END AS charge_off_reason_id, + null, + lo.originator_external_ids AS from_asset_owner_id + FROM m_loan_transaction t + JOIN m_loan m ON m.id = t.loan_id + JOIN m_product_loan l ON l.id = m.product_id + JOIN m_loan_charge_paid_by pd ON pd.loan_transaction_id = t.id + JOIN m_loan_charge c ON c.id = pd.loan_charge_id + JOIN m_charge mc ON mc.id = c.charge_id AND mc.is_penalty = false + LEFT JOIN m_external_asset_owner_transfer e + ON e.loan_id = t.loan_id AND e.settlement_date < '${endDate}' AND + e.effective_date_to >= '${endDate}' + LEFT JOIN loan_originators lo ON lo.loan_id = t.loan_id + WHERE t.submitted_on_date = '${endDate}' + AND t.transaction_type_enum = 10 + AND t.is_reversed = false + AND (t.office_id = ${officeId}) + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + l.name AS product, + t.transaction_type_enum AS transaction_type, + null AS payment_type_id, + null AS classification_name, + mc.name AS chargetype, + false AS reversal_indicator, + 'Penalty' AS Allocation_Type, + CASE WHEN pd.amount is null THEN 0 ELSE pd.amount END AS amount, + CASE + WHEN e.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND e.settlement_date < '${endDate}' + THEN e.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (m.charged_off_on_date <= t.transaction_date) + THEN m.charge_off_reason_cv_id END AS charge_off_reason_id, + null AS from_asset_owner_id, + lo.originator_external_ids AS from_asset_owner_id + FROM m_loan_transaction t + JOIN m_loan m ON m.id = t.loan_id + JOIN m_product_loan l ON l.id = m.product_id + JOIN m_loan_charge_paid_by pd ON pd.loan_transaction_id = t.id + JOIN m_loan_charge c ON c.id = pd.loan_charge_id + JOIN m_charge mc ON mc.id = c.charge_id AND mc.is_penalty = true + LEFT JOIN m_external_asset_owner_transfer e + ON e.loan_id = t.loan_id AND e.settlement_date < '${endDate}' AND + e.effective_date_to >= '${endDate}' + LEFT JOIN loan_originators lo ON lo.loan_id = t.loan_id + WHERE t.submitted_on_date = '${endDate}' + AND t.transaction_type_enum = 10 + AND t.is_reversed = false + AND (t.office_id = ${officeId}) + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + l.name AS product, + t.transaction_type_enum AS transaction_type, + null AS payment_type_id, + null AS classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Interest' AS Allocation_Type, + CASE WHEN t.interest_portion_derived is null THEN 0 ELSE t.interest_portion_derived END AS amount, + CASE + WHEN e.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND e.settlement_date < '${endDate}' + THEN e.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (m.charged_off_on_date <= t.transaction_date) + THEN m.charge_off_reason_cv_id END AS charge_off_reason_id, + null AS from_asset_owner_id, + lo.originator_external_ids AS from_asset_owner_id + FROM m_loan_transaction t + JOIN m_loan m ON m.id = t.loan_id + JOIN m_product_loan l ON l.id = m.product_id + LEFT JOIN m_external_asset_owner_transfer e + ON e.loan_id = t.loan_id AND e.settlement_date < '${endDate}' AND + e.effective_date_to >= '${endDate}' + LEFT JOIN loan_originators lo ON lo.loan_id = t.loan_id + WHERE t.submitted_on_date = '${endDate}' + AND t.transaction_type_enum in (10, 34) + AND t.is_reversed = false + AND (t.office_id = ${officeId}) + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + null AS classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Fees' AS Allocation_Type, + CASE WHEN t.fee_charges_portion_derived is null THEN 0 ELSE t.fee_charges_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null AS from_asset_owner_id, + t.originator_external_ids + FROM slt_charge_adj AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + null AS classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Penalty' AS Allocation_Type, + CASE + WHEN t.penalty_charges_portion_derived is null THEN 0 + ELSE t.penalty_charges_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null AS from_asset_owner_id, + t.originator_external_ids + FROM slt_charge_adj AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + null AS classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Interest' AS Allocation_Type, + CASE WHEN t.interest_portion_derived is null THEN 0 ELSE t.interest_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null AS from_asset_owner_id, + t.originator_external_ids + FROM slt_charge_adj AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + null AS classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Principal' AS Allocation_Type, + CASE WHEN t.principal_portion_derived is null THEN 0 ELSE t.principal_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null AS from_asset_owner_id, + t.originator_external_ids + FROM slt_charge_adj AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + null AS classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Unallocated Credit (UNC)' AS Allocation_Type, + CASE WHEN t.overpayment_portion_derived is null THEN 0 ELSE t.overpayment_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null AS from_asset_owner_id, + t.originator_external_ids + FROM slt_charge_adj AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + true AS reversal_indicator, + 'Principal' AS Allocation_Type, + CASE + WHEN t.transaction_type_enum in (1, 40, 41) THEN (CASE + WHEN t.amount is null THEN 0 + WHEN t.overpayment_portion_derived is null THEN t.amount + WHEN t.overpayment_portion_derived is not null + THEN t.amount - t.overpayment_portion_derived + ELSE t.amount END) + ELSE (CASE + WHEN t.principal_portion_derived is null THEN 0 + ELSE t.principal_portion_derived end) END amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null AS from_asset_owner_id, + t.originator_external_ids + FROM rlt_except_charge_adj_and_accrual AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + true AS reversal_indicator, + 'Interest' AS Allocation_Type, + CASE WHEN t.interest_portion_derived is null THEN 0 ELSE t.interest_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null AS from_asset_owner_id, + t.originator_external_ids + FROM rlt_except_charge_adj_and_accrual AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + true AS reversal_indicator, + 'Fees' AS Allocation_Type, + CASE WHEN t.fee_charges_portion_derived is null THEN 0 ELSE t.fee_charges_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null AS from_asset_owner_id, + t.originator_external_ids + FROM rlt_except_charge_adj_and_accrual AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + true AS reversal_indicator, + 'Penalty' AS Allocation_Type, + CASE + WHEN t.penalty_charges_portion_derived is null THEN 0 + ELSE t.penalty_charges_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null AS from_asset_owner_id, + t.originator_external_ids + FROM rlt_except_charge_adj_and_accrual AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + t.classification_name, + '' AS chargetype, + true AS reversal_indicator, + 'Unallocated Credit (UNC)' AS Allocation_Type, + CASE WHEN t.overpayment_portion_derived is null THEN 0 ELSE t.overpayment_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null AS from_asset_owner_id, + t.originator_external_ids + FROM rlt_except_charge_adj_and_accrual AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + l.name AS product, + t.transaction_type_enum AS transaction_type, + null AS payment_type_id, + null AS classification_name, + mc.name AS chargetype, + true AS reversal_indicator, + 'Fees' AS Allocation_Type, + CASE WHEN pd.amount is null THEN 0 ELSE pd.amount END AS amount, + CASE + WHEN e.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND e.settlement_date < '${endDate}' + THEN e.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (m.charged_off_on_date <= t.transaction_date) + THEN m.charge_off_reason_cv_id END AS charge_off_reason_id, + null AS from_asset_owner_id, + lo.originator_external_ids + FROM m_loan_transaction t + JOIN m_loan m ON m.id = t.loan_id + JOIN m_product_loan l ON l.id = m.product_id + JOIN m_loan_charge_paid_by pd ON pd.loan_transaction_id = t.id + JOIN m_loan_charge c ON c.id = pd.loan_charge_id + JOIN m_charge mc ON mc.id = c.charge_id AND mc.is_penalty = false + LEFT JOIN m_external_asset_owner_transfer e + ON e.loan_id = t.loan_id AND e.settlement_date < '${endDate}' AND + e.effective_date_to >= '${endDate}' + LEFT JOIN loan_originators lo ON lo.loan_id = t.loan_id + WHERE t.reversed_on_date = '${endDate}' + AND t.transaction_type_enum = 10 + AND t.is_reversed = true + AND (t.office_id = ${officeId}) + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + l.name AS product, + t.transaction_type_enum AS transaction_type, + null AS payment_type_id, + null AS classification_name, + mc.name AS chargetype, + true AS reversal_indicator, + 'Penalty' AS Allocation_Type, + CASE WHEN pd.amount is null THEN 0 ELSE pd.amount END AS amount, + CASE + WHEN e.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND e.settlement_date < '${endDate}' + THEN e.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (m.charged_off_on_date <= t.transaction_date) + THEN m.charge_off_reason_cv_id END AS charge_off_reason_id, + null AS from_asset_owner_id, + lo.originator_external_ids + FROM m_loan_transaction t + JOIN m_loan m ON m.id = t.loan_id + JOIN m_product_loan l ON l.id = m.product_id + JOIN m_loan_charge_paid_by pd ON pd.loan_transaction_id = t.id + JOIN m_loan_charge c ON c.id = pd.loan_charge_id + JOIN m_charge mc ON mc.id = c.charge_id AND mc.is_penalty = true + LEFT JOIN m_external_asset_owner_transfer e + ON e.loan_id = t.loan_id AND e.settlement_date < '${endDate}' AND + e.effective_date_to >= '${endDate}' + LEFT JOIN loan_originators lo ON lo.loan_id = t.loan_id + WHERE t.reversed_on_date = '${endDate}' + AND t.transaction_type_enum = 10 + AND t.is_reversed = true + AND (t.office_id = ${officeId}) + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + l.name AS product, + t.transaction_type_enum AS transaction_type, + null AS payment_type_id, + null AS classification_name, + '' AS chargetype, + true AS reversal_indicator, + 'Interest' AS Allocation_Type, + CASE WHEN t.interest_portion_derived is null THEN 0 ELSE t.interest_portion_derived END AS amount, + CASE + WHEN e.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND e.settlement_date < '${endDate}' + THEN e.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (m.charged_off_on_date <= t.transaction_date) + THEN m.charge_off_reason_cv_id END AS charge_off_reason_id, + null AS from_asset_owner_id, + lo.originator_external_ids + FROM m_loan_transaction t + JOIN m_loan m ON m.id = t.loan_id + JOIN m_product_loan l ON l.id = m.product_id + LEFT JOIN m_external_asset_owner_transfer e + ON e.loan_id = t.loan_id AND e.settlement_date < '${endDate}' AND + e.effective_date_to >= '${endDate}' + LEFT JOIN loan_originators lo ON lo.loan_id = t.loan_id + WHERE t.reversed_on_date = '${endDate}' + AND t.transaction_type_enum = 10 + AND t.is_reversed = true + AND (t.office_id = ${officeId}) + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + null AS classification_name, + '' AS chargetype, + true AS reversal_indicator, + 'Fees' AS Allocation_Type, + CASE WHEN t.fee_charges_portion_derived is null THEN 0 ELSE t.fee_charges_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null AS from_asset_owner_id, + t.originator_external_ids + FROM rlt_charge_adj AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + null AS classification_name, + '' AS chargetype, + true AS reversal_indicator, + 'Penalty' AS Allocation_Type, + CASE + WHEN t.penalty_charges_portion_derived is null THEN 0 + ELSE t.penalty_charges_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null AS from_asset_owner_id, + t.originator_external_ids + FROM rlt_charge_adj AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + null AS classification_name, + '' AS chargetype, + true AS reversal_indicator, + 'Interest' AS Allocation_Type, + CASE WHEN t.interest_portion_derived is null THEN 0 ELSE t.interest_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null AS from_asset_owner_id, + t.originator_external_ids + FROM rlt_charge_adj AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + null AS classification_name, + '' AS chargetype, + true AS reversal_indicator, + 'Principal' AS Allocation_Type, + CASE WHEN t.principal_portion_derived is null THEN 0 ELSE t.principal_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null AS from_asset_owner_id, + t.originator_external_ids + FROM rlt_charge_adj AS t + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + t.transaction_type_enum AS transaction_type, + t.payment_type_id, + null AS classification_name, + '' AS chargetype, + true AS reversal_indicator, + 'Unallocated Credit (UNC)' AS Allocation_Type, + CASE WHEN t.overpayment_portion_derived is null THEN 0 ELSE t.overpayment_portion_derived END AS amount, + CASE + WHEN t.status in ('ACTIVE', 'ACTIVE_INTERMEDIATE') AND t.settlement_date < '${endDate}' + THEN t.owner_id END AS asset_owner_id, + CASE + WHEN t.transaction_type_enum = 27 OR (t.charged_off_on_date <= t.transaction_date) + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + null AS from_asset_owner_id, + t.originator_external_ids + FROM rlt_charge_adj AS t + UNION ALL + SELECT t.transactiondate, + t.id, + t.name AS product, + 9999 AS transaction_type, + null AS payment_type_id, + null AS classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Principal' AS Allocation_type, + t.principal_outstanding_derived AS amount, + t.owner_id AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.settlement_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + t.previous_owner_id AS from_asset_owner_id, + t.originator_external_ids + FROM active_external_asset_owner_transfers AS t + WHERE t.principal_outstanding_derived > 0 + UNION ALL + SELECT t.transactiondate, + t.id, + t.name AS product, + 9999 AS transaction_type, + null AS payment_type_id, + null AS classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Interest' AS Allocation_type, + t.interest_outstanding_derived AS amount, + t.owner_id AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.settlement_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + t.previous_owner_id AS from_asset_owner_id, + t.originator_external_ids + FROM active_external_asset_owner_transfers AS t + WHERE t.interest_outstanding_derived > 0 + UNION ALL + SELECT t.transactiondate, + t.id, + t.name AS product, + 9999 AS transaction_type, + null AS payment_type_id, + null AS classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Fees' AS Allocation_type, + t.fee_charges_outstanding_derived AS amount, + t.owner_id AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.settlement_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + t.previous_owner_id AS from_asset_owner_id, + t.originator_external_ids + FROM active_external_asset_owner_transfers AS t + WHERE t.fee_charges_outstanding_derived > 0 + UNION ALL + SELECT t.transactiondate, + t.id, + t.name AS product, + 9999 AS transaction_type, + null AS payment_type_id, + null AS classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Penalty' AS Allocation_type, + t.penalty_charges_outstanding_derived AS amount, + t.owner_id AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.settlement_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + t.previous_owner_id AS from_asset_owner_id, + t.originator_external_ids + FROM active_external_asset_owner_transfers AS t + WHERE t.penalty_charges_outstanding_derived > 0 + UNION ALL + SELECT t.transactiondate, + t.id, + t.name AS product, + 9999 AS transaction_type, + null AS payment_type_id, + null AS classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Unallocated Credit (UNC)' AS Allocation_type, + t.total_overpaid_derived AS amount, + t.owner_id AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.settlement_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + t.previous_owner_id AS from_asset_owner_id, + t.originator_external_ids + FROM active_external_asset_owner_transfers AS t + WHERE t.total_overpaid_derived > 0 + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + 99999 AS transaction_type, + null AS payment_type_id, + null AS classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Principal' AS Allocation_type, + t.principal_outstanding_derived AS amount, + null AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.settlement_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + t.owner_id AS from_asset_owner_id, + t.originator_external_ids + FROM buyback_external_asset_owner_transfers AS t + WHERE t.principal_outstanding_derived > 0 + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + 99999 AS transaction_type, + null AS payment_type_id, + null AS classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Interest' AS Allocation_type, + t.interest_outstanding_derived AS amount, + null AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.settlement_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + t.owner_id AS from_asset_owner_id, + t.originator_external_ids + FROM buyback_external_asset_owner_transfers AS t + WHERE t.interest_outstanding_derived > 0 + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + 99999 AS transaction_type, + null AS payment_type_id, + null AS classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Fees' AS Allocation_type, + t.fee_charges_outstanding_derived AS amount, + null AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.settlement_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + t.owner_id AS from_asset_owner_id, + t.originator_external_ids + FROM buyback_external_asset_owner_transfers AS t + WHERE t.fee_charges_outstanding_derived > 0 + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + 99999 AS transaction_type, + null AS payment_type_id, + null AS classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Penalty' AS Allocation_type, + t.penalty_charges_outstanding_derived AS amount, + null AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.settlement_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + t.owner_id AS from_asset_owner_id, + t.originator_external_ids + FROM buyback_external_asset_owner_transfers AS t + WHERE t.penalty_charges_outstanding_derived > 0 + UNION ALL + SELECT '${endDate}' AS transactiondate, + t.id, + t.name AS product, + 99999 AS transaction_type, + null AS payment_type_id, + null AS classification_name, + '' AS chargetype, + false AS reversal_indicator, + 'Unallocated Credit (UNC)' AS Allocation_type, + t.total_overpaid_derived * -1 AS amount, + null AS asset_owner_id, + CASE + WHEN t.charged_off_on_date <= t.settlement_date + THEN t.charge_off_reason_cv_id END AS charge_off_reason_id, + t.owner_id AS from_asset_owner_id, + t.originator_external_ids + FROM buyback_external_asset_owner_transfers AS t + WHERE t.total_overpaid_derived > 0) a +GROUP BY a.transactiondate, a.product, a.transaction_type, a.payment_type_id, a.classification_name, a.chargetype, + a.reversal_indicator, a.Allocation_Type, a.asset_owner_id, a.charge_off_reason_id, a.from_asset_owner_id, + a.originator_external_ids +ORDER BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 + + ]]> + + report_name='Transaction Summary Report with Asset Owner' + + + + + + + + report_name='Transaction Summary Report' + + +