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));
}
}
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;
}
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);
}
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());
}
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;
}
Aggregations