public function afterSave($insert, $changedAttributes) { if (parent::afterSave($insert, $changedAttributes)) { BalanceItemExt::$use_view = true; return true; } else { return false; } }
private function createBalanceItem($step) { if ($step->type_id > '') { $model = new BalanceItem(); $model->name = $step->title; $model->balance_type_id = $step->type_id; if ($model->save()) { $result = $model->initAccounts(); if ($result) { $step->error = Json::encode($result); return false; } } else { $step->error = Json::encode($model->errors); return false; } } return true; }
public function actionCreateMaster($item_id, $sheet_id) { $item = BalanceItem::findOne($item_id); foreach ($item->accounts as $account) { $model = new BalanceAmount(); $model->account_id = $account->id; $model->balance_sheet_id = $sheet_id; $model->amount = 0; $model->save(); } return $this->redirect(['master/index']); }
public function actionDrop() { $list = \app\models\BalanceItem::find()->all(); foreach ($list as $item) { $item->delete(); } $list = \app\models\BalanceSheet::find()->all(); foreach ($list as $item) { $item->delete(); } return $this->redirect(['index']); }
public function beforeValidate() { if (parent::beforeValidate()) { // ...custom code here... if ($this->order_num == null) { $this->order_num = BalanceItem::find()->where(['balance_type_id' => $this->balance_type_id])->max('order_num') + 1; } $this->order_code = $this->balanceType->order_code . $this->order_num; return true; } else { return false; } }
/** * Finds the BalanceItem model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return BalanceItem the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = BalanceItem::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getBalanceItem() { return $this->hasOne(BalanceItem::className(), ['id' => 'balance_item_id']); }