예제 #1
0
 /**
  * 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::findOne($id);
     if ($model === null) {
         throw new \yii\web\HttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
예제 #2
0
파일: Docs.php 프로젝트: chaimvaid/linet3
 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::findOne(array('doc_id' => $this->id, 'line' => $fline));
             if ($submodel === null) {
                 //new line
                 $submodel = new Docdetails();
             }
             $submodel->attributes = $detial;
             $submodel->valuedate = $this->issue_date;
             $submodel->line = $line;
             $submodel->doc_id = $this->id;
             //if (Item::findOne((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 {
                 $this->addError('docDet', $submodel->errors);
                 Yii::error("fatel error cant save docdetial,doc_id:" . $submodel->line . "," . $submodel->doc_id . ":" . \yii\helpers\Json::encode($submodel->errors));
             }
             //}
         }
         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();
             }
         }
     }
     return true;
 }