]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-302 Редактирование букета
authormarina <m.zozirova@gmail.com>
Thu, 20 Feb 2025 12:55:42 +0000 (15:55 +0300)
committermarina <m.zozirova@gmail.com>
Thu, 20 Feb 2025 12:55:42 +0000 (15:55 +0300)
erp24/controllers/BouquetController.php

index 0351a290b763403c3813fa0fe8cce80f0d7493e2..4e876dbb619f1841d7f3174d8f4fdf354a2d3404 100644 (file)
@@ -76,65 +76,67 @@ class BouquetController extends Controller
             if ($data['matrix_type_id']) {
                 BouquetCompositionMatrixTypeHistory::setData($data['matrix_type_id'], $model->id);
             }
+            if ($model->save()) {
 
-            $month = $data['month'];
-            $year = $data['year'];
+                $month = $data['month'];
+                $year = $data['year'];
 
-            $model->photo_bouquet = UploadedFile::getInstances($model, 'photo_bouquet');
-            if ($model->photo_bouquet) {
-                Files::deleteAll(['file_type' => 'image', 'entity_id' => $model->id, 'entity' => BouquetComposition::PHOTO_BOUQUET]);
-                foreach ($model->photo_bouquet as $photo) {
-                    FileService::saveUploadedFile($photo, BouquetComposition::PHOTO_BOUQUET, $model->id);
+                $model->photo_bouquet = UploadedFile::getInstances($model, 'photo_bouquet');
+                if ($model->photo_bouquet) {
+                    Files::deleteAll(['file_type' => 'image', 'entity_id' => $model->id, 'entity' => BouquetComposition::PHOTO_BOUQUET]);
+                    foreach ($model->photo_bouquet as $photo) {
+                        FileService::saveUploadedFile($photo, BouquetComposition::PHOTO_BOUQUET, $model->id);
+                    }
                 }
-            }
 
-            $model->video_presentation = UploadedFile::getInstances($model, 'video_presentation');
-            if ($model->video_presentation) {
-                Files::deleteAll(['file_type' => 'video', 'entity_id' => $model->id, 'entity' => BouquetComposition::VIDEO_PRESENTATION]);
-                FileService::saveUploadedFile($model->video_presentation, BouquetComposition::VIDEO_PRESENTATION, $model->id);
-            }
+                $model->video_presentation = UploadedFile::getInstances($model, 'video_presentation');
+                if ($model->video_presentation) {
+                    Files::deleteAll(['file_type' => 'video', 'entity_id' => $model->id, 'entity' => BouquetComposition::VIDEO_PRESENTATION]);
+                    FileService::saveUploadedFile($model->video_presentation, BouquetComposition::VIDEO_PRESENTATION, $model->id);
+                }
 
-            $model->video_build_process = UploadedFile::getInstances($model, 'video_build_process');
-            if ($model->video_build_process) {
-                Files::deleteAll(['file_type' => 'video', 'entity_id' => $model->id, 'entity' => BouquetComposition::VIDEO_BUILD_PROCESS]);
-                FileService::saveUploadedFile($model->video_build_process, BouquetComposition::VIDEO_BUILD_PROCESS, $model->id);
-            }
+                $model->video_build_process = UploadedFile::getInstances($model, 'video_build_process');
+                if ($model->video_build_process) {
+                    Files::deleteAll(['file_type' => 'video', 'entity_id' => $model->id, 'entity' => BouquetComposition::VIDEO_BUILD_PROCESS]);
+                    FileService::saveUploadedFile($model->video_build_process, BouquetComposition::VIDEO_BUILD_PROCESS, $model->id);
+                }
 
 
-            if (!empty($data['BouquetForecast']['type_sales_value'])) {
-                $salesData = $data['BouquetForecast']['type_sales_value'];
+                if (!empty($data['BouquetForecast']['type_sales_value'])) {
+                    $salesData = $data['BouquetForecast']['type_sales_value'];
 
-                if (!empty($salesData['offline'])) {
-                    BouquetForecast::processSalesData($model->id, $year, $month, $salesData['offline'], BouquetForecast::OFFLINE_STORES);
-                }
+                    if (!empty($salesData['offline'])) {
+                        BouquetForecast::processSalesData($model->id, $year, $month, $salesData['offline'], BouquetForecast::OFFLINE_STORES);
+                    }
 
-                if (!empty($salesData['online'])) {
-                    BouquetForecast::processSalesData($model->id, $year, $month, $salesData['online'], BouquetForecast::ONLINE_STORES);
-                }
+                    if (!empty($salesData['online'])) {
+                        BouquetForecast::processSalesData($model->id, $year, $month, $salesData['online'], BouquetForecast::ONLINE_STORES);
+                    }
 
-                if (!empty($salesData['marketplace'])) {
-                    BouquetForecast::processSalesData($model->id, $year, $month, $salesData['marketplace'], BouquetForecast::MARKETPLACE);
+                    if (!empty($salesData['marketplace'])) {
+                        BouquetForecast::processSalesData($model->id, $year, $month, $salesData['marketplace'], BouquetForecast::MARKETPLACE);
+                    }
                 }
-            }
 
-            if ($data['products_quantity']) {
-                $bouquetProducts = Yii::$app->request->post('products_quantity');
-                foreach ($bouquetProducts as $key => $value) {
-                    $product = new BouquetCompositionProducts([
-                        'bouquet_id' => $model->id,
-                        'product_guid' => $key,
-                        'count' => $value
-                    ]);
-                    $product->save();
+                if (array_key_exists('products_quantity', $data) ) {
+                    $bouquetProducts = Yii::$app->request->post('products_quantity');
+                    foreach ($bouquetProducts as $key => $value) {
+                        $product = new BouquetCompositionProducts([
+                            'bouquet_id' => $model->id,
+                            'product_guid' => $key,
+                            'count' => $value
+                        ]);
+                        if (!$product->save()) {
+                            var_dump($model->getErrors());
+                            die();
+                        }
+                    }
                 }
-            }
 
-            if ($model->save()) {
                 return $this->redirect(['view', 'id' => $model->id]);
             }
         }
-
-
+        
         $availableItems = ArrayHelper::map(
             Products1c::find()
                 ->where([