From: marina Date: Wed, 18 Dec 2024 10:04:13 +0000 (+0300) Subject: Merge branch 'develop' into feature-zozirova-erp_256-send_doc_on_1c X-Git-Tag: 1.7~150^2 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=6757f3f46b5a308a7b6eaf7547ac92a942ac5319;p=erp24_rep%2Fyii-erp24%2F.git Merge branch 'develop' into feature-zozirova-erp_256-send_doc_on_1c # Conflicts: # erp24/api2/controllers/DataController.php --- 6757f3f46b5a308a7b6eaf7547ac92a942ac5319 diff --cc erp24/api2/controllers/DataController.php index 34563df8,af1e063d..49ed92ac --- a/erp24/api2/controllers/DataController.php +++ b/erp24/api2/controllers/DataController.php @@@ -56,13 -53,11 +58,12 @@@ class DataController extends BaseContro const OUT_DIR = // __DIR__ . "/../json"; - // "/www/api2/json"; - "/var/www/erp24/api2/json"; + // "/www/api2/json"; + "/var/www/erp24/api2/json"; - // "/var/www/www-root/data/www/api.bazacvetov24.ru/data/json"; - public function actionRequest() { + public function actionRequest() + { Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $request = Yii::$app->request->getRawBody(); @@@ -253,8 -239,23 +258,24 @@@ } } + private function getWaybillWriteOffsSetStatusSend($waybillWriteOffIds) { + try { + $waybillWriteOffsErp = WaybillWriteOffs::find()->where(['in', 'id', $waybillWriteOffIds])->all(); + foreach ($waybillWriteOffsErp as $waybillWriteOffsErpElem) { + $waybillWriteOffsErpElem->status = WriteOffsErp::STATUS_SEND; + $waybillWriteOffsErpElem->send_at = date('Y-m-d H:i:s'); + $waybillWriteOffsErpElem->save(); + if ($waybillWriteOffsErpElem->getErrors()) { + LogService::apiErrorLog(json_encode(["error_id" => 2, "error" => $waybillWriteOffsErpElem->getErrors()], JSON_UNESCAPED_UNICODE)); + } + } + } catch (Exception $e3) { + file_put_contents(self::OUT_DIR . '/log_created_write_offs_erp_error.txt', PHP_EOL . date("d.m.Y H:i:s",time()). $e3->getMessage(), FILE_APPEND); + } + } + - private function getWaybillIncomingSetStatusSend($waybillIncomingIds) { + private function getWaybillIncomingSetStatusSend($waybillIncomingIds) + { try { $waybillIncoming = WaybillIncoming::find()->where(['in', 'id', $waybillIncomingIds])->all(); foreach ($waybillIncoming as $waybillIncomingElem) { @@@ -361,8 -345,58 +382,58 @@@ } } + + $waybillWriteOffs = WaybillWriteOffs::find() + ->select([ + 'id', + 'guid', + 'store_guid', + 'number', + 'date', + 'status', + 'comment', + 'quantity', + 'summ' + ]) + ->where(['status' => WriteOffsErp::STATUS_CONFIRM]) + ->asArray() + ->all(); + + if (!empty($waybillWriteOffs)) { + $waybillWriteOffIds = array_column($waybillWriteOffs, 'id'); + + $additionalProducts = WaybillWriteOffsProducts::find() + ->select(['waybill_write_offs_id', 'product_id', 'product_count', 'product_price', 'summ']) + ->where(['in', 'waybill_write_offs_id', $waybillWriteOffIds]) + ->asArray() + ->all(); + + $waybillWriteOffProducts = []; + foreach ($additionalProducts as $product) { + $waybillWriteOffProducts[$product['waybill_write_offs_id']][] = [ + 'product_id' => $product['product_id'], + 'quantity' => (string) $product['product_count'], + 'price' => $product['product_price'], + ]; + } + + foreach ($waybillWriteOffs as $row) { + $waybillProductsRow = $waybillWriteOffProducts[$row['id']] ?? []; + $writeOffResult[] = [ + 'id' => $row['guid'], + 'store_id' => $row['store_guid'], + 'type' => 'ревизия при передаче смены', + 'cause' => 'Документ ревизии при передаче смены в ERP ' . $row['number'], + 'items' => $waybillProductsRow, + 'summ' => $row['summ'], + 'comment' => $row['comment'], + ]; + } + } + + } catch (Exception $e3) { - file_put_contents(self::OUT_DIR . '/log_created_write_offs_erp_error.txt', PHP_EOL . date("d.m.Y H:i:s",time()). $e3->getMessage(). ' file: '. $e3->getFile() . ' line: '. $e3->getLine(), FILE_APPEND); + file_put_contents(self::OUT_DIR . '/log_created_write_offs_erp_error.txt', PHP_EOL . date("d.m.Y H:i:s", time()) . $e3->getMessage() . ' file: ' . $e3->getFile() . ' line: ' . $e3->getLine(), FILE_APPEND); } return [ @@@ -983,32 -934,68 +1058,68 @@@ } } } - - /** @var WriteOffsErp $writeOffsErp */ - $writeOffsErp->status = WriteOffsErp::STATUS_ERROR_1С; - $writeOffsErp->error_text = $errorText; - $writeOffsErp->save(); - if ($writeOffsErp->getErrors()) { - LogService::apiErrorLog( - json_encode( - ["error_id" => 11, "error" => $writeOffsErp->getErrors()], - JSON_UNESCAPED_UNICODE - ) - ); + if (!empty($writeOffsErp)) { + /** @var WriteOffsErp $writeOffsErp */ + $writeOffsErp->status = WriteOffsErp::STATUS_ERROR_1С; + $writeOffsErp->error_text = $errorText; + $writeOffsErp->save(); + if ($writeOffsErp->getErrors()) { + LogService::apiErrorLog( + json_encode( + ["error_id" => 11, "error" => $writeOffsErp->getErrors()], + JSON_UNESCAPED_UNICODE + ) + ); + } + } + if (!empty($waybillWriteOffsErp)) { + /** @var WaybillWriteOffs $waybillWriteOffsErp */ + $waybillWriteOffsErp->status = WriteOffsErp::STATUS_ERROR_1С; + $waybillWriteOffsErp->save(); + if ($waybillWriteOffsErp->getErrors()) { + LogService::apiErrorLog( + json_encode( + ["error_id" => 11, "error" => $waybillWriteOffsErp->getErrors()], + JSON_UNESCAPED_UNICODE + ) + ); + } } + } else { - /** @var WriteOffsErp $writeOffsErp */ - $writeOffsErp->status = WriteOffsErp::STATUS_CREATED_1С; - $writeOffsErp->number_1c = $arr["number"] ?? ''; - $writeOffsErp->save(); - if ($writeOffsErp->getErrors()) { - LogService::apiErrorLog( - json_encode( - ["error_id" => 11, - "error" => $writeOffsErp->getErrors()], - JSON_UNESCAPED_UNICODE - ) - ); + if (!empty($writeOffsErp)) { + /** @var WriteOffsErp $writeOffsErp */ + $writeOffsErp->status = WriteOffsErp::STATUS_CREATED_1С; + $writeOffsErp->number_1c = $arr["number"] ?? ''; + $writeOffsErp->save(); + if ($writeOffsErp->getErrors()) { + LogService::apiErrorLog( + json_encode( + [ + "error_id" => 11, - "error" => $writeOffsErp->getErrors() ++ "error" => $writeOffsErp->getErrors() + ], + JSON_UNESCAPED_UNICODE + ) + ); + } + } + if (!empty($waybillWriteOffsErp)) { + /** @var WaybillWriteOffs $waybillWriteOffsErp */ + $waybillWriteOffsErp->status = WriteOffsErp::STATUS_CREATED_1С; + $waybillWriteOffsErp->number_1c = $arr["number"] ?? ''; + $waybillWriteOffsErp->save(); + if ($waybillWriteOffsErp->getErrors()) { + LogService::apiErrorLog( + json_encode( + [ + "error_id" => 11, + "error" => $waybillWriteOffsErp->getErrors() + ], + JSON_UNESCAPED_UNICODE + ) + ); + } } } @@@ -2012,26 -2005,30 +2136,27 @@@ } - private function insertDataSales($values, $tableName, $columns, $chunks = 1000) - { - $chunkValues = array_chunk($values, $chunks); ++ + { + $chunkValues = array_chunk($values, $chunks); - foreach ($chunkValues as $key => $rows) { - try { - $transaction = \Yii::$app->db->beginTransaction(); - Yii::$app->db->createCommand()->batchInsert($tableName, $columns, $rows)->execute(); - $transaction->commit(); - } catch (Exception $e) { - $errorString = substr($e->getMessage(), 0, 2000); - file_put_contents( - self::OUT_DIR . '/error_upload.txt', - PHP_EOL . $errorString, - FILE_APPEND - ); - $transaction->rollBack(); - InfoLogService::setInfoLog(__FILE__, __LINE__, $tableName, 'error_id_25'); - InfoLogService::setInfoLog(__FILE__, __LINE__, $errorString, 'error_id_25_22'); - LogService::apiErrorLog( - json_encode(["error_id" => 25, "error" => $errorString], JSON_UNESCAPED_UNICODE) + foreach ($chunkValues as $key => $rows) { + + try { + $transaction = \Yii::$app->db->beginTransaction(); + Yii::$app->db->createCommand()->batchInsert($tableName, $columns, $rows)->execute(); + $transaction->commit(); + } catch (Exception $e) { + $errorString = substr($e->getMessage(), 0, 2000); + file_put_contents(self::OUT_DIR . '/error_upload.txt', - PHP_EOL . $errorString, FILE_APPEND); - $transaction->rollBack(); ++ PHP_EOL . $errorString, FILE_APPEND ++ );$transaction->rollBack(); + InfoLogService::setInfoLog(__FILE__, __LINE__, $tableName, 'error_id_25'); + InfoLogService::setInfoLog(__FILE__, __LINE__, $errorString, 'error_id_25_22'); - LogService::apiErrorLog(json_encode(["error_id" => 25, "error" => $errorString], JSON_UNESCAPED_UNICODE)); - ++ LogService::apiErrorLog(json_encode(["error_id" => 25, "error" => $errorString], JSON_UNESCAPED_UNICODE) + ); - } } } + } }