use yii\web\Response;
use yii_app\records\BouquetComposition;
use yii_app\records\BouquetCompositionMatrixTypeHistory;
+use yii_app\records\BouquetForecast;
use yii_app\records\CityStore;
use yii_app\records\CityStoreParams;
use yii_app\records\MatrixType;
$model->load(Yii::$app->request->get());
///////////////////////////////////////////
-// $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 . '-10 23:59:59')])
-// ->asArray()->one();
$total = 0;
$matrixTypes = MatrixType::find()->orderBy(['id' => SORT_ASC])->all();
$boquetCompositionMatrixTypeHistory = BouquetCompositionMatrixTypeHistory::find()->where(['is_active' => true])->all();
- $matrixCost = [];
+ $saleCountPlan = [];
foreach ($boquetCompositionMatrixTypeHistory as $bcmth) {
/** @var BouquetCompositionMatrixTypeHistory $bcmth */
- $bouquetComposition = BouquetComposition::findOne($bcmth->bouquet_id);
- $cost = $bouquetComposition->getCost();
- $matrixCost[$bcmth->matrix_type_id] = ($matrixCost[$bcmth->matrix_type_id] ?? 0) + $cost;
- $total += $cost;
+ $bouquetForecastQuery = BouquetForecast::find()->where([
+ 'bouquet_id' => $bcmth->bouquet_id,
+ 'year' => $model->year,
+ 'month' => $model->month
+ ]);
+ if ($model->sale_type) {
+ $bouquetForecastQuery->andWhere(['type_sales' => $model->sale_type]);
+ }
+ $bouquetForecast = $bouquetForecastQuery->all();
+
+ foreach ($bouquetForecast as $bf) {
+ /** @var BouquetForecast $bf */
+ $count = $bf->type_sales_value ?? 0;
+ $saleCountPlan[$bcmth->matrix_type_id] = ($saleCountPlan[$bcmth->matrix_type_id] ?? 0) + $count;
+ $total += $count;
+ }
}
///////////////////////////////////////////
$years = [];
$stores = ArrayHelper::map(CityStore::find()->andWhere(['visible' => '1'])->all(), 'id', 'name');
- return $this->render('index', compact('model', 'years', 'stores', 'total', 'matrixCost', 'matrixTypes'));
+ return $this->render('index', compact('model', 'years', 'stores', 'total', 'saleCountPlan', 'matrixTypes'));
}
public function actionGetStores() {
/* @var $years array */
/* @var $stores array */
/* @var $total float */
-/* @var $matrixCost array */
+/* @var $saleCountPlan array */
/* @var $matrixTypes array */
$this->registerJsFile('/js/matrix-statistics/index.js', ['position' => \yii\web\View::POS_END]);
<?php /** @var $matrixType MatrixType */ ?>
<div class="row">
<div class="col-1"></div>
- <div class="col-1"><?= $matrixType->name ?></div>
- <?php $cost = $matrixCost[$matrixType->id] ?? 0; ?>
+ <div class="col-1"><?= Html::a($matrixType->name, ['/bouquet/index' , 'matrix_type_id' => $matrixType->id], ['class' => 'btn btn-link']) ?></div>
+ <?php $cost = $saleCountPlan[$matrixType->id] ?? 0; ?>
<div class="col-2"><?= number_format($cost, 0, '.', ' ')?>р.</div>
<div class="col-2"><?= number_format($total == 0 ? 0 : $cost * 100.0 / $total, 0, '.', '')?>%</div>
</div>
<?php endforeach; ?>
+ <div class="row">
+ <div class="col-10"></div>
+ <div class="col-2">
+ <?= Html::a('Создать букет', ['/bouquet/create'], ['class' => 'btn btn-success']) ?>
+ </div>
+ </div>
</div>