public function last_docnumVal($attribute, $params) { $num = Docs::getMax($this->id); if ($num != null) { if (docs::getMax($this->id) != $this->{$attribute}) { $this->addError($attribute, Yii::t('app', 'Not a valid number, last number:') . $num); } } return true; }
public function getDoc() { return $this->hasOne(docs::className(), array('id' => 'doc_id')); }
/** * Retrieves a list of models based on the current search/filter conditions. * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. */ public function search($params) { $query = docs::find(); $dataProvider = new \yii\data\ActiveDataProvider(['query' => $query, "sort" => ['defaultOrder' => ['reg_date' => SORT_DESC, 'docnum' => SORT_DESC]]]); //exit; $this->load($params); if (!$this->validate()) { var_dump($this->getErrors()); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'doctype' => $this->doctype, 'docnum' => $this->docnum, 'account_id' => $this->account_id, 'vatnum' => $this->vatnum, 'refnum' => $this->refnum, 'sub_total' => $this->sub_total, 'novat_total' => $this->novat_total, 'vat' => $this->vat, 'total' => $this->total, 'src_tax' => $this->src_tax, 'printed' => $this->printed, 'currency_id' => $this->currency_id, 'owner' => $this->owner, 'refstatus' => $this->refstatus]); $query->andFilterWhere(['like', 'company', $this->company])->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['like', 'city', $this->city])->andFilterWhere(['like', 'zip', $this->zip])->andFilterWhere(['like', 'comments', $this->comments]); //$sort->defaultOrder = 'issue_date DESC'; return $dataProvider; $criteria->compare('issue_date', $this->issue_date, true); $criteria->compare('due_date', $this->due_date, true); if (!empty($this->issue_from) && empty($this->issue_to)) { $this->issue_from = date("Y-m-d", CDateTimeParser::parse($this->issue_from, Yii::$app->locale->getDateFormat('yiishort'))); $criteria->addCondition("issue_date>=:date_from"); $criteria->params[':date_from'] = $this->issue_from; } elseif (!empty($this->issue_to) && empty($this->issue_from)) { $this->issue_to = date("Y-m-d", CDateTimeParser::parse($this->issue_to, Yii::$app->locale->getDateFormat('yiishort'))); $criteria->addCondition("issue_date>=:date_to"); $criteria->params[':date_to'] = $this->issue_to; } elseif (!empty($this->issue_to) && !empty($this->issue_from)) { $this->issue_from = date("Y-m-d", CDateTimeParser::parse($this->issue_from, Yii::$app->locale->getDateFormat('yiishort'))); $this->issue_to = date("Y-m-d", CDateTimeParser::parse($this->issue_to, Yii::$app->locale->getDateFormat('yiishort'))); $criteria->addCondition("issue_date>=:date_from"); $criteria->addCondition("issue_date<=:date_to"); $criteria->params[':date_from'] = $this->issue_from; $criteria->params[':date_to'] = $this->issue_to; } }