/** * Manages all models. */ public function actionAdmin() { $model = new Departamento('search'); $model->unsetAttributes(); // clear any default values if (isset($_GET['Departamento'])) { $model->attributes = $_GET['Departamento']; } $this->render('admin', array('model' => $model)); }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); $model->fecha = Tools::backFecha($model->fecha); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Egreso'])) { $model->attributes = $_POST['Egreso']; $model->fecha = Tools::fixFecha($model->fecha); $propiedad = null; if ($model->centroCosto != null) { $ok = $model->validate(); if ($model->centroCosto->carga_a == '1') { $propiedad = Propiedad::model()->findByPk($model->propiedad_id); if ($propiedad == null) { $model->addError("propiedad_id", "Propiedad no puede ser nulo."); $ok = false; } } if ($ok) { if ($model->save()) { EgresoPropiedad::model()->deleteAllByAttributes(array('egreso_id' => $model->id)); if ($model->centroCosto->carga_a == '1') { $egPro = new EgresoPropiedad(); $egPro->egreso_id = $model->id; $egPro->propiedad_id = $model->propiedad_id; $egPro->save(); } if ($model->centroCosto->carga_a == '2') { if (isset($_POST['chbDepartamentoId'])) { $cant_deptos = count($_POST['chbDepartamentoId']); if ($cant_deptos > 0) { EgresoDepartamento::model()->deleteAllByAttributes(array('egreso_id' => $model->id)); foreach ($_POST['chbDepartamentoId'] as $i => $departamento) { $egDpto = new EgresoDepartamento(); $egDpto->departamento_id = $departamento; $egDpto->egreso_id = $model->id; if ($egDpto->validate()) { $egDpto->save(); } } } } } $this->redirect(array('admin')); } else { Yii::app()->user->setFlash('error', CHtml::errorSummary($model)); } } else { Yii::app()->user->setFlash('error', CHtml::errorSummary($model)); } } else { Yii::app()->user->setFlash('error', 'ERROR: Centro de costo no puede ser nulo.'); } $model->fecha = Tools::backFecha($model->fecha); } $conceptos = ConceptoPredefinido::model()->findAll(); $cptos = array(); foreach ($conceptos as $concepto) { $cptos[] = $concepto->nombre; } $deptos = new Departamento('search'); $deptos->unsetAttributes(); if (isset($_GET['Departamento'])) { $deptos->attributes = $_GET['Departamento']; } $this->render('update', array('model' => $model, 'conceptos' => $cptos, 'departamentos' => $deptos)); }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); $model->fecha = Tools::backFecha($model->fecha); $deptos = new Departamento('search'); $deptos->unsetAttributes(); if (isset($_GET['Departamento'])) { $deptos->attributes = $_GET['Departamento']; } // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Prestacion'])) { $model->attributes = $_POST['Prestacion']; $model->fecha = Tools::fixFecha($model->fecha); if ($model->save()) { $movimientosPrestacion = PrestacionGeneraMovimiento::model()->findAllByAttributes(array('prestacion_id' => $model->id)); foreach ($movimientosPrestacion as $mov) { $movimiento = $mov->movimiento; if ($movimiento->tipo == Tools::MOVIMIENTO_TIPO_CARGO) { $movimiento->actualizaSaldosPosteriores($movimiento->monto); } $mov->delete(); $movimiento->delete(); } PrestacionADepartamento::model()->deleteAllByAttributes(array('prestacion_id' => $model->id)); if (isset($_POST['chbDepartamentoId']) && !$model->general_prop) { $cant_deptos = count($_POST['chbDepartamentoId']); if ($cant_deptos != 0) { $monto = (int) $model->monto / $cant_deptos; } foreach ($_POST['chbDepartamentoId'] as $i => $departamento) { $prest_depto = new PrestacionADepartamento(); $prest_depto->departamento_id = $departamento; $prest_depto->prestacion_id = $model->id; if ($prest_depto->validate()) { $prest_depto->save(); } if ($model->genera_cargos == "1") { $cargo = new Movimiento(); $contrato = Contrato::model()->findByAttributes(array('departamento_id' => $departamento, 'vigente' => 1)); if ($contrato != null) { if ($contrato->vigente) { $cargo->cuenta_corriente_id = $contrato->cuentaCorriente->id; } else { continue; } } else { continue; } $cargo->fecha = $model->fecha; $cargo->tipo = Tools::MOVIMIENTO_TIPO_CARGO; $cargo->monto = $monto; $cargo->detalle = "PRESTACIÓN REALIZADA: " . $model->descripcion; $cargo->validado = 1; $cargo->saldo_cuenta = $cargo->ultimoSaldo(); $cargo->save(); $cargo->actualizaSaldosPosteriores(-$monto); $prestacionMovimiento = new PrestacionGeneraMovimiento(); $prestacionMovimiento->prestacion_id = $model->id; $prestacionMovimiento->movimiento_id = $cargo->id; $prestacionMovimiento->save(); } } } if ($model->general_prop) { if ($model->genera_cargos == "1") { //se crean los cargos para los deptos $departamentos = Departamento::model()->getVigentesDePropiedad($model->propiedad_id); $cant_deptos = count($departamentos); if ($cant_deptos != 0) { $monto = (int) $model->monto / $cant_deptos; foreach ($departamentos as $depto) { $cargo = new Movimiento(); if ($depto->contrato != null) { if ($depto->contrato->vigente) { $cargo->cuenta_corriente_id = $depto->contrato->cuentaCorriente->id; } else { continue; } } else { continue; } $cargo->fecha = $model->fecha; $cargo->tipo = Tools::MOVIMIENTO_TIPO_CARGO; $cargo->monto = $monto; $cargo->detalle = "PRESTACIÓN REALIZADA: " . $model->descripcion; $cargo->validado = 1; $cargo->saldo_cuenta = $cargo->ultimoSaldo(); $cargo->save(); $cargo->actualizaSaldosPosteriores(-$monto); $prestacionMovimiento = new PrestacionGeneraMovimiento(); $prestacionMovimiento->prestacion_id = $model->id; $prestacionMovimiento->movimiento_id = $cargo->id; $prestacionMovimiento->save(); } } } } $this->redirect(array('view', 'id' => $model->id)); } } $this->render('update', array('model' => $model, 'departamentos' => $deptos)); }