]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Другие правки ошибок - отсутствие плана на магазин
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 4 Jul 2025 13:25:25 +0000 (16:25 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 4 Jul 2025 13:25:25 +0000 (16:25 +0300)
erp24/controllers/CategoryPlanController.php

index d61d7c083bbe8fbaee63b54cb15b693be87ec792..c9f47be3794c12923ea45b1c5a2ccecc5354a5ac 100644 (file)
@@ -51,7 +51,7 @@ class CategoryPlanController extends Controller {
 
         $service = new AutoPlannogrammaService();
         $isEditable = date($model->year . '-' . $model->month . '-d') > date('Y-m-d') && (
-            (date('d') < 27) || (date('Y-m-d', strtotime('-1 month', strtotime(date($model->year . '-' . $model->month . '-d')))) > date('Y-m-d')));
+            (date('d') < 27) || (date('Y-m-d', strtotime('-2 month', strtotime(date($model->year . '-' . $model->month . '-d')))) > date('Y-m-d')));
         //$isEditable = true;
         $categoryPlan = CategoryPlan::find()->where(['year' => $model->year, 'month' => $model->month, 'store_id' => $model->store_id])->indexBy('category')->asArray()->all();
         $types = [];
@@ -159,8 +159,13 @@ class CategoryPlanController extends Controller {
                 $types[$saleMatrix['type']] = 1;
                 $table[$saleMatrix['store_id']][$saleMatrix['type']] = ($table[$saleMatrix['store_id']][$saleMatrix['type']] ?? 0) + $weights[$saleMatrix['month']] * $saleMatrix['total'] ;
             }
+            if (!empty($salesWriteOffsPlan->offline_sales_plan)) {
+                $offlinePlannedSales = self::calculatePlannedSales($table, $salesWriteOffsPlan->offline_sales_plan);
+            } else {
+                $offlinePlannedSales = [];
+                Yii::$app->session->setFlash('error', 'Не установлен план для магазина');
+            }
 
-            $offlinePlannedSales = self::calculatePlannedSales($table, $salesWriteOffsPlan->offline_sales_plan);
 
             $salesOnline = $service->getMonthCategoryShareOrWriteOff($currentDate->format('Y-m-d'), ['sales_type' => 'online', 'store_id' => $model->store_id], AutoPlannogrammaService::TYPE_SALES);
 
@@ -196,7 +201,14 @@ class CategoryPlanController extends Controller {
                 $tableOnline[$saleMatrix['store_id']][$saleMatrix['type']] = ($tableOnline[$saleMatrix['store_id']][$saleMatrix['type']] ?? 0) + $weights[$saleMatrix['month']] * $saleMatrix['total'] ;
             }
 
-            $onlinePlannedSales = self::calculatePlannedSales($tableOnline, $salesWriteOffsPlan->online_sales_shop_plan);
+
+            if (!empty($salesWriteOffsPlan->online_sales_shop_plan)) {
+                $onlinePlannedSales = self::calculatePlannedSales($tableOnline, $salesWriteOffsPlan->online_sales_shop_plan);
+            } else {
+                $onlinePlannedSales = [];
+                Yii::$app->session->setFlash('error', 'Не установлен план для магазина');
+            }
+
 
             $eit = ExportImportTable::find()->where(['entity' => 'city_store', 'export_id' => 1, 'entity_id' => $model->store_id])->one();
             $store_id = $eit->export_val ?? '';
@@ -233,7 +245,15 @@ class CategoryPlanController extends Controller {
                 $tableWriteOffs[$writeOffMatrix['store_id']][$writeOffMatrix['p1ctype']] = ($tableWriteOffs[$writeOffMatrix['store_id']][$writeOffMatrix['p1ctype']] ?? 0) + $weights[$writeOffMatrix['month']] * $writeOffMatrix['total'];
             }
 
-            $plannedWriteOffs = self::calculatePlannedSales($tableWriteOffs, $salesWriteOffsPlan->write_offs_plan);
+
+            if (!empty($salesWriteOffsPlan->write_offs_plan)) {
+                $plannedWriteOffs = self::calculatePlannedSales($tableWriteOffs, $salesWriteOffsPlan->write_offs_plan);
+            } else {
+                $plannedWriteOffs = [];
+                Yii::$app->session->setFlash('error', 'Не установлен план для магазина');
+            }
+
+
             $types = array_keys($types);
             /////////////////////////////////////////////////////////////////////////////////////