/**
  * Renders the data cell content.
  * @param \app\models\transaction\Transaction $model the data model
  * @param mixed $key the key associated with the data model
  * @param integer $index the zero-based index of the data model among the models array returned by [[GridView::dataProvider]].
  * @return string the rendering result
  */
 protected function renderDataCellContent($model, $key, $index)
 {
     $out = "<div>";
     $out .= "<small><i>" . $model->getAllContractorNames() . "</i></small><br/>";
     $out .= "<small>";
     $sums = [];
     foreach ($model->transactionOutgoings as $outgoing) {
         $sums[] = $outgoing->account->title . ": <span class='outSum'>" . $outgoing->account->renderFinance(-$outgoing->sum) . "</span>";
     }
     foreach ($model->transactionIncomings as $incoming) {
         $sums[] = $incoming->account->title . ": <span class='inSum'>+" . $incoming->account->renderFinance($incoming->sum) . "</span>";
     }
     $out .= join('<br/>', $sums);
     $out .= "</small>";
     $out .= "<br/>";
     $out .= "<small><i>" . $model->comment . "</i></small>";
     $out .= "</div>";
     return $out;
 }
Пример #2
0
 /**
  * Lists all Account models.
  * @return mixed
  */
 public function actionIndex()
 {
     $models = Account::hierarcyForUser(Yii::$app->user->getId());
     $date = isset($_GET['date']) ? $_GET['date'] : null;
     if (isset($_GET['date0'])) {
         $date0 = $_GET['date0'] . ' 00:00:00';
         $date1 = date('Y-m-d 00:00:00', strtotime($_GET['date0'] . ' +1 day'));
         //ddump($date1, $date0);
         $t = \app\models\transaction\Transaction::find()->where("date BETWEEN '{$date0}' AND '{$date1}'")->andWhere(['user_id' => 2])->all();
         $incs = [];
         $outs = [];
         foreach ($t as $transaction) {
             foreach ($transaction->transactionOutgoings as $out) {
                 if (!isset($outs[$out->account_id])) {
                     $outs[$out->account_id] = 0;
                 }
                 $outs[$out->account_id] += $out->sum;
             }
             foreach ($transaction->transactionIncomings as $in) {
                 if (!isset($incs[$in->account_id])) {
                     $incs[$in->account_id] = 0;
                 }
                 $incs[$in->account_id] += $in->sum;
             }
         }
         dump($outs, $incs);
         foreach ($models as $m) {
             if (!$m->virtual) {
                 if (isset($outs[$m->id]) || isset($incs[$m->id])) {
                     echo "Balance for account {$m->title}:";
                     echo "<br/>&nbsp;&nbsp;Date: " . $m->getBalance($_GET['date0'])->date;
                     echo "<br/>&nbsp;&nbsp;Sum: " . $m->getBalance($_GET['date0'])->sum;
                     echo "<br/>&nbsp;&nbsp; +" . (isset($incs[$m->id]) ? $incs[$m->id] : 0);
                     echo "<br/>&nbsp;&nbsp; -" . (isset($outs[$m->id]) ? $outs[$m->id] : 0);
                     echo "<br/>";
                     $b = new Balance();
                     $b->account_id = $m->id;
                     $b->date = date('Y-m-d', strtotime($_GET['date0'] . ' +1 day'));
                     $b->sum = $m->getBalance($_GET['date0'])->sum - (isset($outs[$m->id]) ? $outs[$m->id] : 0) + (isset($incs[$m->id]) ? $incs[$m->id] : 0);
                     //                        $b->save();
                     echo $b->sum;
                     echo "<br/><br/>";
                 }
             }
         }
         ddump(9);
     }
     //        $searchModel = new AccountSearch();
     //        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     return $this->render('index', ['models' => $models, 'date' => $date]);
 }
Пример #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTransaction()
 {
     return $this->hasOne(Transaction::className(), ['id' => 'transaction_id']);
 }
Пример #4
0
 /**
  * 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.');
     }
 }