add_summ_info
This commit is contained in:
parent
b24bbf51aa
commit
f2c34d595f
@ -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)
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
@ -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']) ?>
|
||||
</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([
|
||||
'dataProvider' => $dataProvider,
|
||||
'filterModel' => $searchModel,
|
||||
|
Loading…
Reference in New Issue
Block a user