From f2c34d595fb7d38a227ae5e11c04657cd901543a Mon Sep 17 00:00:00 2001
From: SoHardKI
Date: Fri, 28 Jun 2019 12:29:54 +0300
Subject: [PATCH] add_summ_info
---
.../balance/controllers/BalanceController.php | 6 ++--
.../modules/balance/models/BalanceSearch.php | 28 ++++++++++++++++++-
.../modules/balance/views/balance/index.php | 11 +++++++-
3 files changed, 39 insertions(+), 6 deletions(-)
diff --git a/backend/modules/balance/controllers/BalanceController.php b/backend/modules/balance/controllers/BalanceController.php
index b223b08..ed760b5 100644
--- a/backend/modules/balance/controllers/BalanceController.php
+++ b/backend/modules/balance/controllers/BalanceController.php
@@ -30,11 +30,9 @@ class BalanceController extends Controller
$searchModel->dt_to = date('Y-m-d', strtotime('last day of previous month'));
}
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
+ $summ_info = $searchModel->getSummInfo();
- return $this->render('index',[
- 'searchModel' => $searchModel,
- 'dataProvider' => $dataProvider,
- ]);
+ return $this->render('index',compact('dataProvider', 'searchModel', 'summ_info'));
}
public function actionView($id)
diff --git a/backend/modules/balance/models/BalanceSearch.php b/backend/modules/balance/models/BalanceSearch.php
index 1f232eb..6db036c 100644
--- a/backend/modules/balance/models/BalanceSearch.php
+++ b/backend/modules/balance/models/BalanceSearch.php
@@ -2,13 +2,13 @@
namespace backend\modules\balance\models;
+use backend\modules\balance\models\Balance;
use common\classes\Debug;
use common\models\FieldsValueNew;
use DateTime;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
-use backend\modules\balance\models\Balance;
/**
* BalanceSearch represents the model behind the search form of `backend\modules\balance\models\Balance`.
@@ -21,6 +21,9 @@ class BalanceSearch extends Balance
public $dt_to;
public $field_name;
public $field_value;
+ public $active_summ;
+ public $passive_summ;
+ public $difference;
/**
* {@inheritdoc}
*/
@@ -87,4 +90,27 @@ class BalanceSearch extends Balance
return $dataProvider;
}
+
+ public function getSummInfo()
+ {
+ $query = Balance::find()
+ ->andFilterWhere(['>=','dt_add', strtotime($this->dt_from) ?: null])
+ ->andFilterWhere(['<=','dt_add', strtotime($this->dt_to) ?: null])
+ ->all();
+// Debug::dd($query);
+ $active_summ = 0;
+ $passive_summ = 0;
+ $difference = 0;
+ foreach ($query as $item)
+ {
+ if($item->type == 1)
+ {
+ $active_summ += $item->summ;
+ } else {
+ $passive_summ += $item->summ;
+ }
+ }
+ $difference = $active_summ - $passive_summ;
+ return compact('active_summ', 'passive_summ', 'difference');
+ }
}
diff --git a/backend/modules/balance/views/balance/index.php b/backend/modules/balance/views/balance/index.php
index b5ab6a2..7a2a37c 100644
--- a/backend/modules/balance/views/balance/index.php
+++ b/backend/modules/balance/views/balance/index.php
@@ -22,7 +22,16 @@ $this->params['breadcrumps'][] = $this->title;
= Html::a('Показать за прошлый месяц', ['index', 'previous_month' => true], ['class' => 'btn btn-primary']) ?>
= Html::a('Показать за текущий месяц', ['index', 'month' => true], ['class' => 'btn btn-primary']) ?>
-fields); ?>
+
+ = Html::label('Сумма активных балансов: ' . $summ_info['active_summ']); ?>
+
+
+ = Html::label('Сумма пассивных балансов: ' . $summ_info['passive_summ']); ?>
+
+
+ = Html::label('Разница: ' . $summ_info['difference']); ?>
+
+
= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,