public function execute()
 {
     try {
         //                $where[hojaVidaTableClass::ANIMAL] = $idAnimal;
         //                  $where = array(
         //                      hojaVidaTableClass::ANIMAL => $idAnimal
         //                );
         $idAnimal = request::getInstance()->getGet(animalTableClass::ID);
         $fieldsAnimal = array(animalTableClass::ID, animalTableClass::NUMERO);
         $fieldsGenero = array(generoTableClass::ID, generoTableClass::NOMBRE);
         $fieldsRaza = array(razaTableClass::ID, razaTableClass::NOMBRE_RAZA);
         $fields = array(hojaVidaTableClass::ID, hojaVidaTableClass::ANIMAL, hojaVidaTableClass::FECHA_NACIMIENTO, hojaVidaTableClass::GENERO_ID, hojaVidaTableClass::PESO, hojaVidaTableClass::RAZA, hojaVidaTableClass::PARTO);
         $fields1 = array(animalTableClass::NUMERO);
         $fields2 = array(generoTableClass::NOMBRE);
         $fields3 = array(razaTableClass::NOMBRE_RAZA);
         $fJoin1 = hojaVidaTableClass::ANIMAL;
         $fJoin2 = animalTableClass::ID;
         $fJoin3 = hojaVidaTableClass::GENERO_ID;
         $fJoin4 = generoTableClass::ID;
         $fJoin5 = hojaVidaTableClass::RAZA;
         $fJoin6 = razaTableClass::ID;
         $whereAnimal = array(hojaVidaTableClass::ANIMAL => $idAnimal);
         //            $orderBy = array(
         //                hojaVidaTableClass::FECHA_NACIMIENTO
         //            );
         $page = 0;
         if (request::getInstance()->hasGet('page')) {
             $page = request::getInstance()->getGet('page') - 1;
             $page = $page * config::getRowGrid();
         }
         $f = array(hojaVidaTableClass::ID);
         //             $whereAnimal = array(
         //             animalTableClass::getNameTable() . '.' . animalTableClass::NUMERO => $idAnimal
         //                     );
         if (request::getInstance()->hasGet('page')) {
             $this->page = request::getInstance()->getGet('page');
         } else {
             $this->page = $page;
         }
         $lines = config::getRowGrid();
         $this->cntPages = animalTableClass::getAllCount($f, true, $lines);
         // $this->page = request::getInstance()->getGet('page');
         $this->objHojaVida = hojaVidaTableClass::getAllJoin($fields, $fields1, $fields2, $fields3, $fJoin1, $fJoin2, $fJoin3, $fJoin4, $fJoin5, $fJoin6, true, null, null, null, null, $whereAnimal);
         $this->objAnimal = animalTableClass::getAll($fieldsAnimal, true);
         $this->objGenero = generoTableClass::getAll($fieldsGenero, false);
         $this->objRaza = razaTableClass::getAll($fieldsRaza, false);
         $this->defineView('hojadevida', 'animal', session::getInstance()->getFormatOutput());
     } catch (PDOException $exc) {
         session::getInstance()->setFlash('exc', $exc);
         routing::getInstance()->forward('shfSecurity', 'exception');
     }
 }
 public function execute()
 {
     try {
         $fieldsGenero = array(generoTableClass::ID, generoTableClass::NOMBRE);
         $fieldsRaza = array(razaTableClass::ID, razaTableClass::NOMBRE_RAZA);
         $this->objGenero = generoTableClass::getAll($fieldsGenero);
         $this->objRaza = razaTableClass::getAll($fieldsRaza);
         $this->defineView('index', 'animal', session::getInstance()->getFormatOutput());
     } catch (PDOException $exc) {
         session::getInstance()->setFlash('exc', $exc);
         routing::getInstance()->forward('shfSecurity', 'exception');
     }
 }
 public function execute()
 {
     try {
         $where = null;
         if (request::getInstance()->hasPost('filter')) {
             $filter = request::getInstance()->getPost('filter');
             if (isset($filter['numero']) and $filter['numero'] !== null and $filter['numero'] !== '') {
                 $where[animalTableClass::NUMERO] = $filter['numero'];
             }
             if (isset($filter['lote']) and $filter['lote'] !== null and $filter['lote'] !== '') {
                 $where[animalTableClass::LOTE_ID] = $filter['lote'];
             }
             session::getInstance()->setAttribute('animalFiltersAnimal', $where);
         } elseif (session::getInstance()->hasAttribute('animalFiltersAnimal')) {
             $where = session::getInstance()->getAttribute('animalFiltersAnimal');
         }
         $fieldsGestacion = array(gestacionTableClass::ID, gestacionTableClass::ANIMAL, gestacionTableClass::FECHA);
         $objGestacion = gestacionTableClass::getAll($fieldsGestacion, false);
         foreach ($objGestacion as $key) {
             $segundos = strtotime($key->fecha) - strtotime('now');
             $diferencia_dias = intval($segundos / 60 / 60 / 24);
             $diferencia_dias = $diferencia_dias * -1;
             if ($diferencia_dias > 116) {
                 session::getInstance()->setWarning("A la cerda " . $key->animal . " no se le ha realizado el registro de parto");
             }
         }
         //            print_r($objGestacion);
         //            exit();
         $fields = array(animalTableClass::ID, animalTableClass::NUMERO, animalTableClass::LOTE_ID);
         $fieldsLote = array(loteTableClass::ID, loteTableClass::NOMBRE);
         $fields3 = array(loteTableClass::NOMBRE);
         $fieldsHojaVida = array(hojaVidaTableClass::ID, hojaVidaTableClass::ANIMAL, hojaVidaTableClass::FECHA_NACIMIENTO, hojaVidaTableClass::PARTO, hojaVidaTableClass::GENERO_ID, hojaVidaTableClass::RAZA, hojaVidaTableClass::PESO);
         $fieldsGenero = array(generoTableClass::ID, generoTableClass::NOMBRE);
         $fieldsRaza = array(razaTableClass::ID, razaTableClass::NOMBRE_RAZA);
         $fJoin1 = animalTableClass::LOTE_ID;
         $fJoin2 = loteTableClass::ID;
         $fJoin3 = animalTableClass::NUMERO;
         $fJoin4 = hojaVidaTableClass::NUMERO;
         $orderBy = array(animalTableClass::NUMERO);
         $page = 0;
         if (request::getInstance()->hasGet('page')) {
             $page = request::getInstance()->getGet('page') - 1;
             $page = $page * config::getRowGrid();
         }
         $f = array(animalTableClass::ID);
         if (request::getInstance()->hasGet('page')) {
             $this->page = request::getInstance()->getGet('page');
         } else {
             $this->page = $page;
         }
         $objAnimal = animalTableClass::getAllJoin($fields, $fields3, $fieldsHojaVida, null, $fJoin1, $fJoin2, $fJoin3, $fJoin4, null, null, true, $orderBy, 'ASC', config::getRowGrid(), $page, $where);
         //metodo cambio de lote
         foreach ($objAnimal as $key) {
             $p = $key->peso_animal;
             $i = $key->numero_identificacion;
             $segundos = strtotime($key->fecha_nacimiento) - strtotime('now');
             $diferencia_dias = intval($segundos / 60 / 60 / 24);
             $diferencia_dias = $diferencia_dias * -1;
             $ids = array(animalTableClass::NUMERO => $i);
             if ($diferencia_dias >= 42) {
                 if ($p >= 25 and $p < 55) {
                     $dataLote = array(animalTableClass::LOTE_ID => 4);
                     animalTableClass::update($ids, $dataLote);
                 }
                 if ($p >= 55) {
                     $dataLote = array(animalTableClass::LOTE_ID => 5);
                     animalTableClass::update($ids, $dataLote);
                 }
                 if ($p >= 100) {
                     session::getInstance()->setInformation("El cerdo " . $key->numero_identificacion . " esta disponible para la venta");
                 }
             } else {
                 if ($diferencia_dias >= 21 and $diferencia_dias < 42) {
                     $dataLote = array(animalTableClass::LOTE_ID => 3);
                     animalTableClass::update($ids, $dataLote);
                 }
             }
         }
         $lines = config::getRowGrid();
         $this->cntPages = animalTableClass::getAllCount($f, true, $lines, $where);
         $this->objGenero = generoTableClass::getAll($fieldsGenero, false);
         $this->objRaza = razaTableClass::getAll($fieldsRaza, true);
         $this->objLote = loteTableClass::getAll($fieldsLote, true);
         $this->objFilterAnimal = animalTableClass::getAll($fields, true);
         $this->objAnimal = animalTableClass::getAllJoin($fields, $fields3, null, null, $fJoin1, $fJoin2, null, null, null, null, true, $orderBy, 'ASC', config::getRowGrid(), $page, $where);
         $this->objHojaVida = hojaVidaTableClass::getAll($fieldsHojaVida, true);
         $this->defineView('index', 'animal', session::getInstance()->getFormatOutput());
     } catch (PDOException $exc) {
         session::getInstance()->setFlash('exc', $exc);
         routing::getInstance()->forward('shfSecurity', 'exception');
     }
 }