public function save() { //print_r($this->Deposit); $num = 0; $linenum = 1; $tranType = Settings::model()->findByPk('transactionType.chequedeposit')->value; if ($this->refnum == '' || $this->date == '' || !is_array($this->Deposit)) { return false; } $valuedate = date("Y-m-d H:m:s", CDateTimeParser::parse($this->date, Yii::app()->locale->getDateFormat('yiishort'))); foreach ($this->Deposit as $line => $val) { list($a, $b) = explode(',', $line); $cheq = Doccheques::model()->findByPk(array("doc_id" => $a, "line" => $b)); $oppt_acc = PaymentType::model()->findByPk($cheq->type)->oppt_account_id; //print_r($cheq); $accout = new Transactions(); $accout->num = $num; $accout->account_id = $this->account_id; $accout->type = $tranType; $accout->refnum1 = $this->refnum; $accout->valuedate = $valuedate; //$accout->details=$this->company; $accout->currency_id = $cheq->currency_id; $accout->owner_id = Yii::app()->user->id; $accout->linenum = $linenum; $accout->sum = $cheq->sum * -1; $linenum++; $num = $accout->save(); $oppt = new Transactions(); $oppt->num = $num; $oppt->account_id = $oppt_acc; $oppt->type = $tranType; $oppt->refnum1 = $this->refnum; $oppt->valuedate = $valuedate; //$oppt->details=$this->company; $oppt->currency_id = $cheq->currency_id; $oppt->owner_id = Yii::app()->user->id; $oppt->linenum = $linenum; $oppt->sum = $cheq->sum * 1; $linenum++; $num = $oppt->save(); $cheq->bank_refnum = $num; $cheq->save(); } //Yii::app()->end(); return $num; }
/** * 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 = Doccheques::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
private function saveCheq() { if (!is_null($this->docCheq)) { $line = 0; foreach ($this->docCheq as $key => $rcpt) { $submodel = Doccheques::model()->findByPk(array('doc_id' => $this->id, 'line' => $rcpt['line'])); if (!$submodel) { //new line $submodel = new Doccheques(); } //go throw attr if no save new foreach ($rcpt as $key => $value) { if ($submodel->hasAttribute($key)) { $submodel->{$key} = $value; } else { $eav = new DocchequesEav(); $eav->line = $rcpt['line']; $eav->doc_id = $this->id; $eav->attribute = $key; $eav->value = $value['value']; $eav->save(); } } $submodel->doc_id = $this->id; if ((int) $rcpt["type"] != 0) { if ($submodel->save()) { $saved = true; $line++; } else { Yii::log("fatel error cant save rcptdetial,doc_id:" . $submodel->line . "," . $submodel->doc_id, CLogger::LEVEL_ERROR, __METHOD__); //Yii::app()->end(); } } //Yii::app()->end(); } if (count($this->docCheques) != $line) { //if more items in $docCheques delete them for ($curLine = $line; $curLine < count($this->docCheques); $curLine++) { $this->docCheques[$curLine]->delete(); } } } }