Advertisement
Guest User

Untitled

a guest
May 3rd, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.64 KB | None | 0 0
  1. <?php
  2.  
  3. class Dental {
  4.  
  5. public function __isset($name) {
  6. return isset($this->{$name});
  7. }
  8.  
  9. public function __set($name, $value) {
  10. $this->{$name} = $value;
  11. }
  12.  
  13. public function __get($name) {
  14. if ($name == 'db') {
  15. return MySQL::getInstance();
  16. }
  17. elseif (isset($this->{$name})) {
  18. return $this->{$name};
  19. }
  20.  
  21. return null;
  22. }
  23.  
  24. private function __construct($user, $pass){
  25.  
  26. if (!$user || !$pass) {
  27. return false;
  28. }
  29.  
  30. $user = $this->db->escape($user);
  31. $p = $this->db->oneFieldQuery("SELECT clave_seguridad FROM usuarios WHERE correo_electronico = '{$user}'");
  32.  
  33. if ($p == md5($pass)) {
  34. $q = "SELECT id_usuario,correo_electronico,nombre,apellido FROM usuarios WHERE correo_electronico = '{$user}'";
  35. $r = $this->db->oneRowQuery($q);
  36. $this->id = $r['id_usuario'];
  37. $this->fullname = $r['apellido'] . ',' . $r['nombre'];
  38. $this->apellido = $r['apellido'];
  39. $this->nombre = $r['nombre'];
  40.  
  41. return true;
  42. }
  43. else{
  44. return false;
  45. }
  46. }
  47.  
  48. public static function getInstance($user = null, $pass = null) {
  49. if ( !isset($instance)) {
  50. $instance = new self($user, $pass);
  51. }
  52.  
  53. return $instance;
  54. }
  55.  
  56. public function paciente($id){
  57. if (!$id) {
  58. return false;
  59. }
  60.  
  61. // ME FIJO SI EL PACIENTE YA ESTA SETEADO Y LO RETORNO
  62. if (is_array($this->pacientes) && in_array($id, $this->pacientes)) {
  63. return $this->pacientes[$id];
  64. }
  65. else{
  66. // CREO LA LISTA DE PACIENTES SI NO ESTA CREADA
  67. if (!is_array($this->pacientes)){
  68. $this->pacientes = array();
  69. }
  70.  
  71. if (is_array($id)) {
  72. $paciente = new Paciente($this->id, $id);
  73. }
  74. else{
  75. $paciente = new Paciente($id);
  76. }
  77.  
  78.  
  79. if ($paciente) {
  80. $this->pacientes[$id] = $paciente;
  81.  
  82. return $paciente;
  83. }
  84. }
  85.  
  86. return false;
  87. }
  88.  
  89. public function pacientes(){
  90.  
  91. $q = "SELECT id_paciente AS id FROM pacientes WHERE id_usuario = {$this->id} AND eliminado <> 1";
  92.  
  93. $this->db->query($q);
  94.  
  95. if ($this->db->numRows()) {
  96. while ($_ = $this->db->fetchAssoc()) {
  97. $this->paciente($_['id']);
  98. }
  99. }
  100.  
  101. $this->db->free();
  102.  
  103. return $this->pacientes;
  104. }
  105.  
  106. /**
  107. * Trae los usuarios disponebles para compartir dado tal paciente
  108. * @param Paciente
  109. * @return array usuarios
  110. **/
  111. public function usuarios_disponibles($paciente){
  112.  
  113. if (!$paciente || !($paciente instanceof Paciente) || !is_numeric($paciente->id)) {
  114. return false;
  115. }
  116.  
  117. $q = "SELECT id_usuario AS id, apellido, nombre, correo_electronico FROM usuarios WHERE id_usuario NOT IN (SELECT id_usuario_compartir FROM compartidos WHERE id_paciente = {$paciente->id}) AND id_usuario != {$this->id}";
  118.  
  119. $this->db->query($q);
  120.  
  121. $usuarios = array();
  122.  
  123. if ($this->db->numRows()) {
  124. while ($_ = $this->db->fetchAssoc()) {
  125. $_['url'] = crypt_params(array(PACIENTE => $paciente->id, USUARIO => $_['id']));
  126. $_['fullname'] = $_['apellido'] . ', ' . $_['nombre'];
  127.  
  128. $usuarios[$_['id']] = $_;
  129. }
  130. }
  131.  
  132. $this->db->free();
  133.  
  134. return $usuarios;
  135. }
  136.  
  137. /**
  138. * comparte el paciente dado en el primer parametro con el usuario del segundo parametro
  139. *
  140. * @param Paciente $paciente paciente a ser compartido
  141. * @param numeric $usuario usuario con quien compartir paciente
  142. * @return bool puede retornar falso si es que la fila ya existe
  143. **/
  144. public function compartir($paciente, $usuario){
  145. if (!$paciente || !$usuario || !($paciente instanceof Paciente) || !is_numeric($usuario) || !is_numeric($paciente->id)) {
  146. return false;
  147. }
  148.  
  149. $q = "INSERT INTO compartidos (id_usuario, id_usuario_compartir, id_paciente) SELECT * FROM (SELECT '{$this->id}', {$usuario}, '{$paciente->id}') AS tmp WHERE NOT EXISTS (SELECT id_usuario,id_usuario_compartir,id_paciente FROM compartidos WHERE id_usuario = '{$this->id}' AND id_usuario_compartir = '{$usuario}' AND id_paciente = '{$paciente->id}') LIMIT 1";
  150.  
  151. return $this->db->query($q);
  152. }
  153.  
  154. /**
  155. * deja de compartir el paciente dado en relacion con el id compartir
  156. *
  157. * @param Paciente $paciente paciente que se va a dejar de compartir
  158. * @param numeric $id relacion usuario paciente
  159. * @return bool retorna 0 si se elimino la relacion
  160. **/
  161. public function nocompartir($paciente, $id){
  162. if (!$paciente || !$id || !($paciente instanceof Paciente) || !is_numeric($id) || !is_numeric($paciente->id)) {
  163. return false;
  164. }
  165.  
  166. $q = "DELETE FROM compartidos WHERE id_compartir = {$id} AND id_paciente = {$paciente->id} AND id_usuario = {$this->id}";
  167.  
  168. $this->db->query($q);
  169.  
  170. $q = "SELECT COUNT(id_compartir) FROM compartidos WHERE id_compartir = {$id} AND id_paciente = {$paciente->id} AND id_usuario = {$this->id}";
  171.  
  172. return $this->db->oneFieldQuery($q);
  173. }
  174.  
  175. /**
  176. * trae a todas las filas paciente/usuario que comparto
  177. *
  178. * @return void
  179. * @author
  180. **/
  181. public function comparto(){
  182. $comparto = array();
  183.  
  184. $q = "SELECT P.id_paciente AS id, concat(P.apellido, ', ', P.nombre) AS PACIENTE, concat(U.apellido, ', ', U.nombre) AS USUARIO, id_compartir AS COMPARTIR FROM compartidos AS C INNER JOIN pacientes AS P ON P.id_paciente = C.id_paciente INNER JOIN usuarios AS U ON U.id_usuario = C.id_usuario_compartir WHERE C.id_usuario = {$this->id}";
  185.  
  186. $this->db->query($q);
  187.  
  188. if ($this->db->numRows()) {
  189. while ($_ = $this->db->fetchAssoc()) {
  190. $_['COMPARTIR'] = crypt_params(array(PACIENTE => $_['id'], COMPARTIR => $_['COMPARTIR']));
  191. $_['URL'] = URL_ROOT . '/paciente/' . crypt_params(array(PACIENTE => $_['id']));
  192. $comparto[] = $_;
  193. }
  194. }
  195.  
  196. $this->db->free();
  197.  
  198. return $comparto;
  199. }
  200.  
  201. public function mecomparten(){
  202.  
  203. $mecomarten = array();
  204.  
  205. $q = "SELECT P.id_paciente AS id, concat(P.apellido, ', ', P.nombre) AS PACIENTE, concat(U.apellido, ', ', U.nombre) AS USUARIO FROM compartidos AS C INNER JOIN pacientes AS P ON P.id_paciente = C.id_paciente INNER JOIN usuarios AS U ON U.id_usuario = {$this->id} WHERE C.id_usuario_compartir = {$this->id}";
  206.  
  207. $this->db->query($q);
  208.  
  209. if ($this->db->numRows()) {
  210. while ($_ = $this->db->fetchAssoc()) {
  211. $_['URL'] = URL_ROOT . '/paciente/' . crypt_params(array(PACIENTE => $_['id']));
  212. $mecomarten[] = $_;
  213. }
  214. }
  215.  
  216. $this->db->free();
  217.  
  218. return $mecomarten;
  219. }
  220. }
  221.  
  222. class Paciente{
  223. private static $regex = '/^(?:id_)?usuario|fecha_(?:nacimient|ingres)|(?:apellid|telefon|eliminad|estad|sex|fot|correo_electronic)o|[mp]adre_(?:apellido|nombre)|dni|celular|direccion|ciudad|provincia|nombre|derivado_por|codigo_postal$/';
  224.  
  225. public function __isset($name) {
  226. return isset($this->{$name});
  227. }
  228.  
  229. public function __set($name, $value) {
  230. $this->{$name} = $value;
  231. }
  232.  
  233. public function __get($name) {
  234. if ($name == 'db') {
  235. return MySQL::getInstance();
  236. }
  237. elseif (preg_match(self::$regex, $name)) {
  238. if (!isset($this->{$name})) {
  239. return $this->select($name)->{$name};
  240. }
  241. }
  242. elseif (isset($this->{$name})) {
  243. return $this->{$name};
  244. }
  245.  
  246. return null;
  247. }
  248.  
  249. public function __construct($id = null, $data = null){
  250.  
  251. if (!$id && !$data) {
  252. return false;
  253. }
  254.  
  255. if (is_array($data) && is_numeric($id)){
  256. $keys = array('id_usuario');
  257. $values = array($id);
  258.  
  259. foreach ($data as $key => $value) {
  260. if (preg_match(self::$regex, $key)) {
  261. if(preg_match('/^fecha_(?:nacimient|ingres)o$/', $key)){
  262. $v = date('Y-m-d H:i:s', strtotime($value));
  263. }
  264.  
  265. $keys[] = $key;
  266. $values[] = $this->db->escape($value);
  267. }
  268. }
  269.  
  270. $q = "INSERT INTO pacientes (" . implode(",", $keys) . ") VALUES ('" . implode("','", $values) . "')";
  271.  
  272. $this->db->query($q);
  273.  
  274. $this->id = $this->db->lastID();
  275. }
  276. else{
  277. $this->id = $id;
  278. }
  279.  
  280. $this->URL = crypt_params(array(PACIENTE => $this->id));
  281.  
  282. return $this;
  283. }
  284.  
  285. public function edad() {
  286. return (int) floor(diff_date($this->fecha_nacimiento, date('Y-m-d'))/365);
  287. }
  288.  
  289. public function toarray($data) {
  290. pre_dump(func_get_args());
  291. $this->select($data);
  292.  
  293. foreach ($data as $k => $v) {
  294. $data[$v] = $this->{$v};
  295. }
  296.  
  297. pre_dump($data);
  298. }
  299.  
  300. public function tratamiento($id = null){
  301. if (!$id) {
  302. return $this->ultimoTratamiento();
  303. }
  304.  
  305. if (is_array($this->tratamientos) && in_array($id, $this->tratamientos)) {
  306. return $this->tratamientos[$id];
  307. }
  308. else{
  309.  
  310. if (!is_array($this->tratamientos)){
  311. $this->tratamientos = array();
  312. }
  313.  
  314. if (is_array($id)) {
  315. $tratamiento = new Tratamiento($this->id, $id);
  316. }
  317. elseif (is_numeric($id)) {
  318. $tratamiento = new Tratamiento($id);
  319. }
  320.  
  321. if ($tratamiento) {
  322. $this->tratamientos[$tratamiento->id] = $tratamiento;
  323.  
  324. return $tratamiento;
  325. }
  326. }
  327.  
  328. return false;
  329. }
  330.  
  331. public function tratamientos(){
  332. $q = "SELECT T.id_tratamiento AS id FROM tratamientos T INNER JOIN pacientes P ON P.id_paciente = T.id_paciente AND P.id_paciente = {$this->id} AND T.eliminado != 1 ORDER BY T.id_tratamiento DESC";
  333.  
  334. $this->db->query($q);
  335.  
  336. if ($this->db->numRows()) {
  337. while ($_ = $this->db->fetchAssoc()) {
  338. $this->tratamiento($_['id']);
  339. }
  340. }
  341.  
  342. $this->db->free();
  343.  
  344. return $this->tratamientos;
  345. }
  346.  
  347. public function ultimoTratamiento(){
  348. $q = "SELECT id_tratamiento as id FROM tratamientos WHERE id_paciente = {$this->id} AND eliminado <> 1 ORDER BY id_tratamiento DESC LIMIT 0, 1";
  349.  
  350. $this->db = MySQL::getInstance();
  351.  
  352. $id = $this->db->oneFieldQuery($q);
  353.  
  354. $this->db->free();
  355.  
  356. if ($id) {
  357. return $this->tratamiento($id);
  358. }
  359.  
  360. return false;
  361. }
  362.  
  363. public function fullname(){
  364. return $this->apellido . ', ' . $this->nombre;
  365. }
  366.  
  367. /**
  368. * concatena los datos para y forma la url para redirigir a la seccion solicitada
  369. *
  370. * @param string $section seccion a la cual se quiere redirigir
  371. * @return sting url formada
  372. **/
  373. public function url($section = 'paciente'){
  374. if (!preg_match('/^(?:editar|(?:(?:foto|radio)graf|cefalometr)ias|economia|diagnostico\/(?:uno|dos|examen|historia))$/', $section)) {
  375. $section = 'paciente';
  376. }
  377.  
  378. return URL_ROOT . '/' . $section . '/' . $this->URL;
  379. }
  380.  
  381. public function setInfo($data){
  382. $q = "UPDATE pacientes SET ";
  383.  
  384. foreach ($data as $k => $v) {
  385. if (preg_match(self::$regex, $k)){
  386. if(preg_match('/^fecha_(?:nacimient|ingres)o$/', $k)){
  387. $v = date('Y-m-d H:i:s', strtotime($v));
  388. }
  389.  
  390. $q .= $k . "='" . $v ."',";
  391. }
  392. }
  393.  
  394. $q = rtrim($q ,",") . " WHERE id_paciente = '{$this->id}'";
  395.  
  396. $this->db->query($q);
  397.  
  398. return $this->select();
  399. }
  400.  
  401. public function select($data = '*'){
  402. if (is_string($data)) {
  403. $data = array($data);
  404. }
  405.  
  406. if (is_array($data)) {
  407.  
  408. $keys = array();
  409.  
  410. foreach ($data as $field) {
  411. if (preg_match('/^(?:id_)?usuario|fecha_(?:nacimient|ingres)o|(?:apellid|telefon|eliminad|estad|sex|fot|correo_electronic)o|[mp]adre_(?:apellido|nombre)|dni|celular|direccion|ciudad|provincia|nombre|derivado_por|codigo_postal|\*$/', $field)) {
  412. if ($field == 'usuario') {
  413. $field = 'id_' . $field;
  414. }
  415.  
  416. $keys[] = $field;
  417. }
  418. }
  419.  
  420. if (count($keys)) {
  421. $q = "SELECT " . implode(', ', array_unique($keys)) . " FROM pacientes WHERE id_paciente = {$this->id}";
  422.  
  423. $db = MySQL::getInstance();
  424.  
  425. $paciente = $db->oneRowQuery($q);
  426.  
  427. if ($paciente) {
  428. foreach ($paciente as $k => $v) {
  429. if (preg_match('/^fecha_(?:nacimient|ingres)o$/', $v)) {
  430. $v = date('d-m-Y', strtotime($v));
  431. }
  432.  
  433. $this->{str_replace('id_', '', $k)} = utf8_encode($v);
  434. }
  435. }
  436.  
  437. return $this;
  438. }
  439. }
  440.  
  441. return false;
  442. }
  443. }
  444.  
  445. class Tratamiento{
  446.  
  447. public function __isset($name) {
  448. return isset($this->{$name});
  449. }
  450.  
  451. public function __set($name, $value) {
  452. $this->{$name} = $value;
  453. }
  454.  
  455. public function __get($name) {
  456. if ($name == 'db') {
  457. return MySQL::getInstance();
  458. }
  459. elseif (preg_match('/^(?:fecha_hora_inici|estad|presupuest|eliminad)o|tecnica|(?:descrip|dura)cion|avance|fecha$/', $name)) {
  460. if (!isset($this->{$name})) {
  461. return $this->select($name)->{$name};
  462. }
  463. }
  464. elseif ($name == 'odontograma') {
  465. $this->odontograma = $this->odontograma();
  466.  
  467. return $this->odontograma;
  468. }
  469. elseif ($name == 'paciente') {
  470. $this->paciente = new Paciente($this->select('id_paciente')->paciente);
  471.  
  472. return $this->paciente;
  473. }
  474. elseif (isset($this->{$name})) {
  475. return $this->{$name};
  476. }
  477.  
  478. return null;
  479. }
  480.  
  481. public function __construct($id = null, $data = null){
  482.  
  483. if (!$id && !$data) {
  484. return false;
  485. }
  486.  
  487. if (is_array($data) && is_numeric($id)){
  488. $keys = array('id_paciente','estado');
  489. $values = array($id,1);
  490.  
  491. foreach ($data as $k => $v) {
  492. if (preg_match('/^fecha_hora_inicio|duracion|tecnica|presupuesto|descripcion$/', $k)) {
  493. if ($k == 'fecha_hora_inicio') {
  494. $v = $v !== '' ? date('Y-m-d H:i:s', strtotime($v)) : date("Y-m-d H:i:s");
  495. }
  496. elseif ($k == 'estado') {
  497. $v = 1;
  498. }
  499.  
  500. $keys[] = $k;
  501. $values[] = $this->db->escape($v);
  502. }
  503. }
  504.  
  505. $odontograma = new Odontograma();
  506.  
  507. if ($odontograma->id) {
  508. $keys[] = 'id_odontograma';
  509. $values[] = $odontograma->id;
  510. }
  511.  
  512. $q = "INSERT INTO tratamientos (" . implode(",", $keys) . ") VALUES ('" . implode("','", $values) . "')";
  513.  
  514. $this->db->query($q);
  515.  
  516. $this->id = $this->db->lastID();
  517. }
  518. else{
  519. $this->id = $id;
  520. }
  521.  
  522. return $this;
  523. }
  524.  
  525. public function balancear(){
  526. $acumulado = $this->acumulado();
  527.  
  528. foreach($this->pagos() as $pago){
  529. $pago->acumulado = $acumulado;
  530. $pago->balance = $this->presupuesto - $pago->acumulado;
  531. $acumulado -= $pago->monto;
  532.  
  533. $pago->update();
  534. }
  535. }
  536.  
  537. public function url() {
  538. $this->url = crypt_params(array(TRATAMIENTO => $this->id, PACIENTE => $this->paciente->id));
  539.  
  540. return $this->url;
  541. }
  542.  
  543. public function pago($id){
  544. // SI id ES UN ARRAY ES PORQUE SE CREA UN NUEVO PAGO Y LE ADJUNTO EL id DEL TRATAMIENTO
  545. if (is_array($id)) {
  546. $id['id_tratamiento'] = $this->id;
  547. }
  548. // CREO EL ARREGLO DE PAGOS SI NO EXISTE
  549. if (!is_array($this->pagos)){
  550. $this->pagos = array();
  551. }
  552. // SI ES UNA FOTOGRAFIA NUEVA id ES UN ARRAY SINO ES UN NUMERO Y RETORNO LA FOTOGRAFIA POR ID
  553. $pago = new Pago($id);
  554.  
  555. if ($pago->id) {
  556. $this->pagos[$pago->id] = $pago;
  557.  
  558. return $pago;
  559. }
  560.  
  561. return false;
  562. }
  563.  
  564. public function toarray($data) {
  565. pre_dump(func_get_args());
  566. $this->select($data);
  567.  
  568. foreach ($data as $k => $v) {
  569. $data[$v] = $this->{$v};
  570. }
  571.  
  572. pre_dump($data);
  573. }
  574.  
  575. public function pagos() {
  576. $q = "SELECT id_pago AS id FROM pagos WHERE id_tratamiento = {$this->id} ORDER BY fecha_hora DESC";
  577.  
  578. $this->db->query($q);
  579.  
  580. if ($this->db->numRows()) {
  581. $this->pagos = array();
  582.  
  583. while ($_ = $this->db->fetchAssoc()) {
  584. $this->pago($_['id']);
  585. }
  586.  
  587. return $this->pagos;
  588. }
  589.  
  590. return false;
  591. }
  592.  
  593. public function acumulado(){
  594. $q = "SELECT SUM(monto) AS acumulado FROM pagos WHERE id_tratamiento = {$this->id}";
  595.  
  596. return (int) $this->db->oneFieldQuery($q);
  597. }
  598.  
  599. public function odontograma($data = null){
  600.  
  601. return new Odontograma($this->select('id_odontograma')->odontograma);
  602. }
  603.  
  604. /**
  605. * Busca todas las cefalometrias para este tratamiento
  606. *
  607. * @return array array con todas las filas de cefalometrias
  608. **/
  609. public function cefalometrias(){
  610. $q = "SELECT id_cefalometria AS id FROM cefalometrias WHERE id_tratamiento = {$this->id} AND eliminado <> 1 ORDER BY fecha_hora DESC";
  611.  
  612. if (is_array($this->cefalometrias)) {
  613. return $this->cefalometrias;
  614. }
  615.  
  616. $this->db->query($q);
  617.  
  618. if ($this->db->numRows()) {
  619. while ($_ = $this->db->fetchAssoc()) {
  620. $this->cefalometria($_['id']);
  621. }
  622. }
  623.  
  624. return $this->cefalometrias;
  625. }
  626.  
  627. public function cefalometria($id = null, $data = null){
  628. // SI VIENE UN NUMERO Y ESTA FOTOGRAFIA YA EXISTE LA MANDO
  629. if (is_numeric($id) && is_array($this->cefalometrias) && in_array($id, $this->cefalometrias)) {
  630. return $this->cefalometrias[$id];
  631. }
  632. else{
  633. // SI id ES UN ARRAY ES PORQUE SE INSERTA UNA NUEVA FOTOGRAFIA Y LE ADJUNTO EL id DEL TRATAMIENTO
  634. if (is_array($id)) {
  635. $id['id_tratamiento'] = $this->id;
  636. }
  637. // CREO EL ARREGLO DE FOTOGRAFIAS SI NO EXISTE
  638. if (!is_array($this->cefalometrias)){
  639. $this->cefalometrias = array();
  640. }
  641. // SI ES UNA FOTOGRAFIA NUEVA id ES UN ARRAY SINO ES UN NUMERO Y RETORNO LA FOTOGRAFIA POR ID
  642. $cefalometria = new Cefalometria($id);
  643.  
  644. if ($cefalometria) {
  645. $this->cefalometrias[$cefalometria->id] = $cefalometria;
  646.  
  647. return $cefalometria;
  648. }
  649. }
  650.  
  651. return false;
  652. }
  653. /**
  654. * Busca todas las fotografias para este tratamiento
  655. *
  656. * @return array array con todas las filas de fotografias
  657. **/
  658. public function fotografias(){
  659. $q = "SELECT id_fotografia AS id FROM fotografias WHERE id_tratamiento = {$this->id} AND eliminado <> 1 ORDER BY fecha_hora DESC";
  660.  
  661. if (is_array($this->fotografias)) {
  662. return $this->fotografias;
  663. }
  664.  
  665. $this->db->query($q);
  666.  
  667. if ($this->db->numRows()) {
  668. while ($_ = $this->db->fetchAssoc()) {
  669. $this->fotografia($_['id']);
  670. }
  671. }
  672.  
  673. return $this->fotografias;
  674. }
  675.  
  676. public function fotografia($id = null, $data = null){
  677. // SI VIENE UN NUMERO Y ESTA FOTOGRAFIA YA EXISTE LA MANDO
  678. if (is_numeric($id) && is_array($this->fotografias) && in_array($id, $this->fotografias)) {
  679. return $this->fotografias[$id];
  680. }
  681. else{
  682. // SI id ES UN ARRAY ES PORQUE SE INSERTA UNA NUEVA FOTOGRAFIA Y LE ADJUNTO EL id DEL TRATAMIENTO
  683. if (is_array($id)) {
  684. $id['id_tratamiento'] = $this->id;
  685. }
  686. // CREO EL ARREGLO DE FOTOGRAFIAS SI NO EXISTE
  687. if (!is_array($this->fotografias)){
  688. $this->fotografias = array();
  689. }
  690. // SI ES UNA FOTOGRAFIA NUEVA id ES UN ARRAY SINO ES UN NUMERO Y RETORNO LA FOTOGRAFIA POR ID
  691. $fotografia = new Fotografia($id);
  692.  
  693. if ($fotografia) {
  694. $this->fotografias[$fotografia->id] = $fotografia;
  695.  
  696. return $fotografia;
  697. }
  698. }
  699.  
  700. return false;
  701. }
  702.  
  703. /**
  704. * Busca todas las radiografias para este tratamiento
  705. *
  706. * @return array array con todas las filas de radiografias
  707. **/
  708. public function radiografias(){
  709. $q = "SELECT id_radiografia AS id FROM radiografias WHERE id_tratamiento = {$this->id} AND eliminado <> 1 ORDER BY fecha_hora DESC";
  710.  
  711. if (is_array($this->radiografias)) {
  712. return $this->radiografias;
  713. }
  714.  
  715. $this->db->query($q);
  716.  
  717. if ($this->db->numRows()) {
  718. while ($_ = $this->db->fetchAssoc()) {
  719. $this->radiografia($_['id']);
  720. }
  721. }
  722.  
  723. return $this->radiografias;
  724. }
  725.  
  726. public function radiografia($id = null, $data = null){
  727. // SI VIENE UN NUMERO Y ESTA RADIOGRAFIA YA EXISTE LA MANDO
  728. if (is_numeric($id) && is_array($this->radiografias) && in_array($id, $this->radiografias)) {
  729. return $this->radiografias[$id];
  730. }
  731. else{
  732. // SI id ES UN ARRAY ES PORQUE SE INSERTA UNA NUEVA RADIOGRAFIA Y LE ADJUNTO EL id DEL TRATAMIENTO
  733. if (is_array($id)) {
  734. $id['id_tratamiento'] = $this->id;
  735. }
  736. // CREO EL ARREGLO DE RADIOGRAFIAS SI NO EXISTE
  737. if (!is_array($this->radiografias)){
  738. $this->radiografias = array();
  739. }
  740. // SI ES UNA RADIOGRAFIA NUEVA id ES UN ARRAY SINO ES UN NUMERO Y RETORNO LA RADIOGRAFIA POR ID
  741. $radiografia = new Radiografia($id);
  742.  
  743. if ($radiografia) {
  744. $this->radiografias[$radiografia->id] = $radiografia;
  745.  
  746. return $radiografia;
  747. }
  748. }
  749.  
  750. return false;
  751. }
  752.  
  753. public function setInfo($data){
  754. $q = "UPDATE tratamientos SET ";
  755.  
  756. foreach ($data as $k => $v) {
  757. if (preg_match('/^fecha_hora_inicio|estado|duracion|tecnica|presupuesto|descripcion$/', $k)) {
  758. if ($k == 'fecha_hora_inicio') {
  759. $v = date('Y-m-d H:i:s', strtotime($v));
  760. }
  761. $q .= $k . "='" . $v ."',";
  762. }
  763. }
  764.  
  765. $q = rtrim($q ,",") . " WHERE id_tratamiento = '{$this->id}'";
  766.  
  767. $this->db->query($q);
  768.  
  769. return $this->select();
  770. }
  771.  
  772. public function select($data = '*'){
  773. if (is_string($data)) {
  774. $data = array($data);
  775. }
  776.  
  777. if (is_array($data)) {
  778. $keys = array();
  779.  
  780. if (in_array('fecha', $data)) {
  781. $keys[] = 'fecha_hora_inicio';
  782. }
  783.  
  784. // VALIDO LOS CAMPOS SOLICITADOS, LOS ID PUEDEN VENIR SIN EL PREFIJO
  785. foreach ($data as $field) {
  786. if (preg_match('/^(?:fecha_hora_inici|estad|presupuest|eliminad)o|tecnica|(?:descrip|dura)cion|\*$/', $field)) {
  787. $keys[] = $field;
  788. }
  789. else{
  790. preg_match('/^(?:id_)?(examen|paciente|historia|diagnostico|resumen|odontograma)$/', $field, $m);
  791. if (count($m)) {
  792. $keys[] = 'id_' . $m[1];
  793. }
  794. }
  795. }
  796.  
  797. // SI PIDE EL AVANCE SE NECESITAN DOS CAMPOS MAS
  798. if (in_array('avance', $data)) {
  799. $keys[] = 'fecha_hora_inicio';
  800. $keys[] = 'duracion';
  801. }
  802.  
  803. // SI HAY CAMPOS VALIDADOS
  804. if (count($keys)) {
  805. $q = "SELECT " . implode(', ', array_unique($keys)) . " FROM tratamientos WHERE id_tratamiento = {$this->id}";
  806.  
  807. $tratamiento = $this->db->oneRowQuery($q);
  808.  
  809. if ($tratamiento) {
  810. foreach ($tratamiento as $k => $v) {
  811. if ($k == 'fecha_hora_inicio') {
  812. $v = date('d-m-Y', strtotime($v));
  813. }
  814. elseif($k == 'estado'){
  815. $v = is_numeric($v) ? constant('TRATAMIENTO_ESTADO_' . $v) : $v;
  816. }
  817. elseif($k == 'tecnica'){
  818. $v = is_numeric($v) ? constant('TECNICA_' . $v) : $v;
  819. }
  820.  
  821. $this->{str_replace('id_', '', $k)} = utf8_encode($v);
  822. }
  823.  
  824. if (array_key_exists('fecha_hora_inicio', $tratamiento)) {
  825. $this->fecha = date('d-m-Y', strtotime($tratamiento['fecha_hora_inicio']));
  826. }
  827. }
  828.  
  829.  
  830. // SI PIDIO EL AVANCE LO CALCULO
  831. if (in_array('avance', $data)) {
  832. $this->avance = (int) progress($this->fecha_hora_inicio, $this->duracion);
  833. }
  834.  
  835. return $this;
  836. }
  837. }
  838.  
  839. $this->url = crypt_params(array(TRATAMIENTO => $this->id, PACIENTE => $this->paciente));
  840.  
  841. return false;
  842. }
  843. }
  844.  
  845. class File {
  846. public function __isset($name) {
  847. return isset($this->{$name});
  848. }
  849.  
  850. public function __set($name, $value) {
  851. $this->{$name} = $value;
  852. }
  853.  
  854. /**
  855. * concatena los datos para obtener la url necesaria para ver
  856. *
  857. * @return sting url para ver la radiografia
  858. **/
  859. public function url_ver(){
  860. return URL_ROOT . '/' . strtolower(get_class($this)) . 's/ver/' . $this->url;
  861. }
  862.  
  863. /**
  864. * concatena los datos para obtener la url para editar
  865. *
  866. * @return sting url para editar la radiografia
  867. **/
  868. public function url_editar(){
  869. return URL_ROOT . '/' . strtolower(get_class($this)) . 's/editar/' . $this->url;
  870. }
  871.  
  872. public function eliminar(){
  873. $this->eliminado = 1;
  874.  
  875. $this->update();
  876. }
  877.  
  878. public function select(){
  879. if (!$this->id) {
  880. return false;
  881. }
  882.  
  883. $name = strtolower(get_class($this));
  884.  
  885. $extra_field = $name == 'cefalometria' ? ', tipo' : null;
  886.  
  887. $q = "SELECT X.eliminado, X.etapa, X.id_tratamiento AS tratamiento, X.fecha_hora, X.datos_json, T.id_paciente AS paciente{$extra_field} FROM {$name}s AS X INNER JOIN tratamientos AS T ON T.id_tratamiento = X.id_tratamiento WHERE X.id_{$name} = {$this->id}";
  888.  
  889. $_ = $this->db->oneRowQuery($q);
  890.  
  891. $this->fecha_hora = date('d-m-Y', strtotime($_['fecha_hora']));
  892. $this->datos_json = (array) json_decode($_['datos_json']);
  893. $this->cantidad = count((array) end($this->datos_json));
  894. $this->key = key($this->datos_json);
  895. $this->etapa = constant('ETAPA_' . $_['etapa']);
  896. $this->_etapa = $_['etapa'];
  897. $this->tratamiento = new Tratamiento($_['tratamiento']);
  898. $this->url = crypt_params(array(constant(strtoupper($name)) => $this->id, TRATAMIENTO => $this->tratamiento->id, PACIENTE => $this->tratamiento->paciente->id));
  899.  
  900. if ($extra_field) {
  901. $this->tipo =constant('C_TIPO_' . $_['tipo']);
  902. $this->_tipo = $_['tipo'];
  903. }
  904.  
  905. return $this;
  906. }
  907.  
  908. public function update($data = null){
  909. // ES NECESARIO EL id Y LA INFO
  910. if (!$this->id) {
  911. return false;
  912. }
  913.  
  914. $name = strtolower(get_class($this));
  915.  
  916. $q = "UPDATE {$name}s SET ";
  917.  
  918. if (!is_array($data)) {
  919. $data = array('datos_json' => json_encode($this->datos_json), 'etapa' => $this->_etapa, 'eliminado' => $this->eliminado);
  920. }
  921.  
  922. if ($name == 'cefalometria'){
  923. $data['tipo'] = $this->_tipo;
  924. }
  925.  
  926. foreach ($data as $k => $v) {
  927. if (preg_match('/^datos_json|etapa|eliminado|tipo$/', $k)) {
  928. $q .= $k . "='" . $v ."',";
  929. }
  930. }
  931.  
  932. $q = rtrim($q ,",") . " WHERE id_{$name} = '{$this->id}'";
  933.  
  934. $this->db->query($q);
  935.  
  936. $this->db->free();
  937.  
  938. return $this->select();
  939. }
  940. }
  941.  
  942. class Radiografia extends File{
  943.  
  944. public function __get($name) {
  945. if ($name == 'db') {
  946. return MySQL::getInstance();
  947. }
  948. // elseif (preg_match('/^$/', $name)) {
  949. // if (!isset($this->{$name})) {
  950. // return $this->select($name)->{$name};
  951. // }
  952. // }
  953. elseif (isset($this->{$name})) {
  954. return $this->{$name};
  955. }
  956.  
  957. return null;
  958. }
  959.  
  960. public function __construct($id = null, $data = null){
  961. // SI id ES UN ARRAY ES PARA INSERTAR UNO NUEVO
  962. if (is_array($id)) {
  963.  
  964. if (isset($id['datos_json'], $id['id_tratamiento'])) {
  965. // VALIDO LOS VALORES ENVIADOS
  966. if (!json_decode($id['datos_json']) || !is_numeric($id['id_tratamiento'])) {
  967. return false;
  968. }
  969. else{
  970. if( isset($id['etapa']) || !is_numeric($id['etapa'])){
  971. $id['etapa'] = 1;
  972. }
  973. // SI LOS DATOS SON VALIDOS LOS INSERTO EN LA BASE
  974. $date = date('Y-m-d H:i:s');
  975. $json = stripslashes($id['datos_json']);
  976. $q = "INSERT INTO radiografias (id_tratamiento, fecha_hora, datos_json, etapa) VALUES ({$id['id_tratamiento']}, '{$date}', '{$json}', {$id['etapa']})";
  977.  
  978. $this->db->query($q);
  979.  
  980. $this->id = $this->db->lastID();
  981. }
  982. }
  983. }
  984. // SI id ES UN NUEMERO LEVANTO LA INFO DE LA BBDD
  985. if (is_numeric($id) && $data == null) {
  986. $this->id = $id;
  987. }
  988. // TENGO EL id SETEADO ASIQUE TRAIGO LOS DATOS
  989. return $this->select();
  990. }
  991.  
  992.  
  993. public function update($data = null){
  994. // ES NECESARIO EL id Y LA INFO
  995. if (!$this->id) {
  996. return false;
  997. }
  998.  
  999. $q = "UPDATE radiografias SET ";
  1000.  
  1001. if (!is_array($data)) {
  1002. $data = array('datos_json' => json_encode($this->datos_json), 'etapa' => $this->_etapa, 'eliminado' => $this->eliminado);
  1003. }
  1004.  
  1005. foreach ($data as $k => $v) {
  1006. if (preg_match('/^datos_json|etapa|eliminado$/', $k)) {
  1007. $q .= $k . "='" . $v ."',";
  1008. }
  1009. }
  1010.  
  1011. $q = rtrim($q ,",") . " WHERE id_radiografia = '{$this->id}'";
  1012.  
  1013. $this->db->query($q);
  1014.  
  1015. $this->db->free();
  1016.  
  1017. return $this->select();
  1018. }
  1019.  
  1020. public function select(){
  1021. if (!$this->id) {
  1022. return false;
  1023. }
  1024.  
  1025. $q = "SELECT R.eliminado, R.etapa, R.id_tratamiento AS tratamiento, R.fecha_hora, R.datos_json, T.id_paciente AS paciente FROM radiografias AS R INNER JOIN tratamientos AS T ON T.id_tratamiento = R.id_tratamiento WHERE R.id_radiografia = {$this->id}";
  1026.  
  1027. $_ = $this->db->oneRowQuery($q);
  1028.  
  1029. $this->fecha_hora = date('d-m-Y', strtotime($_['fecha_hora']));
  1030. $this->datos_json = (array) json_decode($_['datos_json']);
  1031. $this->cantidad = count((array) end($this->datos_json));
  1032. $this->key = key($this->datos_json);
  1033. $this->etapa = constant('ETAPA_' . $_['etapa']);
  1034. $this->_etapa = $_['etapa'];
  1035. $this->tratamiento = new Tratamiento($_['tratamiento']);
  1036. $this->url = crypt_params(array(RADIOGRAFIA => $this->id, TRATAMIENTO => $this->tratamiento->id, PACIENTE => $this->tratamiento->paciente->id));
  1037.  
  1038. return $this;
  1039. }
  1040. }
  1041.  
  1042. class Fotografia extends File{
  1043.  
  1044. public function __get($name) {
  1045. if ($name == 'db') {
  1046. return MySQL::getInstance();
  1047. }
  1048. elseif (isset($this->{$name})) {
  1049. return $this->{$name};
  1050. }
  1051.  
  1052. return null;
  1053. }
  1054.  
  1055. public function __construct($id = null, $data = null){
  1056. // SI id ES UN ARRAY ES PARA INSERTAR UNO NUEVO
  1057. if (is_array($id)) {
  1058.  
  1059. if (isset($id['datos_json'], $id['id_tratamiento'])) {
  1060. // VALIDO LOS VALORES ENVIADOS
  1061. if (!json_decode($id['datos_json']) || !is_numeric($id['id_tratamiento'])) {
  1062. return false;
  1063. }
  1064. else{
  1065. if(!isset($id['etapa']) || !is_numeric($id['etapa'])){
  1066. $id['etapa'] = 1;
  1067. }
  1068. // SI LOS DATOS SON VALIDOS LOS INSERTO EN LA BASE
  1069. $date = date('Y-m-d H:i:s');
  1070. $json = stripslashes($id['datos_json']);
  1071. $q = "INSERT INTO fotografias (id_tratamiento, fecha_hora, datos_json, etapa) VALUES ({$id['id_tratamiento']}, '{$date}', '{$json}', {$id['etapa']})";
  1072.  
  1073. $this->db->query($q);
  1074.  
  1075. $this->id = $this->db->lastID();
  1076. }
  1077. }
  1078. }
  1079. // SI id ES UN NUEMERO LEVANTO LA INFO DE LA BBDD
  1080. if (is_numeric($id) && $data == null) {
  1081. $this->id = $id;
  1082. }
  1083. // CON id SETEADO TRAIGO LOS DATOS
  1084. return $this->select();
  1085. }
  1086. }
  1087.  
  1088. class Cefalometria extends File{
  1089.  
  1090. public function __get($name) {
  1091. if ($name == 'db') {
  1092. return MySQL::getInstance();
  1093. }
  1094. elseif (isset($this->{$name})) {
  1095. return $this->{$name};
  1096. }
  1097.  
  1098. return null;
  1099. }
  1100.  
  1101. public function __construct($id = null, $data = null){
  1102. // SI id ES UN ARRAY ES PARA INSERTAR UNO NUEVO
  1103. if (is_array($id)) {
  1104.  
  1105. if (isset($id['datos_json'], $id['id_tratamiento'])) {
  1106. // VALIDO LOS VALORES ENVIADOS
  1107. if (!json_decode($id['datos_json']) || !is_numeric($id['id_tratamiento'])) {
  1108. return false;
  1109. }
  1110. else{
  1111. if(!isset($id['etapa']) || !is_numeric($id['etapa'])){
  1112. $id['etapa'] = 1;
  1113. }
  1114.  
  1115. if(!isset($id['tipo']) || !is_numeric($id['tipo'])){
  1116. $id['tipo'] = 5;
  1117. }
  1118. // SI LOS DATOS SON VALIDOS LOS INSERTO EN LA BASE
  1119. $date = date('Y-m-d H:i:s');
  1120. $json = stripslashes($id['datos_json']);
  1121. $q = "INSERT INTO cefalometrias (id_tratamiento, fecha_hora, datos_json, etapa, tipo) VALUES ({$id['id_tratamiento']}, '{$date}', '{$json}', {$id['etapa']}, {$id['tipo']})";
  1122.  
  1123. $this->db->query($q);
  1124.  
  1125. $this->id = $this->db->lastID();
  1126. }
  1127. }
  1128. }
  1129. // SI id ES UN NUEMERO LEVANTO LA INFO DE LA BBDD
  1130. if (is_numeric($id) && $data == null) {
  1131. $this->id = $id;
  1132. }
  1133. // CON id SETEADO TRAIGO LOS DATOS
  1134. return $this->select();
  1135. }
  1136. }
  1137.  
  1138. class Odontograma {
  1139.  
  1140. public function __get($name) {
  1141. if ($name == 'db') {
  1142. return MySQL::getInstance();
  1143. }
  1144. elseif ($name == 'url') {
  1145. $this->url = crypt_params(array(ODONTOGRAMA => $this->id, TRATAMIENTO => $this->tratamiento->id, PACIENTE => $this->tratamiento->paciente->id));
  1146.  
  1147. return $this->url;
  1148. }
  1149. elseif ($name == 'tratamiento') {
  1150. $q = "SELECT id_tratamiento AS id FROM tratamientos WHERE id_odontograma = {$this->id}";
  1151.  
  1152. $this->tratamiento = new Tratamiento($this->db->oneFieldQuery($q));
  1153.  
  1154. return $this->tratamiento;
  1155. }
  1156. elseif (isset($this->{$name})) {
  1157. return $this->{$name};
  1158. }
  1159.  
  1160. return null;
  1161. }
  1162.  
  1163. function __construct($id = null){
  1164. if (!$id) {
  1165. $q = "INSERT INTO odontogramas (datos_json) VALUES ('{}')";
  1166.  
  1167. $this->db->query($q);
  1168.  
  1169. $id = $this->db->lastID();
  1170. }
  1171.  
  1172. $this->id = $id;
  1173.  
  1174. return $this->select();
  1175. }
  1176.  
  1177. public function select(){
  1178. if (!$this->id || !is_numeric($this->id)) {
  1179. return false;
  1180. }
  1181.  
  1182. $q = "SELECT datos_json FROM odontogramas WHERE id_odontograma = {$this->id}";
  1183.  
  1184. $_ = $this->db->oneFieldQuery($q);
  1185.  
  1186. $this->datos_json = (array) json_decode($_);
  1187.  
  1188. return $this;
  1189. }
  1190.  
  1191. public function update($data = null){
  1192. // ES NECESARIO EL id Y LA INFO
  1193. if (!$this->id) {
  1194. return false;
  1195. }
  1196.  
  1197. $name = strtolower(get_class($this));
  1198.  
  1199. if (!is_string($this->datos_json)) {
  1200. $this->datos_json = json_encode($this->datos_json);
  1201. }
  1202.  
  1203. $q = "UPDATE odontogramas SET datos_json = '{$this->datos_json}' WHERE id_odontograma = '{$this->id}'";
  1204.  
  1205. $this->db->query($q);
  1206.  
  1207. $this->db->free();
  1208.  
  1209. return $this->select();
  1210. }
  1211. }
  1212.  
  1213. class Pago {
  1214.  
  1215. public function __get($name) {
  1216. if ($name == 'db') {
  1217. return MySQL::getInstance();
  1218. }
  1219. elseif ($name == 'tratamiento') {
  1220. $q = "SELECT id_tratamiento AS id FROM tratamientos WHERE id_odontograma = {$this->id}";
  1221.  
  1222. $this->tratamiento = new Tratamiento($this->db->oneFieldQuery($q));
  1223.  
  1224. return $this->tratamiento;
  1225. }
  1226. elseif (isset($this->{$name})) {
  1227. return $this->{$name};
  1228. }
  1229.  
  1230. return null;
  1231. }
  1232.  
  1233. public function __construct($id){
  1234. if (!$id) {
  1235. return false;
  1236. }
  1237.  
  1238. if (is_numeric($id)) {
  1239. $this->id = $id;
  1240. }
  1241. elseif(is_array($id)) {
  1242. // CAMPOS NECESARIOS
  1243. if (!isset($id['id_tratamiento'], $id['monto']) && !is_numeric($id['id_tratamiento']) && !is_numeric($id['monto'])) {
  1244. return false;
  1245. }
  1246.  
  1247. $this->tratamiento = new Tratamiento($id['id_tratamiento']);
  1248.  
  1249. foreach ($id as $k => $v) {
  1250. if (preg_match('/^id_tratamiento|monto|anotaciones|motivo$/', $k)) {
  1251.  
  1252. $keys[] = $k;
  1253. $values[] = $this->db->escape($v);
  1254. }
  1255. }
  1256.  
  1257. $keys[] = 'fecha_hora';
  1258.  
  1259. if (!isset($id['fecha_hora']) || !$id['fecha_hora']) {
  1260. $values[] = date('Y-m-d H:i:s');
  1261. }
  1262. else{
  1263. $values[] = date('Y-m-d H:i:s', strtotime($id['fecha_hora']));
  1264. }
  1265.  
  1266. $keys[] = 'acumulado';
  1267. $acumulado = $this->tratamiento->acumulado() + ($id['monto'] + 0);
  1268. $values[] = $acumulado;
  1269.  
  1270. $keys[] = 'balance';
  1271. $values[] = ($this->tratamiento->presupuesto + 0) - $acumulado;
  1272.  
  1273. $q = "INSERT INTO pagos (" . implode(",", $keys) . ") VALUES ('" . implode("','", $values) . "')";
  1274.  
  1275. $this->db->query($q);
  1276.  
  1277. $this->id = $this->db->lastID();
  1278. }
  1279.  
  1280. return $this->select();
  1281. }
  1282.  
  1283. /**
  1284. * concatena los datos para obtener la url necesaria
  1285. * @param string $action 'editar' | 'ver' devuelven la url para segun sea ver o editar los detalles del pago, sino retorna url
  1286. * @return sting url para ver la radiografia
  1287. **/
  1288. public function url($action = null){
  1289. if (preg_match('/^ver|editar$/', $action)) {
  1290. return URL_ROOT . '/economia/' . $action . '/' . $this->url;
  1291. }
  1292.  
  1293. return $this->url;
  1294. }
  1295.  
  1296. public function select($data = '*'){
  1297. if (!$this->id || !is_numeric($this->id)) {
  1298. return false;
  1299. }
  1300.  
  1301. $keys = ' * ';
  1302.  
  1303. if ($data != '*') {
  1304. if (!is_array($data)) {
  1305. $data = array($data);
  1306. }
  1307.  
  1308. foreach ($data as $k) {
  1309. if (is_string($k)) {
  1310. if (preg_match('/^monto|anotaciones|motivo|acumulado|balance$/', $k)) {
  1311. $keys[] = $k;
  1312. }
  1313. elseif (preg_match('/^(:?id_)tratamiento$/', $k)) {
  1314. $keys[] = 'id_tratamiento AS tratamiento';
  1315. }
  1316. }
  1317. }
  1318.  
  1319. $keys = implode(', ', $keys);
  1320. }
  1321.  
  1322. $q = "SELECT {$keys} FROM pagos WHERE id_pago = {$this->id}";
  1323.  
  1324. $_ = $this->db->oneRowQuery($q);
  1325.  
  1326. if ($_) {
  1327. foreach ($_ as $k => $v) {
  1328. if ($k == 'fecha_hora') {
  1329. $this->{$k} = date('d-m-Y', strtotime($v));
  1330. }
  1331. elseif (preg_match('/^monto|anotaciones|motivo|acumulado|balance$/', $k)) {
  1332. $this->{$k} = utf8_encode($v);
  1333. }
  1334. elseif (preg_match('/^(:?id_)tratamiento$/', $k)) {
  1335. $this->tratamiento = new Tratamiento($v);
  1336. }
  1337. }
  1338.  
  1339. $this->url = crypt_params(array(PAGO => $this->id, TRATAMIENTO => $this->tratamiento->id, PACIENTE => $this->tratamiento->paciente->id));
  1340.  
  1341. return $this;
  1342. }
  1343.  
  1344. unset($this->id);
  1345. }
  1346.  
  1347. public function eliminar() {
  1348. $tratamiento = $this->tratamiento;
  1349. $q = "DELETE FROM pagos WHERE id_pago = '{$this->id}';";
  1350.  
  1351. $this->db->query($q);
  1352. }
  1353.  
  1354. public function update($data = null){
  1355. $q = "UPDATE pagos SET acumulado ='{$this->acumulado}', balance ='{$this->balance}' WHERE id_pago = '{$this->id}';";
  1356.  
  1357. $this->db->query($q);
  1358.  
  1359. return $this;
  1360. }
  1361. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement