]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Загрузка букетов
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 8 Sep 2025 15:02:47 +0000 (18:02 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 8 Sep 2025 15:02:47 +0000 (18:02 +0300)
erp24/api2/controllers/DataController.php
erp24/records/Admin.php

index 5a33815b76fc984f14cee905bc088426679b22a8..c23fc2b5208b0a297e47d39b23836b6b3fa68e91 100644 (file)
@@ -16,6 +16,9 @@ use yii_app\records\AnalystsBusinessOperationsTypes;
 use yii_app\records\ApiCron;
 use yii_app\records\Assemblies;
 use yii_app\records\Balances;
+use yii_app\records\BouquetComposition;
+use yii_app\records\BouquetCompositionMatrixTypeHistory;
+use yii_app\records\BouquetCompositionProducts;
 use yii_app\records\Cashes;
 use yii_app\records\CityStore;
 use yii_app\records\CreateChecks;
@@ -1189,6 +1192,7 @@ class DataController extends BaseController
             }
             if (!empty($result["nomenclature"]["elements"])) {
 //                Products1c::deleteAll(['and', ['tip' => 'products'], ['view' => 0]]);
+                $bouquets = BouquetComposition::find()->select('guid')->column();
                 foreach ($result["nomenclature"]["elements"] as $gi => $arr) {
 //                    if (!empty($arr["name"]) && in_array($arr["name"][0], ['ь', 'Ь', 'ъ', 'Ъ'])) { // Не вносим номенклатуру, помеченную на удаление
 //                        continue;
@@ -1212,6 +1216,45 @@ class DataController extends BaseController
                         LogService::apiErrorLog(json_encode(["error_id" => 8, "error" => $products1c6->getErrors()], JSON_UNESCAPED_UNICODE));
                     }
 
+                    if(!empty($arr["components"])) {
+                        if(!in_array($arr["id"], $bouquets)) {
+                            $newBouquetComp = new BouquetComposition();
+                            $newBouquetComp->guid = $arr["id"];
+                            $newBouquetComp->name = $arr["name"];
+                            $newBouquetComp->created_by = Admin::getAdminAgentId() ?: null;
+                            if(!$newBouquetComp->save()) {
+                                LogService::apiErrorLog(json_encode(["error_id" => 8.1, "error" => $newBouquetComp->getErrors()], JSON_UNESCAPED_UNICODE));
+                            } else {
+                                foreach ($arr["components"] as $guid => $quantity) {
+                                    $newBouquetCompProd = new BouquetCompositionProducts();
+                                    $newBouquetCompProd->bouquet_id = $newBouquetComp->id;
+                                    $newBouquetCompProd->product_guid = $guid;
+                                    $newBouquetCompProd->count = $quantity;
+                                    $newBouquetCompProd->created_by = Admin::getAdminAgentId() ?: null;
+                                    if(!$newBouquetCompProd->save()) {
+                                        LogService::apiErrorLog(json_encode(["error_id" => 8.2, "error" => $newBouquetCompProd->getErrors()], JSON_UNESCAPED_UNICODE));
+                                    }
+                                }
+                                $costModels = [];
+                                foreach (BouquetComposition::getRegions() as $region_id) {
+                                    $costModels[$region_id] = $newBouquetComp->getCostModel($region_id, array_keys($arr["components"]), true);
+                                }
+                                if(empty($costModels)) {
+                                    LogService::apiErrorLog(json_encode(["error_id" => 8.3, "error" => "Стоимость и цена не подсчитаны"], JSON_UNESCAPED_UNICODE));
+                                }
+                                $bouquetTypeHistory = new BouquetCompositionMatrixTypeHistory();
+                                $bouquetTypeHistory->bouquet_id = $newBouquetComp->id;
+                                $bouquetTypeHistory->matrix_type_id = 1;
+                                $bouquetTypeHistory->created_by = Admin::getAdminAgentId() ?: null;
+                                $bouquetTypeHistory->is_active = 1;
+                                $bouquetTypeHistory->date_from = date('Y-m-d H:i:s');
+                                if(!$bouquetTypeHistory->save()) {
+                                    LogService::apiErrorLog(json_encode(["error_id" => 8.4, "error" => $bouquetTypeHistory->getErrors()], JSON_UNESCAPED_UNICODE));
+                                }
+                            }
+                        }
+                    }
+
                     foreach ($arr as $key => $property) {
                         if (!in_array($key, Products1c::PRODUCT1C_FIELDS)) {
                             if (empty($property)) continue;
index a81b332268ed85cf48319a62daaf9a05b06c356c..449b928761174fabe3db2d98bb72ed9ac6f347d5 100755 (executable)
@@ -89,6 +89,8 @@ class Admin extends ActiveRecord implements IdentityInterface
         72, //
     ];
 
+    const ADMIN_AGENT_FOR_EXCHANGE_NAME = 'agent';
+
     public $imageFile;
 
     private $store_arrArr;
@@ -732,6 +734,12 @@ class Admin extends ActiveRecord implements IdentityInterface
 //        $_SESSION['name_group_admin'] = "Пользователь";
     }
 
+    public static function getAdminAgentId() {
+        $id = Admin::find()->select('id')->where(['name' => self::ADMIN_AGENT_FOR_EXCHANGE_NAME])->scalar();
+        return $id;
+    }
+
+
     public function hasPermission($permission)
     {