]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
upload waybillIncoming created_write_ons
authorAlexander Smirnov <fredeom@mail.ru>
Wed, 18 Dec 2024 13:06:28 +0000 (16:06 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Wed, 18 Dec 2024 13:06:28 +0000 (16:06 +0300)
erp24/api2/controllers/DataController.php

index a43a92e8b158a946fd65dc66a16e5cfe94106078..b31c256173dfb3da3a4803ffc19c660fb3269c9c 100644 (file)
@@ -1123,6 +1123,106 @@ class DataController extends BaseController {
                 }
             }
 
+            if (!empty($result['created_write_ons'])) {
+                file_put_contents(
+                    self::OUT_DIR . '/created_write_ons_upload_'
+                    . date("Y_m_d") . '.json',
+                    PHP_EOL
+                    . json_encode($result["created_write_ons"], JSON_UNESCAPED_UNICODE),
+                    FILE_APPEND
+                );
+                foreach ($result["created_write_ons"] as $arr) {
+                    if (!empty($arr["id"])) {
+                        $waybillIncoming = WaybillIncoming::find()->where(['guid' => $arr["arr"]])->one();
+                    }
+
+                    if (!empty($waybillIncoming)) {
+                        if (!empty($arr["errors"]) || !empty($arr["errors_items"])) {
+                            $errorText = '';
+                            if (!empty($arr["errors"])) {
+                                //"errors": [
+                                //{
+                                //"error": "Ошибка преобразования ИД документа",
+                                //"error_description": "ИД документа 01202307-2705-1039-09bc-100015809667 уже записан в системе",
+                                //"error_json": [
+                                //{
+                                //"field": "id",
+                                //"error": "Документ с данным ИД уже записан в системе"
+                                //}
+                                //
+
+                                foreach ($arr["errors"] as $errorRow) {
+                                    if (!empty($errorRow['error'])) {
+                                        $errorText .= $errorRow['error'];
+
+                                        $errorText .= ' ,' . $errorRow['error_description'];
+                                        if (!empty($errorRow['error_json'])) {
+                                            foreach ($errorRow['error_json'] as $errorJsonRow) {
+                                                $errorText .= ' , поле: ' . $errorJsonRow['field'];
+                                                $errorText .= ' , ошибка: ' . $errorJsonRow['error'];
+                                            }
+                                        }
+                                    }
+
+                                    if (!empty($errorRow["errors_items"])) {
+                                        foreach ($errorRow["errors_items"] as $errorDopRow) {
+                                            //"errors_items": [
+                                            //{
+                                            //"error_dop": "Ошибка проверки количества номенклатуры",
+                                            //"field": "quantity",
+                                            //"product_id": "bdd17587-09d8-11e5-bd74-1c6f659fb563",
+                                            //"error": "У данной позиции запрещён ввод дробного значения!"
+                                            //},
+                                            //
+                                            //
+                                            $productName = $errorDopRow['product_id'];
+
+                                            if (array_key_exists($errorDopRow['product_id'], $productsNames)) {
+                                                $productName = $productsNames[$errorDopRow['product_id']];
+                                            }
+
+                                            $errorText .= ' ' . $errorDopRow['error_dop'];
+                                            $errorText .= ' , поле: ' . $errorDopRow['field'];
+                                            $errorText .= ' , товар: ' . $productName;
+                                            $errorText .= ' , ошибка: ' . $errorDopRow['error'];
+                                        }
+                                    }
+                                }
+                            }
+                            if (!empty($waybillIncoming)) {
+                                /** @var WaybillIncoming $waybillIncoming */
+                                $waybillIncoming->status = WriteOffsErp::STATUS_ERROR_1С;
+                                $waybillIncoming->error_text = $errorText;
+                                $waybillIncoming->save();
+                                if ($waybillIncoming->getErrors()) {
+                                    LogService::apiErrorLog(
+                                        json_encode(
+                                            ["error_id" => 11.5, "error" => $waybillIncoming->getErrors()],
+                                            JSON_UNESCAPED_UNICODE
+                                        )
+                                    );
+                                }
+                            }
+                        } else {
+                            if (!empty($waybillIncoming)) {
+                                /** @var WaybillIncoming $waybillIncoming */
+                                $waybillIncoming->status = WriteOffsErp::STATUS_CREATED_1С;
+                                $waybillIncoming->number_1c = $arr["number"] ?? '';
+                                $waybillIncoming->save();
+                                if ($waybillIncoming->getErrors()) {
+                                    LogService::apiErrorLog(
+                                        json_encode(
+                                            ["error_id" => 11.55, "error" => $waybillIncoming->getErrors()],
+                                            JSON_UNESCAPED_UNICODE
+                                        )
+                                    );
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+
             $update = false;
             if (!empty($start_time) && !empty($end_time)) {
                 $start_time_unix = strtotime($start_time);