use of org.folio.invoices.utils.ResourcePathResolver.INVOICE_LINES in project mod-invoice by folio-org.
the class InvoicesApiTest method testUpdateValidInvoiceTransitionToPaidReleaseEncumbranceTrue.
@Test
void testUpdateValidInvoiceTransitionToPaidReleaseEncumbranceTrue() {
logger.info("=== Test transition invoice to paid and releaseEncumbrance true for all invoice lines ===");
List<InvoiceLine> invoiceLines = new ArrayList<>();
List<CompositePoLine> poLines = new ArrayList<>();
for (int i = 0; i < 3; i++) {
invoiceLines.add(getMockAsJson(INVOICE_LINE_WITH_APPROVED_INVOICE_SAMPLE_PATH).mapTo(InvoiceLine.class));
poLines.add(getMockAsJson(String.format("%s%s.json", PO_LINE_MOCK_DATA_PATH, EXISTENT_PO_LINE_ID)).mapTo(CompositePoLine.class));
}
Invoice reqData = getMockAsJson(APPROVED_INVOICE_SAMPLE_PATH).mapTo(Invoice.class).withStatus(Invoice.Status.PAID);
String id = reqData.getId();
for (int i = 0; i < 3; i++) {
InvoiceLine invoiceLine = invoiceLines.get(i);
invoiceLine.setId(UUID.randomUUID().toString());
invoiceLine.setInvoiceId(reqData.getId());
String poLineId = UUID.randomUUID().toString();
invoiceLine.setPoLineId(poLineId);
poLines.get(i).setId(poLineId);
}
invoiceLines.forEach(line -> addMockEntry(INVOICE_LINES, JsonObject.mapFrom(line)));
poLines.forEach(line -> addMockEntry(ORDER_LINES, JsonObject.mapFrom(line)));
prepareMockVoucher(id);
verifyPut(String.format(INVOICE_ID_PATH, id), JsonObject.mapFrom(reqData), "", 204);
assertThat(getRqRsEntries(HttpMethod.PUT, INVOICES).get(0).getString(STATUS), is(Invoice.Status.PAID.value()));
assertThat(getRqRsEntries(HttpMethod.GET, INVOICE_LINES), hasSize(1));
assertThat(getRqRsEntries(HttpMethod.GET, INVOICE_LINES).get(0).mapTo(InvoiceLineCollection.class).getTotalRecords(), equalTo(3));
assertThat(getRqRsEntries(HttpMethod.PUT, ORDER_LINES), hasSize(3));
getRqRsEntries(HttpMethod.PUT, ORDER_LINES).stream().map(entries -> entries.mapTo(CompositePoLine.class)).forEach(compositePoLine -> assertThat(compositePoLine.getPaymentStatus(), equalTo(CompositePoLine.PaymentStatus.FULLY_PAID)));
assertThatVoucherPaid();
List<JsonObject> invoiceLinesUpdates = serverRqRs.get(INVOICE_LINES, HttpMethod.PUT);
List<InvoiceLine> lines = invoiceLinesUpdates.stream().map(entry -> entry.mapTo(InvoiceLine.class)).collect(toList());
assertThat(lines, everyItem(hasProperty("invoiceLineStatus", is(InvoiceLine.InvoiceLineStatus.PAID))));
assertThat(getRqRsEntries(HttpMethod.GET, FINANCE_TRANSACTIONS), hasSize(2));
assertThat(getRqRsEntries(HttpMethod.POST, FINANCE_PAYMENTS), hasSize(5));
assertThat(getRqRsEntries(HttpMethod.POST, FINANCE_CREDITS), hasSize(0));
checkCreditsPayments(reqData, invoiceLines);
}
use of org.folio.invoices.utils.ResourcePathResolver.INVOICE_LINES in project mod-invoice by folio-org.
the class InvoicesApiTest method testUpdateInvoiceTransitionToPaidPoLineIdNotSpecified.
@Test
void testUpdateInvoiceTransitionToPaidPoLineIdNotSpecified() {
logger.info("=== Test transition invoice to paid, invoice line doesn't have poLineId ===");
Invoice reqData = getMockAsJson(APPROVED_INVOICE_SAMPLE_PATH).mapTo(Invoice.class).withStatus(Invoice.Status.PAID);
String id = reqData.getId();
prepareMockVoucher(id);
InvoiceLine invoiceLine1 = getMinimalContentInvoiceLine(id).withPoLineId(null);
addMockEntry(INVOICE_LINES, JsonObject.mapFrom(invoiceLine1));
InvoiceLine invoiceLine2 = getMinimalContentInvoiceLine(id).withPoLineId(null);
addMockEntry(INVOICE_LINES, JsonObject.mapFrom(invoiceLine2));
CompositePoLine poLine = getMockAsJson(String.format("%s%s.json", PO_LINE_MOCK_DATA_PATH, EXISTENT_PO_LINE_ID)).mapTo(CompositePoLine.class).withPaymentStatus(CompositePoLine.PaymentStatus.AWAITING_PAYMENT);
addMockEntry(ORDER_LINES, JsonObject.mapFrom(poLine));
InvoiceLine invoiceLine3 = getMinimalContentInvoiceLine(id).withPoLineId(poLine.getId());
addMockEntry(INVOICE_LINES, JsonObject.mapFrom(invoiceLine3));
String jsonBody = JsonObject.mapFrom(reqData).encode();
verifyPut(String.format(INVOICE_ID_PATH, id), jsonBody, "", 204);
assertThat(serverRqRs.get(INVOICES, HttpMethod.PUT).get(0).getString(STATUS), is(Invoice.Status.PAID.value()));
final List<CompositePoLine> updatedPoLines = getRqRsEntries(HttpMethod.PUT, ORDER_LINES).stream().map(line -> line.mapTo(CompositePoLine.class)).collect(Collectors.toList());
assertThat(updatedPoLines, hasSize(1));
assertThatVoucherPaid();
}
use of org.folio.invoices.utils.ResourcePathResolver.INVOICE_LINES in project mod-invoice by folio-org.
the class InvoicesApiTest method testUpdateValidInvoiceTransitionToPaidReleaseEncumbranceFalse.
@Test
void testUpdateValidInvoiceTransitionToPaidReleaseEncumbranceFalse() {
logger.info("=== Test transition invoice to paid and releaseEncumbrance false for all invoice lines ===");
Invoice reqData = getMockAsJson(APPROVED_INVOICE_SAMPLE_PATH).mapTo(Invoice.class).withStatus(Invoice.Status.PAID);
String id = reqData.getId();
List<InvoiceLine> invoiceLines = new ArrayList<>();
// Prepare invoice lines
for (int i = 0; i < 3; i++) {
InvoiceLine invoiceLine = getMockAsJson(INVOICE_LINE_WITH_APPROVED_INVOICE_SAMPLE_PATH).mapTo(InvoiceLine.class);
invoiceLine.setId(UUID.randomUUID().toString());
invoiceLine.setInvoiceId(id);
invoiceLine.setPoLineId(EXISTENT_PO_LINE_ID);
invoiceLine.setReleaseEncumbrance(false);
invoiceLines.add(invoiceLine);
addMockEntry(INVOICE_LINES, JsonObject.mapFrom(invoiceLine));
}
prepareMockVoucher(id);
verifyPut(String.format(INVOICE_ID_PATH, id), JsonObject.mapFrom(reqData), "", 204);
assertThat(serverRqRs.get(INVOICES, HttpMethod.PUT).get(0).getString(STATUS), is(Invoice.Status.PAID.value()));
assertThat(serverRqRs.get(INVOICE_LINES, HttpMethod.GET), notNullValue());
assertThat(serverRqRs.get(INVOICE_LINES, HttpMethod.GET).get(0).mapTo(InvoiceLineCollection.class).getTotalRecords(), equalTo(3));
assertThat(serverRqRs.get(ORDER_LINES, HttpMethod.PUT), notNullValue());
assertThat(serverRqRs.get(ORDER_LINES, HttpMethod.PUT), hasSize(1));
assertThat(serverRqRs.get(ORDER_LINES, HttpMethod.PUT).get(0).mapTo(CompositePoLine.class).getPaymentStatus(), equalTo(CompositePoLine.PaymentStatus.PARTIALLY_PAID));
List<JsonObject> invoiceLinesUpdates = serverRqRs.get(INVOICE_LINES, HttpMethod.PUT);
List<InvoiceLine> lines = invoiceLinesUpdates.stream().map(entry -> entry.mapTo(InvoiceLine.class)).collect(toList());
assertThat(lines, everyItem(hasProperty("invoiceLineStatus", is(InvoiceLine.InvoiceLineStatus.PAID))));
checkCreditsPayments(reqData, invoiceLines);
}
use of org.folio.invoices.utils.ResourcePathResolver.INVOICE_LINES in project mod-invoice by folio-org.
the class InvoicesApiTest method verifyTransitionToApproved.
private void verifyTransitionToApproved(Voucher voucherCreated, List<InvoiceLine> invoiceLines, Invoice invoice, int createdVoucherLines) {
List<JsonObject> invoiceLinesSearches = serverRqRs.get(INVOICE_LINES, HttpMethod.GET);
List<JsonObject> invoiceLinesUpdates = serverRqRs.get(INVOICE_LINES, HttpMethod.PUT);
List<JsonObject> voucherLinesCreated = serverRqRs.get(VOUCHER_LINES, HttpMethod.POST);
List<JsonObject> fundsSearches = serverRqRs.get(FUNDS, HttpMethod.GET);
List<JsonObject> invoiceUpdates = serverRqRs.get(INVOICES, HttpMethod.PUT);
List<JsonObject> transactionSummariesCreated = serverRqRs.get(INVOICE_TRANSACTION_SUMMARIES, HttpMethod.POST);
List<JsonObject> pendingPaymentCreated = Optional.ofNullable(serverRqRs.get(FINANCE_PENDING_PAYMENTS, HttpMethod.POST)).orElse(emptyList());
assertThat(invoiceLinesSearches, notNullValue());
assertThat(invoiceLinesUpdates, notNullValue());
assertThat(fundsSearches, notNullValue());
assertThat(voucherLinesCreated, notNullValue());
assertThat(invoiceUpdates, notNullValue());
assertThat(transactionSummariesCreated, notNullValue());
assertThat(invoiceLinesSearches, hasSize(invoiceLines.size() / MAX_IDS_FOR_GET_RQ + 1));
List<InvoiceLine> linesWithUpdatedStatus = invoiceLinesUpdates.stream().map(entries -> entries.mapTo(InvoiceLine.class)).filter(invoiceLine -> invoiceLine.getInvoiceLineStatus() == InvoiceLine.InvoiceLineStatus.APPROVED).collect(toList());
assertThat(linesWithUpdatedStatus, hasSize(invoiceLines.size()));
assertThat(voucherLinesCreated, hasSize(createdVoucherLines));
InvoiceTransactionSummary transactionSummary = transactionSummariesCreated.get(0).mapTo(InvoiceTransactionSummary.class);
Invoice invoiceUpdate = invoiceUpdates.get(0).mapTo(Invoice.class);
List<VoucherLine> voucherLines = voucherLinesCreated.stream().map(json -> json.mapTo(VoucherLine.class)).collect(Collectors.toList());
assertThat(Invoice.Status.APPROVED, equalTo(invoiceUpdate.getStatus()));
assertThat(invoiceUpdate.getVoucherNumber(), equalTo(voucherCreated.getVoucherNumber()));
assertThat(invoiceUpdate.getId(), equalTo(voucherCreated.getInvoiceId()));
assertThat(invoiceUpdate.getCurrency(), equalTo(voucherCreated.getInvoiceCurrency()));
// assertThat(HelperUtils.getInvoiceExchangeRateProvider().getExchangeRate(voucherCreated.getInvoiceCurrency(), voucherCreated.getSystemCurrency()).getFactor().doubleValue(), equalTo(voucherCreated.getExchangeRate()));
assertThat(voucherCreated.getAccountingCode(), equalTo(invoiceUpdate.getAccountingCode()));
assertThat(voucherCreated.getExportToAccounting(), is(false));
assertThat(Voucher.Status.AWAITING_PAYMENT, equalTo(voucherCreated.getStatus()));
assertThat(Voucher.Type.VOUCHER, equalTo(voucherCreated.getType()));
int paymentCreditNumber = invoiceLines.stream().filter(invoiceLine -> invoiceLine.getTotal() >= 0).mapToInt(line -> line.getFundDistributions().size()).sum();
paymentCreditNumber += invoice.getAdjustments().stream().mapToInt(adj -> adj.getFundDistributions().size()).sum();
assertThat(pendingPaymentCreated, hasSize(paymentCreditNumber));
List<Transaction> pendingPayments = pendingPaymentCreated.stream().map(entries -> entries.mapTo(Transaction.class)).collect(toList());
assertThat(pendingPayments, Every.everyItem(hasProperty("sourceInvoiceId", is(invoice.getId()))));
assertThat(transactionSummary.getNumPendingPayments(), is(paymentCreditNumber));
assertThat(transactionSummary.getNumPaymentsCredits(), is(paymentCreditNumber));
assertThat(calculateVoucherAmount(voucherCreated, voucherLines), equalTo(voucherCreated.getAmount()));
assertThat(createdVoucherLines, equalTo(voucherLinesCreated.size()));
invoiceLines.forEach(invoiceLine -> calculateInvoiceLineTotals(invoiceLine, invoiceUpdate));
voucherLines.forEach(voucherLine -> {
assertThat(voucherCreated.getId(), equalTo(voucherLine.getVoucherId()));
assertThat(voucherLine.getFundDistributions(), allOf(Every.everyItem(hasProperty("distributionType", is(AMOUNT))), Every.everyItem(hasProperty("code"))));
assertThat(calculateVoucherLineAmount(voucherLine.getFundDistributions(), voucherCreated), equalTo(voucherLine.getAmount()));
assertThat(voucherLine.getFundDistributions().stream().filter(fundDistribution -> Objects.nonNull(fundDistribution.getInvoiceLineId())).map(FundDistribution::getInvoiceLineId).distinct().collect(Collectors.toList()), hasSize(voucherLine.getSourceIds().size()));
});
}
use of org.folio.invoices.utils.ResourcePathResolver.INVOICE_LINES in project mod-invoice by folio-org.
the class InvoicesApiTest method testUpdateValidInvoiceTransitionToPaid.
@Test
void testUpdateValidInvoiceTransitionToPaid() {
logger.info("=== Test transition invoice to paid and mixed releaseEncumbrance ===");
Invoice reqData = getMockAsJson(APPROVED_INVOICE_SAMPLE_PATH).mapTo(Invoice.class).withStatus(Invoice.Status.PAID);
String id = reqData.getId();
prepareMockVoucher(id);
String jsonBody = JsonObject.mapFrom(reqData).encode();
verifyPut(String.format(INVOICE_ID_PATH, id), jsonBody, "", 204);
assertThat(serverRqRs.get(INVOICES, HttpMethod.PUT).get(0).getString(STATUS), is(Invoice.Status.PAID.value()));
List<JsonObject> invoiceLinesUpdates = serverRqRs.get(INVOICE_LINES, HttpMethod.PUT);
List<InvoiceLine> invoiceLines = invoiceLinesUpdates.stream().map(entry -> entry.mapTo(InvoiceLine.class)).collect(toList());
assertThat(invoiceLines, everyItem(hasProperty("invoiceLineStatus", is(InvoiceLine.InvoiceLineStatus.PAID))));
validatePoLinesPaymentStatus();
assertThatVoucherPaid();
// Check that the invoice has updated paid date (equals to the one from the metadata).
logger.info("Test that the invoice has updated paid date on pay transition.");
var invoices = serverRqRs.get(INVOICES, HttpMethod.PUT).stream().map(entry -> entry.mapTo(Invoice.class)).collect(toList());
var expectedPaymentDate = invoices.get(0).getMetadata().getUpdatedDate();
assertThat(invoices, everyItem(hasProperty("paymentDate", is(expectedPaymentDate))));
var payments = getRqRsEntries(HttpMethod.POST, FINANCE_PAYMENTS).stream().map(json -> json.mapTo(Transaction.class)).collect(toList());
invoiceLines.forEach(invLine -> {
var sumPaymentsByLine = payments.stream().filter(tr -> tr.getSourceInvoiceLineId() != null).filter(tr -> tr.getSourceInvoiceLineId().equals(invLine.getId())).map(tr -> Money.of(tr.getAmount(), tr.getCurrency())).reduce(Money::add).get().getNumber().doubleValue();
assertEquals(invLine.getTotal(), sumPaymentsByLine);
});
invoiceLines.forEach(invLine -> {
var sumPaymentsByNonProratedAdjs = payments.stream().filter(tr -> tr.getSourceInvoiceLineId() == null).map(tr -> Money.of(tr.getAmount(), tr.getCurrency())).reduce(Money::add).get().getNumber().doubleValue();
var invNonProratedAdjs = invoices.get(0).getAdjustments().stream().map(adj -> Money.of(adj.getValue(), invoices.get(0).getCurrency())).reduce(Money::add).get().getNumber().doubleValue();
assertEquals(invNonProratedAdjs, sumPaymentsByNonProratedAdjs);
});
}
Aggregations