/////////////////////////////////////////////////////////////////////////////////////
foreach ($types as $type) {
- if (!isset($categoryPlan[$type])) {
+ if (!empty($type) && !isset($categoryPlan[$type])) {
$categoryPlanNew = new CategoryPlan;
$categoryPlanNew->year = $model->year;
$categoryPlanNew->month = $model->month;
use yii_app\records\BouquetComposition;
use yii_app\records\BouquetCompositionMatrixTypeHistory;
use yii_app\records\BouquetForecast;
+use yii_app\records\CategoryPlan;
use yii_app\records\CityStore;
use yii_app\records\CityStoreParams;
use yii_app\records\MatrixType;
$total += $count;
}
}
+ $categoryPlans = CategoryPlan::find()->where(['year' => $model->year, 'month' => $model->month, 'store_id' => $model->store_id])->all();
+ $withoutMatrix = 0;
+ $withOnlyMatrix = 0;
+ foreach ($categoryPlans as $categoryPlan) {
+ /** @var $categoryPlan CategoryPlan */
+ $category = $categoryPlan->category;
+ $sum = 0;
+ switch ($model->sale_type) {
+ case 0: $sum = $categoryPlan->offline + $categoryPlan->internet_shop + $categoryPlan->marketplace; break;
+ case 1: $sum = $categoryPlan->offline; break;
+ case 2: $sum = $categoryPlan->internet_shop; break;
+ case 3: $sum = $categoryPlan->marketplace; break;
+ }
+ if ($category == 'Матрица') {
+ $withOnlyMatrix += $sum;
+ } else {
+ $withoutMatrix += $sum;
+ }
+ }
///////////////////////////////////////////
$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', 'total', 'saleCountPlan', 'matrixTypes'));
+ return $this->render('index', compact('model', 'years', 'stores', 'total',
+ 'withoutMatrix', 'withOnlyMatrix', 'saleCountPlan', 'matrixTypes'));
}
public function actionGetStores() {
/* @var $years array */
/* @var $stores array */
/* @var $total float */
+/* @var $withoutMatrix float */
+/* @var $withOnlyMatrix float */
/* @var $saleCountPlan array */
/* @var $matrixTypes array */
</div>
<div class="row">
<div class="col-1 text-right">% цели магазина</div>
- <div class="col-2">27%</div>
+ <div class="col-2"><?= number_format($withoutMatrix > 0 ? $total * 100.0 / $withoutMatrix : 0, 0, '.', ' ')?>%</div>
</div>
<div class="row">
<div class="col-1 text-right">% цели матрицы</div>
- <div class="col-2">-3%</div>
+ <div class="col-2"><?= number_format($withOnlyMatrix > 0 ? $total * 100.0 / $withOnlyMatrix : 0, 0, '.', ' ')?>%</div>
</div>
<div class="row">