LibreDTE / libredte-lib-core

LibreDTE: Biblioteca PHP (Núcleo)
https://lib-core.docs.libredte.cl
GNU Affero General Public License v3.0
194 stars 157 forks source link

Barrier #53

Closed petyots closed 6 years ago

petyots commented 6 years ago

Hello, i am trying to integrate this lib which looks nice in existing project. There is a big language barrier and i can't understand many of the things. My clients wants to issue electronic invoices on sale, so far so good, at least i know that the type of document is 39. So far so good, i believe i have to use example boletas.php. I have working certificate. Btw the framework which we are using is Laravel if thats matter. My question is what are the steps to Generate, Sign, and send the documents to Sii. Example 009 gives me always errors about validation and out of range stuff...(google translate). Any help will be really appreciated i am really stuck. Also i can't understand what is "caratula" and what is used for...

$caratula = [
    //'RutEnvia' => '11222333-4', // se obtiene de la firma
    'RutReceptor' => '60803000-K', 
    'FchResol' => '2014-12-05',
    'NroResol' => 0,
];
// What does the keys mean ? Which are required which not ?
'RUTEmisor' => '76192083-9',
            'RznSoc' => 'SASCO SpA', 
            'GiroEmis' => 'Servicios integrales de informática',
            'Acteco' => 726000,
            'DirOrigen' => 'Santiago',
            'CmnaOrigen' => 'Santiago',

Also This is the header

'IdDoc' => [
            'TipoDTE' => 33,
            'Folio' => 1, // What does this mean ?
        ],
$Folios = new \sasco\LibreDTE\Sii\Folios(file_get_contents('xml/folios/33.xml')); 
// I understood that i have to download this file from Sii when i log in with the certificate go to Factura Electronica -> xxx Enter some numbers and it's available for download but i am not sure if it's correct...

No fue posible generar XML del EnvioDte No hay ningún DTE agregado al envío No hay ningún DTE agregado al envío Folio del DTE LibreDTE_T33F1 está fuera de rango This is the response from the code bellow

public function makeReceipt()
    {
        // datos

        $caratula = [
            //'RutEnvia' => '11222333-4', // se obtiene de la firma
            'RutReceptor' => '6666666-6',
            'FchResol' => '2018-12-05',
            'NroResol' => 0,
        ];

        $Emisor = [
            'RUTEmisor' => '76192083-9',
            'RznSoc' => 'SASCO SpA',
            'GiroEmis' => 'Servicios integrales de informática',
            //'Acteco' => 726000,
            'DirOrigen' => 'Santiago',
            'CmnaOrigen' => 'Santiago',
        ];

        // datos del receptor
        $Receptor = [
            'RUTRecep' => '55666777-8',
            'RznSocRecep' => 'Empresa S.A.',
            'GiroRecep' => 'Servicios jurídicos',
            'DirRecep' => 'Santiago',
            'CmnaRecep' => 'Santiago',
        ];

        $documentos = [
            // 1 - Factura: 1 producto, sin descuentos
            [
                'Encabezado' => [
                    'IdDoc' => [
                        'TipoDTE' => 33,
                        'Folio' => 1,
                    ],
                    'Emisor' => $Emisor,
                    'Receptor' => $Receptor,
                ],
                'Detalle' => [
                    [
                        'NmbItem' => 'Karting 16 Laps',
                        'QtyItem' => 1,
                        'PrcItem' => 70000,
                    ],
                ],
            ]
        ];
        // Objetos de Firma y Folios
        $Firma = new \sasco\LibreDTE\FirmaElectronica($this->companySettings);
        //$Folios = new \sasco\LibreDTE\Sii\Folios(file_get_contents(storage_path('folios/33.xml')));

        $Folios[33] = new \sasco\LibreDTE\Sii\Folios(file_get_contents(storage_path('folios/33.xml')));
        $EnvioDTE = new \sasco\LibreDTE\Sii\EnvioDte();

        // generar cada DTE, timbrar, firmar y agregar al sobre de EnvioDTE
        foreach ($documentos as $documento) {
            $DTE = new \sasco\LibreDTE\Sii\Dte($documento);
            if (!$DTE->timbrar($Folios[$DTE->getTipo()]))
                break;
            if (!$DTE->firmar($Firma))
                break;
            $EnvioDTE->agregar($DTE);
        }

        // enviar dtes y mostrar resultado del envío: track id o bien =false si hubo error
        $EnvioDTE->setCaratula($caratula);
        $EnvioDTE->setFirma($Firma);
        $track_id = $EnvioDTE->enviar();
        var_dump($track_id);

        // si hubo errores mostrar
        foreach (\sasco\LibreDTE\Log::readAll() as $error)
            echo $error,"\n";
    }

Also Is it possible to send the receptor to be without RUT ?. Thanks in advance i really need some help...

Losstarot commented 6 years ago

Ptyots pidio que realizara esta pregunta en español "en $caratula sobre los campos RutReceptor, FchResol Y NroResol cual sería un ejemplo de datos para estos y de donde debiera obtenerlos, la duda con RutReceptor nace por que es distinto al campo RutRecep el cual debiera ser rut del cliente si no me equivoco?., basicamente que es Caratula"

estebandelaf commented 6 years ago

Todos los campos están documentados en el esquema del XML:

https://archivos.libredte.cl/sii/diagramas/diagrama_dte/EnvioDTE_v10.html

Se recomienda hacer este tipo de consultas (ayuda, y no reporte de un bug) en el foro de la comunidad: https://groups.google.com/forum/#!forum/libredte