Skip to content

Instantly share code, notes, and snippets.

@patrickmast
Last active July 2, 2025 10:42
Show Gist options
  • Save patrickmast/c9ec60bc8c605922d5dc077e92451bf5 to your computer and use it in GitHub Desktop.
Save patrickmast/c9ec60bc8c605922d5dc077e92451bf5 to your computer and use it in GitHub Desktop.

Winfakt Template Engine en Formules Documentatie

Overzicht

Winfakt gebruikt Go's ingebouwde html/template package voor het dynamisch genereren van verkoopdocumenten zoals facturen, offertes en leveringsbonnen. Deze documentatie beschrijft de beschikbare variabelen en formule syntax.

Template Engine

  • Engine: Go html/template package
  • Syntax: Dubbele accolades {{ }} voor variabelen en functies
  • Veiligheid: Automatische HTML escaping om XSS aanvallen te voorkomen
  • Documentatie: https://pkg.go.dev/html/template

Beschikbare Variabelen (._Row)

Elke verkoopregel heeft toegang tot de volgende variabelen via het ._Row object:

Variabele Type Beschrijving
._Row.ID int Uniek ID van de verkoopregel
._Row.Amount float Aantal van het product op deze regel
._Row.ProductSku string SKU (Stock Keeping Unit) van het product
._Row.ProductDescription string Omschrijving van het product op deze regel
._Row.UnitName string Eenheid van het product (bijv. stuks, kg, liter)
._Row.UnitPrice float Verkoopprijs per eenheid (excl. btw, vóór korting)
._Row.UnitBuyPrice float Inkoopprijs per eenheid
._Row.Discount float Korting in procent op deze regel
._Row.Vat float BTW-percentage toegepast op deze regel
._Row.TotalPriceExcVat float Totaalprijs van deze regel exclusief btw (na korting)
._Row.TotalPriceIncVat float Totaalprijs van deze regel inclusief btw (na korting)
._Row.TotalVat float Totaalbedrag aan btw op deze regel
._Row.TotalBuyPrice float Totale inkoopprijs voor deze regel
._Row.TotalProfit float Totale winst op deze regel (totaal verkoop - totaal inkoop)
._Row.LedgerAccountCode string Grootboekrekeningcode gekoppeld aan deze regel
._Row.Duration float Duur (voor diensten, bijv. aantal uren)
._Row.Backorder float Aantal dat nog in backorder staat
._Row.Delivered float Aantal dat reeds geleverd is
._Row.LastDelivered float Aantal dat bij de laatste levering geleverd werd
._Row.DeliveryDate time.Time Leverdatum van deze regel (datum object)
._Row.BookYear int Boekjaar waarin deze regel valt

Beschikbare Functies

Wiskundige Functies (._Utils.Math)

  • ._Utils.Math.Add: Optellen van twee getallen
  • ._Utils.Math.Sub: Aftrekken van twee getallen
  • ._Utils.Math.Mul: Vermenigvuldigen van twee getallen
  • ._Utils.Math.Div: Delen van twee getallen

Afrondingsfunctie

  • ._RoundDecimals: Rondt een getal af op een specifiek aantal decimalen
    • Syntax: {{call ._RoundDecimals [getal] [decimalen] [afronding]}}
    • Voorbeeld: {{call ._RoundDecimals 10.456 2 true}} → 10.46

Formule Voorbeelden

1. Prijs per stuk (excl. btw)

{{call ._RoundDecimals ((call ._Utils.Math.Div ._Row.TotalPriceExcVat ._Row.Amount)) 2 true}}
Berekent de prijs per stuk door de totaalprijs te delen door het aantal, afgerond op 2 decimalen.

2. Totaalprijs incl. BTW zonder korting

{{call ._RoundDecimals (call ._Utils.Math.Mul (call ._Utils.Math.Mul ._Row.UnitPrice ._Row.Amount)
(call ._Utils.Math.Div (call ._Utils.Math.Add ._Row.Vat 100.0) 100.0)) 2 true}}
Berekent de totaalprijs inclusief BTW zonder de korting toe te passen.

Let op: Gebruik 100.0 in plaats van 100 voor correcte float berekeningen.

3. Leverdatum weergeven

{{ if ne ._Row.DeliveryDate nil}}{{ ._Row.DeliveryDate.Format "02/01/2006" }}{{end}}
Geeft de leverdatum weer in DD/MM/YYYY formaat. De datum wordt alleen getoond als deze ingevuld is.

Template Syntax Basis

Variabelen weergeven

{{ ._Row.ProductDescription }}

Conditionele logica

{{ if gt ._Row.Discount 0 }}
  Korting: {{ ._Row.Discount }}%
{{ end }}

Loops (voor meerdere regels)

{{ range ._Rows }}
  Product: {{ .ProductDescription }}
  Prijs: {{ .UnitPrice }}
{{ end }}

Functies aanroepen

{{ call ._Utils.Math.Add ._Row.UnitPrice 10.0 }}

Belangrijke Aandachtspunten

1. Null waarden: Niet elk veld is altijd gevuld. Controleer op nil waar nodig.
2. Type conversie: Gebruik decimale notatie (bijv. 100.0) voor float berekeningen.
3. HTML Escaping: De template engine escapet automatisch HTML voor veiligheid.
4. Datum formatting: Gebruik Go's datum format syntax (bijv. "02/01/2006" voor DD/MM/YYYY).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment