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; true], ['class' => 'btn btn-primary']) ?> true], ['class' => 'btn btn-primary']) ?>

-fields); ?> +

+ +

+

+ +

+

+ +

+ $dataProvider, 'filterModel' => $searchModel,