add_summ_info

This commit is contained in:
SoHardKI 2019-06-28 12:29:54 +03:00
parent b24bbf51aa
commit f2c34d595f
3 changed files with 39 additions and 6 deletions

View File

@ -30,11 +30,9 @@ class BalanceController extends Controller
$searchModel->dt_to = date('Y-m-d', strtotime('last day of previous month')); $searchModel->dt_to = date('Y-m-d', strtotime('last day of previous month'));
} }
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$summ_info = $searchModel->getSummInfo();
return $this->render('index',[ return $this->render('index',compact('dataProvider', 'searchModel', 'summ_info'));
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
} }
public function actionView($id) public function actionView($id)

View File

@ -2,13 +2,13 @@
namespace backend\modules\balance\models; namespace backend\modules\balance\models;
use backend\modules\balance\models\Balance;
use common\classes\Debug; use common\classes\Debug;
use common\models\FieldsValueNew; use common\models\FieldsValueNew;
use DateTime; use DateTime;
use Yii; use Yii;
use yii\base\Model; use yii\base\Model;
use yii\data\ActiveDataProvider; use yii\data\ActiveDataProvider;
use backend\modules\balance\models\Balance;
/** /**
* BalanceSearch represents the model behind the search form of `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 $dt_to;
public $field_name; public $field_name;
public $field_value; public $field_value;
public $active_summ;
public $passive_summ;
public $difference;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -87,4 +90,27 @@ class BalanceSearch extends Balance
return $dataProvider; 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');
}
} }

View File

@ -22,7 +22,16 @@ $this->params['breadcrumps'][] = $this->title;
<?= Html::a('Показать за прошлый месяц', ['index', 'previous_month' => true], ['class' => 'btn btn-primary']) ?> <?= Html::a('Показать за прошлый месяц', ['index', 'previous_month' => true], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Показать за текущий месяц', ['index', 'month' => true], ['class' => 'btn btn-primary']) ?> <?= Html::a('Показать за текущий месяц', ['index', 'month' => true], ['class' => 'btn btn-primary']) ?>
</p> </p>
<!-- --><?php //\common\classes\Debug::dd($searchModel->fields); ?> <p>
<?= Html::label('Сумма активных балансов: ' . $summ_info['active_summ']); ?>
</p>
<p>
<?= Html::label('Сумма пассивных балансов: ' . $summ_info['passive_summ']); ?>
</p>
<p>
<?= Html::label('Разница: ' . $summ_info['difference']); ?>
</p>
<?= GridView::widget([ <?= GridView::widget([
'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,
'filterModel' => $searchModel, 'filterModel' => $searchModel,