/application/inc/clases/Cumples.php

https://github.com/sbarrat/cni3 · PHP · 114 lines · 99 code · 15 blank · 0 comment · 10 complexity · 67eddc25e49ef28c39a81fdd469399d3 MD5 · raw file

  1. <?php
  2. require_once 'Sql.php';
  3. require_once 'funcionesAuxiliares.php';
  4. class Cumples extends Sql
  5. {
  6. private $_tablas = array('pcentral','pempresa','empleados');
  7. private $_dias = array('today','tomorrow','month');
  8. private $_month = array();
  9. function __construct ()
  10. {
  11. parent::__construct();
  12. }
  13. function DatosCumples()
  14. {
  15. foreach($this->_tablas as $tabla){
  16. switch($tabla){
  17. case "pcentral":$nombre = "`{$tabla}`.`persona_central` AS `nombre`";
  18. $cumple = "`{$tabla}`.`cumple`";
  19. $id = "`{$tabla}`.`idemp`";
  20. break;
  21. case "pempresa": $nombre = "CONCAT(`{$tabla}`.`nombre`,' ',
  22. `{$tabla}`.`apellidos`) AS `nombre`";
  23. $cumple = "`{$tabla}`.`cumple`";
  24. $id = "`{$tabla}`.`idemp`";
  25. break;
  26. case "empleados": $nombre = "CONCAT(`{$tabla}`.`Nombre`, ' ',
  27. `{$tabla}`.`Apell1`, ' ',
  28. `{$tabla}`.`Apell2`) AS `nombre`";
  29. $cumple = "`{$tabla}`.`FechNac`";
  30. $id = FALSE;
  31. break;
  32. default:return FALSE;
  33. break;
  34. }
  35. $orden = " ";
  36. if(date("m")==12)
  37. $orden = " DESC ";
  38. $sql = "SELECT ";
  39. if($id)
  40. $sql .= "`clientes`.`id`,`clientes`.`Nombre`,";
  41. else
  42. $sql .= "0 AS id, 'Centro' as Nombre, ";
  43. $sql .= "{$nombre},
  44. DATE_FORMAT( {$cumple}, '%d-%m' ) AS cumple
  45. FROM ";
  46. if($id)
  47. $sql .= "`clientes` INNER JOIN {$tabla}
  48. ON `clientes`.`Id` = {$id} ";
  49. else
  50. $sql .= "{$tabla} ";
  51. $sql .= "WHERE (
  52. DAY({$cumple}) >= DAY(CURDATE())
  53. AND
  54. MONTH({$cumple}) LIKE MONTH(CURDATE())
  55. OR
  56. MONTH({$cumple})
  57. LIKE MONTH(DATE_ADD(CURDATE(), INTERVAL 1 MONTH))
  58. ) ";
  59. if($id)
  60. $sql .= "AND `clientes`.`Estado_de_cliente` != 0 ";
  61. $sql.=" ORDER BY MONTH({$cumple}) {$orden}, DAY({$cumple}) ";
  62. parent::consulta($sql);
  63. $this->_month[] = parent::datos();
  64. }
  65. $this->close();
  66. $i=0;
  67. $mes = 0;
  68. $anyo = 0;
  69. foreach($this->_month as $dia){
  70. if(count($dia)>=1){
  71. foreach($dia as $datos){
  72. if(count($datos)!=0){
  73. $partfecha = explode("-",$datos['cumple']);
  74. if($mes!= $partfecha[1]){
  75. if($partfecha[1]< $mes){
  76. $anyo = 1;
  77. }
  78. $mes == $partfecha[1];
  79. }
  80. $dia =
  81. mktime(0, 0, 0, $partfecha[1] , $partfecha[0], date("Y")+$anyo);
  82. $registros[] = array(
  83. 'stamp'=>$dia,
  84. 'id'=>$datos['id'],
  85. 'empresa'=> utf8_encode($datos['Nombre']),
  86. 'nombre' => utf8_encode($datos['nombre']),
  87. 'cumple' => $datos['cumple']);
  88. }
  89. }
  90. }
  91. }
  92. array_multisort($registros);
  93. return $registros;
  94. }
  95. function close(){
  96. parent::close();
  97. }
  98. }
  99. ?>