$model->load(Yii::$app->request->get());
///////////////////////////////////////////
- $sales = Sales::find()->where(['operation' => Sales::OPERATION_SALE])
+ $sales = Sales::find()->select(['SUM(summ) as total'])->where(['operation' => Sales::OPERATION_SALE])
->andWhere(['>=', 'date', date($model->year . '-' . $model->month . '-01 00:00:00')])
- ->andWhere(['<=', 'date', date($model->year . '-' . $model->month . '-t 23:59:59')])
- ->all();
+ ->andWhere(['<=', 'date', date($model->year . '-' . $model->month . '-10 23:59:59')])
+ ->asArray()->one();
+ $total = $sales['total'] ?? 0;
///////////////////////////////////////////
$years = [];
for ($i = 3; $i >= 0; $i--) {
$stores = ArrayHelper::map(CityStore::find()->andWhere(['visible' => '1'])->all(), 'id', 'name');
- return $this->render('index', compact('model', 'years', 'stores'));
+ return $this->render('index', compact('model', 'years', 'stores', 'total'));
}
public function actionGetStores() {
/* @var $model DynamicModel */
/* @var $years array */
/* @var $stores array */
-
+/* @var $total float */
$this->registerJsFile('/js/matrix-statistics/index.js', ['position' => \yii\web\View::POS_END]);
<div class="row">
<div class="col-1 text-right">Сумма тотал</div>
- <div class="col-2">976 250 р</div>
+ <div class="col-2"><?= number_format($total, 0, '.', ' ')?>р</div>
</div>
<div class="row">
<div class="col-1 text-right">% цели магазина</div>