protected function process() { $this->codejercicio = $this->empresa->codejercicio; $this->ejercicio = new ejercicio(); $grupo0 = new grupo_epigrafes(); $epi0 = new epigrafe(); $this->super_epigrafes = array(); /// ¿El usuario tiene permiso para eliminar en esta página? $this->allow_delete = $this->user->allow_delete_on(__CLASS__); if (isset($_POST['ngrupo'])) { $this->epigrafe = FALSE; $this->grupo = $grupo0->get_by_codigo($_GET['ngrupo'], $_POST['ejercicio']); if (!$this->grupo) { $this->grupo = new grupo_epigrafes(); $this->grupo->codejercicio = $_POST['ejercicio']; $this->grupo->codgrupo = $_POST['ngrupo']; $this->grupo->descripcion = $_POST['descripcion']; if ($this->grupo->save()) { header('Location: ' . $this->grupo->url()); } else { $this->new_error_msg('Error al guardar el grupo.'); $this->grupo = FALSE; } } } else { if (isset($_GET['grupo'])) { $this->epigrafe = FALSE; $this->grupo = $grupo0->get($_GET['grupo']); if ($this->grupo and isset($_POST['descripcion'])) { $this->grupo->descripcion = $_POST['descripcion']; if ($this->grupo->save()) { $this->new_message('Grupo modificado correctamente.'); } else { $this->new_error_msg('Error al modificar el grupo.'); } } } else { if (isset($_GET['deleteg'])) { $grupo1 = $grupo0->get($_GET['deleteg']); if ($grupo1) { if ($grupo1->delete()) { $this->new_message('Grupo eliminado correctamente.'); } else { $this->new_error_msg('Error al eliminar el grupo.'); } } else { $this->new_error_msg('Grupo no encontrado.'); } $this->grupo = FALSE; $this->epigrafe = FALSE; } else { if (isset($_POST['nepigrafe'])) { $this->epigrafe = $epi0->get_by_codigo($_POST['nepigrafe'], $_POST['ejercicio']); if (!$this->epigrafe) { $this->epigrafe = new epigrafe(); $this->epigrafe->codejercicio = $_POST['ejercicio']; $this->epigrafe->codepigrafe = $_POST['nepigrafe']; if (isset($_POST['idpadre'])) { $this->epigrafe->idpadre = $_POST['idpadre']; } else { $this->epigrafe->codgrupo = $_POST['codgrupo']; $this->epigrafe->idgrupo = $_POST['idgrupo']; $this->grupo = $grupo0->get($_POST['idgrupo']); } $this->epigrafe->descripcion = $_POST['descripcion']; if ($this->epigrafe->save()) { header('Location: ' . $this->epigrafe->url()); } else { $this->new_error_msg('Error al guardar el epígrafe.'); } } } else { if (isset($_GET['epi'])) { $this->grupo = FALSE; $this->epigrafe = $epi0->get($_GET['epi']); if ($this->ejercicio and isset($_POST['descripcion'])) { $this->epigrafe->descripcion = $_POST['descripcion']; if ($this->epigrafe->save()) { $this->new_message('Epígrafe modificado correctamente.'); } else { $this->new_error_msg('Error al modificar el epígrafe.'); } } } else { if (isset($_GET['deletee'])) { $epi1 = $epi0->get($_GET['deletee']); if ($epi1) { $this->grupo = $grupo0->get($epi1->idgrupo); if ($epi1->delete()) { $this->new_message('Epígrafe eliminado correctamente.'); } else { $this->new_error_msg('Error al eliminar el epígrafe.'); } } else { $this->new_error_msg('Epígrafe no encontrado.'); $this->grupo = FALSE; } } else { if (isset($_POST['ncuenta'])) { $this->grupo = FALSE; $this->epigrafe = FALSE; $cuenta0 = new cuenta(); $cuenta1 = $cuenta0->get_by_codigo($_POST['ncuenta'], $_POST['ejercicio']); if ($cuenta1) { header('Location: ' . $cuenta1->url()); } else { $cuenta1 = new cuenta(); $cuenta1->codcuenta = $_POST['ncuenta']; $cuenta1->codejercicio = $_POST['ejercicio']; $cuenta1->codepigrafe = $_POST['codepigrafe']; $cuenta1->descripcion = $_POST['descripcion']; $cuenta1->idepigrafe = $_POST['idepigrafe']; if ($cuenta1->save()) { header('Location: ' . $cuenta1->url()); } else { $this->new_error_msg('Error al guardar la cuenta.'); } $this->epigrafe = $epi0->get($_POST['idepigrafe']); } } else { if (isset($_GET['deletec'])) { $this->grupo = FALSE; $this->epigrafe = FALSE; $cuenta0 = new cuenta(); $cuenta1 = $cuenta0->get($_GET['deletec']); if ($cuenta1) { $this->epigrafe = $epi0->get($cuenta1->idepigrafe); if ($cuenta1->delete()) { $this->new_message('Cuenta eliminada correctamente.'); } else { $this->new_error_msg('Error al eliminar la cuenta.'); } } else { $this->new_error_msg('Cuenta no encontrada.'); } } } } } } } } } if ($this->grupo) { $this->ppage = $this->page->get($this->page->name); $this->page->title = 'Grupo: ' . $this->grupo->codgrupo; $this->resultados = $this->grupo->get_epigrafes(); } else { if ($this->epigrafe) { /// configuramos la página previa $this->ppage = $this->page->get($this->page->name); if (!is_null($this->epigrafe->idgrupo)) { $this->ppage->title = 'Grupo: ' . $this->epigrafe->codgrupo; $this->ppage->extra_url = '&grupo=' . $this->epigrafe->idgrupo; } else { if (!is_null($this->epigrafe->idpadre)) { $this->ppage->title = 'Padre'; $this->ppage->extra_url = '&epi=' . $this->epigrafe->idpadre; } } $this->page->title = 'Epigrafe: ' . $this->epigrafe->codepigrafe; $this->resultados = $this->epigrafe->get_cuentas(); } else { if (isset($_POST['ejercicio'])) { $this->codejercicio = $_POST['ejercicio']; $this->grupo = FALSE; $this->epigrafe = FALSE; $this->resultados = $grupo0->all_from_ejercicio($this->codejercicio); $this->super_epigrafes = $epi0->super_from_ejercicio($this->codejercicio); } else { $this->grupo = FALSE; $this->epigrafe = FALSE; $this->resultados = $grupo0->all_from_ejercicio($this->empresa->codejercicio); $this->super_epigrafes = $epi0->super_from_ejercicio($this->empresa->codejercicio); } } } }
/** * Función auxiliar para generar el balance de sumas y saldos de un ejercicio y unas fechas concretas. * Este informe muestra los saldos (distintos de cero) de cada cuenta y subcuenta * por periodos, pero siempre excluyendo los asientos de cierre y pérdidas y ganancias. */ public function sumas_y_saldos(&$pdf_doc, &$eje, $titulo, $fechaini, $fechafin, $excluir = FALSE, $np = TRUE) { $ge0 = new grupo_epigrafes(); $epi0 = new epigrafe(); $cuenta0 = new cuenta(); $subcuenta0 = new subcuenta(); $lineas = array(); $sql = "SELECT p.codsubcuenta, SUM(p.debe) as debe, SUM(p.haber) as haber" . " FROM co_partidas p, co_asientos a WHERE p.idasiento = a.idasiento" . " AND a.codejercicio = " . $this->empresa->var2str($eje->codejercicio) . " AND a.fecha >= " . $this->empresa->var2str($fechaini) . " AND fecha <= " . $this->empresa->var2str($fechafin); if ($excluir) { foreach ($excluir as $exc) { $sql .= " AND p.idasiento != " . $this->empresa->var2str($exc); } } $sql .= " GROUP BY p.codsubcuenta ORDER BY codsubcuenta ASC;"; $data = $this->db->select($sql); if ($data) { $grupos = $ge0->all_from_ejercicio($eje->codejercicio); $epigrafes = $epi0->all_from_ejercicio($eje->codejercicio); for ($i = 1; $i < 10; $i++) { $debe = 0; $haber = 0; foreach ($data as $d) { if (substr($d['codsubcuenta'], 0, 1) == (string) $i) { $debe += floatval($d['debe']); $haber += floatval($d['haber']); } } /// añadimos el grupo foreach ($grupos as $ge) { if ($ge->codgrupo == $i) { $lineas[] = array('cuenta' => $i, 'descripcion' => $ge->descripcion, 'debe' => $debe, 'haber' => $haber); break; } } for ($j = 0; $j < 10; $j++) { $debe = 0; $haber = 0; foreach ($data as $d) { if (substr($d['codsubcuenta'], 0, 2) == (string) $i . $j) { $debe += floatval($d['debe']); $haber += floatval($d['haber']); } } /// añadimos el epígrafe foreach ($epigrafes as $ep) { if ($ep->codepigrafe == (string) $i . $j) { $lineas[] = array('cuenta' => $i . $j, 'descripcion' => $ep->descripcion, 'debe' => $debe, 'haber' => $haber); break; } } for ($k = 0; $k < 10; $k++) { $debe = 0; $haber = 0; foreach ($data as $d) { if (substr($d['codsubcuenta'], 0, 3) == (string) $i . $j . $k) { $debe += floatval($d['debe']); $haber += floatval($d['haber']); } } /// añadimos la cuenta if ($debe != 0 or $haber != 0) { $cuenta = $cuenta0->get_by_codigo($i . $j . $k, $eje->codejercicio); if ($cuenta) { $lineas[] = array('cuenta' => $i . $j . $k, 'descripcion' => $cuenta->descripcion, 'debe' => $debe, 'haber' => $haber); } else { $lineas[] = array('cuenta' => $i . $j . $k, 'descripcion' => '-', 'debe' => $debe, 'haber' => $haber); } } /// añadimos las subcuentas foreach ($data as $d) { if (substr($d['codsubcuenta'], 0, 3) == (string) $i . $j . $k) { $desc = ''; $subc = $subcuenta0->get_by_codigo($d['codsubcuenta'], $eje->codejercicio); if ($subc) { $desc = $subc->descripcion; } $lineas[] = array('cuenta' => $d['codsubcuenta'], 'descripcion' => $desc, 'debe' => floatval($d['debe']), 'haber' => floatval($d['haber'])); } } } } } } /// a partir de la lista generamos el documento $linea = 0; $tdebe = 0; $thaber = 0; while ($linea < count($lineas)) { if ($linea > 0) { $pdf_doc->pdf->ezNewPage(); } $pdf_doc->pdf->ezText($this->empresa->nombre . " - Balance de sumas y saldos " . $eje->year() . ' ' . $titulo . ".\n\n", 12); /// Creamos la tabla con las lineas $pdf_doc->new_table(); $pdf_doc->add_table_header(array('cuenta' => '<b>Cuenta</b>', 'descripcion' => '<b>Descripción</b>', 'debe' => '<b>Debe</b>', 'haber' => '<b>Haber</b>', 'saldo' => '<b>Saldo</b>')); for ($i = $linea; $i < min(array($linea + 48, count($lineas))); $i++) { if (strlen($lineas[$i]['cuenta']) == 1) { $a = '<b>'; $b = '</b>'; $tdebe += $lineas[$i]['debe']; $thaber += $lineas[$i]['haber']; } else { if (strlen($lineas[$i]['cuenta']) == 2) { $a = $b = ''; } else { $a = '<i>'; $b = '</i>'; } } $pdf_doc->add_table_row(array('cuenta' => $a . $lineas[$i]['cuenta'] . $b, 'descripcion' => $a . substr($lineas[$i]['descripcion'], 0, 50) . $b, 'debe' => $a . $this->show_numero($lineas[$i]['debe']) . $b, 'haber' => $a . $this->show_numero($lineas[$i]['haber']) . $b, 'saldo' => $a . $this->show_numero(floatval($lineas[$i]['debe']) - floatval($lineas[$i]['haber'])) . $b)); } $linea += 48; /// añadimos las sumas de la línea actual $desc = 'Suma y sigue'; if ($linea >= count($lineas)) { $desc = 'Totales'; } $pdf_doc->add_table_row(array('cuenta' => '', 'descripcion' => '<b>' . $desc . '</b>', 'debe' => '<b>' . $this->show_numero($tdebe) . '</b>', 'haber' => '<b>' . $this->show_numero($thaber) . '</b>', 'saldo' => '<b>' . $this->show_numero($tdebe - $thaber) . '</b>')); $pdf_doc->save_table(array('fontSize' => 9, 'cols' => array('debe' => array('justification' => 'right'), 'haber' => array('justification' => 'right'), 'saldo' => array('justification' => 'right')), 'width' => 540, 'shaded' => 0)); } }
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(); }
public function __construct($e = FALSE) { parent::__construct('co_epigrafes'); if ($e) { $this->idepigrafe = $this->intval($e['idepigrafe']); $this->idpadre = $this->intval($e['idpadre']); $this->codepigrafe = $e['codepigrafe']; $this->idgrupo = $this->intval($e['idgrupo']); $this->descripcion = $e['descripcion']; $this->codejercicio = $e['codejercicio']; if (!isset(self::$grupos)) { $ge = new grupo_epigrafes(); self::$grupos = $ge->all_from_ejercicio($this->codejercicio); } foreach (self::$grupos as $g) { if ($g->idgrupo == $this->idgrupo) { $this->codgrupo = $g->codgrupo; break; } } } else { $this->idepigrafe = NULL; $this->idpadre = NULL; $this->codepigrafe = NULL; $this->idgrupo = NULL; $this->codgrupo = NULL; $this->descripcion = NULL; $this->codejercicio = NULL; } }