package com.ankurm.pdfinvoice; import java.math.BigDecimal; import java.math.RoundingMode; import java.time.LocalDate; import java.util.List; /** * The one invoice all three libraries render. Plain records, no framework types, so each writer * is a function {@code Invoice -> bytes} and the comparison is about the PDF libraries, not about Spring. */ public record Invoice(String number, LocalDate date, Party seller, Party buyer, List lines, String note) { public record Party(String name, String address, String gstin) {} /** {@code description} may be Devanagari; that is the point of the exercise. */ public record Line(String description, int quantity, BigDecimal unitPrice) { public BigDecimal amount() { return unitPrice.multiply(BigDecimal.valueOf(quantity)); } } /** GST at 18 percent, split evenly into CGST and SGST as an intra-state sale would be. */ public static final BigDecimal GST_RATE = new BigDecimal("0.18"); public BigDecimal subtotal() { return lines.stream().map(Line::amount).reduce(BigDecimal.ZERO, BigDecimal::add); } public BigDecimal gst() { return subtotal().multiply(GST_RATE).setScale(2, RoundingMode.HALF_UP); } public BigDecimal total() { return subtotal().add(gst()); } }