use of org.folio.rest.acq.model.VoucherLine in project mod-invoice by folio-org.
the class MockServer method handleGetVoucherLines.
private void handleGetVoucherLines(RoutingContext ctx) {
logger.info("handleGetVoucherLines got: {}?{}", ctx.request().path(), ctx.request().query());
String queryParam = StringUtils.trimToEmpty(ctx.request().getParam(QUERY));
String tenant = ctx.request().getHeader(OKAPI_HEADER_TENANT);
String voucherId = EMPTY;
if (queryParam.contains(VOUCHER_ID)) {
voucherId = queryParam.split(VOUCHER_ID + "==")[1];
}
if (queryParam.contains(BAD_QUERY)) {
serverResponse(ctx, 400, APPLICATION_JSON, Response.Status.BAD_REQUEST.getReasonPhrase());
} else if (queryParam.contains(ID_FOR_INTERNAL_SERVER_ERROR) || GET_VOUCHER_LINES_ERROR_TENANT.equals(tenant)) {
serverResponse(ctx, 500, APPLICATION_JSON, Response.Status.INTERNAL_SERVER_ERROR.getReasonPhrase());
} else {
Supplier<List<VoucherLine>> getFromFile = () -> {
try {
return new JsonObject(getMockData(VOUCHER_LINES_COLLECTION)).mapTo(VoucherLineCollection.class).getVoucherLines();
} catch (IOException e) {
return Collections.emptyList();
}
};
VoucherLineCollection voucherLineCollection = new VoucherLineCollection();
List<VoucherLine> voucherLines = getMockEntries(VOUCHER_LINES, VoucherLine.class).orElseGet(getFromFile);
Function<VoucherLine, String> voucherIdGetter = VoucherLine::getVoucherId;
voucherLineCollection.setVoucherLines(filterEntriesByStringValue(voucherId, voucherLines, voucherIdGetter));
voucherLineCollection.setTotalRecords(voucherLineCollection.getVoucherLines().size());
JsonObject voucherLinesJson = JsonObject.mapFrom(voucherLineCollection);
logger.info(voucherLinesJson.encodePrettily());
addServerRqRsData(HttpMethod.GET, VOUCHER_LINES, voucherLinesJson);
serverResponse(ctx, 200, APPLICATION_JSON, voucherLinesJson.encode());
}
}
use of org.folio.rest.acq.model.VoucherLine in project mod-invoice by folio-org.
the class MockServer method handleGetVoucherLineById.
private void handleGetVoucherLineById(RoutingContext ctx) {
logger.info("handleGetVoucherLinesById got: GET " + ctx.request().path());
String id = ctx.request().getParam(AbstractHelper.ID);
logger.info("id: " + id);
try {
String filePath = String.format(MOCK_DATA_PATH_PATTERN, VOUCHER_LINES_MOCK_DATA_PATH, id);
JsonObject voucherLine = new JsonObject(getMockData(filePath));
// validate content against schema
VoucherLine voucherSchema = voucherLine.mapTo(VoucherLine.class);
voucherSchema.setId(id);
voucherLine = JsonObject.mapFrom(voucherSchema);
addServerRqRsData(HttpMethod.GET, VOUCHER_LINES, voucherLine);
serverResponse(ctx, 200, APPLICATION_JSON, voucherLine.encodePrettily());
} catch (IOException e) {
ctx.response().setStatusCode(404).end(id);
}
}
use of org.folio.rest.acq.model.VoucherLine in project mod-invoice by folio-org.
the class VoucherLinesRetrieveServiceTest method positiveGetInvoiceMapTest.
@Test
public void positiveGetInvoiceMapTest() throws IOException, ExecutionException, InterruptedException {
VoucherLinesRetrieveService service = new VoucherLinesRetrieveService(okapiHeaders, context, "en");
JsonObject vouchersList = new JsonObject(getMockData(VOUCHERS_LIST_PATH));
List<Voucher> vouchers = vouchersList.getJsonArray("vouchers").stream().map(obj -> ((JsonObject) obj).mapTo(Voucher.class)).collect(toList());
vouchers.remove(1);
VoucherCollection voucherCollection = new VoucherCollection();
voucherCollection.setVouchers(vouchers);
CompletableFuture<Map<String, List<VoucherLine>>> future = service.getVoucherLinesMap(voucherCollection);
Map<String, List<VoucherLine>> lineMap = future.get();
Assertions.assertEquals(3, lineMap.get("a9b99f8a-7100-47f2-9903-6293d44a9905").size());
}
use of org.folio.rest.acq.model.VoucherLine in project mod-invoice by folio-org.
the class BatchVoucherGenerateService method buildBatchedVoucher.
private BatchedVoucher buildBatchedVoucher(Voucher voucher, Map<String, List<VoucherLine>> mapVoucherLines, Map<String, Invoice> mapInvoices, Map<String, List<InvoiceLine>> invoiceLinesMap, Map<String, Organization> vendorsMap) {
BatchedVoucher batchedVoucher = new BatchedVoucher();
batchedVoucher.setVoucherNumber(voucher.getVoucherNumber());
batchedVoucher.setAccountingCode(voucher.getAccountingCode());
batchedVoucher.setVoucherDate(voucher.getVoucherDate());
batchedVoucher.setType(BatchedVoucher.Type.fromValue(voucher.getType().value()));
batchedVoucher.setAmount(voucher.getAmount());
batchedVoucher.setSystemCurrency(voucher.getSystemCurrency());
batchedVoucher.setInvoiceCurrency(voucher.getInvoiceCurrency());
batchedVoucher.setExchangeRate(voucher.getExchangeRate());
batchedVoucher.setStatus(BatchedVoucher.Status.fromValue(voucher.getStatus().value()));
Optional.ofNullable(voucher.getEnclosureNeeded()).ifPresentOrElse(batchedVoucher::setEnclosureNeeded, () -> batchedVoucher.setEnclosureNeeded(false));
Optional.ofNullable(voucher.getAccountNo()).ifPresent(batchedVoucher::setAccountNo);
Invoice invoice = mapInvoices.get(voucher.getInvoiceId());
batchedVoucher.setFolioInvoiceNo(invoice.getFolioInvoiceNo());
batchedVoucher.setVendorInvoiceNo(invoice.getVendorInvoiceNo());
batchedVoucher.setInvoiceDate(invoice.getInvoiceDate());
batchedVoucher.setInvoiceTerms(invoice.getPaymentTerms());
batchedVoucher.setInvoiceNote(invoice.getNote());
Organization organization = vendorsMap.get(invoice.getVendorId());
batchedVoucher.setVendorName(organization.getName());
List<Adjustment> adjustments = new ArrayList<>();
List<InvoiceLine> invoiceLines = invoiceLinesMap.get(invoice.getId());
List<String> invoiceAdjustmentIds = invoice.getAdjustments().stream().map(Adjustment::getId).collect(Collectors.toList());
if (invoiceLines != null && !invoiceLines.isEmpty()) {
for (InvoiceLine invoiceLine : invoiceLines) {
adjustments.addAll(getInvoiceLineAdjustments(invoiceLine, invoiceAdjustmentIds, voucher.getExchangeRate()));
}
}
List<Adjustment> invoiceAdjustmentToExport = invoice.getAdjustments().stream().filter(Adjustment::getExportToAccounting).map(adjustment -> calculateTotalAmount(adjustment, invoice.getSubTotal(), voucher.getExchangeRate())).collect(Collectors.toList());
adjustments.addAll(invoiceAdjustmentToExport);
batchedVoucher.setAdjustments(adjustments);
List<Address> addresses = organization.getAddresses();
if (addresses != null && !addresses.isEmpty()) {
Address primaryAddress = addresses.stream().filter(a -> a.getIsPrimary() != null && a.getIsPrimary()).findFirst().orElse(addresses.get(0));
batchedVoucher.setVendorAddress(addressConverter.convert(primaryAddress));
}
if (Objects.nonNull(voucher.getDisbursementNumber())) {
batchedVoucher.setDisbursementNumber(voucher.getDisbursementNumber());
batchedVoucher.setDisbursementDate(voucher.getDisbursementDate());
}
batchedVoucher.setDisbursementAmount(voucher.getDisbursementAmount());
batchedVoucher.withBatchedVoucherLines(buildBatchedVoucherLines(voucher.getId(), mapVoucherLines));
return batchedVoucher;
}
use of org.folio.rest.acq.model.VoucherLine in project mod-invoice by folio-org.
the class BatchVoucherGenerateService method buildBatchVoucher.
private CompletableFuture<BatchVoucher> buildBatchVoucher(BatchVoucherExport batchVoucherExport, VoucherCollection voucherCollection, Map<String, List<VoucherLine>> voucherLinesMap, Map<String, Invoice> invoiceMap, Map<String, List<InvoiceLine>> invoiceLinesMap, RequestContext requestContext) {
List<Invoice> invoices = new ArrayList<>(invoiceMap.values());
return vendorRetrieveService.getVendorsMap(invoices, requestContext).thenCombine(batchGroupHelper.getBatchGroup(batchVoucherExport.getBatchGroupId()), (vendorsMap, batchGroup) -> {
BatchVoucher batchVoucher = new BatchVoucher();
batchVoucher.setStart(batchVoucherExport.getStart());
batchVoucher.setEnd(batchVoucherExport.getStart());
List<BatchedVoucher> batchedVouchers = voucherCollection.getVouchers().stream().map(voucher -> buildBatchedVoucher(voucher, voucherLinesMap, invoiceMap, invoiceLinesMap, vendorsMap)).collect(toList());
batchVoucher.setTotalRecords(batchedVouchers.size());
batchVoucher.withBatchedVouchers(batchedVouchers);
batchVoucher.setCreated(new Date());
batchVoucher.setBatchGroup(batchGroup.getName());
return batchVoucher;
});
}
Aggregations