/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Account::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'parent_id' => $this->parent_id, 'virtual' => $this->virtual]); $query->andFilterWhere(['like', 'type', $this->type])->andFilterWhere(['like', 'currency', $this->currency])->andFilterWhere(['like', 'title', $this->title]); return $dataProvider; }
public function actionIndex() { $fname = __DIR__ . "/../expense.csv"; $lines = file($fname); $expenses = []; $current = null; foreach ($lines as $line) { $arr = explode(',', $line); if (trim($line) == ',,,,,,,,,') { continue; } if ($arr[0]) { var_dump($arr[1], $arr[8]); $expenses[] = ['date' => $arr[0], 'contractor' => $arr[1], 'contractor_id' => \app\models\contractor\Contractor::getByName($arr[1], 2)->id, 'bonus' => $arr[7], 'account' => $arr[8], 'account_id' => \app\models\account\Account::getByName($arr[8], 2)->id, 'expenses' => [['title' => $arr[2], 'price' => $arr[3], 'count' => $arr[4], 'discount' => $arr[5], 'sum' => $arr[6], 'comment' => trim($arr[9])]]]; } else { $expenses[count($expenses) - 1]['expenses'][] = ['title' => $arr[2], 'price' => $arr[3], 'count' => $arr[4], 'discount' => $arr[5], 'sum' => $arr[6], 'comment' => trim($arr[9])]; } } foreach ($expenses as $expense) { $transfer = new \app\models\transaction\Transaction(); $transfer->comment = ""; preg_match('!^(\\d{1,2})[\\.\\-](\\d{1,2}) (\\d{1,2})-(\\d{2})$!', $expense['date'], $m); $transfer->date = date('Y-m-d H:i:s', strtotime("{$m['1']}.{$m['2']}.2015 {$m['3']}:{$m['4']}:00")); var_dump($transfer->date); $transfer->user_id = 2; $transfer->comment = $expense['expenses'][0]['comment']; $transfer->type = 'expense'; $transfer->save(false); $exps = []; $total = 0; foreach ($expense['expenses'] as $e) { $exp = new \app\models\transaction\TransactionExpense(); $exp->name = $e['title']; $exp->price = $e['price']; $exp->qty = $e['count']; $exp->discount = floatval($e['discount']); $exp->sum = $exp->price * $exp->qty * (1 - $exp->discount); $exp->comment = $e['comment']; $exp->contractor_id = $expense['contractor_id']; $exp->user_id = 2; $total += $exp->sum; $exp->transaction_id = $transfer->id; $exp->save(false); } $out = new \app\models\transaction\TransactionOutgoing(); $out->account_id = $expense['account_id']; $out->sum = $total; $out->user_id = 2; $out->transaction_id = $transfer->id; $out->save(false); if ($expense['bonus']) { var_dump($expense['bonus']); $in = new \app\models\transaction\TransactionIncoming(); $in->account_id = \app\models\account\Account::getByName('Okeycity', 2)->id; $in->sum = $expense['bonus']; $in->user_id = 3; $in->transaction_id = $transfer->id; $in->contractor_id = \app\models\contractor\Contractor::getByName('Okeycity', 2)->id; $in->save(false); } } }
/** * @return \yii\db\ActiveQuery */ public function getAccount() { return $this->hasOne(Account::className(), ['id' => 'account_id']); }
use app\models\account\Account; use app\models\contractor\Contractor; use app\models\transaction\TransactionIncoming; use yii\helpers\ArrayHelper; if (is_null($__ITEM)) { $__ITEM = new TransactionIncoming(); } ?> <li class="incoming" data-key="incoming-<?php echo $__ITEM->id; ?> "> <?php echo $form->field($__ITEM, 'account_id')->label(false)->dropDownList(ArrayHelper::merge(["" => "Select account"], Account::plainHierarcyForUser(Yii::$app->user->getId()))); ?> <?php echo $form->field($__ITEM, 'contractor_id')->label(false)->dropDownList(ArrayHelper::merge(["" => "Select contractor"], Contractor::dropdown(Yii::$app->user->getId())), ['style' => 'display: none;']); ?> <?php echo $form->field($__ITEM, 'sum')->label(false)->textInput(); ?> <div role="comment-container-incoming-<?php echo $__ITEM->id; ?> "> <?php if ($__ITEM->comment) { ?> <?php
public function actionIndex() { $models = Account::find()->where(['user_id' => Yii::$app->user->getId(), 'type' => ['credit', 'creditcard'], 'virtual' => 0])->all(); return $this->render('index', ['models' => $models]); }
/** * @return \yii\db\ActiveQuery */ public function getAccounts() { return $this->hasMany(Account::className(), ['parent_id' => 'id']); }
<?php } ?> <?php echo $form->field($model, 'title')->textInput(['maxlength' => 255]); ?> <?php echo $form->field($model, 'virtual')->checkbox(['1']); ?> <?php if ($model->scenario == 'insert') { ?> <?php echo $form->field($model, 'parent_id')->dropDownList(ArrayHelper::merge(['' => ''], Account::plainHierarcyForUser(Yii::$app->user->getId()))); ?> <?php } else { ?> <div class="form-group field-account-currency"> <label class="control-label" for="account-currency">Parent</label> <div><?php echo $model->parent_id; ?> </div> <div class="help-block"></div> </div> <?php }
/** * Finds the Account model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Account the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Account::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }