/** * 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) { if (isset($_POST["General_company_name"]) && $_POST["General_company_name"] != "") { $company_id = $_REQUEST["General_company_name"]; $company_name = $_REQUEST["company_name"]; $year = $_REQUEST["year"]; $general = General::model()->findByPk($id); if (!isset($general)) { $general = new General(); } $general->company_id = $company_id; $general->company_name = $company_name; $general->year = $year; $general->save(); $ret = ItemValue::model()->deleteAll("company_id ='" . $company_id . "' and year ='" . $year . "'"); foreach ($_POST as $key => $value) { if ($key == 'General_company_name' || $key == 'year' || $key == 'company_name') { continue; } if ($value != "") { $item = new ItemValue(); $it = explode("_", $key); $item->item_id = $it[1]; $item->value = $value; $item->company_id = $company_id; $item->year = $year; $item->save(); } } //$this->redirect(Yii::app()->getBaseUrl().'/index.php/general/admin'); } $model = $this->loadModel($id); $items = Yii::app()->db->createCommand("\n select I.id,I.name,IV.value,I.isMandatory \n from tbl_item as I \n inner join tbl_item_value as IV on I.id = IV.item_id \n where IV.company_id='" . $model->company_id . "' \n and IV.year='" . $model->year . "'")->queryAll(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); $this->render('update', array('model' => $model, 'items' => $items)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionGenerateLedgerGeneral() { if (isset($_REQUEST['General_company_name'])) { $company_id = $_POST["General_company_name"]; $year = $_POST["year"]; $ret = ItemValue::model()->deleteAll("company_id ='" . $company_id . "' and year ='" . $year . "'"); foreach ($_REQUEST as $key => $value) { if ($key == 'General_company_name' || $key == 'year') { continue; } if ($value != "") { $item = new ItemValue(); $it = explode('_', $key); $item->item_id = $it[1]; $item->value = $value; $item->company_id = $company_id; $item->year = $year; $item->save(); } } } }