From: marina Date: Thu, 15 Aug 2024 08:14:34 +0000 (+0300) Subject: ERP-85 Реализовать обмен данных с 1С Бухгалтерия X-Git-Tag: 1.4~22^2~27 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=74a6b089738d11eccac0ebe66a42f721a02ae47e;p=erp24_rep%2Fyii-erp24%2F.git ERP-85 Реализовать обмен данных с 1С Бухгалтерия поправлено сохранение при получении --- diff --git a/erp24/api2/config/api2.config.php b/erp24/api2/config/api2.config.php index 8aaaf733..8cba7a24 100644 --- a/erp24/api2/config/api2.config.php +++ b/erp24/api2/config/api2.config.php @@ -39,6 +39,7 @@ return [ 'auth' => 'auth/login', 'delivery/admin-auth' => 'delivery/admin-auth', ['class' => 'yii\rest\UrlRule', 'controller' => ['task']], + 'POST data-buh/request/' => 'data-buh/request' ], ], 'request' => [ diff --git a/erp24/api2/controllers/DataBuhController.php b/erp24/api2/controllers/DataBuhController.php index 6ac6b6a6..4f613e53 100644 --- a/erp24/api2/controllers/DataBuhController.php +++ b/erp24/api2/controllers/DataBuhController.php @@ -7,6 +7,7 @@ use Exception; use Yii; use yii\helpers\Json; use yii_app\records\ApiCronBuh; +use yii_app\records\Firms; class DataBuhController extends BaseController { @@ -15,50 +16,53 @@ class DataBuhController extends BaseController "/var/www/erp24/api2/json_buh"; // "/var/www/www-root/data/www/api.bazacvetov24.ru/data/json"; - public function actionRequest() + public function actionRequest($inn) { \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; - \Yii::$app->response->headers->set('firm', 'IP_Belov'); $request = \Yii::$app->request->getRawBody(); - try { - $result = Json::decode($request); - } catch (\Exception $ex) { - return $this->asJson(['error' => ['code' => 400, 'message' => 'Json body invalid']]); - } + if (array_key_exists($inn, Firms::getInn())) { + try { + $result = Json::decode($request); + } catch (\Exception $ex) { + return $this->asJson(['error' => ['code' => 400, 'message' => 'Json body invalid']]); + } - $result['ver'] = $result['ver'] ?? ''; + $result['ver'] = $result['ver'] ?? ''; - if (empty($result['ver']) || round($result['ver'], 2) < 1.1) { - return $this->asJson(["error_id" => 1, "error" => "minimal version is 1.1"]); - } + if (empty($result['ver']) || round($result['ver'], 2) < 1.1) { + return $this->asJson(["error_id" => 1, "error" => "minimal version is 1.1"]); + } - $json = ''; + $json = ''; - try { - $apiCronTest = ApiCronBuh::find() - ->where(['status' => 0]) - ->orderBy(['date' => SORT_ASC]) - ->one(); + try { + $apiCronTest = ApiCronBuh::find() + ->where(['status' => 0]) + ->orderBy(['date' => SORT_ASC]) + ->one(); - if ($apiCronTest) { - $json = $apiCronTest->json_post; + if ($apiCronTest) { + $json = $apiCronTest->json_post; - $apiCronTest->status = 1; - $apiCronTest->date_up = date("Y-m-d H:i:s"); + $apiCronTest->status = 1; + $apiCronTest->date_up = date("Y-m-d H:i:s"); - $validate = $apiCronTest->validate(); - if ($validate) { - $apiCronTest->save(); + $validate = $apiCronTest->validate(); + if ($validate) { + $apiCronTest->save(); + } } + } catch (Exception $e) { + return $e; } - } catch (Exception $e) { - return $e; - } - return $this->asJson(json_decode($json, true)); + return $this->asJson(json_decode($json, true)); + } else { + return 'Такого ИНН нет в списке'; + } } @@ -98,7 +102,7 @@ class DataBuhController extends BaseController file_put_contents(self::OUT_DIR . '/error_buh_upload.txt', PHP_EOL . 'result empty', FILE_APPEND); } - return $this->asJson(['response' => true]); + return $this->asJson(['request_id' => $requestId,'response' => true]); } } \ No newline at end of file diff --git a/erp24/controllers/CronController.php b/erp24/controllers/CronController.php index 0c58e5cb..9c4df848 100644 --- a/erp24/controllers/CronController.php +++ b/erp24/controllers/CronController.php @@ -40,7 +40,7 @@ class CronController extends Controller } $dataProvider = new ActiveDataProvider([ 'query' => ApiCronBuh::find() - ->orderBy('request_id desc'), + ->orderBy('date_up desc'), 'pagination' => [ 'pageSize' => 30 ], diff --git a/erp24/records/Firms.php b/erp24/records/Firms.php index 87b64dbe..e29ac619 100644 --- a/erp24/records/Firms.php +++ b/erp24/records/Firms.php @@ -50,6 +50,16 @@ class Firms extends \yii\db\ActiveRecord return 'firms'; } + public static function getInn() + { + return array( + '525911109960' => 'ИП Белов', + '526003058422' => 'ИП Кузнецов', + '526107741457' => 'ИП Лазарев', + '891103803770' => 'ИП Мочалина' + ); + } + /** * {@inheritdoc} */