public function actionExportExcel()
{
- $rows = [];
- /* $rows[] = [
- 'week' => '1',
- 'type_pm' => 'max',
- 'shop' => 'Ванеева',
- 'category' => 'Срезка',
- 'subcategory' => 'Розы',
- 'species' => 'Роза',
- 'product_name' => 'Роза Эквадор',
- 'quantity' => '3',
- 'value_type' => 'offline',
- 'group_name' => 'Оффлайн',
- ];*/
$request = Yii::$app->request;
$this->layout = false;
Yii::$app->response->format = Response::FORMAT_RAW;
ob_end_clean();
}
- $filters = [
- 'category' => $request->get('category'),
- 'subcategory' => $request->get('subcategory') ?? null,
- 'species' => $request->get('species') ?? null,
- 'store_id' => $request->get('store_id') ?? [],
- 'year' => $request->get('year'),
- 'month' => $request->get('month'),
- 'type' => $request->get('type'),
- ];
-
-
-
- $bouquetSpeciesForecast = [];
-
-
- $filters['plan_date'] = $filters['year'] . '-' . str_pad($filters['month'], 2, '0', STR_PAD_LEFT) . '-01';
- // var_dump( $filters['plan_date']); die();
- $service = new AutoPlannogrammaService();
-
- $monthCategoryShare = $service->getMonthCategoryShareOrWriteOff($filters['plan_date'], $filters);
- $monthCategoryGoal = $service->getMonthCategoryGoal($monthCategoryShare, $filters['plan_date']);
- $monthSubcategoryShare = $service->getMonthSubcategoryShareOrWriteOff($filters['plan_date'], $filters);
- $monthSubcategoryGoal = $service->getMonthSubcategoryGoal($monthSubcategoryShare, $monthCategoryGoal);
- $monthSpeciesShare = $service->getMonthSpeciesShareOrWriteOff($filters['plan_date'], $filters);
- $goals = $service->getMonthSpeciesGoalDirty($monthSpeciesShare, $monthSubcategoryGoal);
-
- if ($filters['type'] == AutoPlannogrammaService::TYPE_WRITE_OFFS) {
- $monthCategoryWriteOffsShare = $service->getMonthCategoryShareOrWriteOff($filters['plan_date'], $filters, $filters['type']);
- $monthCategoryWriteOffsGoal = $service->getMonthCategoryGoal($monthCategoryWriteOffsShare, $filters['plan_date'], $filters['type']);
- $monthSubcategoryWriteOffsShare = $service->getMonthSubcategoryShareOrWriteOff($filters['plan_date'], $filters, $filters['type']);
- $monthSubcategoryWriteOffsGoals = $service->getMonthSubcategoryGoal($monthSubcategoryWriteOffsShare, $monthCategoryWriteOffsGoal, $filters['type']);
- $monthSpeciesWriteOffShare = $service->getMonthSpeciesShareOrWriteOff($filters['plan_date'], $filters, $filters['type']);
- $goals = $service->getMonthSpeciesGoalDirty($monthSpeciesWriteOffShare, $monthSubcategoryWriteOffsGoals, $filters['type'], $data);
- }
-
-
- $result = StorePlanService::calculateHistoricalShare(
- $filters['store_id'],
- $filters['month'],
- $filters['year'],
- $filters['category'],
- $filters['subcategory'],
- $filters['species']
- );
-
- $noHistoryProductData = $service->calculateSpeciesForecastForProductsWithoutHistory($filters['plan_date'], $filters);
-
- $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']])
- ->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);
-
-
- $salesProductForecastShare = $service->calculateProductForecastShare($noHistoryProductData, $productSalesForecast);
+ $filters = $request->get();
- $productForecastSpecies = $service->calculateProductSalesBySpecies($salesProductForecastShare, $cleanedSpeciesGoals);
+ $query = Autoplannogramma::find()
+ ->alias('a')
+ ->leftJoin('products_1c_nomenclature p1n', 'p1n.id = a.product_id')
+ ->leftJoin('city_store_params cp', 'cp.store_id = a.store_id')
+ // ->where(['p1n.category' => $category])
+ // ->andWhere(['p1n.subcategory' => $subcategory])
+ ->andFilterWhere(['=', 'a.year', $filters['year']])
+ ->andFilterWhere(['=', 'a.week', $filters['week']])
+ ->andFilterWhere(['=', 'cp.address_city', $filters['city']])
+ ->andFilterWhere(['=', 'cp.address_region', $filters['region']])
+ ->andFilterWhere(['=', 'cp.address_district', $filters['district']])
+ ->andFilterWhere(['=', 'cp.store_type', $filters['store_type']])
+ ->andFilterWhere(['=', 'a.capacity_type', $filters['capacity_type']]);
+ if (!empty($filters['territorial_manager'])) {
+ $territorialManagerStoreIds = StoreDynamic::find()
+ ->select('store_id')
+ ->where(['category' => 3, 'active' => 1, 'value_int' => $filters['territorial_manager']])
+ ->column();
+ $query->andWhere(['in', 'a.store_id', $territorialManagerStoreIds ?: [-1]]);
+ }
- $weeklySales = $service->getHistoricalSpeciesShareByWeek($filters['plan_date'], $filters);
+ if (!empty($filters['bush_chef_florist'])) {
+ $bushChefFloristStoreIds = StoreDynamic::find()
+ ->select('store_id')
+ ->where(['category' => 2, 'active' => 1, 'value_int' => $filters['bush_chef_florist']])
+ ->column();
+ $query->andWhere(['in', 'a.store_id', $bushChefFloristStoreIds ?: [-1]]);
+ }
- $weeklySalesForecast = $service->calculateWeeklyProductForecastPieces($productForecastSpecies, $weeklySales);
+ $models = $query
+ ->select([
+ 'a.id AS plan_id',
+ 'p1n.id AS product_id',
+ 'p1n.name AS product_name',
+ 'a.store_id',
+ 'a.modify',
+ 'a.details',
+ 'a.month'
+ ])
+ ->asArray()
+ ->all();
foreach ($weeklySalesForecast as $fc ) {