Переглянути джерело

changed reclamation status, added resume to reclamations import

Alexander Musikhin 1 день тому
батько
коміт
c1c18eccf2

+ 1 - 1
app/Models/Reclamation.php

@@ -32,7 +32,7 @@ class Reclamation extends Model
         self::STATUS_IN_WORK => 'В работе',
         self::STATUS_SUBSCRIBE_ACT => 'Подпись акта',
         self::STATUS_DONE => 'Исправлена',
-        self::STATUS_SENT => 'Отправлена',
+        self::STATUS_SENT => 'Закрыта, оплачивается',
         self::STATUS_DO_DOCS => 'Подготовка документов',
         self::STATUS_HANDOVER_TO_CHECK => 'Передана на проверку',
         self::STATUS_PAID => 'Оплачена',

+ 54 - 0
app/Services/ImportReclamationsService.php

@@ -48,6 +48,15 @@ class ImportReclamationsService extends ImportBaseService
             'reclamationsCreated' => 0,
             'mafAttached' => 0,
         ];
+        $errors = [
+            'district_not_found' => [],
+            'area_not_found' => [],
+            'status_not_found' => [],
+            'order_not_found' => [],
+            'product_not_found' => [],
+            'sku_not_found' => [],
+            'exceptions' => [],
+        ];
 
 
         foreach ($this->rowIterator as $row) {
@@ -64,11 +73,13 @@ class ImportReclamationsService extends ImportBaseService
 
                 // округ
                 if (!($districtId = $this->findId('districts.shortname', $r['districts.name'] ?? ''))) {
+                    $errors['district_not_found'][] = $strNumber;
                     continue;
                 }
 
                 // район
                 if (!($areaId = $this->findId('areas.name', $r['areas.name']))) {
+                    $errors['area_not_found'][] = $strNumber;
                     continue;
                 }
 
@@ -77,6 +88,7 @@ class ImportReclamationsService extends ImportBaseService
 
                 // status
                 if (!($statusId = $this->findId('reclamation_statuses.name', $r['reclamation_statuses.name']))) {
+                    $errors['status_not_found'][] = $strNumber;
                     continue;
                 }
 
@@ -88,6 +100,7 @@ class ImportReclamationsService extends ImportBaseService
                     ->first();
                 if (!$order) {
                     echo $this->import->log('Order NOT FOUND: ' . $r['orders.object_address'], 'WARNING');
+                    $errors['order_not_found'][] = $strNumber;
                     continue;
                 } else {
                     $logMessage .= 'Found order: ' . $order->object_address . ". ";
@@ -101,6 +114,7 @@ class ImportReclamationsService extends ImportBaseService
                     ->first();
                 if (!$product) {
                     echo $this->import->log('Product not found: ' . $r['products.nomenclature_number'], 'WARNING');
+                    $errors['product_not_found'][] = $strNumber;
                     continue;
                 }
 
@@ -123,6 +137,7 @@ class ImportReclamationsService extends ImportBaseService
                 }
                 if (!$productSKU) {
                     echo $this->import->log('SKU not found: ' . $r['products.nomenclature_number'], 'WARNING');
+                    $errors['sku_not_found'][] = $strNumber;
                     continue;
                 }
 
@@ -173,10 +188,49 @@ class ImportReclamationsService extends ImportBaseService
                 echo $this->import->log($logMessage);
             } catch(\Exception $e) {
                 echo $this->import->log($e->getMessage(), 'WARNING');
+                $errors['exceptions'][] = $strNumber;
             }
         }
 
         echo $this->import->log(print_r($result, true));
+
+        // Резюме по ошибкам
+        $totalErrors = array_sum(array_map('count', $errors));
+        if ($totalErrors > 0) {
+            echo $this->import->log('--- РЕЗЮМЕ ПО ОШИБКАМ ---');
+            if (count($errors['district_not_found']) > 0) {
+                $rows = implode(', ', $errors['district_not_found']);
+                echo $this->import->log("Округ не найден: " . count($errors['district_not_found']) . " ({$rows})", 'WARNING');
+            }
+            if (count($errors['area_not_found']) > 0) {
+                $rows = implode(', ', $errors['area_not_found']);
+                echo $this->import->log("Район не найден: " . count($errors['area_not_found']) . " ({$rows})", 'WARNING');
+            }
+            if (count($errors['status_not_found']) > 0) {
+                $rows = implode(', ', $errors['status_not_found']);
+                echo $this->import->log("Статус не найден: " . count($errors['status_not_found']) . " ({$rows})", 'WARNING');
+            }
+            if (count($errors['order_not_found']) > 0) {
+                $rows = implode(', ', $errors['order_not_found']);
+                echo $this->import->log("Заказ не найден: " . count($errors['order_not_found']) . " ({$rows})", 'WARNING');
+            }
+            if (count($errors['product_not_found']) > 0) {
+                $rows = implode(', ', $errors['product_not_found']);
+                echo $this->import->log("Товар не найден: " . count($errors['product_not_found']) . " ({$rows})", 'WARNING');
+            }
+            if (count($errors['sku_not_found']) > 0) {
+                $rows = implode(', ', $errors['sku_not_found']);
+                echo $this->import->log("МАФ (SKU) не найден: " . count($errors['sku_not_found']) . " ({$rows})", 'WARNING');
+            }
+            if (count($errors['exceptions']) > 0) {
+                $rows = implode(', ', $errors['exceptions']);
+                echo $this->import->log("Исключения: " . count($errors['exceptions']) . " ({$rows})", 'WARNING');
+            }
+            echo $this->import->log("Всего ошибок: {$totalErrors}", 'WARNING');
+        } else {
+            echo $this->import->log('Импорт завершён без ошибок');
+        }
+
         $this->import->status = 'DONE';
         $this->import->save();