]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-256 Сделать отправку документов Пересортица в 1с
authormarina <m.zozirova@gmail.com>
Thu, 19 Dec 2024 10:38:15 +0000 (13:38 +0300)
committermarina <m.zozirova@gmail.com>
Thu, 19 Dec 2024 10:38:15 +0000 (13:38 +0300)
erp24/api2/controllers/DataController.php

index 8d0c688929238c347f10c97bb1ac0883557bc80e..2244b9287806f54b77621091c0add46fce8543da 100644 (file)
@@ -1234,6 +1234,86 @@ class DataController extends BaseController
                 }
             }
 
+            if (!empty($result['create_resortings'])) {
+                file_put_contents(
+                    self::OUT_DIR . '/create_resortings_upload_'
+                    . date("Y_m_d") . '.json',
+                    PHP_EOL
+                    . json_encode($result["create_resortings"], JSON_UNESCAPED_UNICODE),
+                    FILE_APPEND
+                );
+                foreach ($result["create_resortings"] as $arr) {
+                    if (!empty($arr["id"])) {
+                        $replacementInvoice = ReplacementInvoice::findOne(['guid' => $arr["arr"]]);
+                    }
+
+                    if (!empty($replacementInvoice)) {
+                        if (!empty($arr["errors"]) || !empty($arr["errors_items"])) {
+                            $errorText = '';
+                            if (!empty($arr["errors"])) {
+                                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) {
+                                            $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'];
+                                        }
+                                    }
+                                }
+                            }
+
+                            /** @var ReplacementInvoice $replacementInvoice */
+                            $replacementInvoice->status = WriteOffsErp::STATUS_ERROR_1С;
+                            $replacementInvoice->error_text = $errorText;
+                            $replacementInvoice->save();
+                            if ($replacementInvoice->getErrors()) {
+                                LogService::apiErrorLog(
+                                    json_encode(
+                                        ["error_id" => 4.55, "error" => $replacementInvoice->getErrors()],
+                                        JSON_UNESCAPED_UNICODE
+                                    )
+                                );
+                            }
+
+                        } else {
+                            if (isset($arr["held"]) && $arr["held"] == 'true') {
+                                /** @var ReplacementInvoice $replacementInvoice */
+                                $replacementInvoice->status = WriteOffsErp::STATUS_CREATED_1С;
+                                $replacementInvoice->number_1c = $arr["name"] ?? '';
+                                $replacementInvoice->save();
+                                if ($replacementInvoice->getErrors()) {
+                                    LogService::apiErrorLog(
+                                        json_encode(
+                                            ["error_id" => 4.55, "error" => $replacementInvoice->getErrors()],
+                                            JSON_UNESCAPED_UNICODE
+                                        )
+                                    );
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+
             $update = false;
             if (!empty($start_time) && !empty($end_time)) {
                 $start_time_unix = strtotime($start_time);