Search in sources :

Example 1 with InvoiceLine

use of org.folio.rest.jaxrs.model.InvoiceLine in project mod-invoice by folio-org.

the class CreateInvoiceEventHandler method preparePayloadWithMappedInvoiceLines.

private void preparePayloadWithMappedInvoiceLines(DataImportEventPayload dataImportEventPayload) {
    if (dataImportEventPayload.getContext().get(INVOICE_LINES_KEY) != null) {
        List<InvoiceLine> invoiceLines = mapInvoiceLinesArrayToList(new JsonArray(dataImportEventPayload.getContext().get(INVOICE_LINES_KEY)));
        InvoiceLineCollection invoiceLineCollection = new InvoiceLineCollection().withInvoiceLines(invoiceLines).withTotalRecords(invoiceLines.size());
        dataImportEventPayload.getContext().put(INVOICE_LINES_KEY, Json.encode(invoiceLineCollection));
    }
}
Also used : JsonArray(io.vertx.core.json.JsonArray) InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine) InvoiceLineCollection(org.folio.rest.jaxrs.model.InvoiceLineCollection)

Example 2 with InvoiceLine

use of org.folio.rest.jaxrs.model.InvoiceLine in project mod-invoice by folio-org.

the class AdjustmentsService method applyAmountTypeProratedAdjustments.

private List<InvoiceLine> applyAmountTypeProratedAdjustments(Adjustment adjustment, List<InvoiceLine> lines, CurrencyUnit currencyUnit, BiFunction<MonetaryAmount, InvoiceLine, MonetaryAmount> prorateFunction) {
    List<InvoiceLine> updatedLines = new ArrayList<>();
    MonetaryAmount expectedAdjustmentTotal = Money.of(adjustment.getValue(), currencyUnit);
    Map<String, MonetaryAmount> lineIdAdjustmentValueMap = calculateAdjValueForEachLine(lines, prorateFunction, expectedAdjustmentTotal);
    MonetaryAmount remainder = expectedAdjustmentTotal.abs().subtract(getActualAdjustmentTotal(lineIdAdjustmentValueMap, currencyUnit).abs());
    int remainderSignum = remainder.signum();
    MonetaryAmount smallestUnit = getSmallestUnit(expectedAdjustmentTotal, remainderSignum);
    for (ListIterator<InvoiceLine> iterator = getIterator(lines, remainderSignum); isIteratorHasNext(iterator, remainderSignum); ) {
        final InvoiceLine line = iteratorNext(iterator, remainderSignum);
        MonetaryAmount amount = lineIdAdjustmentValueMap.get(line.getId());
        if (!remainder.isZero()) {
            amount = amount.add(smallestUnit);
            remainder = remainder.abs().subtract(smallestUnit.abs()).multiply(remainderSignum);
        }
        Adjustment proratedAdjustment = prepareAdjustmentForLine(adjustment);
        proratedAdjustment.setValue(amount.getNumber().doubleValue());
        if (addAdjustmentToLine(line, proratedAdjustment)) {
            updatedLines.add(line);
        }
    }
    return updatedLines;
}
Also used : MonetaryAmount(javax.money.MonetaryAmount) Adjustment(org.folio.rest.jaxrs.model.Adjustment) InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine) ArrayList(java.util.ArrayList)

Example 3 with InvoiceLine

use of org.folio.rest.jaxrs.model.InvoiceLine in project mod-invoice by folio-org.

the class InvoiceLinesApiTest method testPutInvoicingInvoiceLinesWithError.

@Test
public void testPutInvoicingInvoiceLinesWithError() {
    InvoiceLine reqData = getMockAsJson(INVOICE_LINE_WITH_APPROVED_INVOICE_SAMPLE_PATH).mapTo(InvoiceLine.class);
    reqData.setId(ID_FOR_INTERNAL_SERVER_ERROR);
    String jsonBody = JsonObject.mapFrom(reqData).encode();
    verifyPut(ID_FOR_INTERNAL_SERVER_ERROR, jsonBody, APPLICATION_JSON, 500);
}
Also used : InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 4 with InvoiceLine

use of org.folio.rest.jaxrs.model.InvoiceLine in project mod-invoice by folio-org.

