OrderExportService
in package
Service for exporting orders in multiple accounting formats.
Supports QuickBooks Online, Xero, Wave, and generic CSV exports at both order-level and line-item level, with US/Canada tax column handling and date range filtering.
Tags
Table of Contents
Constants
- COUNTRIES = ['US', 'CA']
- FORMATS = ['generic', 'qbo', 'xero', 'wave']
- LEVELS = ['order', 'line_item']
Methods
- formatLabel() : string
- Get a human-readable label for a format code.
- generateCsv() : string
- Generate CSV content for the given orders and format settings.
- getFilename() : string
- Get the filename for the export download.
- getLineItemHeaders() : array<string|int, mixed>
- Get line-item CSV headers for the given format.
- getOrderHeaders() : array<string|int, mixed>
- Get order-level CSV headers for the given format.
- levelLabel() : string
- Get a human-readable label for an export level.
- getGenericLineItemHeaders() : array<string|int, mixed>
- Get generic line-item headers.
- getGenericOrderHeaders() : array<string|int, mixed>
- Get generic order-level headers.
- getQboLineItemHeaders() : array<string|int, mixed>
- Get QBO line-item headers.
- getQboOrderHeaders() : array<string|int, mixed>
- Get QBO order-level headers.
- getWaveLineItemHeaders() : array<string|int, mixed>
- Get Wave line-item headers.
- getWaveOrderHeaders() : array<string|int, mixed>
- Get Wave order-level headers.
- getXeroLineItemHeaders() : array<string|int, mixed>
- Get Xero line-item headers.
- getXeroOrderHeaders() : array<string|int, mixed>
- Get Xero order-level headers.
- money() : string
- Format a value as a money string with two decimal places.
- writeLineItemRows() : void
- Write line-item rows to the output handle.
- writeOrderRows() : void
- Write order-level rows to the output handle.
Constants
COUNTRIES
public
array<string|int, string>
COUNTRIES
= ['US', 'CA']
Supported countries for tax handling
FORMATS
public
array<string|int, string>
FORMATS
= ['generic', 'qbo', 'xero', 'wave']
Supported export formats
LEVELS
public
array<string|int, string>
LEVELS
= ['order', 'line_item']
Supported export levels
Methods
formatLabel()
Get a human-readable label for a format code.
public
static formatLabel(string $format) : string
Parameters
- $format : string
-
Format code
Return values
stringgenerateCsv()
Generate CSV content for the given orders and format settings.
public
generateCsv(array<string|int, mixed> $orders[, string $format = 'generic' ][, string $level = 'order' ][, string $country = 'US' ][, array<string|int, mixed> $business = [] ][, array<string|int, mixed> $columnMappings = [] ]) : string
Parameters
- $orders : array<string|int, mixed>
-
Orders (with 'items' key for line-item exports)
- $format : string = 'generic'
-
Export format (generic, qbo, xero, wave)
- $level : string = 'order'
-
Export level (order, line_item)
- $country : string = 'US'
-
Country code (US, CA)
- $business : array<string|int, mixed> = []
-
Business record for context
- $columnMappings : array<string|int, mixed> = []
-
Optional custom column mappings
Return values
string —CSV content
getFilename()
Get the filename for the export download.
public
getFilename(string $format, string $level, string $startDate, string $endDate) : string
Parameters
- $format : string
-
Export format
- $level : string
-
Export level
- $startDate : string
-
Start date
- $endDate : string
-
End date
Return values
stringgetLineItemHeaders()
Get line-item CSV headers for the given format.
public
getLineItemHeaders(string $format[, string $country = 'US' ]) : array<string|int, mixed>
Parameters
- $format : string
-
Export format
- $country : string = 'US'
-
Country code
Return values
array<string|int, mixed>getOrderHeaders()
Get order-level CSV headers for the given format.
public
getOrderHeaders(string $format[, string $country = 'US' ]) : array<string|int, mixed>
Parameters
- $format : string
-
Export format
- $country : string = 'US'
-
Country code
Return values
array<string|int, mixed>levelLabel()
Get a human-readable label for an export level.
public
static levelLabel(string $level) : string
Parameters
- $level : string
-
Export level
Return values
stringgetGenericLineItemHeaders()
Get generic line-item headers.
private
getGenericLineItemHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed>getGenericOrderHeaders()
Get generic order-level headers.
private
getGenericOrderHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed>getQboLineItemHeaders()
Get QBO line-item headers.
private
getQboLineItemHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed>getQboOrderHeaders()
Get QBO order-level headers.
private
getQboOrderHeaders(string $country) : array<string|int, mixed>
Parameters
- $country : string
-
Country code
Return values
array<string|int, mixed>getWaveLineItemHeaders()
Get Wave line-item headers.
private
getWaveLineItemHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed>getWaveOrderHeaders()
Get Wave order-level headers.
private
getWaveOrderHeaders(string $country) : array<string|int, mixed>
Parameters
- $country : string
-
Country code
Return values
array<string|int, mixed>getXeroLineItemHeaders()
Get Xero line-item headers.
private
getXeroLineItemHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed>getXeroOrderHeaders()
Get Xero order-level headers.
private
getXeroOrderHeaders(string $country) : array<string|int, mixed>
Parameters
- $country : string
-
Country code
Return values
array<string|int, mixed>money()
Format a value as a money string with two decimal places.
private
money(mixed $value) : string
Parameters
- $value : mixed
-
Numeric value
Return values
stringwriteLineItemRows()
Write line-item rows to the output handle.
private
writeLineItemRows(resource $output, array<string|int, mixed> $orders, string $format, string $country, array<string|int, mixed> $business) : void
Parameters
- $output : resource
-
File handle
- $orders : array<string|int, mixed>
-
Order records with 'items' key
- $format : string
-
Export format
- $country : string
-
Country code
- $business : array<string|int, mixed>
-
Business record
writeOrderRows()
Write order-level rows to the output handle.
private
writeOrderRows(resource $output, array<string|int, mixed> $orders, string $format, string $country, array<string|int, mixed> $business) : void
Parameters
- $output : resource
-
File handle
- $orders : array<string|int, mixed>
-
Order records
- $format : string
-
Export format
- $country : string
-
Country code
- $business : array<string|int, mixed>
-
Business record