public function execute()
 {
     try {
         $where = null;
         //            $idAnimal = request::getInstance()->getRequest(animalTableClass::ID);
         if (request::getInstance()->hasRequest('filter')) {
             $report = request::getInstance()->getPost('filter');
             if (isset($report['numero']) and $report['numero'] !== null and $report['numero'] !== '') {
                 $where[animalTableClass::getNameTable() . '.' . animalTableClass::ID] = $report['numero'];
             }
             //close if
             if (isset($report['lote']) and $report['lote'] !== null and $report['lote'] !== '') {
                 $where[animalTableClass::getNameTable() . '.' . animalTableClass::LOTE_ID] = $report['lote'];
             }
             //close if
         }
         //close if
         $fieldsAnimal = array(animalTableClass::ID, animalTableClass::NUMERO, animalTableClass::LOTE_ID);
         $fieldsLote = array(loteTableClass::NOMBRE);
         $fJoin1 = animalTableClass::LOTE_ID;
         $fJoin2 = loteTableClass::ID;
         //            print_r($where);
         //echo 12;
         //        exit();
         $this->objAnimal = animalTableClass::getAllJoin($fieldsAnimal, $fieldsLote, null, null, $fJoin1, $fJoin2, null, null, null, null, true, null, null, null, null, $where);
         $this->mensajeDetalle = "Inventario de Cerdos por Lote";
         log::register(i18n::__('reporte'), animalTableClass::getNameTable());
         $this->defineView('reportDetalle', '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');
     }
 }
 public function execute()
 {
     try {
         $where = null;
         if (session::getInstance()->hasAttribute('animalFiltersAnimal')) {
             $where = session::getInstance()->getAttribute('animalFiltersAnimal');
         }
         if (request::getInstance()->hasPost('report')) {
             $report = request::getInstance()->getPost('report');
             //
             if (isset($report['edad_inicial']) and $report['edad_inicial'] !== null and $report['edad_inicial'] !== '' and isset($report['edad_fin']) and $report['edad_fin'] !== null and $report['edad_fin'] !== '') {
                 $edad_inicial = validate::getInstance()->validateCharactersNumber($report['edad_inicial']);
                 $edad_fin = validate::getInstance()->validateCharactersNumber($report['edad_fin']);
                 /* echo ($edad_inicial) ? 'verdadero' : 'falso';
                    exit(); */
                 if ($edad_inicial == true or $edad_fin == true) {
                     throw new PDOException(i18n::__(10007, null, 'errors'));
                 }
                 $where[animalTableClass::EDAD] = array($report['edad_inicial'], $report['edad_fin']);
             }
             if (isset($report['peso_inicial']) and $report['peso_inicial'] !== null and $report['peso_inicial'] !== '' and isset($report['peso_fin']) and $report['peso_fin'] !== null and $report['peso_fin'] !== '') {
                 $peso_inicial = validate::getInstance()->validateCharactersNumber($report['peso_inicial']);
                 $peso_fin = validate::getInstance()->validateCharactersNumber($report['peso_fin']);
                 if ($edad_inicial == true or $edad_fin == true) {
                     throw new PDOException(i18n::__(10007, null, 'errors'));
                 }
                 $where[animalTableClass::PESO] = array($report['peso_inicial'], $report['peso_fin']);
             }
             if (isset($report['fecha_inicial']) and $report['fecha_inicial'] !== null and $report['fecha_inicial'] !== '' and isset($report['fecha_fin']) and $report['fecha_fin'] !== null and $report['fecha_fin'] !== '') {
                 $fecha_inicial = validate::getInstance()->validateDate($filter['fecha_inicial']);
                 $fecha_fin = validate::getInstance()->validateDate($filter['fecha_fin']);
                 if ($fecha_inicial == false or $fecha_fin == false) {
                     throw new PDOException(i18n::__(10008, null, 'errors'));
                 }
                 $where[animalTableClass::FECHA_INGRESO] = array(date(config::getFormatTimestamp(), strtotime($report['fecha_inicial'])), date(config::getFormatTimestamp(), strtotime($report['fecha_fin'])));
             }
             if (isset($report['genero']) and $report['genero'] !== null and $report['genero'] !== '' and $report['genero'] !== "default") {
                 $genero = validate::getInstance()->validateCharactersNumber($report['genero']);
                 if ($genero == true) {
                     throw new PDOException(i18n::__(10007, null, 'errors'));
                 }
                 $where[animalTableClass::GENERO_ID] = $report['genero'];
             }
             if (isset($report['lote']) and $report['lote'] !== null and $report['lote'] !== '' and $report['lote'] !== "default") {
                 $lote = validate::getInstance()->validateCharactersNumber($report['lote']);
                 if ($lote == true) {
                     throw new PDOException(i18n::__(10007, null, 'errors'));
                 }
                 $where[animalTableClass::LOTE_ID] = $report['lote'];
             }
             if (isset($report['raza']) and $report['raza'] !== null and $report['raza'] !== '' and $report['raza'] !== "default") {
                 $raza = validate::getInstance()->validateCharactersNumber($report['raza']);
                 if ($raza == true) {
                     throw new PDOException(i18n::__(10007, null, 'errors'));
                 }
                 $where[animalTableClass::RAZA] = $report['raza'];
             }
         }
         $fields = array(animalTableClass::ID, animalTableClass::PESO, animalTableClass::PRECIO_ANIMAL, animalTableClass::FECHA_NACIMIENTO, animalTableClass::NUMERO, animalTableClass::PRECIO_ANIMAL, animalTableClass::FECHA_NACIMIENTO, animalTableClass::PARTO);
         $fields2 = array(generoTableClass::NOMBRE);
         $fields3 = array(loteTableClass::NOMBRE);
         $fields4 = array(razaTableClass::NOMBRE_RAZA);
         $fJoin1 = animalTableClass::GENERO_ID;
         $fJoin2 = generoTableClass::ID;
         $fJoin3 = animalTableClass::LOTE_ID;
         $fJoin4 = loteTableClass::ID;
         $fJoin5 = animalTableClass::RAZA;
         $fJoin6 = razaTableClass::ID;
         $orderBy = array(animalTableClass::ID);
         $this->objAnimal = animalTableClass::getAllJoin($fields, $fields2, $fields3, $fields4, $fJoin1, $fJoin2, $fJoin3, $fJoin4, $fJoin5, $fJoin6, true, $orderBy, 'ASC', null, null, $where);
         $this->mensaje = 'Informe de Cerdos en Nuestro Sistema';
         $this->defineView('index', 'animal', session::getInstance()->getFormatOutput());
     } catch (PDOException $exc) {
         session::getInstance()->setFlash('exc', $exc);
         routing::getInstance()->forward('shfSecurity', 'exception');
     }
 }