/** * Updates an existing Po model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $countPoItems = PoItem::find()->where(['po_id' => $id])->count(); $modelsPoItem = PoItem::find()->where(['po_id' => $id])->all(); if ($model->load(Yii::$app->request->post())) { // $model->save(); $oldIDs = ArrayHelper::map($modelsPoItem, 'id', 'id'); $modelsPoItem = Model::createMultiple(PoItem::classname(), $modelsPoItem); Model::loadMultiple($modelsPoItem, Yii::$app->request->post()); $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsPoItem, 'id', 'id'))); // validate all models $valid = $model->validate(); $valid = Model::validateMultiple($modelsPoItem) && $valid; if ($valid) { $transaction = \Yii::$app->db->beginTransaction(); try { if ($flag = $model->save(false)) { if (!empty($deletedIDs)) { PoItem::deleteAll(['id' => $deletedIDs]); } foreach ($modelsPoItem as $modelPoItem) { $modelPoItem->po_id = $model->id; if (!($flag = $modelPoItem->save(false))) { $transaction->rollBack(); break; } } } if ($flag) { $transaction->commit(); return $this->redirect(['view', 'id' => $model->id]); } } catch (Exception $e) { $transaction->rollBack(); } } return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'modelsPoItem' => $modelsPoItem]); } }
/** * Creates a new Prerrequisito model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Prerrequisito(); $modelsDetallepre = [new Detallepre()]; if ($model->load(Yii::$app->request->post()) && $model->save()) { $modelsDetallepre = Model::createMultiple(Detallepre::classname()); Model::loadMultiple($modelsDetallepre, Yii::$app->request->post()); // validate all models $valid = $model->validate(); $valid = Model::validateMultiple($modelsDetallepre) && $valid; if ($valid) { $transaction = \Yii::$app->db->beginTransaction(); try { if ($flag = $model->save(false)) { foreach ($modelsDetallepre as $modelsDetallepre) { $modelsDetallepre->idPrerreq = $model->idPrerreq; if (!($flag = $modelsDetallepre->save(false))) { $transaction->rollBack(); break; } } } if ($flag) { $transaction->commit(); return $this->redirect(['view', 'id' => $model->idPrerreq]); } } catch (Exception $e) { $transaction->rollBack(); } } return $this->redirect(['view', 'id' => $model->idPrerreq]); } else { return $this->render('create', ['model' => $model, 'modelsDetallepre' => empty($modelsDetallepre) ? [new Detallepre()] : $modelsDetallepre]); } }
public function actionCreate() { $model = new Po(); $modelsPoItem = [new PoItem()]; if ($model->load(Yii::$app->request->post()) && $model->save()) { $modelsPoItem = Model::createMultiple(PoItem::classname()); Model::loadMultiple($modelsPoItem, Yii::$app->request->post()); // validate all models $valid = $model->validate(); $valid = Model::validateMultiple($modelsPoItem) && $valid; if ($valid) { $transaction = \Yii::$app->db->beginTransaction(); try { if ($flag = $model->save(false)) { foreach ($modelsPoItem as $modelPoItem) { $modelPoItem->po_id = $model->id; if (!($flag = $modelPoItem->save(false))) { $transaction->rollBack(); break; } } } if ($flag) { $transaction->commit(); return $this->redirect(['view', 'id' => $model->id]); } } catch (Exception $e) { $transaction->rollBack(); } } } else { return $this->render('create', ['model' => $model, 'modelsPoItem' => empty($modelsPoItem) ? [new PoItem()] : $modelsPoItem]); } }
/** * Creates a new Matricula model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Matricula(); $modeldetallemat = [new Detallemat()]; if ($model->load(Yii::$app->request->post()) && $model->save()) { $modeldetallemat = Model::createMultiple(Detallemat::classname()); Model::loadMultiple($modeldetallemat, Yii::$app->request->post()); // validate all models $valid = $model->validate(); $valid = Model::validateMultiple($modeldetallemat) && $valid; if ($valid) { $transaction = \Yii::$app->db->beginTransaction(); try { if ($flag = $model->save(false)) { foreach ($modeldetallemat as $modeldetallemat) { $modeldetallemat->idMatricula = $model->idMatricula; if (!($flag = $modeldetallemat->save(false))) { $transaction->rollBack(); break; } } } if ($flag) { $transaction->commit(); return $this->redirect(['view', 'id' => $model->idMatricula]); } } catch (Exception $e) { $transaction->rollBack(); } } return $this->redirect(['view', 'id' => $model->idMatricula]); } else { return $this->render('create', ['model' => $model, 'modeldetallemat' => empty($modeldetallemat) ? [new Detallemat()] : $modeldetallemat]); } }
/** * Creates a new Po model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Po(); $modelsPoItem = [new PoItem()]; if ($model->load(Yii::$app->request->post()) && $model->save()) { $oldIDs = ArrayHelper::map($modelsPoItem, 'id', 'id'); $modelsPoItem = Model::createMultiple(PoItem::classname(), $modelsPoItem); echo PoItem::classname(); echo '<pre>'; print_r($modelsPoItem); print_r($oldIDs); echo '</pre>'; die; Model::loadMultiple($modelsPoItem, Yii::$app->request->post()); $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsPoItem, 'id', 'id'))); // ajax validation // if (Yii::$app->request->isAjax) { // Yii::$app->response->format = Response::FORMAT_JSON; // return ArrayHelper::merge( // ActiveForm::validateMultiple($modelsPoItem), // ActiveForm::validate($modelCustomer) // ); // } // validate all models $valid = $model->validate(); $valid = Model::validateMultiple($modelsPoItem) && $valid; // echo '<pre>'; // print_r($valid); // echo '</pre>'; // die(); if ($valid) { $transaction = \Yii::$app->db->beginTransaction(); try { if ($flag = $model->save(false)) { if (!empty($deletedIDs)) { PoItem::deleteAll(['id' => $deletedIDs]); } foreach ($modelsPoItem as $modelPoItem) { $modelPoItem->po_id = $model->id; if (!($flag = $modelPoItem->save(false))) { $transaction->rollBack(); break; } } } if ($flag) { $transaction->commit(); return $this->redirect(['view', 'id' => $model->id]); } } catch (Exception $e) { $transaction->rollBack(); } } } else { return $this->render('create', ['model' => $model, 'modelsPoItem' => empty($modelsPoItem) ? [new PoItem()] : $modelsPoItem]); } }
/** * Updates an existing Po model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $modelsPoItem = $model->poItems; if ($model->load(Yii::$app->request->post())) { $oldIDs = ArrayHelper::map($modelsPoItem, 'id', 'id'); $modelsPoItem = Model::createMultiple(Address::classname(), $modelsPoItem); Model::loadMultiple($modelsPoItem, Yii::$app->request->post()); $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsPoItem, 'id', 'id'))); // ajax validation /*if (Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; return ArrayHelper::merge( ActiveForm::validateMultiple($modelsPoItem), ActiveForm::validate($model) ); }*/ // validate all models $valid = $model->validate(); $valid = Model::validateMultiple($modelsPoItem) && $valid; if ($valid) { $transaction = \Yii::$app->db->beginTransaction(); try { if ($flag = $model->save(false)) { if (!empty($deletedIDs)) { Address::deleteAll(['id' => $deletedIDs]); } foreach ($modelsPoItem as $modelPoItem) { $modelPoItem->po_id = $model->id; if (!($flag = $modelPoItem->save(false))) { $transaction->rollBack(); break; } } } if ($flag) { $transaction->commit(); return $this->redirect(['view', 'id' => $model->id]); } } catch (Exception $e) { $transaction->rollBack(); } } } return $this->render('update', ['model' => $model, 'modelsPoItem' => empty($modelsPoItem) ? [new PoItem()] : $modelsPoItem]); }
/** * Updates an existing Comunicado model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $modelsContactos = $model->comunicadosContactos; $vista = \common\models\Refactor::TipoComunicadobyVista($model->tipocomunicado_id); if ($model->load(Yii::$app->request->post())) { // Lista todos los contactos $oldIDs = ArrayHelper::map($modelsContactos, 'ccontactos_id', 'ccontactos_id'); $modelsContactos = Model::createMultipleccontacto(ComunicadosContactos::classname(), $modelsContactos); Model::loadMultiple($modelsContactos, Yii::$app->request->post()); $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsContactos, 'ccontactos_id', 'ccontactos_id'))); // validate all models $valid = $model->validate(); // Debido a que el campo dependenciaid no se captura ( y es un campo obligatorio) $valid = Model::validateMultiple($modelsContactos, ['nombre', 'cargo', 'telefono', 'correo']) && $valid; // Modificando los contactos if ($valid) { $transaction = \Yii::$app->db->beginTransaction(); try { if ($flag = $model->save(false)) { if (!empty($deletedIDs)) { ComunicadosContactos::deleteAll(['ccontactos_id' => $deletedIDs]); } foreach ($modelsContactos as $modelContacto) { $modelContacto->dependenciaid = $model->dependencia_id; if (!($flag = $modelContacto->save(false))) { $transaction->rollBack(); break; } } } if ($flag) { $transaction->commit(); return $this->redirect([\common\models\Refactor::TipoComunicadobyVista($model->tipocomunicado_id), 'id' => $model->tipocomunicado_id]); } } catch (Exception $e) { $transaction->rollBack(); } } } else { if ($vista == 'gobierno-federal') { return $this->render('update-gob', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new ComunicadosContactos()] : $modelsContactos]); } elseif ($vista == 'embajadas') { return $this->render('update-embajada', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new ComunicadosContactos()] : $modelsContactos]); } elseif ($vista == 'gdf') { return $this->render('update-gdf', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new ComunicadosContactos()] : $modelsContactos]); } elseif ($vista == 'estatales') { return $this->render('update-estatales', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new ComunicadosContactos()] : $modelsContactos]); } elseif ($vista == 'partidos-politicos') { return $this->render('update-ppoliticos', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new ComunicadosContactos()] : $modelsContactos]); } elseif ($vista == 'delegaciones') { return $this->render('update-delegacion', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new ComunicadosContactos()] : $modelsContactos]); } } }
/** * Updates an existing Proveedores model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $modelsContactos = $model->proveedoresContactos; if ($model->load(Yii::$app->request->post())) { // Lista todos los contactos $oldIDs = ArrayHelper::map($modelsContactos, 'pcontacto_id', 'pcontacto_id'); $modelsContactos = Model::createMultiplepcontacto(ProveedoresContacto::classname(), $modelsContactos); Model::loadMultiple($modelsContactos, Yii::$app->request->post()); $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsContactos, 'pcontacto_id', 'pcontacto_id'))); // validate all models $valid = $model->validate(); // Debido a que el campo dependenciaid no se captura ( y es un campo obligatorio) $valid = Model::validateMultiple($modelsContactos, ['nombre', 'apellido', 'telefono', 'celular', 'email']) && $valid; // Modificando los contactos if ($valid) { $transaction = \Yii::$app->db->beginTransaction(); try { if ($flag = $model->save(false)) { if (!empty($deletedIDs)) { ProveedoresContacto::deleteAll(['pcontacto_id' => $deletedIDs]); } foreach ($modelsContactos as $modelContacto) { $modelContacto->proveedorid = $model->proveedor_id; if (!($flag = $modelContacto->save(false))) { $transaction->rollBack(); break; } } } if ($flag) { $transaction->commit(); return $this->redirect(['index']); } } catch (Exception $e) { $transaction->rollBack(); } } } else { return $this->render('update', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new ProveedoresContacto()] : $modelsContactos]); } }
/** * Updates an existing Cuentas model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $modelsContactos = $model->contactos; $vista = \common\models\Refactor::TipoCuentabyVista($model->tipocuenta_id); if ($model->load(Yii::$app->request->post()) && $model->save()) { // Lista todos los contactos $oldIDs = ArrayHelper::map($modelsContactos, 'contactosid', 'contactosid'); $modelsContactos = Model::createMultiple(Contactos::classname(), $modelsContactos); Model::loadMultiple($modelsContactos, Yii::$app->request->post()); $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsContactos, 'contactosid', 'contactosid'))); // validate all models $valid = $model->validate(); $valid = Model::validateMultiple($modelsContactos) && $valid; // Obteniendo el archivo que se subió. /* FUNCIONA CORRECTAMENTE PERO ES PARA MOSTRAR Y GUARDAR UN SOLO ARCHIVO, EL CODIGO UTILIZADO ES PARA VARIOS ARCHIVOS $model->archivo = UploadedFile::getInstance($model, 'archivo'); if ($model->archivo && $model->validate()) { if ($model->docto_propuesta && file_exists(Yii::$app->basePath.'/web/'.$model->docto_propuesta)) { unlink(Yii::$app->basePath.'/web/'.$model->docto_propuesta); } $nombreImagen = $model->cuenta .'-'.date('Ymd-His'); // Guardando la direccion en la BD $model->docto_propuesta = 'doctos/' .$nombreImagen. '.' .$model->archivo->extension; $model->save(); $model->archivo->saveAs('doctos/'.$nombreImagen.'.'.$model->archivo->extension ); } */ // Obteniendo el archivo que se subió. $model->archivo = UploadedFile::getInstance($model, 'archivo'); if ($model->archivo && $model->validate()) { $archivo = $model->archivo->name; echo $model->docto_propuesta; // Desserializando los valores de la BD $dato_inicial = unserialize($model->docto_propuesta); // Obteniendo el nuevo archivo del formulario //$nombreImagen = $model->cuenta .'-'.date('Ymd-His'); //$dato_nuevo = 'doctos/' .$nombreImagen. '.' .$model->archivo->extension; $dato_nuevo = 'doctos/' . $archivo; // Serializando los nuevos datos if (!is_array($dato_inicial)) { $dato_inicial = explode("\n", $dato_inicial); } $temporal[0] = $dato_nuevo; $i = 1; foreach ($dato_inicial as $valor) { $temporal[$i] = $dato_inicial[$i - 1]; $i++; } // Guardando en la BD $model->docto_propuesta = serialize($temporal); $model->save(); //$model->archivo->saveAs('doctos/'.$nombreImagen.'.'.$model->archivo->extension ); $model->archivo->saveAs('doctos/' . $archivo); } // Modificando los contactos if ($valid) { $transaction = \Yii::$app->db->beginTransaction(); try { if ($flag = $model->save(false)) { if (!empty($deletedIDs)) { Contactos::deleteAll(['contactosid' => $deletedIDs]); } foreach ($modelsContactos as $modelContacto) { $modelContacto->cuenta_id = $model->cuentasid; if (!($flag = $modelContacto->save(false))) { $transaction->rollBack(); break; } } } if ($flag) { $transaction->commit(); //return $this->redirect([$vista, 'id' => $model->cuentasid]); return $this->redirect(Yii::$app->session->get('regresa_anterior')); } } catch (Exception $e) { $transaction->rollBack(); } } //return $this->redirect([$vista, 'id' => $model->cuentasid]); } else { Yii::$app->session->set('regresa_anterior', Yii::$app->request->referrer); if ($vista == 'estatales') { return $this->render('update_estatal', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new Contactos()] : $modelsContactos]); } elseif ($vista == 'gdf') { return $this->render('update_gdf', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new Contactos()] : $modelsContactos]); } elseif ($vista == 'gobierno-federal') { return $this->render('update_gobiernofederal', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new Contactos()] : $modelsContactos]); } elseif ($vista == 'iniciativa-privada') { return $this->render('update_ip', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new Contactos()] : $modelsContactos]); } elseif ($vista == 'partidos') { return $this->render('update_partidos', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new Contactos()] : $modelsContactos]); } elseif ($vista == 'delegacion') { return $this->render('update_delegacion', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new Contactos()] : $modelsContactos]); } elseif ($vista == 'intercambio') { return $this->render('update_intercambio', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new Contactos()] : $modelsContactos]); } elseif ($vista == 'fundacion') { return $this->render('update_fundacion', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new Contactos()] : $modelsContactos]); } } }
/** * Updates an existing Arqueo model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $modelsNotas = $model->conteonotas; //$modelsNotas = Conteonotas::findAll(['arqueo_id' => 70]); //var_dump($modelsNotas->prepare(Yii::$app->db->queryBuilder)->createCommand()->rawSql); exit(); if ($model->load(Yii::$app->request->post())) { Model::loadMultiple($modelsNotas, Yii::$app->request->post()); $valid = $model->validate(); $valid = Model::validateMultiple($modelsNotas) && $valid; if ($valid) { $transaction = Yii::$app->db->beginTransaction(); try { foreach ($modelsNotas as $modelNotas) { $modelNotas->arqueo_id = $model->id; if (!($flag = $modelNotas->save(false))) { $transaction->rollBack(); break; } } $this->actualizaArqueo($model); $model->save(false); /* if ($flag = $model->save(false)) { }*/ if ($flag) { $transaction->commit(); return $this->redirect(['view', 'id' => $model->id]); } } catch (Exception $e) { $transaction->rollBack(); } } } else { return $this->render('update', ['model' => $model, 'modelsNotas' => $modelsNotas]); } }