PageRenderTime 44ms CodeModel.GetById 7ms RepoModel.GetById 0ms app.codeStats 0ms

/stable/web/modulos/contabilidad/cuentas.php

http://facturascripts.googlecode.com/
PHP | 253 lines | 194 code | 36 blank | 23 comment | 18 complexity | 68be39e3ae2cc29c5745cc854a1a5b1c MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /*
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  14. Autor: Carlos Garcia Gomez
  15. */
  16. require("clases/script.php");
  17. require_once("clases/cuentas.php");
  18. require_once("clases/ejercicios.php");
  19. require_once("clases/opciones.php");
  20. class script_ extends script
  21. {
  22. private $cuentas;
  23. private $ejercicios;
  24. private $opciones;
  25. public function __construct($ppal)
  26. {
  27. parent::__construct($ppal);
  28. $this->cuentas = new cuentas();
  29. $this->ejercicios = new ejercicios();
  30. $this->opciones = new opciones();
  31. }
  32. /// devuelve el titulo del script
  33. public function titulo()
  34. {
  35. return("Cuentas");
  36. }
  37. /// codigo javascript
  38. public function javas()
  39. {
  40. ?>
  41. <script type="text/javascript">
  42. function fs_onload()
  43. {
  44. document.cuentas.b.focus();
  45. }
  46. function fs_unload() {
  47. }
  48. </script>
  49. <?php
  50. }
  51. /// capturar las variables necesarias para el script enviadas por GET y POST
  52. public function datos()
  53. {
  54. $datos['buscar'] = $_GET['b'];
  55. $datos['tipo'] = $_GET['t'];
  56. $datos['campo'] = $_GET['c'];
  57. /// cargamos el ejercicio predefinido
  58. $this->opciones->get('ejercicio', $datos['ejercicio']);
  59. /// si no se selecciona ningun ejercicio, cogemos el predefinido
  60. if($_GET['e'] != '')
  61. {
  62. $datos['codejercicio'] = $_GET['e'];
  63. }
  64. else
  65. {
  66. $datos['codejercicio'] = $datos['ejercicio'];
  67. }
  68. return($datos);
  69. }
  70. /// cargar el cuerpo del script
  71. public function cuerpo($mod, $pag, &$datos)
  72. {
  73. $ejercicios = false;
  74. $items = false;
  75. echo "<div class='destacado'>\n",
  76. "<form name='cuentas' action='ppal.php' method='get'>\n",
  77. "<input type='hidden' name='mod' value='" , $mod , "'/>\n",
  78. "<input type='hidden' name='pag' value='" , $pag , "'/>\n",
  79. "<span>";
  80. if($datos['tipo'] == 's')
  81. {
  82. echo "<input type='radio' name='t' value='c'/>Cuentas\n",
  83. "<input type='radio' name='t' value='s' checked/>Subcuentas\n";
  84. }
  85. else
  86. {
  87. echo "<input type='radio' name='t' value='c' checked/>Cuentas\n",
  88. "<input type='radio' name='t' value='s'/>Subcuentas\n";
  89. }
  90. echo "<img src='images/system-search.png' alt='buscar'/>\n",
  91. "<input type='text' name='b' size='18' maxlength='18' value='" , $datos['buscar'] , "'/>";
  92. switch($datos['campo'])
  93. {
  94. default:
  95. echo "<input type='radio' name='c' value='cod' checked/>C&oacute;digo\n",
  96. "<input type='radio' name='c' value='des'/>Descripci&oacute;n | \n";
  97. break;
  98. case 'des':
  99. echo "<input type='radio' name='c' value='cod'/>C&oacute;digo\n",
  100. "<input type='radio' name='c' value='des' checked/>Descripci&oacute;n | \n";
  101. break;
  102. }
  103. if( $this->ejercicios->all($ejercicios) )
  104. {
  105. echo "Ejercicio <select name='e' size='0'>";
  106. foreach($ejercicios as $col)
  107. {
  108. if($col['codejercicio'] == $datos['codejercicio'])
  109. {
  110. echo "<option value='" , $col['codejercicio'] , "' selected='selected'>" , $col['nombre'] , "</option>\n";
  111. }
  112. else
  113. {
  114. echo "<option value='" , $col['codejercicio'] , "'>" , $col['nombre'] , "</option>\n";
  115. }
  116. }
  117. echo "</select>";
  118. }
  119. echo "<input type='submit' value='buscar'/></span>\n</form>\n</div>\n";
  120. if($datos['buscar'] != "")
  121. {
  122. $items = $this->cuentas->buscar($datos['buscar'], $datos['tipo'], $datos['campo'], $datos['codejercicio']);
  123. if($items)
  124. {
  125. echo "<div class='mensaje'>Se encontraron los siguientes resultados para el ejercicio <b>",
  126. $this->ejercicios->get_nombre($datos['codejercicio']) , "</b></div>\n";
  127. if($datos['tipo'] == 'c')
  128. {
  129. $this->listar_cuentas($mod, $pag, $items);
  130. }
  131. else if($datos['tipo'] == 's')
  132. {
  133. $this->subcuentas($mod, $pag, $items);
  134. }
  135. }
  136. else
  137. {
  138. echo "<div class='mensaje'>No se encontraron resultados para el ejercicio <b>",
  139. $this->ejercicios->get_nombre($datos['codejercicio']) , "</b></div>\n";
  140. }
  141. }
  142. else
  143. {
  144. if( $this->cuentas->lista_cuentas($datos['codejercicio'], $items) )
  145. {
  146. echo "<div class='lista'>Lista de cuentas (" , $this->ejercicios->get_nombre($datos['codejercicio']) , ")</div>\n";
  147. $this->listar_cuentas($mod, $pag, $items);
  148. }
  149. else
  150. {
  151. echo "<div class='mensaje'>Nada que mostrar</div>\n";
  152. }
  153. }
  154. }
  155. private function listar_cuentas($mod, $pag, $cuentas)
  156. {
  157. if($cuentas)
  158. {
  159. echo "<table class='lista'>\n",
  160. "<tr class='destacado'>\n",
  161. "<td>Cuenta</td>\n",
  162. "<td>Grupo</td>\n",
  163. "<td>Descripci&oacute;n</td>\n",
  164. "<td align='right'>Subcuentas</td>\n",
  165. "</tr>\n";
  166. foreach($cuentas as $col)
  167. {
  168. if($col['subcuentas'] > 1)
  169. {
  170. echo "<tr class='amarillo'>\n";
  171. }
  172. else
  173. {
  174. echo "<tr>\n";
  175. }
  176. echo "<td><a href='ppal.php?mod=" , $mod , "&amp;pag=cuenta&amp;tipo=c&amp;id=" , $col['idcuenta'] , "'>" , $col['codcuenta'] , "</a></td>\n",
  177. "<td>" , $col['codepigrafe'] , "</td>\n",
  178. "<td>" , $col['descripcion'] , "</td>\n",
  179. "<td align='right'>" , number_format($col['subcuentas'], 0) , "</td>\n",
  180. "</tr>\n";
  181. }
  182. echo "</table>\n";
  183. }
  184. else
  185. {
  186. echo "<div class='mensaje'>Nada que mostrar</div>\n";
  187. }
  188. }
  189. private function subcuentas($mod, $pag, $subcuentas)
  190. {
  191. echo "<table class='lista'>\n",
  192. "<tr class='destacado'>\n",
  193. "<td>Cuenta</td>\n",
  194. "<td>Subcuenta</td>\n",
  195. "<td>Descripci&oacute;n</td>\n",
  196. "<td align='right'>Debe</td>\n",
  197. "<td align='right'>Haber</td>\n",
  198. "<td align='right'>Saldo</td>\n",
  199. "</tr>\n";
  200. foreach($subcuentas as $col)
  201. {
  202. echo "<tr>\n",
  203. "<td><a href='ppal.php?mod=" , $mod , "&amp;pag=cuenta&amp;tipo=c&amp;id=" , $col['idcuenta'] , "'>" , $col['codcuenta'] , "</a></td>\n",
  204. "<td><a href='ppal.php?mod=" , $mod , "&amp;pag=cuenta&amp;tipo=s&amp;id=" , $col['idsubcuenta'] , "'>" , $col['codsubcuenta'] , "</a></td>\n",
  205. "<td>" , substr($col['descripcion'], 0, 60) , "</td>\n",
  206. "<td align='right'>" , number_format($col['debe'], 1) , " &euro;</td>\n",
  207. "<td align='right'>" , number_format($col['haber'], 1) , " &euro;</td>\n",
  208. "<td align='right'>" , number_format($col['saldo'], 1) , " &euro;</td>\n",
  209. "</tr>\n";
  210. }
  211. echo "</table>\n";
  212. }
  213. }
  214. ?>