]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-85 Реализовать обмен данных с 1С Бухгалтерия feature_zozirova_erp-85_1c_buh_connect origin/feature_zozirova_erp-85_1c_buh_connect
authormarina <m.zozirova@gmail.com>
Wed, 28 Aug 2024 12:36:13 +0000 (15:36 +0300)
committermarina <m.zozirova@gmail.com>
Wed, 28 Aug 2024 12:36:13 +0000 (15:36 +0300)
erp24/api2/controllers/DataBuhController.php
erp24/services/MotivationServiceBuh.php

index 7f6f21c3d932c30e169145a4ea9d0a5ac3acdd08..315595973e3f27ddaf98f05187eaeab7f6d5aac4 100644 (file)
@@ -97,6 +97,7 @@ class DataBuhController extends BaseController
         file_put_contents(self::OUT_DIR . '/upload_' . $fl . '.json', PHP_EOL . $request);
 
         try {
+
             $apiCron = ApiCronBuh::findOne(['request_id' => $requestId]);
             if ($apiCron) {
                 $apiCron->date_up = date("Y-m-d H:i:s");
index b61108c22107e2fcf3bc8d6592f96a83ff5783a0..583d9aaef418ec5025e3e72e68d54fcd43789199 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace yii_app\services;
 
+use yii\helpers\ArrayHelper;
 use yii_app\records\Motivation;
 use yii_app\records\MotivationBuh;
 use yii_app\records\MotivationBuhValue;
@@ -40,25 +41,28 @@ class MotivationServiceBuh
 
             $alias = $validate === 'month' ? 'month' : 'week' . $week;
             $motivationValueGroup = MotivationValueGroup::findOne(['alias' =>   $alias]);
+
+            $storeBuhIds = ArrayHelper::map(StoreGuidBuh::find()->select(['store_guid', 'store_id'])->asArray()->all(), 'store_guid', 'store_id');
+            $motivationCostsItems = ArrayHelper::map(MotivationCostsItem::find()->select(['name', 'code'])->asArray()->all(), 'name', 'code');
+
             if (!empty($data['cost_items'])) {
                 foreach ($data['cost_items'] as $stores) {
                     foreach ($stores as $storeData) {
-                        $storeBuh = StoreGuidBuh::find()
-                            ->andWhere(['store_guid' => $storeData['store_guid']])
-                            ->one();
+                        $storeBuh = array_key_exists($storeData['store_guid'], $storeBuhIds);
 
                         if (!$storeBuh) {
                             LogService::apiErrorLog(json_encode(["error_id" => 45, "error" => 'Несуществующий магазин! Название: ' . $storeData['store_name'] . ' , guid: ' . $storeData['store_guid']], JSON_UNESCAPED_UNICODE));
                             return;
                         }
 
-                            $store = CityStore::getCityStoreById($storeBuh->store_id, true);
+                            $storeId = $storeBuhIds[$storeData['store_guid']];
                             foreach ($storeData['items'] as $items) {
                                 foreach ($items as $item) {
-                                    $value = MotivationCostsItem::findOne(['name' => $item['name']]);
+                                    $value = array_key_exists($item['name'], $motivationCostsItems);
 
                                     if (!$value) {
                                         LogService::apiErrorLog(json_encode(["error_id" => 46, "error" => $item['name']], JSON_UNESCAPED_UNICODE));
+                                        return;
                                     }
 
                                     $motivationBuh = MotivationBuh::findOne([
@@ -79,9 +83,9 @@ class MotivationServiceBuh
 
                                     $motivationBuhValue = MotivationBuhValue::findOne([
                                         'motivation_buh_id' => $motivationBuh->id,
-                                        'store_id' => $store['id'],
+                                        'store_id' => $storeId,
                                         'motivation_group_id' => $motivationValueGroup->id,
-                                        'value_id' => $value->id,
+                                        'value_id' => $motivationCostsItems[$storeData['items']],
                                         'value_type' => MotivationCostsItem::DATA_TYPE_FLOAT,
                                     ]);
 
@@ -91,9 +95,9 @@ class MotivationServiceBuh
                                         $motivationBuhValue = new MotivationBuhValue();
                                         $motivationBuhValue->setAttributes([
                                             'motivation_buh_id' => $motivationBuh->id,
-                                            'store_id' => $store['id'],
+                                            'store_id' => $storeId,
                                             'motivation_group_id' => $motivationValueGroup->id,
-                                            'value_id' => $value->id,
+                                            'value_id' => $motivationCostsItems[$storeData['items']],
                                             'value_type' => MotivationCostsItem::DATA_TYPE_FLOAT,
                                             'value_float' => $item['summ']
                                         ]);