7.10.1. Invoice Items

We make the class for viewing the invoice items via jqGrid a little simpler. Its records are filtered by invoice header code and user-driven search and sort options are not implemented.

  1. package ru.ibase.fbjavaex.jqgrid;
  2. import org.jooq.*;
  3. import java.util.List;
  4. import java.util.Map;
  5. import static ru.ibase.fbjavaex.exampledb.Tables.INVOICE_LINE;
  6. import static ru.ibase.fbjavaex.exampledb.Tables.PRODUCT;
  7. /**
  8. * The grid handler for the invoice items
  9. *
  10. * @author Simonov Denis
  11. */
  12. public class JqGridInvoiceLine extends JqGrid {
  13. private int invoiceId;
  14. public int getInvoiceId() {
  15. return this.invoiceId;
  16. }
  17. public void setInvoiceId(int invoiceId) {
  18. this.invoiceId = invoiceId;
  19. }
  20. /**
  21. * Returns the total number of records
  22. *
  23. * @return
  24. */
  25. @Override
  26. public int getCountRecord() {
  27. SelectFinalStep<?> select
  28. = dsl.selectCount()
  29. .from(INVOICE_LINE)
  30. .where(INVOICE_LINE.INVOICE_ID.eq(this.invoiceId));
  31. SelectQuery<?> query = select.getQuery();
  32. return (int) query.fetch().getValue(0, 0);
  33. }
  34. /**
  35. * Returns invoice items
  36. *
  37. * @return
  38. */
  39. @Override
  40. public List<Map<String, Object>> getRecords() {
  41. SelectFinalStep<?> select = dsl.select(
  42. INVOICE_LINE.INVOICE_LINE_ID,
  43. INVOICE_LINE.INVOICE_ID,
  44. INVOICE_LINE.PRODUCT_ID,
  45. PRODUCT.NAME.as("PRODUCT_NAME"),
  46. INVOICE_LINE.QUANTITY,
  47. INVOICE_LINE.SALE_PRICE,
  48. INVOICE_LINE.SALE_PRICE.mul(INVOICE_LINE.QUANTITY).as("TOTAL"))
  49. .from(INVOICE_LINE)
  50. .innerJoin(PRODUCT).on(PRODUCT.PRODUCT_ID.eq(INVOICE_LINE.PRODUCT_ID))
  51. .where(INVOICE_LINE.INVOICE_ID.eq(this.invoiceId));
  52. SelectQuery<?> query = select.getQuery();
  53. return query.fetchMaps();
  54. }
  55. }