'year' => $request->get('year'),
'month' => $request->get('month'),
'type' => $request->get('type'),
+ 'sales_type' => $request->get('sales_type'),
];
$dataProvider = new ArrayDataProvider([
$service = new AutoPlannogrammaService();
$monthCategoryShare = $service->getMonthCategoryShareOrWriteOff($filters['plan_date'], $filters, $filters['type']);
- $data = $service->getMonthCategoryGoal($monthCategoryShare, $filters['plan_date'], $filters['type']);
+ $data = $service->getMonthCategoryGoal($monthCategoryShare, $filters['plan_date'], $filters['type'], $filters['sales_type']);
$flatData = array_filter($data, function ($row) use ($filters) {
foreach ($filters as $key => $value) {
'year' => $request->get('year'),
'month' => $request->get('month'),
'type' => $request->get('type'),
+ 'sales_type' => $request->get('sales_type'),
];
$dataProvider = new ArrayDataProvider([
'year' => $request->get('year'),
'month' => $request->get('month'),
'type' => $request->get('type'),
+ 'sales_type' => $request->get('sales_type'),
];
$dataProvider = new ArrayDataProvider([
$service = new AutoPlannogrammaService();
$monthCategoryShare = $service->getMonthCategoryShareOrWriteOff($filters['plan_date'], $filters);
- $monthCategoryGoal = $service->getMonthCategoryGoal($monthCategoryShare, $filters['plan_date']);
+ $monthCategoryGoal = $service->getMonthCategoryGoal($monthCategoryShare, $filters['plan_date'], $filters['type'], $filters['sales_type']);
$monthSubcategoryShare = $service->getMonthSubcategoryShareOrWriteOff($filters['plan_date'], $filters);
$data = $service->getMonthSubcategoryGoal($monthSubcategoryShare, $monthCategoryGoal);
'year' => $request->get('year'),
'month' => $request->get('month'),
'type' => $request->get('type'),
+ 'sales_type' => $request->get('sales_type'),
];
$dataProvider = new ArrayDataProvider([
'year' => $request->get('year'),
'month' => $request->get('month'),
'type' => $request->get('type'),
+ 'sales_type' => $request->get('sales_type'),
];
$dataProvider = new ArrayDataProvider([
$service = new AutoPlannogrammaService();
$monthCategoryShare = $service->getMonthCategoryShareOrWriteOff($filters['plan_date'], $filters);
- $monthCategoryGoal = $service->getMonthCategoryGoal($monthCategoryShare, $filters['plan_date']);
+ $monthCategoryGoal = $service->getMonthCategoryGoal($monthCategoryShare, $filters['plan_date'], $filters['type'], $filters['sales_type']);
$monthSubcategoryShare = $service->getMonthSubcategoryShareOrWriteOff($filters['plan_date'], $filters);
$monthSubcategoryGoal = $service->getMonthSubcategoryGoal($monthSubcategoryShare, $monthCategoryGoal);
$monthSpeciesShare = $service->getMonthSpeciesShareOrWriteOff($filters['plan_date'], $filters);
* @param array $filters Фильтры
* @return array Массив с целями по категориям
*/
- public function getMonthCategoryGoal(array $categoryShare, string $datePlan, string $type = self::TYPE_SALES): array
+ public function getMonthCategoryGoal(array $categoryShare, string $datePlan, string $type = self::TYPE_SALES, string $sales_type = null): array
{
$timestamp = strtotime($datePlan);
$year = date('Y', $timestamp);
if (!isset($categoryShare[$storeId])) {
continue;
}
+ $goal = match ($sales_type) {
+ 'offline' => $plan['offline_sales_plan'],
+ 'online' => (int)$plan['online_sales_shop_plan'] + (int)$plan['online_sales_marketplace_plan'],
+ default => ($type === self::TYPE_WRITE_OFFS ? $plan['write_offs_plan'] : $plan['total_sales_plan']),
+ };
foreach ($categoryShare[$storeId] as $item) {
$result[] = [
'category' => $item['category'],
'store_id' => $storeId,
- 'goal' => round($item['percent'] * ($type === self::TYPE_WRITE_OFFS ? $plan['write_offs_plan'] : $plan['total_sales_plan']), 2),
+ 'goal' => round($item['percent'] * $goal, 2),
];
}
}
$storeIds = array_intersect($storeIds, [(int)$filters['store_id']]);
}
+ $mode = null;
+
+ if (!empty($filters['sales_type'])) {
+ $mode = $filters['sales_type'];
+ }
+ $orderCondition = [];
+ if ($mode === 'offline') {
+ $orderCondition = ['order_id' => ['', '0']];
+ } elseif ($mode === 'online') {
+ $orderCondition = ['not in', 'order_id', ['', '0']];
+ }
+
$sumExpression = $type === self::TYPE_WRITE_OFFS
? 'SUM(wp.summ)'
: "SUM(CASE
->leftJoin('export_import_table ex', $storeJoinCondition)
->leftJoin('products_1c p1', "p1.id = $productJoinCondition")
->andWhere(['ex.entity_id' => $storeIds])
+ ->andFilterWhere($orderCondition)
->andWhere(['p1.components' => ''])
->andWhere(['not in', 'p1c.category', ['', 'букет', 'сборка', 'сервис']])
->andWhere(['or', ...$months])
->leftJoin('export_import_table ex', $storeJoinCondition)
->leftJoin('products_1c p1', "p1.id = $productJoinCondition")
->andWhere(['ex.entity_id' => $storeIds])
+ ->andFilterWhere($orderCondition)
->andWhere(['p1.components' => ''])
->andWhere(['not in', 'p1c.category', ['', 'букет', 'сборка', 'сервис']])
->andWhere(['or', ...$months])
];
$componentAdds = [];
$componentAddsSumAll = [];
- $allComponentsProdIds = [];
+ $allComponentsProductIds = [];
foreach ($storeIds as $sid) {
foreach ($periods as $dt) {
continue;
}
- foreach ($items as $it) {
- $allComponentsProdIds[$sid][] = $it['product_id'];
- }
+ $filtered = match ($mode) {
+ 'offline' => array_filter($items, fn($it) => in_array($it['order_id'], ['', '0'], true)),
+ 'online' => array_filter($items, fn($it) => !in_array($it['order_id'], ['', '0'], true)),
+ default => $items, // для writeOffs — всё
+ };
+
+ $allComponentsProductIds[$sid] = array_merge(
+ $allComponentsProductIds[$sid] ?? [],
+ array_column($filtered, 'product_id')
+ );
+ $sums = $this->sumProductsComponentsByGroup($filtered, $type, 'subcategory');
- $sums = $this->sumProductsComponentsByGroup($items, $type, 'subcategory');
- $allComponentsProdIds[$sid] = array_unique($allComponentsProdIds[$sid]);
+ $allComponentsProductIds[$sid] = array_values(array_unique($allComponentsProductIds[$sid]));
foreach ($sums as $sr) {
$cat = $sr['category'];
'type' => $type,
'new_total_store' => $newCatTotal,
'base_total_store' => $catTotal,
- 'products_components_list' => implode(',', $allComponentsProdIds[$sid] ?? []),
+ 'products_components_list' => implode(',', $allComponentsProductIds[$sid] ?? []),
+ 'mode' => $mode
];
}
$storeIds = array_intersect($storeIds, [(int)$filters['store_id']]);
}
+ $mode = null;
+
+ if (!empty($filters['sales_type'])) {
+ $mode = $filters['sales_type'];
+ }
+ $orderCondition = [];
+ if ($mode === 'offline') {
+ $orderCondition = ['order_id' => ['', '0']];
+ } elseif ($mode === 'online') {
+ $orderCondition = ['not in', 'order_id', ['', '0']];
+ }
+
$sumExpression = $type === self::TYPE_WRITE_OFFS
? 'SUM(wp.summ)'
: "SUM(CASE
->leftJoin('export_import_table ex', $storeJoinCondition)
->leftJoin('products_1c p1', "p1.id = $productJoinCondition")
->andWhere(['ex.entity_id' => $storeIds])
+ ->andFilterWhere($orderCondition)
->andWhere(['p1.components' => ''])
->andWhere(['not in', 'p1c.category', ['', 'букет', 'сборка', 'сервис']])
->andWhere(['or', ...$months])
->leftJoin('export_import_table ex', $storeJoinCondition)
->leftJoin('products_1c p1', "p1.id = $productJoinCondition")
->andWhere(['ex.entity_id' => $storeIds])
+ ->andFilterWhere($orderCondition)
->andWhere(['p1.components' => ''])
->andWhere(['not in', 'p1c.category', ['', 'букет', 'сборка', 'сервис']])
->andWhere(['or', ...$months])
$finalResult = [];
$componentAdds = [];
$componentAddsSumAll = [];
- $allComponentsProdIds = [];
+ $allComponentsProductIds = [];
foreach ($storeIds as $sid) {
foreach ($periods as $dt) {
continue;
}
- foreach ($items as $it) {
- $allComponentsProdIds[$sid][] = $it['product_id'];
- }
+ $filtered = match ($mode) {
+ 'offline' => array_filter($items, fn($it) => in_array($it['order_id'], ['', '0'], true)),
+ 'online' => array_filter($items, fn($it) => !in_array($it['order_id'], ['', '0'], true)),
+ default => $items, // для writeOffs — всё
+ };
+
+ $allComponentsProductIds[$sid] = array_merge(
+ $allComponentsProductIds[$sid] ?? [],
+ array_column($filtered, 'product_id')
+ );
+ $sums = $this->sumProductsComponentsByGroup($filtered, $type, 'species');
- $sums = $this->sumProductsComponentsByGroup($items, $type, 'species');
- $allComponentsProdIds[$sid] = array_unique($allComponentsProdIds[$sid]);
+ $allComponentsProductIds[$sid] = array_values(array_unique($allComponentsProductIds[$sid]));
foreach ($sums as $sr) {
$cat = $sr['category'];
'type' => $type,
'new_total_store' => $newSubcatTotal,
'base_total_store' => $subcatTotal,
- 'products_components_list' => implode(',', $allComponentsProdIds[$sid] ?? []),
+ 'products_components_list' => implode(',', $allComponentsProductIds[$sid] ?? []),
+ 'mode' => $mode
];
}