}
}
+ 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);