public function Loginventario() { $tiempo = time(); $dia = date('d'); $mes = date('m'); $ani = date('y'); $fecmax = Yii::app()->db->createCommand()->select('max(fecha)')->from('{{montoinventario}} a')->queryScalar(); $tiempoult = strtotime($fecmax . ''); if ($tiempo - $tiempoult > 60 * 60 * 24 * 3) { $alin = new Alinventario(); $stocks = $alin->getStockValAlmacen(); foreach ($stocks as $filastock) { $registro = new Montoinventario(); $registro->setAttributes(array('dia' => $dia, 'mes' => $mes, 'anno' => $ani, 'iduser' => Yii::app()->user->id, 'montolibre' => round($filastock['stock_cantlibre'], 0), 'montotran' => round($filastock['stock_canttran'], 0), 'montoreserva' => round($filastock['stock_cantreserva'], 0), 'montodif' => 0, 'montototal' => round($filastock['stock_total'], 2), 'codal' => $filastock['codalm'], 'codcen' => $filastock['codcen'], 'fecha' => date("Y-m-d"))); if (!$registro->save()) { print_r($registro->geterrors()); yii::app()->end(); } //$almacenes=Yii::app()->db->createCommand("SELECT *FROM public_almacenes ")->queryAll(); /*print_r($filastock); echo "<br>"; print_r($registro->attributes); echo "<br>"; print_r($registro->geterrors()); yii::app()->end();*/ } } }