public function save($runValidation = true, $attributes = NULL) { if (isset($this->system_acc)) { if ($this->system_acc != 1) { return parent::save($runValidation, $attributes); } } else { return parent::save($runValidation, $attributes); } //else no save return false; }
public function save($runValidation = true, $attributes = NULL) { if (isset(Yii::$app->user)) { $this->owner = Yii::$app->user->id; } if (is_null($this->discount)) { $this->discount = 0; } if ($this->total == 0) { $this->total = $this->rcptsum; } $this->accountLoader(); $a = parent::save($runValidation, $attributes); if (!$a) { return $a; } //if think we can skip this //if (!is_null($attributes)) // return $a; //shuld be valid and calced by now //if ($a) { //if switch no save $this->saveRef(); //load docs and re-save them if (!$this->action) { if ($this->status === null) { throw new \Exception(Yii::t('app', 'No status recived')); } //500 //$this->docStatus = Docstatus::findOne(array('num' => $this->status, 'doc_type' => $this->doctype)); if ($this->docStatus === null) { throw new \Exception(Yii::t('app', 'Status is Invalid')); } //500 $this->saveDet(); $this->saveCheq(); if (count($this->errors) != 0) { return $a; } //$this->calc(); //$this->validate(); //if (count($this->getErrors()) != 0) // return false; if (isset($this->docStatus)) { if ($this->docStatus->action != 0) { //will run only once $transaction = Yii::$app->db->beginTransaction(\yii\db\Transaction::READ_UNCOMMITTED); //-shuld start transaction here try { $this->docnum = $this->newNum(); //get num if (!$this->docnum) { $this->addError('docnum', Yii::t('app', 'Document exists please fix last_num Value')); return false; } $this->action = 1; $a = parent::save($runValidation, $attributes); $this->transaction((int) $this->docStatus->action); if (is_null($this->docType->transactionType_id)) { //only if !transaction stock foreach ($this->docDetailes as $docdetail) { $this->stock($docdetail->item_id, $docdetail->qty); } } //commit it here $transaction->commit(); } catch (\Exception $e) { $transaction->rollBack(); $message = $e->getMessage(); $this->addError('docnum', $message); } } } } return $a; }