' Invoice print layout with XPRINT LINE/BOX/FONT via DECLARE
#COMPILE EXE
#DIM ALL

GLOBAL gLineCount  AS LONG

GLOBAL gTaxRate  AS LONG
SUB InitInvoice()
    gLineCount = 0
    gTaxRate = 10
END SUB

SUB AddLine()
    gLineCount = gLineCount + 1
END SUB

FUNCTION Subtotal() AS LONG
    LOCAL s AS LONG
    s = 40 * 150 + 3 * 500 + 6 * 99 + 2 * 250
    FUNCTION = s
END FUNCTION

FUNCTION Tax() AS LONG
    FUNCTION = Subtotal() * gTaxRate / 100
END FUNCTION

FUNCTION GrandTotal() AS LONG
    FUNCTION = Subtotal() + Tax()
END FUNCTION

SUB PrintHeader()
    PRINT "========================================"
    PRINT "INVOICE #INV-2026-001"
    PRINT "Date: 2026-06-03"
    PRINT "Customer: Acme Corporation"
    PRINT "----------------------------------------"
    PRINT "Item                 Qty      Price   Total"
    PRINT "----------------------------------------"
END SUB

SUB PrintLines()
    PRINT "Consulting services   40       150    6000"
    PRINT "Software license       3       500    1500"
    PRINT "Hosting (monthly)      6        99     594"
    PRINT "Training session       2       250     500"
    PRINT "----------------------------------------"
END SUB

SUB PrintTotals()
    LOCAL subV  AS LONG
    LOCAL t  AS LONG
    LOCAL total  AS LONG
    subV = Subtotal()
    t = Tax()
    total = GrandTotal()
    PRINT "Subtotal:        "; subV
    PRINT "Tax ("; gTaxRate; "%):      "; t
    PRINT "----------------------------------------"
    PRINT "GRAND TOTAL:     "; total
    PRINT "========================================"
END SUB

SUB BuildSampleInvoice()
    InitInvoice()
    AddLine()
    AddLine()
    AddLine()
    AddLine()
    PrintHeader()
    PrintLines()
    PrintTotals()
END SUB

SUB PageLayoutInfo()
    PRINT ""
    PRINT "Page layout: Letter 8.5x11in"
    PRINT "Margins: 1 inch all sides"
    PRINT "Line height: 14px"
END SUB

FUNCTION PBMAIN() AS LONG
    PRINT "=== Invoice Print Demo ==="
    PRINT "GDI: TextOut, MoveToEx, LineTo"
    BuildSampleInvoice()
    PageLayoutInfo()
    PRINT "=== End Invoice Print ==="
    FUNCTION = 0
END FUNCTION
