From: marina Date: Thu, 19 Dec 2024 10:38:15 +0000 (+0300) Subject: ERP-256 Сделать отправку документов Пересортица в 1с X-Git-Tag: 1.7~128^2~2 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=e2263ea7ba1a853a5d69c97691171afcde4e6777;p=erp24_rep%2Fyii-erp24%2F.git ERP-256 Сделать отправку документов Пересортица в 1с --- diff --git a/erp24/api2/controllers/DataController.php b/erp24/api2/controllers/DataController.php index 8d0c6889..2244b928 100644 --- a/erp24/api2/controllers/DataController.php +++ b/erp24/api2/controllers/DataController.php @@ -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);