Skip to content

APLT Module

The APLT Module is a custom B2B ERP system built into the Medusa backend. It handles the complete quotation-to-invoice pipeline, including CRM, access control, PDF generation, and AI-assisted workflows.

APLT data lives in a separate database from standard Medusa data, connected via APLT_DB_* environment variables.

Quotation ──► Order ──► Invoice
│ │ │
│ │ └──► Credit Note
│ │
└────────────┴──► PDF Generation

Thread-safe via aplt_number_sequences table with row-level locking:

PrefixDocumentExample
QQuotationQ-2024-0001
OOrderO-2024-0015
FInvoice (Factuur)F-2024-0042
CCredit NoteC-2024-0003
PProformaP-2024-0001
TablePurpose
aplt_quotation_headersQuotation master records
aplt_quotation_linesQuotation line items
aplt_quotation_line_setup_costsSetup costs per quotation line
aplt_order_headersOrder master records
aplt_order_linesOrder line items
aplt_invoice_headersInvoice master records
aplt_invoice_linesInvoice line items
aplt_invoice_vat_summaryVAT summary per invoice
aplt_document_relationsCross-document links (quotation->order->invoice)
aplt_opstartkostenStartup/setup costs
TablePurpose
aplt_productsProduct catalog (multi-language, tiered pricing)
aplt_techniquesPrint/decoration techniques per product
aplt_technique_pricingPricing per technique
aplt_categoriesProduct categories
aplt_category_mappingsProduct-to-category mappings
aplt_colorsColor definitions
aplt_suppliersSupplier information
aplt_discount_groupsDiscount configurations
TablePurpose
aplt_cms_settingsKey/value settings per brand
aplt_cms_pagesMulti-language content pages
aplt_cms_menu_itemsMenu items
aplt_cms_menusMenu definitions
aplt_cms_footer_sectionsFooter section organization
aplt_cms_footer_linksFooter links
TablePurpose
aplt_brandsBrand configurations
aplt_settingsGeneral settings
aplt_number_sequencesThread-safe document numbering
aplt_payment_termsPayment term definitions
aplt_vat_codesVAT rates
aplt_tenantsTenant configurations
TablePurpose
aplt_paymentsPayment records
aplt_payment_allocationsPayment-to-invoice allocations
aplt_journal_entriesJournal entry headers
aplt_journal_linesJournal entry lines
aplt_ledger_accountsChart of accounts
TablePurpose
aplt_customersB2B customer database
aplt_access_requestsIP-based access requests
TablePurpose
aplt_3d_config3D viewer configuration
aplt_3d_products3D product models
aplt_3d_products_config3D product-specific configuration
TablePurpose
aplt_audit_logChange audit trail
aplt_deployment_logsDeployment history
aplt_logo_cacheCached logo data
aplt_migrationsDatabase migration tracking
aplt_modulesModule registry
aplt_tenant_modulesModule-to-tenant assignments
aplt_releasesRelease version tracking

B2B shipping with free-shipping threshold:

  • Franco Limit: €750 (configurable via APLT_FRANCO_LIMIT)
  • Above limit → Free shipping
  • Below limit → Calculated per box or default cost (APLT_SHIPPING_COST_DEFAULT: €12.99)
  • Shipping boxes tracked per quotation/order

All documents can be generated as PDFs using PDFKit:

EndpointDocument
GET /admin/aplt/orders/pdf?id=XOrder confirmation
GET /admin/aplt/quotations/pdf?id=XQuotation/offerte
GET /admin/aplt/invoices/pdf?id=XInvoice
GET /admin/aplt/credit-notes/pdf?id=XCredit note

PDFs include:

  • Company info from aplt_cms_settings (name, address, KvK, BTW, IBAN)
  • Line items with techniques and pricing
  • VAT calculations
  • Terms and conditions (quotations)
  • Payment terms (invoices)

Invoice PDFs are persisted to /mnt/data/brinxx_invoices/.

Documents can be exported as .eml files with the PDF already attached. Opening the .eml file in any email client (Outlook, Thunderbird, Apple Mail) gives a ready-to-send draft with pre-filled To, Subject, body text, and PDF attachment.

EndpointDocumentFilename
POST /admin/aplt/quotations/emlOfferteofferte-{number}.eml
POST /admin/aplt/orders/emlOrderbevestigingorderbevestiging-{number}.eml
POST /admin/aplt/invoices/emlFactuurfactuur-{number}.eml

Request body: { "id": <document_id> }

EML features:

  • X-Unsent: 1 header — opens as draft (compose mode) in email clients
  • PDF fetched internally from existing PDF routes (no code duplication)
  • Company info (From, name) from aplt_cms_settings
  • Customer email pre-filled in To field
  • Standard Dutch email body text per document type
  • MIME multipart/mixed with base64-encoded PDF attachment

Admin UI: Green “Email + PDF” button with EnvelopeSolid icon on Quotations, Orders, and Invoices pages.

Three AI-powered features using the Anthropic Claude API:

EndpointPurpose
POST /admin/aplt/wayne-assistAI admin assistant
POST /admin/aplt/ai-generate-linesAuto-generate quotation line items
POST /admin/agent/product-searchIntelligent product search
  • 30-day default validity
  • Discount group integration
  • Franco pricing calculations
  • Auto-recalculate totals on line changes
  • Print colors specification per line
  • Convert to order (POST /admin/aplt/quotations/confirm)

Scheduled job for recurring invoices:

src/jobs/subscription-billing.ts
// Schedule: 0 8 1 * * (1st of month at 08:00)
// Status: Currently DISABLED

The APLT module adds 25+ admin pages organized in sections:

  • 01-quotations — Quotation management
  • 02-aplt-orders — Order management
  • 03-invoices — Invoice management
  • 04-customers — Customer management
  • 05-credit-notes — Credit notes
  • 06-payments — Payment tracking
  • 07-reports — Reporting dashboard
  • 08-subscriptions — Subscription management
  • 09-crm — CRM functionality
  • 11-cms — Content management
  • 12-brand-wizard — Brand configuration
  • 13-cms-modules — Module management
  • 14-page-manager — Page layout editor
  • 15-menu-manager — Menu configuration
  • 21-connectors — Supplier data connectors
  • 22-access-requests — Access approvals
  • 23-aplt-products — Product catalog
  • 24-category-manager — Categories
  • 25-technique-pricing — Technique pricing
  • 26-translations — Multi-language translations