the class InvoiceLinesApiTest method testPutInvoiceLineUpdateTotalAndInvoice.

@Test
public void testPutInvoiceLineUpdateTotalAndInvoice() {
    logger.info("=== Test case when invoice line updates triggers also invoice update ===");
    InvoiceLine invoiceLine = getMockAsJson(INVOICE_LINE_OUTDATED_TOTAL_PATH).mapTo(InvoiceLine.class);
    addMockEntry(INVOICE_LINES, invoiceLine);
    invoiceLine.setSubTotal(100.500d);
    verifyPut(invoiceLine.getId(), JsonObject.mapFrom(invoiceLine), "", 204);
    MatcherAssert.assertThat(getInvoiceLineRetrievals(), hasSize(1));
    MatcherAssert.assertThat(getInvoiceRetrievals(), hasSize(1));
    MatcherAssert.assertThat(getInvoiceLineUpdates(), hasSize(1));
    InvoiceLine updatedInvoiceLine = getInvoiceLineUpdates().get(0).mapTo(InvoiceLine.class);
    Assertions.assertEquals(100.5d, updatedInvoiceLine.getSubTotal());
    Assertions.assertEquals(10.15d, updatedInvoiceLine.getAdjustmentsTotal());
    Assertions.assertEquals(110.65d, updatedInvoiceLine.getTotal());
    MatcherAssert.assertThat(getInvoiceUpdates(), hasSize(1));
    Invoice updatedInvoice = getInvoiceUpdates().get(0).mapTo(Invoice.class);
    // invoice totals are using the line totals pre-update because the mock server is not actually modifying the line,
    // but we can check the total was correctly updated
    Assertions.assertEquals(4.2d, updatedInvoice.getSubTotal());
    Assertions.assertEquals(0.42d, updatedInvoice.getAdjustmentsTotal());
    Assertions.assertEquals(4.62d, updatedInvoice.getTotal());
}
Also used : Invoice(org.folio.rest.jaxrs.model.Invoice) InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine) Test(org.junit.jupiter.api.Test)

Example 5 with InvoiceLine

use of org.folio.rest.jaxrs.model.InvoiceLine in project mod-invoice by folio-org.

the class InvoiceLinesApiTest method verifySuccessGetById.

private InvoiceLine verifySuccessGetById(String id, boolean lineUpdate, boolean invoiceUpdate) {
    InvoiceLine invoiceLine = verifySuccessGet(String.format(INVOICE_LINE_ID_PATH, id), InvoiceLine.class);
    // MODINVOICE-86 calculate the totals and if different from what was retrieved, write it back to storage
    MatcherAssert.assertThat(getInvoiceLineUpdates(), hasSize(lineUpdate ? 1 : 0));
    MatcherAssert.assertThat(getInvoiceUpdates(), hasSize(invoiceUpdate ? 1 : 0));
    return invoiceLine;
}
Also used : InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine)

Aggregations

InvoiceLine (org.folio.rest.jaxrs.model.InvoiceLine)120 Test (org.junit.jupiter.api.Test)88 Invoice (org.folio.rest.jaxrs.model.Invoice)83 Matchers.containsString (org.hamcrest.Matchers.containsString)58 Adjustment (org.folio.rest.jaxrs.model.Adjustment)45 JsonObject (io.vertx.core.json.JsonObject)39 Errors (org.folio.rest.jaxrs.model.Errors)36 Headers (io.restassured.http.Headers)34 Error (org.folio.rest.jaxrs.model.Error)30 FundDistribution (org.folio.rest.jaxrs.model.FundDistribution)26 ArrayList (java.util.ArrayList)25 InvoiceLineCollection (org.folio.rest.jaxrs.model.InvoiceLineCollection)25 List (java.util.List)24 RequestContext (org.folio.rest.core.models.RequestContext)22 Collections (java.util.Collections)21 Fund (org.folio.rest.acq.model.finance.Fund)20 Voucher (org.folio.rest.jaxrs.model.Voucher)20 Vertx (io.vertx.core.Vertx)19 LogManager (org.apache.logging.log4j.LogManager)17 Logger (org.apache.logging.log4j.Logger)17