<?php
/*
define( 'SF_ROOT_DIR', realpath( dirname(__FILE__).'/../' ) );
define( 'SF_APP',      'mst' );
define( 'SF_DEBUG',    true );

require_once( SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php' );
*/

define( 'SF_ROOT_DIR', "../" );
define( 'SF_APP',      'mst' );
define( 'SF_DEBUG',    false );

require_once( SF_ROOT_DIR.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'configGlobal.php' );

try
{
    $o_VTA_DocumentoBN = VTA_DocumentoFN::selectByDocumentNumber( 182 );
    //pr( $o_VTA_DocumentoBN->getConcatGuiaRemision() );

    //VTA_OrdenDP::actualizarCabaceraMontos( 17 );

    $venta = iSunatCPE::ventas_model()->query_cabecera( '183' );
    //pr( $venta );

    $nombre = SF_ROOT_DIR."/services/ws_sunat/R-20604479011-03-B001-1.xml";
    $resultado = array();
    if( file_exists( $nombre ) )
    {
        $library = new SimpleXMLElement( $nombre, null, true );

        $ns = $library->getDocNamespaces();
        $ext1 = $library->children($ns['cac']);
        $ext2 = $ext1->DocumentResponse;
        $ext3 = $ext2->children($ns['cac']);
        $ext4 = $ext3->children($ns['cbc']);

        $resultado = array(
            'respuesta_sunat_codigo' => trim($ext4->ResponseCode),
            'respuesta_sunat_descripcion' => trim($ext4->Description)
        );

        $ns = $library->getDocNamespaces();
        $ext1 = $library->children($ns['ext']);
        $ext2 = $ext1->UBLExtensions;
        $ext3 = $ext2->UBLExtension;
        $ext4 = $ext3->ExtensionContent;
        $ext5 = $ext4->children();
        $ext6 = $ext5->Signature;
        $ext7 = $ext6->SignedInfo;
        $ext8 = $ext7->Reference;
        $ext9 = $ext8->DigestValue;

        pr( ( string ) $ext9 );
        pr( $ext9 );
        //pr( $ext9 );

    }

    pr( $resultado );
}
catch( Exception $exc )
{
    pr( $exc, false );
}
