/** * Lists all Journal models. * @return mixed */ public function actionIndex() { $searchModel = new JournalSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); $query = $dataProvider->query; if (!isset($req["sort"])) { $query->orderBy(Transaction::tableName() . ".time desc"); } return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }
public static function find() { return parent::find()->where([Transaction::tableName() . '.isdel' => 0]); }
use yii\helpers\Html; use yii\helpers\ArrayHelper; //use yii\grid\GridView; //use kartik\grid\GridView; use amilna\yap\GridView; use amilna\cap\models\Transaction; //use dosamigos\grid\GroupGridView; /* @var $this yii\web\View */ /* @var $searchModel amilna\cap\models\JournalSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('app', 'Journals'); $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'CAP'), 'url' => ['/cap/default']]; $this->params['breadcrumbs'][] = $this->title; $dataProvider->pagination = ['pageSize' => 10]; $module = Yii::$app->getModule('cap'); $tra = new Transaction(); ?> <div class="journal-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php /*= Html::a(Yii::t('app', 'Create {modelClass}', [ 'modelClass' => Yii::t('app','Transaction'),
/** * Finds the Transaction model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Transaction the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Transaction::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function getSaldo() { return $this->db->createCommand("SELECT \n\t\t\t\t\tsum(case when j.type = 0 then amount else j.amount*(-1) end) as saldo \n\t\t\t\t\tFROM " . Journal::tableName() . " as j\n\t\t\t\t\tLEFT JOIN " . $this->tableName() . " as a on j.account_id = a.id\n\t\t\t\t\tLEFT JOIN " . Transaction::tableName() . " as t on j.transaction_id = t.id\n\t\t\t\t\tWHERE (a.id_left >= :lid AND a.id_right <= :rid) AND j.isdel = 0 AND t.isdel = 0")->bindValues(["lid" => $this->id_left, "rid" => $this->id_right])->queryScalar(); }
public function getTags() { $models = Transaction::find()->all(); $tags = []; foreach ($models as $m) { $ts = explode(",", $m->tags); foreach ($ts as $t) { if (!in_array($t, $tags)) { $tags[$t] = $t; } } } return $tags; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = $this->find(); $query->joinWith(['transaction', 'account']); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->sort->attributes['time'] = ['asc' => [Transaction::tableName() . '.time' => SORT_ASC], 'desc' => [Transaction::tableName() . '.time' => SORT_DESC]]; $dataProvider->sort->attributes['title'] = ['asc' => [Transaction::tableName() . '.title' => SORT_ASC], 'desc' => [Transaction::tableName() . '.title' => SORT_DESC]]; $dataProvider->sort->attributes['subject'] = ['asc' => [Transaction::tableName() . '.subject' => SORT_ASC], 'desc' => [Transaction::tableName() . '.subject' => SORT_DESC]]; $dataProvider->sort->attributes['tags'] = ['asc' => [Transaction::tableName() . '.tags' => SORT_ASC], 'desc' => [Transaction::tableName() . '.tags' => SORT_DESC]]; $dataProvider->sort->attributes['transactionRemarks'] = ['asc' => [Transaction::tableName() . '.remarks' => SORT_ASC], 'desc' => [Transaction::tableName() . '.remarks' => SORT_DESC]]; $dataProvider->sort->attributes['accountName'] = ['asc' => [AccountCode::tableName() . '.code' => SORT_ASC], 'desc' => [AccountCode::tableName() . '.code' => SORT_DESC]]; if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'account_id' => $this->account_id, 'transaction_id' => $this->transaction_id, 'type' => $this->type, 'isdel' => $this->isdel]); $params = self::queryNumber([['quantity'], ['amount']]); foreach ($params as $p) { $query->andFilterWhere($p); } $params = self::queryTime([['time', Transaction::tableName()]]); foreach ($params as $p) { $query->andFilterWhere($p); } $params = self::queryString([['remarks', Journal::tableName()], ['title', Transaction::tableName()], ['subject', Transaction::tableName()], ['tags', Transaction::tableName()]]); foreach ($params as $p) { $query->andFilterWhere($p); } $query->andFilterWhere(['like', 'lower(' . Transaction::tableName() . '.remarks)', strtolower($this->transactionRemarks)])->andFilterWhere(['like', "lower(concat(" . AccountCode::tableName() . ".code,' - '," . AccountCode::tableName() . ".name))", strtolower($this->accountName)]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getTransaction() { return $this->hasOne(Transaction::className(), ['id' => 'transaction_id']); }