PHP code example of dazza-dev / dian-xml-generator

1. Go to this page and download the library: Download dazza-dev/dian-xml-generator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dazza-dev / dian-xml-generator example snippets


$software = [
    'identifier' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
    'test_set_id' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
    'pin' => 'pin_software',
];

$documentData = [
    'operation_type' => '10',
    'prefix' => 'SETP',
    'number' => '990000001',
    'date' => '2024-01-17 10:30:00-05:00',
    'currency' => 'COP',
    'note' => 'notas de prueba',
    'payment_mean' => '1',
    'company' => ...
];

'company' => [
    'identification_type' => 31,
    'identification_number' => '123456789',
    'entity_type' => 1,
    'regime' => 49,
    'liability' => 'R-99-PN',
    'name' => 'EMPRESA EJEMPLO S.A.S.',
    'email' => '[email protected]',
    'phone' => '3001234567',
    'merchant_registration' => '12345678',
    'address' => 'Carrera 10 # 20-30',
    'city' => '11001',
    'state' => '11',
    'country' => 'CO'
];

'customer' => [
    'identification_type' => 13,
    'identification_number' => '987654321',
    'entity_type' => 2,
    'regime' => 49,
    'liability' => 'R-99-PN',
    'name' => 'Juan Pérez',
    'email' => '[email protected]',
    'phone' => '3109876543',
    'address' => 'Calle 45 # 67-89',
    'city' => '11001',
    'state' => '11',
    'country' => 'CO'
];

'numbering_range' => [
    'prefix' => 'SETP',
    'authorized_code' => '18760000001',
    'start_date' => '2019-01-19',
    'end_date' => '2030-01-19',
    'start_number' => '990000000',
    'end_number' => '995000000'
];

'totals' => [
    'line_extension_amount' => 8403.36,
    'tax_exclusive_amount' => 8403.36,
    'tax_inclusive_amount' => 10000,
    'prepaid_amount' => 10000,
    'payable_amount' => 10000
];

'payments' => [
    [
        'amount' => 10000,
        'received_date' => '2024-01-17T10:30:00Z',
        'paid_date' => '2024-01-17T10:30:00Z',
        'payment_method' => '10',
        'payment_reference' => '1234567890'
    ]
];

'taxes' => [
    [
        'code' => '01',
        'percent' => 19.0,
        'tax_amount' => 1596.64,
        'taxable_amount' => 8403.36
    ]
];

'order_reference' => [
    'number' => 'purchase_order_number',
    'issue_date' => '2024-01-17T10:30:00Z',
];

'line_items' => [
    [
        'name' => 'Producto 1',
        'code' => '1234567890',
        'quantity' => 1.0,
        'unit_code' => '94',
        'unit_price' => 8403.36,
        'total_amount' => 8403.36,
        'free_of_charge' => false,
        'item_type' => '010',
        'taxes' => [
            [
                'code' => '01',
                'percent' => 19.0,
                'tax_amount' => 1596.64,
                'taxable_amount' => 8403.36
            ]
        ],
        'allowance_charges' => ...
    ]
];

'allowance_charges' => [
    [
        'is_charge' => true, // true: cargo, false: descuento
        'reason_code' => '00', // Codigo del motivo del descuento o cargo (ver listado de codigos)
        'percentage' => 10.00, // Porcentaje de descuento o cargo
        'amount' => 840.34, // Monto del descuento o cargo
        'base_amount' => 8403.36, // Monto base del descuento o cargo
    ],
];

'operation_type' => '2' // Anulación de factura electrónica

use DazzaDev\DianXmlGenerator\Builder\DocumentBuilder;

$documentBuilder = new DocumentBuilder(
    type: 'invoice',
    documentData: $documentData,
    environment: '2', // 1: Producción, 2: Pruebas
    software: $software,
);

$xml = $documentBuilder->getXml();

$document = $documentBuilder->getDocument();