public function consultarPrecios($fecha)
 {
     $query = new \yii\db\Query();
     $query->select('Producto,Fecha,Tipo,AVG(Pond_Suma) as Pond_Suma')->from('alhondigas')->where('Tipo=:tipo and Fecha=:fecha', array(':tipo' => 'Precios', ':fecha' => $fecha))->groupBy('Producto');
     $rows = $query->all(AlhondigasPreciosPonderados::getDb());
     return $rows;
 }
示例#2
0
 /**
  * Se encarga de gestion de datos para las diferentes graficas y tablas 
  * de precios ponderados y toneladas, consultando los valores del dia actual
  * o segun parametros introducidos por los diferentes formularios que corresponden.
  * 
  * @return type 
  */
 public function actionPreciosponderados()
 {
     if (!\Yii::$app->user->isGuest) {
         //Iniciamos instancia con el modelo
         $alhondigasppModels = new AlhondigasPreciosPonderados();
         // Leemos la petición POST/GET
         $request = yii::$app->request;
         //$fecha_actual2 = date('Y-m-d');
         //Si recibe pararemos busca datos segun los mismos,
         //En caso de no recibir busca segun la fecha actual
         if (count($request->queryParams) != 0) {
             $fecha_actual = $request->get('datetimepicker2');
             $empresas = $request->get('empresas');
             $productos = $request->get('productos');
             $sd = $request->get('sd');
             $fechafin = $request->get('datetimepicker-2');
             $fechainicio = $request->get('datetimepicker-3');
             //COMPARADOR PRECIOS Y TONELADAS PP
             if ($fecha_actual != "") {
                 $ayer = $alhondigasppModels->leerDiaAnterior($fecha_actual);
                 $ayer = $ayer[0]['Fecha'];
                 $ToneladasAyer = $alhondigasppModels->consultarToneladas($ayer);
                 $PreciosAyer = $alhondigasppModels->consultarPrecios($ayer);
                 $ToneladasHoy = $alhondigasppModels->consultarToneladas($fecha_actual);
                 $PreciosHoy = $alhondigasppModels->consultarPrecios($fecha_actual);
                 $compararPrecios = array();
                 $compararToneladas = array();
                 for ($x = 0; $x < 13; $x++) {
                     if (isset($PreciosAyer[$x]['Pond_Suma']) && isset($PreciosHoy[$x]['Pond_Suma'])) {
                         if ($PreciosAyer[$x]['Pond_Suma'] < $PreciosHoy[$x]['Pond_Suma']) {
                             $compararPrecios[$x] = "<img class='flechas' src='/images/flechaVerde.png'/>";
                         } else {
                             if ($PreciosAyer[$x]['Pond_Suma'] > $PreciosHoy[$x]['Pond_Suma']) {
                                 $compararPrecios[$x] = "<img class='flechas' src='/images/flechaRoja.png'/>";
                             } else {
                                 $compararPrecios[$x] = "<img class='flechas' src='/images/igual.png'/>";
                             }
                         }
                     } else {
                         $compararPrecios[$x] = "";
                     }
                     if (isset($ToneladasAyer[$x]['Pond_Suma']) && isset($ToneladasHoy[$x]['Pond_Suma'])) {
                         if ($ToneladasAyer[$x]['Pond_Suma'] < $ToneladasHoy[$x]['Pond_Suma']) {
                             $compararToneladas[$x] = "<img class='flechas' src='/images/flechaVerde.png'/>";
                         } else {
                             if ($ToneladasAyer[$x]['Pond_Suma'] > $ToneladasHoy[$x]['Pond_Suma']) {
                                 $compararToneladas[$x] = "<img class='flechas' src='/images/flechaRoja.png'/>";
                             } else {
                                 $compararToneladas[$x] = "<img class='flechas' src='/images/igual.png'/>";
                             }
                         }
                     } else {
                         $compararPrecios[$x] = "";
                     }
                 }
             } else {
                 $compararPrecios = array();
                 $compararToneladas = array();
             }
             //
             $resultado = $alhondigasppModels->laUnion($fecha_actual);
             $resultado2 = $alhondigasppModels->casi($fecha_actual);
             $resultado3 = $alhondigasppModels->costa($fecha_actual);
             $resultado4 = $alhondigasppModels->femago($fecha_actual);
             $resultado5 = $alhondigasppModels->agroponiente($fecha_actual);
             $grafico1 = $alhondigasppModels->graficoPpt($fecha_actual);
             $grafico2 = $alhondigasppModels->graficoEvolucion($productos, $empresas, $sd, $fechafin, $fechainicio);
             return $this->render('preciosponderados', ['tablaLaunion' => $resultado, 'tablaCasi' => $resultado2, 'tablaCosta' => $resultado3, 'tablaFemago' => $resultado4, 'tablaAgroponiente' => $resultado5, 'tablaGraficoppt' => $grafico1, 'tablaGraficoevolucion' => $grafico2, 'tablaCompararToneladas' => $compararToneladas, 'tablaCompararPrecios' => $compararPrecios]);
         } else {
             //CODIGO PARA MOSTRAR DATOS DEL DIA ANTERIOR
             /*$fecha_actual2 = date('Y-m-d');
               if(date("l")=="Monday"){
                   $fecha_actual = date('Y-m-d', strtotime('-2 day', strtotime($fecha_actual2)));
               }else{
                   $fecha_actual = date('Y-m-d', strtotime('-1 day', strtotime($fecha_actual2)));
               }*/
             //CODIGO PARA MOSTRAR DASTOS DEL ULTIMO DIA DISPONIBLE
             $fecha_actual = $alhondigasppModels->leerUltimoDia();
             $fecha_actual = $fecha_actual[0]['Fecha'];
             //COMPARADOR PRECIOS Y TONELADAS PP
             $ayer = $alhondigasppModels->leerDiaAnterior($fecha_actual);
             $ayer = $ayer[0]['Fecha'];
             $ToneladasAyer = $alhondigasppModels->consultarToneladas($ayer);
             $PreciosAyer = $alhondigasppModels->consultarPrecios($ayer);
             $ToneladasHoy = $alhondigasppModels->consultarToneladas($fecha_actual);
             $PreciosHoy = $alhondigasppModels->consultarPrecios($fecha_actual);
             $compararPrecios = array();
             $compararToneladas = array();
             for ($x = 0; $x < 13; $x++) {
                 if (isset($PreciosAyer[$x]['Pond_Suma']) && isset($PreciosHoy[$x]['Pond_Suma'])) {
                     if ($PreciosAyer[$x]['Pond_Suma'] < $PreciosHoy[$x]['Pond_Suma']) {
                         $compararPrecios[$x] = "<img class='flechas' src='/images/flechaVerde.png'/>";
                     } else {
                         if ($PreciosAyer[$x]['Pond_Suma'] > $PreciosHoy[$x]['Pond_Suma']) {
                             $compararPrecios[$x] = "<img class='flechas' src='/images/flechaRoja.png'/>";
                         } else {
                             $compararPrecios[$x] = "<img class='flechas' src='/images/igual.png'/>";
                         }
                     }
                 } else {
                     $compararPrecios[$x] = "";
                 }
                 if (isset($ToneladasAyer[$x]['Pond_Suma']) && isset($ToneladasHoy[$x]['Pond_Suma'])) {
                     if ($ToneladasAyer[$x]['Pond_Suma'] < $ToneladasHoy[$x]['Pond_Suma']) {
                         $compararToneladas[$x] = "<img class='flechas' src='/images/flechaVerde.png'/>";
                     } else {
                         if ($ToneladasAyer[$x]['Pond_Suma'] > $ToneladasHoy[$x]['Pond_Suma']) {
                             $compararToneladas[$x] = "<img class='flechas' src='/images/flechaRoja.png'/>";
                         } else {
                             $compararToneladas[$x] = "<img class='flechas' src='/images/igual.png'/>";
                         }
                     }
                 } else {
                     $compararPrecios[$x] = "";
                 }
             }
             //
             $resultado = $alhondigasppModels->laUnion($fecha_actual);
             $resultado2 = $alhondigasppModels->casi($fecha_actual);
             $resultado3 = $alhondigasppModels->costa($fecha_actual);
             $resultado4 = $alhondigasppModels->femago($fecha_actual);
             $resultado5 = $alhondigasppModels->agroponiente($fecha_actual);
             $grafico1 = $alhondigasppModels->graficoPpt($fecha_actual);
             return $this->render('preciosponderados', ['tablaLaunion' => $resultado, 'tablaCasi' => $resultado2, 'tablaCosta' => $resultado3, 'tablaFemago' => $resultado4, 'tablaAgroponiente' => $resultado5, 'tablaGraficoppt' => $grafico1, 'tablaCompararToneladas' => $compararToneladas, 'tablaCompararPrecios' => $compararPrecios]);
         }
     } else {
         return $this->goHome();
     }
 }