Skip to main content
The Document Component (billing.document) handles the complete lifecycle of tax documents, including creation, validation, rendering, and batch processing.

Overview

This component provides all functionality needed to work with Chilean electronic tax documents (DTE). It processes input data, validates it, builds XML documents, and prepares them for signing and submission.

Workers

The Document Component contains the following workers:

Builder

Constructs tax documents from normalized data

Parser

Parses input data into internal format

Validator

Validates document data and structure

Normalizer

Normalizes data to standard format

Renderer

Renders documents to XML, PDF, or other formats

Sanitizer

Cleans and sanitizes input data

Loader

Loads existing documents from storage

Dispatcher

Dispatches documents for processing

Batch Processor

Processes multiple documents in batch

Document Bag Manager

Manages DocumentBag containers

Main Methods

bill

Creates a complete tax document ready for signing and submission.
data
string|array|stdClass
required
Document data in JSON string, array, or object format. Contains all document information like header, items, totals, etc.
caf
string|CafInterface|null
default:"null"
CAF (Folio Authorization Code). Can be:
  • XML string containing the CAF
  • CafInterface object
  • null if not required
certificate
string|array|CertificateInterface|null
default:"null"
Digital certificate for signing. Can be:
  • Path to certificate file
  • Array with certificate data
  • CertificateInterface object
  • null if signing will be done later
options
array|OptionsInterface
default:"[]"
Additional options for document processing
return
DocumentBagInterface
Returns a DocumentBag containing the processed document with all metadata
use libredte\lib\Core\Package\Billing\Component\Document\DocumentComponent;

// Create a simple invoice
$data = [
    'Encabezado' => [
        'IdDoc' => [
            'TipoDTE' => 33,
            'Folio' => 123,
        ],
        'Emisor' => [
            'RUTEmisor' => '76123456-7',
            'RznSoc' => 'Mi Empresa',
        ],
        'Receptor' => [
            'RUTRecep' => '77654321-8',
            'RznSocRecep' => 'Cliente',
        ],
    ],
    'Detalle' => [
        [
            'NmbItem' => 'Producto 1',
            'QtyItem' => 1,
            'PrcItem' => 1000,
        ],
    ],
];

$cafXml = file_get_contents('folio_33.xml');
$certificate = '/path/to/certificate.pfx';

$documentBag = $documentComponent->bill(
    data: $data,
    caf: $cafXml,
    certificate: $certificate
);

// Access the built document
$document = $documentBag->getDocument();

Worker Access Methods

getBuilderWorker
BuilderWorkerInterface
Returns the builder worker for constructing documents
getParserWorker
ParserWorkerInterface
Returns the parser worker for parsing input data
getValidatorWorker
ValidatorWorkerInterface
Returns the validator worker for document validation
getNormalizerWorker
NormalizerWorkerInterface
Returns the normalizer worker for data normalization
getRendererWorker
RendererWorkerInterface
Returns the renderer worker for document rendering
getSanitizerWorker
SanitizerWorkerInterface
Returns the sanitizer worker for data sanitization
getLoaderWorker
LoaderWorkerInterface
Returns the loader worker for loading documents
getDispatcherWorker
DispatcherWorkerInterface
Returns the dispatcher worker for document dispatch
getBatchProcessorWorker
BatchProcessorWorkerInterface
Returns the batch processor worker for processing multiple documents
getDocumentBagManagerWorker
DocumentBagManagerWorkerInterface
Returns the document bag manager worker
getWorkers
array
Returns an array of all workers with their keys

Document Processing Flow

When calling the bill() method, the component:
  1. Loads the CAF if provided as a string
  2. Creates a DocumentBag container with input data, options, CAF, and certificate
  3. Parses the input data through the ParserWorker
  4. Builds the final document through the BuilderWorker
  5. Returns the DocumentBag with the complete document

Source Reference

Namespace: libredte\lib\Core\Package\Billing\Component\Document\DocumentComponent Location: /workspace/source/src/Package/Billing/Component/Document/DocumentComponent.php:55

Build docs developers (and LLMs) love