private function exportar_xml()
 {
     /// desactivamos el motor de plantillas
     $this->template = FALSE;
     /// creamos el xml
     $cadena_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!--\n    Document   : ejercicio_" . $this->ejercicio->codejercicio . ".xml\n    Description:\n        Estructura de grupos de epígrafes, epígrafes, cuentas y subcuentas del ejercicio " . $this->ejercicio->codejercicio . ".\n-->\n\n<ejercicio>\n</ejercicio>\n";
     $archivo_xml = simplexml_load_string($cadena_xml);
     /// añadimos los balances
     $balance = new balance();
     foreach ($balance->all() as $ba) {
         $aux = $archivo_xml->addChild("balance");
         $aux->addChild("codbalance", $ba->codbalance);
         $aux->addChild("naturaleza", $ba->naturaleza);
         $aux->addChild("nivel1", $ba->nivel1);
         $aux->addChild("descripcion1", base64_encode($ba->descripcion1));
         $aux->addChild("nivel2", $ba->nivel2);
         $aux->addChild("descripcion2", base64_encode($ba->descripcion2));
         $aux->addChild("nivel3", $ba->nivel3);
         $aux->addChild("descripcion3", base64_encode($ba->descripcion3));
         $aux->addChild("orden3", $ba->orden3);
         $aux->addChild("nivel4", $ba->nivel4);
         $aux->addChild("descripcion4", base64_encode($ba->descripcion4));
         $aux->addChild("descripcion4ba", base64_encode($ba->descripcion4ba));
     }
     /// añadimos las cuentas de balances
     $balance_cuenta = new balance_cuenta();
     foreach ($balance_cuenta->all() as $ba) {
         $aux = $archivo_xml->addChild("balance_cuenta");
         $aux->addChild("codbalance", $ba->codbalance);
         $aux->addChild("codcuenta", $ba->codcuenta);
         $aux->addChild("descripcion", base64_encode($ba->desccuenta));
     }
     /// añadimos las cuentas de balance abreviadas
     $balance_cuenta_a = new balance_cuenta_a();
     foreach ($balance_cuenta_a->all() as $ba) {
         $aux = $archivo_xml->addChild("balance_cuenta_a");
         $aux->addChild("codbalance", $ba->codbalance);
         $aux->addChild("codcuenta", $ba->codcuenta);
         $aux->addChild("descripcion", base64_encode($ba->desccuenta));
     }
     /// añadimos las cuentas especiales
     $cuenta_esp = new cuenta_especial();
     foreach ($cuenta_esp->all() as $ce) {
         $aux = $archivo_xml->addChild("cuenta_especial");
         $aux->addChild("idcuentaesp", $ce->idcuentaesp);
         $aux->addChild("descripcion", base64_encode($ce->descripcion));
     }
     /// añadimos los grupos de epigrafes
     $grupo_epigrafes = new grupo_epigrafes();
     $grupos_ep = $grupo_epigrafes->all_from_ejercicio($this->ejercicio->codejercicio);
     foreach ($grupos_ep as $ge) {
         $aux = $archivo_xml->addChild("grupo_epigrafes");
         $aux->addChild("codgrupo", $ge->codgrupo);
         $aux->addChild("descripcion", base64_encode($ge->descripcion));
     }
     /// añadimos los epigrafes
     $epigrafe = new epigrafe();
     foreach ($epigrafe->all_from_ejercicio($this->ejercicio->codejercicio) as $ep) {
         $aux = $archivo_xml->addChild("epigrafe");
         $aux->addChild("codgrupo", $ep->codgrupo);
         $aux->addChild("codpadre", $ep->codpadre());
         $aux->addChild("codepigrafe", $ep->codepigrafe);
         $aux->addChild("descripcion", base64_encode($ep->descripcion));
     }
     /// añadimos las cuentas
     $cuenta = new cuenta();
     $num = 0;
     $cuentas = $cuenta->full_from_ejercicio($this->ejercicio->codejercicio);
     foreach ($cuentas as $c) {
         $aux = $archivo_xml->addChild("cuenta");
         $aux->addChild("codepigrafe", $c->codepigrafe);
         $aux->addChild("codcuenta", $c->codcuenta);
         $aux->addChild("descripcion", base64_encode($c->descripcion));
         $aux->addChild("idcuentaesp", $c->idcuentaesp);
     }
     /// añadimos las subcuentas
     $subcuenta = new subcuenta();
     foreach ($subcuenta->all_from_ejercicio($this->ejercicio->codejercicio) as $sc) {
         $aux = $archivo_xml->addChild("subcuenta");
         $aux->addChild("codcuenta", $sc->codcuenta);
         $aux->addChild("codsubcuenta", $sc->codsubcuenta);
         $aux->addChild("descripcion", base64_encode($sc->descripcion));
         $aux->addChild("coddivisa", $sc->coddivisa);
     }
     /// volcamos el XML
     header("content-type: application/xml; charset=UTF-8");
     header('Content-Disposition: attachment; filename="ejercicio_' . $this->ejercicio->codejercicio . '.xml"');
     echo $archivo_xml->asXML();
 }
 protected function private_core()
 {
     $this->balance = new balance();
     $this->balance_cuenta_a = new balance_cuenta_a();
     $this->ejercicio = new ejercicio();
     if (isset($_REQUEST['buscar_subcuenta'])) {
         /// esto es para el autocompletar las subcuentas de la vista
         $this->buscar_subcuenta();
     } else {
         if (isset($_GET['diario'])) {
             $this->libro_diario_csv($_GET['diario']);
         } else {
             if (isset($_GET['balance']) and isset($_GET['eje'])) {
                 $this->template = FALSE;
                 $iba = new inventarios_balances($this->db);
                 if ($_GET['balance'] == 'pyg') {
                     $iba->generar_pyg($_GET['eje']);
                 } else {
                     $iba->generar_sit($_GET['eje']);
                 }
             } else {
                 if (isset($_POST['informe'])) {
                     if ($_POST['informe'] == 'sumasysaldos') {
                         $this->balance_sumas_y_saldos();
                     } else {
                         if ($_POST['informe'] == 'situacion') {
                             $this->balance_situacion();
                         } else {
                             if ($_POST['informe'] == 'perdidasyg') {
                                 $this->balance_perdidasyg();
                             } else {
                                 if ($_POST['informe'] == 'librom') {
                                     if ($_POST['filtro'] == '') {
                                         $this->libro_diario_csv($_POST['codejercicio'], $_POST['desde'], $_POST['hasta']);
                                     } else {
                                         if (isset($_POST['codgrupo'])) {
                                             $this->libro_mayor_csv($_POST['codejercicio'], $_POST['desde'], $_POST['hasta'], $_POST['codgrupo']);
                                         } else {
                                             if (isset($_POST['codepigrafe'])) {
                                                 $this->libro_mayor_csv($_POST['codejercicio'], $_POST['desde'], $_POST['hasta'], FALSE, $_POST['codepigrafe']);
                                             } else {
                                                 if (isset($_POST['codcuenta'])) {
                                                     $this->libro_mayor_csv($_POST['codejercicio'], $_POST['desde'], $_POST['hasta'], FALSE, FALSE, $_POST['codcuenta']);
                                                 } else {
                                                     if (isset($_POST['codsubcuenta'])) {
                                                         $this->libro_mayor_csv($_POST['codejercicio'], $_POST['desde'], $_POST['hasta'], FALSE, FALSE, FALSE, $_POST['codsubcuenta']);
                                                     } else {
                                                         $this->template = 'ajax/informe_libro_mayor';
                                                         $this->grupos = FALSE;
                                                         $this->epigrafes = FALSE;
                                                         $this->cuentas = FALSE;
                                                         if ($_POST['filtro'] == 'grupo') {
                                                             $ge = new grupo_epigrafes();
                                                             $this->grupos = $ge->all_from_ejercicio($_POST['codejercicio']);
                                                         } else {
                                                             if ($_POST['filtro'] == 'epigrafe') {
                                                                 $ep = new epigrafe();
                                                                 $this->epigrafes = $ep->all_from_ejercicio($_POST['codejercicio']);
                                                             } else {
                                                                 if ($_POST['filtro'] == 'cuenta') {
                                                                     $cuenta = new cuenta();
                                                                     $this->cuentas = $cuenta->full_from_ejercicio($_POST['codejercicio']);
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }