krasselt / afs-order-format
Generates AFS Vorgangimport email bodies from order data
Requires
- php: ^8.2
Requires (Dev)
- phpunit/phpunit: ^12.5
This package is auto-updated.
Last update: 2026-04-27 10:39:04 UTC
README
PHP library that generates email bodies in the AFS Vorgangimport format (###AFS_VORGANGIMPORT#). Designed to bridge online shop orders into AFS billing software via email.
The output contains both a human-readable order summary and the machine-readable ###FIELD:VALUE# import block that AFS parses automatically.
Requirements
- PHP 8.2+
ext-bcmath
Installation
composer require krasselt/afs-order-format
Usage
use Krasselt\AfsOrderFormat\AfsOrderGenerator; use Krasselt\AfsOrderFormat\OrderData; use Krasselt\AfsOrderFormat\CustomerData; use Krasselt\AfsOrderFormat\ShippingData; use Krasselt\AfsOrderFormat\PaymentData; use Krasselt\AfsOrderFormat\CartItem; $generator = new AfsOrderGenerator(shopName: 'My Shop'); $order = new OrderData( customer: new CustomerData( customerNumber: 'KU-1937', company: 'Example GmbH', lastName: 'Mustermann', firstName: 'Max', street: 'Musterstraße 1', zip: '01234', city: 'Musterstadt', state: 'Sachsen', phone: '0123-456789', email: 'max@example.de', ), shipping: new ShippingData( method: 'Vorkasse DHL-Paketversand', cost: '5.50', deliveryType: 'per DHL Paketdienst', ), payment: new PaymentData( method: 'Vorkasse DHL-Paketversand', ), items: [ new CartItem( position: 1, quantity: 2, articleNumber: '031', description: 'Terminal Servicegebühr', unitPrice: '10.00', totalPrice: '20.00', ), new CartItem( position: 2, quantity: 1, articleNumber: '109', description: 'Mobile-Daten SIM Karte n. Verb.', unitPrice: '4.35', totalPrice: '4.35', ), ], orderDate: new \DateTimeImmutable(), orderId: 'ORD-001', vatAmount: '3.89', ); // Full email body (human-readable + AFS import block) $emailBody = $generator->generate($order); // Or generate sections individually $humanReadable = $generator->generateHumanReadable($order); $afsImport = $generator->generateAfsImport($order);
Data classes
| Class | Purpose |
|---|---|
CustomerData |
Customer number, company, name, address, contact, EU tax ID |
ShippingData |
Shipping method, cost, delivery type, surcharge, delivery address |
PaymentData |
Payment method, bank details, credit card, voucher |
CartItem |
Position number, quantity, article number, description, unit/total price |
OrderData |
Composes all of the above + order date, ID, remarks, VAT |
All fields default to empty strings, so you only need to pass what you have. OrderData provides getSubtotal() and getGrandTotal() computed from the cart items and shipping.
Output format
The generated text contains two sections:
1. Human-readable summary — formatted order confirmation with customer data, articles, and totals.
2. AFS import block — starts with AUTOVORGANGIMPORT: ###AFS_VORGANGIMPORT# followed by tagged fields:
###KNUMMER:KU-1937#
###FIRMA:Example GmbH#
###NAME:Mustermann#
...
###POSTEN#
###POS_NR:1#
###POS_ANZAHL:2#
###POS_ARTIKELNR:031#
###POS_ARTIKELBE:Terminal Servicegebühr#
###POS_EPREIS:10.00#
###POS_GPREIS:20.00#
License
Proprietary