$filters = [
'category' => $request->get('category'),
'store_id' => $request->get('store_id'),
- 'year' => $request->get('year'),
- 'month' => $request->get('month'),
- 'type' => $request->get('type'),
+ 'year' => $request->get('year'),
+ 'month' => $request->get('month'),
+ 'type' => $request->get('type'),
];
$categoriesProvider = new ArrayDataProvider([
- 'allModels' => [],
+ 'allModels' => [],
'pagination' => ['pageSize' => 50],
]);
$productsProvider = new ArrayDataProvider([
- 'allModels' => [],
+ 'allModels' => [],
'pagination' => ['pageSize' => 100],
]);
);
$service = new AutoPlannogrammaService();
- $data = $service->getMonthCategoryShareOrWriteOff(
+ $data = $service->getMonthCategoryShareOrWriteOff(
$filters['plan_date'],
$filters,
$filters['type']
);
- $allProdIds = [];
+ $allProdIds = [];
$categoryRows = [];
$storeNames = CityStore::find()->select(['id', 'name'])->indexBy('id')->asArray()->all();
foreach ($data as $storeId => $categories) {
foreach ($categories as $row) {
- $prodIds = array_filter(explode(',', $row['products_list'] ?? ''), fn($v)=>$v!=='');
- $prodCompIds = array_filter(explode(',', $row['products_components_list'] ?? ''), fn($v)=>$v!=='');
- $rowProdIds = array_merge($prodIds, $prodCompIds);
+ $prodIds = array_filter(explode(',', $row['products_list'] ?? ''), fn($v) => $v !== '');
+ $prodCompIds = array_filter(explode(',', $row['products_components_list'] ?? ''), fn($v) => $v !== '');
+ $rowProdIds = array_merge($prodIds, $prodCompIds);
$categoryRows[] = [
- 'store_id' => (string)$storeId,
- 'store_name' => $storeNames[$storeId]['name'] ?? null,
- 'category' => $row['category'],
+ 'store_id' => (string)$storeId,
+ 'store_name' => $storeNames[$storeId]['name'] ?? null,
+ 'category' => $row['category'],
'base_total_store' => $row['base_total_store'],
- 'new_total_store' => $row['new_total_store'],
- 'total_sum' => $row['total_sum'],
- 'percent' => $row['percent'],
- 'product_ids' => $rowProdIds,
+ 'new_total_store' => $row['new_total_store'],
+ 'total_sum' => $row['total_sum'],
+ 'percent' => $row['percent'],
+ 'product_ids' => $rowProdIds,
];
$allProdIds = array_merge($allProdIds, $rowProdIds);
$allProdIds = array_values(array_unique($allProdIds));
$products = Products1c::find()
- ->select(['id','name','type','components'])
- ->andWhere(['id'=>$allProdIds])
+ ->select(['id', 'name', 'type', 'components'])
+ ->andWhere(['id' => $allProdIds])
->asArray()
->indexBy('id')
->all();
->andWhere(['region_id' => 52])
->andWhere(['active' => 1])
->one()->price ?? null;
- $productsRows[] = $prod;
+ $productsRows[] = $prod;
}
}
if (!empty($filters['category'])) {
- $productsRows = array_filter($productsRows, function($prod) use ($filters) {
+ $productsRows = array_filter($productsRows, function ($prod) use ($filters) {
return $prod['category'] === $filters['category'];
});
}
$productsProvider = new ArrayDataProvider([
- 'allModels' => $productsRows,
- 'pagination' => ['pageSize'=>500],
+ 'allModels' => $productsRows,
+ 'pagination' => ['pageSize' => 500],
]);
- $categoryRows = array_filter($categoryRows, function($row) use ($filters) {
+ $categoryRows = array_filter($categoryRows, function ($row) use ($filters) {
foreach ($filters as $key => $value) {
if (!$value || !isset($row[$key])) {
continue;
$categoriesProvider = new ArrayDataProvider([
- 'allModels' => array_values($categoryRows),
+ 'allModels' => array_values($categoryRows),
'pagination' => ['pageSize' => 500],
]);
return $this->render('1_2', [
'categoriesProvider' => $categoriesProvider,
- 'productsProvider' => $productsProvider,
- 'filters' => $filters,
+ 'productsProvider' => $productsProvider,
+ 'filters' => $filters,
]);
}
$matrixGroups = array_unique(ArrayHelper::getColumn($matrixForecast, 'group'));
$bouquetForecast = StorePlanService::getBouquetSpiecesMonthGoalFromForecast($filters['month'], $filters['year'], $filters['store_id'], $matrixGroups);
$speciesData = $bouquetForecast['final'];
- foreach ($speciesData as $store_id => $categoryData) {
+ foreach ($speciesData as $store_id => $categoryData) {
foreach ($categoryData as $category => $subcategoryData) {
foreach ($subcategoryData as $subcategory => $species) {
foreach ($species as $speciesInd => $row) {
$filters['species']
);
-/* $matrixForecast = MatrixBouquetForecast::find()
- ->where(['year' => $filters['year'], 'month' => $filters['month']])
- ->asArray()
- ->all();
- $matrixGroups = array_unique(ArrayHelper::getColumn($matrixForecast, 'group'));
- $bouquetForecast = StorePlanService::getBouquetSpiecesMonthGoalFromForecast($filters['month'], $filters['year'], $filters['store_id'], $matrixGroups);
- $speciesData = $bouquetForecast['final'];
- foreach ($speciesData as $store_id => $categoryData) {
- foreach ($categoryData as $category => $subcategoryData) {
- foreach ($subcategoryData as $subcategory => $species) {
- foreach ($species as $speciesInd => $row) {
- $bouquetSpeciesForecast[] = [
- 'category' => $category,
- 'subcategory' => $subcategory,
- 'store_id' => $store_id,
- 'species' => $speciesInd,
- 'goal' => $row
- ];
- }
- }
- }
+ /* $matrixForecast = MatrixBouquetForecast::find()
+ ->where(['year' => $filters['year'], 'month' => $filters['month']])
+ ->asArray()
+ ->all();
+ $matrixGroups = array_unique(ArrayHelper::getColumn($matrixForecast, 'group'));
+ $bouquetForecast = StorePlanService::getBouquetSpiecesMonthGoalFromForecast($filters['month'], $filters['year'], $filters['store_id'], $matrixGroups);
+ $speciesData = $bouquetForecast['final'];
+ foreach ($speciesData as $store_id => $categoryData) {
+ foreach ($categoryData as $category => $subcategoryData) {
+ foreach ($subcategoryData as $subcategory => $species) {
+ foreach ($species as $speciesInd => $row) {
+ $bouquetSpeciesForecast[] = [
+ 'category' => $category,
+ 'subcategory' => $subcategory,
+ 'store_id' => $store_id,
+ 'species' => $speciesInd,
+ 'goal' => $row
+ ];
+ }
+ }
+ }
- }
- $cleanedSpeciesGoals = $service->subtractSpeciesGoals($goals, $bouquetSpeciesForecast, $noHistoryProductData);*/
+ }
+ $cleanedSpeciesGoals = $service->subtractSpeciesGoals($goals, $bouquetSpeciesForecast, $noHistoryProductData);*/
$salesProductForecastShare = $service->calculateProductForecastShare($noHistoryProductData, $productSalesForecast);
- // $productForecastSpecies = $service->calculateProductSalesBySpecies($salesProductForecastShare, $cleanedSpeciesGoals);
+ // $productForecastSpecies = $service->calculateProductSalesBySpecies($salesProductForecastShare, $cleanedSpeciesGoals);
$flatData = array_filter($salesProductForecastShare, function ($row) use ($filters) {
foreach ($filters as $key => $value) {
$matrixGroups = array_unique(ArrayHelper::getColumn($matrixForecast, 'group'));
$bouquetForecast = StorePlanService::getBouquetSpiecesMonthGoalFromForecast($filters['month'], $filters['year'], $filters['store_id'], $matrixGroups);
$speciesData = $bouquetForecast['final'];
- foreach ($speciesData as $store_id => $categoryData) {
+ foreach ($speciesData as $store_id => $categoryData) {
foreach ($categoryData as $category => $subcategoryData) {
foreach ($subcategoryData as $subcategory => $species) {
foreach ($species as $speciesInd => $row) {
$salesProductForecastShare = $service->calculateProductForecastShare($noHistoryProductData, $productSalesForecast);
- $productForecastSpecies = $service->calculateProductSalesBySpecies($salesProductForecastShare, $cleanedSpeciesGoals);
+ $productForecastSpecies = $service->calculateProductSalesBySpecies($salesProductForecastShare, $cleanedSpeciesGoals);
$flatData = array_filter($productForecastSpecies, function ($row) use ($filters) {
foreach ($filters as $key => $value) {
$matrixGroups = array_unique(ArrayHelper::getColumn($matrixForecast, 'group'));
$bouquetForecast = StorePlanService::getBouquetSpiecesMonthGoalFromForecast($filters['month'], $filters['year'], $filters['store_id'], $matrixGroups);
$speciesData = $bouquetForecast['final'];
- foreach ($speciesData as $store_id => $categoryData) {
+ foreach ($speciesData as $store_id => $categoryData) {
foreach ($categoryData as $category => $subcategoryData) {
foreach ($subcategoryData as $subcategory => $species) {
foreach ($species as $speciesInd => $row) {
$service = new AutoPlannogrammaService();
-
$weeklySales = $service->getHistoricalSpeciesShareByWeek($filters['plan_date'], $filters);
-
-
-
-
$flatData = array_filter($weeklySales, function ($row) use ($filters) {
foreach ($filters as $key => $value) {
if (empty($value)) continue;
}
- /* $result = StorePlanService::calculateHistoricalShare(
- $filters['store_id'],
- $filters['month'],
- $filters['year'],
- null,
- null,
- null
- );*/
+ /* $result = StorePlanService::calculateHistoricalShare(
+ $filters['store_id'],
+ $filters['month'],
+ $filters['year'],
+ null,
+ null,
+ null
+ );*/
$noHistoryProductData = $service->calculateSpeciesForecastForProductsWithoutHistory($filters['plan_date'], $filters);
$historyProductData = $service->calculateSpeciesForecastForProductsWithHistory($filters['plan_date'], $filters, $goals);
- /* $productSalesShare = StorePlanService::calculateProductSalesShareProductsWithHistory(
- $filters['store_id'],
- $filters['month'],
- $result['with_history']
- );
-
- $productSalesForecast = $service->calculateProductForecastInPiecesProductsWithHistory(
- $filters['store_id'],
- $filters['month'],
- $productSalesShare,
- $goals,
- $filters['subcategory'],
- $filters['category'],
- $filters['species']
- );*/
+ /* $productSalesShare = StorePlanService::calculateProductSalesShareProductsWithHistory(
+ $filters['store_id'],
+ $filters['month'],
+ $result['with_history']
+ );
+
+ $productSalesForecast = $service->calculateProductForecastInPiecesProductsWithHistory(
+ $filters['store_id'],
+ $filters['month'],
+ $productSalesShare,
+ $goals,
+ $filters['subcategory'],
+ $filters['category'],
+ $filters['species']
+ );*/
$matrixForecast = MatrixBouquetForecast::find()
->where(['year' => $filters['year'], 'month' => $filters['month']])
$matrixGroups = array_unique(ArrayHelper::getColumn($matrixForecast, 'group'));
$bouquetForecast = StorePlanService::getBouquetSpiecesMonthGoalFromForecast($filters['month'], $filters['year'], $filters['store_id'], $matrixGroups);
$speciesData = $bouquetForecast['final'];
- foreach ($speciesData as $store_id => $categoryData) {
+ foreach ($speciesData as $store_id => $categoryData) {
foreach ($categoryData as $category => $subcategoryData) {
foreach ($subcategoryData as $subcategory => $species) {
foreach ($species as $speciesInd => $row) {
}
-
-
public function actionControlSpeciesOld()
{
$model = new DynamicModel([
->addRule('storeId', 'integer');
$storeList = CityStore::find()
- ->select(['name','id'])
+ ->select(['name', 'id'])
->where(['visible' => CityStore::IS_VISIBLE])
->indexBy('id')
->column();
list($m, $y) = explode('-', $model->month);
$dateFrom = date("Y-m-d 00:00:00", strtotime(sprintf('%04d-%02d-01', $y, $m)));
- $dateTo = date("Y-m-t 23:59:59", strtotime($dateFrom));
+ $dateTo = date("Y-m-t 23:59:59", strtotime($dateFrom));
if ($model->storeId) {
$filters['store_id'] = $model->storeId;
$monthSpeciesGoalsMap[$monthSpeciesGoal['store_id']]
[$monthSpeciesGoal['category']]
[$monthSpeciesGoal['subcategory']]
- [$monthSpeciesGoal['species']] = $monthSpeciesGoal['goal'] ;
+ [$monthSpeciesGoal['species']] = $monthSpeciesGoal['goal'];
}
$weeksShareResult = $service->getHistoricalWeeklySpeciesShare($model->month, $filters, null, 'writeOffs');
- $weeksData = $service->calculateWeeklySpeciesGoals($weeksShareResult['weeksData'], $monthSpeciesGoals) ;
+ $weeksData = $service->calculateWeeklySpeciesGoals($weeksShareResult['weeksData'], $monthSpeciesGoals);
$datePlan = $filters['plan_date'];
$monthCategoryShare = $service->getMonthCategoryShareOrWriteOffWeighted($datePlan, $filters, null, $filters['type']);
$monthCategoryGoal = $service->getMonthCategoryGoal($monthCategoryShare, $datePlan, $filters['type']);
foreach ($monthCategoryShare as $sid => $cats) {
- foreach($cats as $cat) {
+ foreach ($cats as $cat) {
$monthCategoryShareResult[$sid][$cat['category']]['total_sum_cat'] = $cat['total_sum_cat'];
$monthCategoryShareResult[$sid][$cat['category']]['share_of_total'] = $cat['share_of_total'];
}
}
foreach ($monthCategoryGoal as $cats) {
- $monthCategoryShareResult[$cats['store_id']][$cats['category']]['goal'] = $cats['goal'];
+ $monthCategoryShareResult[$cats['store_id']][$cats['category']]['goal'] = $cats['goal'];
}
$monthSubcategoryGoal = $service->getMonthSubcategoryGoal($monthSubcategoryShare, $monthCategoryGoal);
if ($filters['type'] === 'writeOffs') {
- $salesSubShare = $service->getMonthSubcategoryShareOrWriteOffWeighted($datePlan, $filters, null, 'sales');
- $salesSubGoal = $service->getMonthSubcategoryGoal($salesSubShare, $monthCategoryGoal);
+ $salesSubShare = $service->getMonthSubcategoryShareOrWriteOffWeighted($datePlan, $filters, null, 'sales');
+ $salesSubGoal = $service->getMonthSubcategoryGoal($salesSubShare, $monthCategoryGoal);
$catGoalMap = [];
foreach ($monthCategoryGoal as $row) {
$writeShare = $row['percent_of_month'];
- $writeGoal = ($catGoalMap[$cat] ?? 0) * $writeShare;
- $saleGoal = $salesSubGoalMap[$cat][$sub] ?? 0;
+ $writeGoal = ($catGoalMap[$cat] ?? 0) * $writeShare;
+ $saleGoal = $salesSubGoalMap[$cat][$sub] ?? 0;
if ($saleGoal > 0 && $writeGoal > 0.1 * $saleGoal) {
$row['share'] = 0.1;
}
foreach ($monthSubcategoryShare as $subcat) {
- $monthCategoryShareResult[$subcat['store_id']][$subcat['category']][$subcat['subcategory']]['total_sum'] = $subcat['total_sum'];
- $monthCategoryShareResult[$subcat['store_id']][$subcat['category']][$subcat['subcategory']]['percent_of_month'] = $subcat['percent_of_month'];
+ $monthCategoryShareResult[$subcat['store_id']][$subcat['category']][$subcat['subcategory']]['total_sum'] = $subcat['total_sum'];
+ $monthCategoryShareResult[$subcat['store_id']][$subcat['category']][$subcat['subcategory']]['percent_of_month'] = $subcat['percent_of_month'];
}
foreach ($monthSubcategoryGoal as $cats) {
$monthCategoryShareResult[$cats['store_id']][$cats['category']][$cats['subcategory']]['goal'] = $cats['goal'];
$monthSpeciesGoal = $service->getMonthSpeciesGoalDirty($monthSpeciesShare, $monthSubcategoryGoal);
if ($filters['type'] === 'writeOffs') {
$salesSpecShare = $service->getMonthSpeciesShareOrWriteOffWeighted($datePlan, $datePlan, $filters, null, 'sales');
- $salesSpecGoal = $service->getMonthSpeciesGoalDirty($salesSpecShare, $monthSubcategoryGoal);
+ $salesSpecGoal = $service->getMonthSpeciesGoalDirty($salesSpecShare, $monthSubcategoryGoal);
$subGoalMap = [];
foreach ($monthSubcategoryGoal as $row) {
}
foreach ($monthSpeciesShare as &$row) {
- $cat = $row['category'];
- $sub = $row['subcategory'];
+ $cat = $row['category'];
+ $sub = $row['subcategory'];
$spec = $row['species'];
$writeShare = $row['percent_of_month'];
- $writeGoal = ($subGoalMap[$cat][$sub] ?? 0) * $writeShare;
- $saleGoal = $salesSpecGoalMap[$cat][$sub][$spec] ?? 0;
+ $writeGoal = ($subGoalMap[$cat][$sub] ?? 0) * $writeShare;
+ $saleGoal = $salesSpecGoalMap[$cat][$sub][$spec] ?? 0;
if ($saleGoal > 0 && $writeGoal > 0.1 * $saleGoal) {
$row['share'] = 0.1;
$forecasts = $service->calculateWeekForecastSpeciesProducts($r['category'], $r['subcategory'], $r['species'], $r['store_id'], $r['weekly_goal']);
foreach ($forecasts as $forecast) {
$weeksProductForecast[] = [
- 'category' => $forecast['category'] ?? '',
+ 'category' => $forecast['category'] ?? '',
'subcategory' => $forecast['subcategory'] ?? '',
- 'species' => $forecast['species'] ?? '',
- 'product_id' => $forecast['product_id'] ?? '',
- 'name' => $forecast['name'] ?? '',
- 'price' => $forecast['price'] ?? '',
- 'goal' => $forecast['goal'] ?? 0,
- 'forecast' => $forecast['forecast'] ?? 0,
- 'week' => $r['week'],
+ 'species' => $forecast['species'] ?? '',
+ 'product_id' => $forecast['product_id'] ?? '',
+ 'name' => $forecast['name'] ?? '',
+ 'price' => $forecast['price'] ?? '',
+ 'goal' => $forecast['goal'] ?? 0,
+ 'forecast' => $forecast['forecast'] ?? 0,
+ 'week' => $r['week'],
];
}
}
- usort($weeksProductForecast, function($a, $b) {
- foreach (['category','subcategory','species','name','week'] as $key) {
+ usort($weeksProductForecast, function ($a, $b) {
+ foreach (['category', 'subcategory', 'species', 'name', 'week'] as $key) {
$va = $a[$key];
$vb = $b[$key];
if ($va < $vb) return -1;
- if ($va > $vb) return 1;
+ if ($va > $vb) return 1;
}
return 0;
});
}
return $this->render('control-species-old', [
- 'model' => $model,
- 'result' => $monthResult,
- 'weeksData' => $weeksData,
+ 'model' => $model,
+ 'result' => $monthResult,
+ 'weeksData' => $weeksData,
'monthCategoryShare' => $monthCategoryShareResult,
'weeksProductForecast' => $weeksProductForecast,
- 'totals' => $totals,
- 'storeList' => $storeList,
- 'monthsList' => $monthsList,
+ 'totals' => $totals,
+ 'storeList' => $storeList,
+ 'monthsList' => $monthsList,
]);
}
->addRule('storeId', 'integer');
$storeList = CityStore::find()
- ->select(['name','id'])
+ ->select(['name', 'id'])
->where(['visible' => CityStore::IS_VISIBLE])
->indexBy('id')
->column();
list($m, $y) = explode('-', $model->month);
$dateFrom = date("Y-m-d 00:00:00", strtotime(sprintf('%04d-%02d-01', $y, $m)));
- $dateTo = date("Y-m-t 23:59:59", strtotime($dateFrom));
+ $dateTo = date("Y-m-t 23:59:59", strtotime($dateFrom));
if ($model->storeId) {
$filters['store_id'] = $model->storeId;
$weeksShareResult = $service->getHistoricalWeeklySpeciesShare($model->month, $filters, null, 'writeOffs');
- $weeksData = $service->calculateWeeklySpeciesGoals($weeksShareResult, $monthSpeciesGoals) ;
+ $weeksData = $service->calculateWeeklySpeciesGoals($weeksShareResult, $monthSpeciesGoals);
$datePlan = $filters['plan_date'];
- $monthCategoryShare = $service->getMonthCategoryShareOrWriteOff($datePlan, $filters, $filters['type']);
- $monthCategoryGoal = $service->getMonthCategoryGoal($monthCategoryShare, $datePlan, $filters['type']);
+ $monthCategoryShare = $service->getMonthCategoryShareOrWriteOff($datePlan, $filters, $filters['type']);
+ $monthCategoryGoal = $service->getMonthCategoryGoal($monthCategoryShare, $datePlan, $filters['type']);
$monthCategorySalesShare = $service->getMonthCategoryShareOrWriteOff($datePlan, $filters);
$monthCategorySalesGoal = $service->getMonthCategoryGoal($monthCategorySalesShare, $datePlan);
foreach ($monthCategoryShare as $sid => $cats) {
- foreach($cats as $cat) {
+ foreach ($cats as $cat) {
$monthCategoryShareResult[$sid][$cat['category']]['total_sum'] = $cat['total_sum'];
$monthCategoryShareResult[$sid][$cat['category']]['percent'] = $cat['percent'];
}
$monthSubcategorySalesShare = $service->getMonthSubcategoryShareOrWriteOff($datePlan, $filters);
$monthSubcategorySalesGoal = $service->getMonthSubcategoryGoal($monthSubcategorySalesShare, $monthCategorySalesGoal);
- $monthSubcategoryShare = $service->getMonthSubcategoryShareOrWriteOff($datePlan, $filters, $filters['type']);
- $monthSubcategoryGoal = $service->getMonthSubcategoryGoal($monthSubcategoryShare, $monthCategoryGoal, $filters['type'], $monthSubcategorySalesGoal);
+ $monthSubcategoryShare = $service->getMonthSubcategoryShareOrWriteOff($datePlan, $filters, $filters['type']);
+ $monthSubcategoryGoal = $service->getMonthSubcategoryGoal($monthSubcategoryShare, $monthCategoryGoal, $filters['type'], $monthSubcategorySalesGoal);
foreach ($monthSubcategoryShare as $subcat) {
$monthCategoryShareResult[$subcat['store_id']][$subcat['category']][$subcat['subcategory']]['total_sum'] = $subcat['total_sum'];
$forecasts = $service->calculateWeekForecastSpeciesProducts($r['category'], $r['subcategory'], $r['species'], $r['store_id'], $r['weekly_goal']);
foreach ($forecasts as $forecast) {
$weeksProductForecast[] = [
- 'category' => $forecast['category'] ?? '',
+ 'category' => $forecast['category'] ?? '',
'subcategory' => $forecast['subcategory'] ?? '',
- 'species' => $forecast['species'] ?? '',
- 'product_id' => $forecast['product_id'] ?? '',
- 'name' => $forecast['name'] ?? '',
- 'price' => $forecast['price'] ?? '',
- 'goal' => $forecast['goal'] ?? 0,
- 'forecast' => $forecast['forecast'] ?? 0,
- 'week' => $r['week'],
+ 'species' => $forecast['species'] ?? '',
+ 'product_id' => $forecast['product_id'] ?? '',
+ 'name' => $forecast['name'] ?? '',
+ 'price' => $forecast['price'] ?? '',
+ 'goal' => $forecast['goal'] ?? 0,
+ 'forecast' => $forecast['forecast'] ?? 0,
+ 'week' => $r['week'],
];
}
}
- usort($weeksProductForecast, function($a, $b) {
- foreach (['category','subcategory','species','name','week'] as $key) {
+ usort($weeksProductForecast, function ($a, $b) {
+ foreach (['category', 'subcategory', 'species', 'name', 'week'] as $key) {
$va = $a[$key];
$vb = $b[$key];
if ($va < $vb) return -1;
- if ($va > $vb) return 1;
+ if ($va > $vb) return 1;
}
return 0;
});
}
return $this->render('control-species', [
- 'model' => $model,
- 'result' => $monthResult,
- 'weeksData' => $weeksData,
+ 'model' => $model,
+ 'result' => $monthResult,
+ 'weeksData' => $weeksData,
'monthCategoryShare' => $monthCategoryShareResult,
'weeksProductForecast' => $weeksProductForecast,
- 'totals' => $totals,
- 'storeList' => $storeList,
- 'monthsList' => $monthsList,
+ 'totals' => $totals,
+ 'storeList' => $storeList,
+ 'monthsList' => $monthsList,
]);
}
+ public function actionGetSubcategories(string $category, int $year, int $week): array
+ {
+ Yii::$app->response->format = Response::FORMAT_JSON;
+ $data = Autoplannogramma::find()
+ ->alias('a')
+ ->leftJoin('products_1c_nomenclature p', 'a.product_id = p.id')
+ ->where(['p.category' => $category])
+ ->andWhere(['a.year' => $year])
+ ->andWhere(['a.week' => $week])
+ ->select([
+ 'p.subcategory as name',
+ new \yii\db\Expression("CASE WHEN COUNT(a.id) > 0 THEN 1 ELSE 0 END AS hasData")
+ ])
+ ->groupBy('p.subcategory')
+ ->asArray()
+ ->all();
+ return $data;
+ }
}