function validarDisponibilidadIva($attribute, $params) { $ivaRegistrado = PresupuestoPartidas::model()->calcularIvaRegistrado(); $ivaFacturas = $this->calcularIvaFacturas(); $productoActual = $this->costo_unitario * $this->cantidad_adquirida * $this->iva->porcentaje / 100; if ($ivaRegistrado < $ivaFacturas + $productoActual) { $this->addError($attribute, 'No se puede agregar el producto. IVA disponible (' . number_format($ivaRegistrado - $ivaFacturas, 2, ',', '.') . ' Bs.) insuficiente.'); } }
public function partidaAsignada($attribute, $params) { $criteria = new CDbCriteria(); $usuario = Usuarios::model()->findByPk(Yii::app()->user->getId()); if ($this->nombre) { $accion = Acciones::model()->find('codigo=:codigo', array(':codigo' => $this->nombre)); $presupuestopartidaproyecto = PresupuestoPartidaAcciones::model()->findAll('accion_id=:accion_id and ente_organo_id=:ente_organo_id and anho=:anho', array(':accion_id' => $accion->accion_id, ':ente_organo_id' => $usuario->ente_organo_id, ':anho' => Yii::app()->params['trimestresFechas'][Yii::app()->session['trimestreSeleccionado']]['anho'])); foreach ($presupuestopartidaproyecto as $key => $value) { $value->presupuesto_partida_id; $partida = PresupuestoPartidas::model()->find('presupuesto_partida_id=:presupuesto_partida_id and ente_organo_id=:ente_organo_id and tipo=:tipo and anho=:anho', array(':ente_organo_id' => $usuario->ente_organo_id, ':presupuesto_partida_id' => $value->presupuesto_partida_id, ':tipo' => 'A', ':anho' => Yii::app()->params['trimestresFechas'][Yii::app()->session['trimestreSeleccionado']]['anho'])); if ($partida->partida_id == $this->{$attribute}) { $this->addError($attribute, 'Esta partida ya tiene asignado dinero para esta acción centralizada!'); //$partida = $attribute['especifica']; break; } } } //$criteria->condition = "ente_organo_id=".$usuario->ente_organo_id ; //$criteria->addSearchCondition('t.nombre', $this->nombre); //$criteria->compare('LOWER(nombre)',strtolower($this->nombre),true); }
/** * Displays a particular model. * @param integer $id the ID of the model to be displayed */ public function actionFilaProducto() { $model = new FacturasProductos(); //echo '<tr>'; $form = $this->beginWidget('booster.widgets.TbActiveForm', array('id' => 'facturas-productos-fila', 'enableAjaxValidation' => false)); //echo '<div id="retorno">'; echo '<td>'; echo '<div class="form-group">'; $list = CHtml::listData(PresupuestoPartidas::model()->findAllByAttributes(array('ente_organo_id' => Usuarios::model()->findByPk(Yii::app()->user->getId())->enteOrgano->ente_organo_id, 'anho' => Yii::app()->params['trimestresFechas'][Yii::app()->session['trimestreSeleccionado']]['anho'])), 'partida_id', function ($presuPartida) { return $presuPartida->partida->etiquetaPartida(); }); echo CHtml::label('Seleccionar partida', 'partida'); echo "<br>"; $this->widget('booster.widgets.TbSelect2', array('asDropDownList' => true, 'model' => $model, 'attribute' => 'presupuesto_partida_id', 'data' => $list, 'htmlOptions' => array('id' => 'partida', 'ajax' => array('type' => 'POST', 'url' => CController::createUrl('facturasProductos/buscarProductosPartida'), 'update' => '#producto')), 'options' => array('placeholder' => 'Partida', 'width' => '40%', 'tokenSeparators' => array(',', ' ')))); echo '</div>'; echo '</td>'; echo '<td>'; echo '<div class="form-group">'; echo CHtml::label('Seleccionar producto', 'producto'); echo "<br>"; $this->widget('booster.widgets.TbSelect2', array('asDropDownList' => true, 'model' => $model, 'attribute' => 'producto_id', 'data' => array(), 'htmlOptions' => array('id' => 'producto'), 'options' => array('placeholder' => 'Producto', 'width' => '40%', 'tokenSeparators' => array(',', ' ')))); echo '</div>'; echo '</td>'; echo '<td>'; echo $form->textFieldGroup($model, 'costo_unitario', array('widgetOptions' => array('htmlOptions' => array('class' => 'span5', 'maxlength' => 38)))); echo '</td>'; echo '<td>'; echo $form->textFieldGroup($model, 'cantidad_adquirida', array('widgetOptions' => array('htmlOptions' => array('class' => 'span5')))); echo '</td>'; echo '<td>'; $list = CHtml::listData(Iva::model()->findAll(), 'id', 'porcentaje'); echo $form->dropDownListGroup($model, 'iva_id', array('wrapperHtmlOptions' => array('class' => 'col-sm-5'), 'widgetOptions' => array('data' => $list, 'htmlOptions' => array()))); echo '</td>'; echo '</div>'; $this->endWidget(); //echo '</tr>'; }
public function actionAsignarpartidasproyecto() { $model = new Proyectos('creaproyecto'); $usuario = Usuarios::model()->findByPk(Yii::app()->user->getId()); //$model->ente_organo_id = $usuario->ente_organo_id; $criteria = new CDbCriteria(); $criteria->condition = "activo=true"; $fuentes = FuentesFinanciamiento::model()->findAll($criteria); $fuentesSel[] = new FuentePresupuesto(); $partidas_principal = $this->obtenerPartidas("*"); $proyectos = $usuario->enteOrgano->proyectos; if (isset($_POST['Proyectos'])) { $model->attributes = $_POST['Proyectos']; $model->subespecifica = $_POST['Proyectos']['subespecifica']; $model->ente_organo_id = $usuario->ente_organo_id; $model->codigo = $model->nombreid; $fuente_ids = $_POST['f']['fuente_id']; $montos = $_POST['f']['monto']; if (count($fuente_ids) == count($montos)) { $cantidad = count($fuente_ids); for ($i = 0; $i < $cantidad; $i++) { $fuentePresu = new FuentePresupuesto(); $fuentePresu->fuente_id = $fuente_ids[$i]; $fuentePresu->monto = $montos[$i]; $fuentesSel[$i] = $fuentePresu; } } $verificar = true; foreach ($fuentesSel as $key => $fuentep) { $verificar = $fuentep->validate() && $verificar; } $nombre_proyecto = Proyectos::model()->find('codigo=:codigo and ente_organo_id=:ente_organo_id and anho=:anho', array(':codigo' => $model->codigo, ':ente_organo_id' => $usuario->ente_organo_id, ':anho' => Yii::app()->params['trimestresFechas'][Yii::app()->session['trimestreSeleccionado']]['anho'])); $model->nombre = $nombre_proyecto->nombre; $model->setScenario(!empty($model->subespecifica) ? 'creaproyectose' : 'creaproyecto'); /*CVarDumper::dump($model); //Yii::app()->end();*/ if ($model->validate() && $verificar) { $presupuesto_partida = new PresupuestoPartidas(); $presupuesto_partida_proyecto = new PresupuestoPartidaProyecto(); $presupuesto_partida->partida_id = !empty($model->subespecifica) ? $model->subespecifica : $model->especifica; $presupuesto_partida->monto_presupuestado = 200; //$model->monto; //aqui va la suma de todos los montos. $presupuesto_partida->fecha_desde = "1900-01-01"; $presupuesto_partida->fecha_hasta = "2199-12-31"; $presupuesto_partida->tipo = "P"; $presupuesto_partida->anho = Yii::app()->params['trimestresFechas'][Yii::app()->session['trimestreSeleccionado']]['anho']; //date("Y"); $presupuesto_partida->ente_organo_id = $usuario->ente_organo_id; //$presupuesto_partida->fuente_fianciamiento_id = $model->fuente; $presupuesto_partida_proyecto->setScenario($model->scenario); $transaction = $presupuesto_partida->dbConnection->beginTransaction(); // Transaction begin //Yii::app()->db->beginTransaction try { if ($presupuesto_partida->save() && $verificar) { $verificar = true; $monto_total = 0; //$cont = count($fuentesSel); //aqui realmente es que tiene que ir. foreach ($fuentesSel as $key => $fuentep) { $fuentep->presupuesto_partida_id = $presupuesto_partida->presupuesto_partida_id; $monto_total += $fuentep->monto; $verificar = $fuentep->save() && $verificar; } //$accion = Acciones::model()->find('codigo=:codigo', array(':codigo'=>$model->nombre)); $presupuesto_partida_proyecto->presupuesto_partida_id = $presupuesto_partida->presupuesto_partida_id; $presupuesto_partida_proyecto->proyecto_id = $nombre_proyecto->proyecto_id; if ($presupuesto_partida_proyecto->save() && $verificar) { $actualizar_presupuesto_partida = PresupuestoPartidas::model()->findByPk($presupuesto_partida->presupuesto_partida_id); $actualizar_presupuesto_partida->monto_presupuestado = $monto_total; $actualizar_presupuesto_partida->save(array('monto_presupuestado')); $transaction->commit(); // committing Yii::app()->user->setFlash('success', 'Partida asignada con éxito!'); $model = new Proyectos('creaproyecto'); unset($fuentesSel); // borramos el arreglo para mandarlo limpio a la vista. $fuentesSel[] = new FuentePresupuesto(); } else { throw new Exception("Error Processing Request", 1); } } else { throw new Exception("Error Processing Request", 1); } } catch (Exception $e) { Yii::app()->user->setFlash('error', "No se pudo guardar la asigacion de la partida."); $transaction->rollBack(); } } else { if ($model->partida) { $tipo = Partidas::model()->findByPk($model->partida); $generales = $this->GeneralXpartida($tipo->p1); $generales_todas = CHtml::listData($generales, function ($generales) { return CHtml::encode($generales->partida_id); }, function ($generales) { return CHtml::encode($generales->p1 . '-' . $generales->p2 . '-' . $generales->p3 . '- ' . $generales->nombre); }); if ($model->general) { $especificas_todas = $this->buscar_especifica($model->general); $this->render('asignarpartidasproyecto', array('model' => $model, 'fuentes' => $fuentes, 'generales_todas' => $generales_todas, 'partidas' => $partidas_principal, 'proyectos' => $proyectos, 'especificas_todas' => $especificas_todas, 'fuentesSel' => $fuentesSel)); Yii::app()->end(); } //Yii::app()->end(); $this->render('asignarpartidasproyecto', array('model' => $model, 'fuentes' => $fuentes, 'generales_todas' => $generales_todas, 'partidas' => $partidas_principal, 'proyectos' => $proyectos, 'fuentesSel' => $fuentesSel)); Yii::app()->end(); } } } $this->render('asignarpartidasproyecto', array('model' => $model, 'fuentes' => $fuentes, 'partidas' => $partidas_principal, 'proyectos' => $proyectos, 'fuentesSel' => $fuentesSel)); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = PresupuestoPartidas::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function partidaAsignada($attribute, $params) { $criteria = new CDbCriteria(); $usuario = Usuarios::model()->findByPk(Yii::app()->user->getId()); if ($this->nombreid) { $proyecto = Proyectos::model()->find('codigo=:codigo', array(':codigo' => $this->nombreid)); $presupuestopartidaproyecto = PresupuestoPartidaProyecto::model()->findAll('proyecto_id=:proyecto_id', array(':proyecto_id' => $proyecto->proyecto_id)); foreach ($presupuestopartidaproyecto as $key => $value) { $value->presupuesto_partida_id; if ($partida = PresupuestoPartidas::model()->find('presupuesto_partida_id=:presupuesto_partida_id and ente_organo_id=:ente_organo_id and tipo=:tipo', array(':ente_organo_id' => $usuario->ente_organo_id, ':presupuesto_partida_id' => $value->presupuesto_partida_id, ':tipo' => 'P'))) { if ($partida->partida_id == $this->{$attribute}) { $this->addError($attribute, 'Esta partida ya tiene asignado dinero para este proyecto!'); break; } } } } //$criteria->condition = "ente_organo_id=".$usuario->ente_organo_id ; //$criteria->addSearchCondition('t.nombre', $this->nombre); //$criteria->compare('LOWER(nombre)',strtolower($this->nombre),true); }