/** * 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 = Docdetails::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
private function saveDet() { if (!is_null($this->docDet)) { $line = 1; foreach ($this->docDet as $key => $detial) { $fline = isset($detial['line']) ? $detial['line'] : 0; $submodel = Docdetails::model()->findByPk(array('doc_id' => $this->id, 'line' => $fline)); if ($submodel === null) { //new line $submodel = new Docdetails(); } $submodel->attributes = $detial; $submodel->line = $line; $submodel->doc_id = $this->id; if (Item::model()->findByPk((int) $detial["item_id"]) !== null) { $submodel->iItem = null; if ($submodel->save()) { $this->docDet[$key]['iTotalVat'] = $submodel->iTotalVat; $this->docDet[$key]['ihTotal'] = $submodel->ihTotal; $saved = true; $line++; } else { Yii::log("fatel error cant save docdetial,doc_id:" . $submodel->line . "," . $submodel->doc_id, CLogger::LEVEL_ERROR, __METHOD__); } } } if (count($this->docDetailes) != $line - 1) { //if more items in $docdetails delete them for ($curLine = $line; $curLine < count($this->docDetailes); $curLine++) { $this->docDetailes[$curLine]->delete(); } } } }