]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Cбор и вывод данных 1С бухгалтерия
authorMarina Zozirova <marina.zozirova@erp-flowers.ru>
Wed, 4 Sep 2024 12:12:39 +0000 (12:12 +0000)
committerAleksey Filippov <aleksey.filippov@erp-flowers.ru>
Wed, 4 Sep 2024 12:12:39 +0000 (12:12 +0000)
erp24/scripts/tasks/task_32_create_request_for_1c_buh.php
erp24/scripts/tasks/task_33_insert_data_to_monitvation_from_motivation_buh.php
erp24/services/MotivationServiceBuh.php
erp24/views/motivation/index.php

index 857d1788a0b563bf1fec3d65353bfc6ca3cf0879..f9254fd824a20cdf77bcc662c04ccedb947a2ec2 100644 (file)
@@ -68,9 +68,7 @@ try {
 
         $weekRange = Motivation::getWeekRangeForDate();
 
-
         if ((date('d') % 7 == 0 || date('t') == date('d'))) {
-
             foreach (Firms::getInn() as $key => $firm) {
                 for ($week = Motivation::getWeek(); $week >= 1; $week--) {
                     sleep(1);
@@ -85,52 +83,16 @@ try {
                     $date = strtotime("{$day}-{$month}-{$year}");
 
                     $weekRange = Motivation::getWeekRangeForDate($date);
-                    $model = new ApiCronBuh();
-                    $model->date = date('Y-m-d H:i:s');
-                    $model->request_id = strval(strtotime($model->date) . '_' . $key);
-
-                    $model->json_post = Json::encode([
-                        'request_id' => $model->request_id,
-                        'cost_items' => [
-                            'start_time' => date('Y-m-d 00:00:00', strtotime($weekRange['start_time'])),
-                            'end_time' => date('Y-m-d 23:59:59', strtotime($weekRange['end_time'])),
-                        ]
-                    ]);
-                    $model->inn = $key;
-                    try {
-                        $model->save();
-                    } catch (Exception $e) {
-                        throw new Exception($e);
-                    }
+                    createApiCron($key, $weekRange);
                 }
             }
         } else {
             foreach (Firms::getInn() as $key => $firm) {
-                $model = new ApiCronBuh();
-                $model->date = date('Y-m-d H:i:s');
-                $model->request_id = strval(strtotime($model->date) . '_' . $key);
-                $model->json_post = Json::encode([
-                    'request_id' => $model->request_id,
-                    'cost_items' => [
-                        'start_time' => date('Y-m-d 00:00:00', strtotime($weekRange['start_time'])),
-                        'end_time' => date('Y-m-d 23:59:59', strtotime($weekRange['end_time'])),
-                    ]
-                ]);
-                $model->inn = $key;
-                try {
-                    $model->save();
-                } catch (Exception $e) {
-                    throw new Exception($e);
-                }
-
+                createApiCron($key, $weekRange);
             }
 
         }
 
-        if (!in_array(Admin::findOne([Yii::$app->user->id])->group_id, [AdminGroup::GROUP_IT])) {
-            return $this->render('/site/index');
-        }
-
 
         $info = ' ================ test Task ' . $taskNum . ' stop ================';
         echo $info;
@@ -169,4 +131,23 @@ if (empty($schedulerTaskLog)) {
 $validate = $schedulerTaskLog->validate();
 if ($validate) {
     $schedulerTaskLog->save();
+}
+
+function createApiCron($key, $weekRange) {
+    $model = new ApiCronBuh();
+    $model->date = date('Y-m-d H:i:s');
+    $model->request_id = strval(strtotime($model->date) . '_' . $key);
+    $model->json_post = Json::encode([
+        'request_id' => $model->request_id,
+        'cost_items' => [
+            'start_time' => date('Y-m-d 00:00:00', strtotime($weekRange['start_time'])),
+            'end_time' => date('Y-m-d 23:59:59', strtotime($weekRange['end_time'])),
+        ]
+    ]);
+    $model->inn = $key;
+    try {
+        $model->save();
+    } catch (Exception $e) {
+        throw new Exception($e);
+    }
 }
\ No newline at end of file
index d229169b02c59dec2f73e19f29e12c6de660d4e4..464d9c563cc43d4a02c07ced611b2aa49675aaca 100644 (file)
@@ -111,7 +111,7 @@ try {
             $motivationValue = new MotivationValue();
             $motivationValue->setAttributes([
                 'motivation_id' => $motivation->id,
-                'motivation_group_id' => $value->id,
+                'motivation_group_id' => $value->motivation_group_id,
                 'value_id' => $value->value_id,
                 'value_type' => MotivationCostsItem::DATA_TYPE_FLOAT,
                 'value_float' => $value->value_float,
index 583d9aaef418ec5025e3e72e68d54fcd43789199..d04dd0c45e0da713f2a8da589d54f4df0a7a265e 100644 (file)
@@ -42,8 +42,12 @@ 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');
+            $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) {
@@ -52,7 +56,7 @@ class MotivationServiceBuh
 
                         if (!$storeBuh) {
                             LogService::apiErrorLog(json_encode(["error_id" => 45, "error" => 'Несуществующий магазин! Название: ' . $storeData['store_name'] . ' , guid: ' . $storeData['store_guid']], JSON_UNESCAPED_UNICODE));
-                            return;
+                            continue;
                         }
 
                             $storeId = $storeBuhIds[$storeData['store_guid']];
@@ -62,7 +66,7 @@ class MotivationServiceBuh
 
                                     if (!$value) {
                                         LogService::apiErrorLog(json_encode(["error_id" => 46, "error" => $item['name']], JSON_UNESCAPED_UNICODE));
-                                        return;
+                                        continue;
                                     }
 
                                     $motivationBuh = MotivationBuh::findOne([
@@ -85,7 +89,7 @@ class MotivationServiceBuh
                                         'motivation_buh_id' => $motivationBuh->id,
                                         'store_id' => $storeId,
                                         'motivation_group_id' => $motivationValueGroup->id,
-                                        'value_id' => $motivationCostsItems[$storeData['items']],
+                                        'value_id' => $motivationCostsItems[$item['name']],
                                         'value_type' => MotivationCostsItem::DATA_TYPE_FLOAT,
                                     ]);
 
@@ -97,7 +101,7 @@ class MotivationServiceBuh
                                             'motivation_buh_id' => $motivationBuh->id,
                                             'store_id' => $storeId,
                                             'motivation_group_id' => $motivationValueGroup->id,
-                                            'value_id' => $motivationCostsItems[$storeData['items']],
+                                            'value_id' => $motivationCostsItems[$item['name']],
                                             'value_type' => MotivationCostsItem::DATA_TYPE_FLOAT,
                                             'value_float' => $item['summ']
                                         ]);
index 189ea595ded0c269d4138562c0072f15039cc044..581dea58cbed840233f4ac1e21caceae82904bdd 100644 (file)
@@ -159,8 +159,7 @@ $this->registerJsFile('/js/motivation/index.js', ['position' => \yii\web\View::P
 
                             'header' => 'Неделя 1<br>(1-7)',
                             'value' => function ($model) {
-                                return $model["week1"] !== null ? FormatHelper::asDecimalMotivation($model["week1"]) : " ";
-
+                                return $model["week1"] !== null ? FormatHelper::asDecimalMotivation($model["week1"]) : "0";
                             },
                         ],
                         [
@@ -169,8 +168,7 @@ $this->registerJsFile('/js/motivation/index.js', ['position' => \yii\web\View::P
 
                             'header' => 'Неделя 2<br>(8-14)',
                             'value' => function ($model) {
-                                return $model["week2"] !== null ? FormatHelper::asDecimalMotivation($model["week2"]) : " ";
-
+                                return $model["week2"] !== null ? FormatHelper::asDecimalMotivation($model["week2"]) : "0";
                             },
 
                         ],
@@ -180,8 +178,7 @@ $this->registerJsFile('/js/motivation/index.js', ['position' => \yii\web\View::P
 
                             'header' => 'Неделя 3<br>(15-21)',
                             'value' => function ($model) {
-                                return $model["week3"] !== null ? FormatHelper::asDecimalMotivation($model["week3"]) : " ";
-
+                                return $model["week3"] !== null ? FormatHelper::asDecimalMotivation($model["week3"]) : "0";
                             },
 
                         ],
@@ -191,8 +188,7 @@ $this->registerJsFile('/js/motivation/index.js', ['position' => \yii\web\View::P
 
                             'header' => 'Неделя 4<br>(22-28)',
                             'value' => function ($model) {
-                                return $model["week4"] !== null ? FormatHelper::asDecimalMotivation($model["week4"]) : " ";
-
+                                return $model["week4"] !== null ? FormatHelper::asDecimalMotivation($model["week4"]) : "0";
                             },
 
                         ],
@@ -202,8 +198,7 @@ $this->registerJsFile('/js/motivation/index.js', ['position' => \yii\web\View::P
 
                             'header' => $week5Header,
                             'value' => function ($model) {
-                                return $model["week5"] !== null ? FormatHelper::asDecimalMotivation($model["week5"]) : " ";
-
+                                return $model["week5"] !== null ? FormatHelper::asDecimalMotivation($model["week5"]) : "0";
                             },
                         ],
                         [