Skip to content

Commit

Permalink
added oktmo, update party, update address (#6)
Browse files Browse the repository at this point in the history
* update PartyRequest and PartyResponse
* update Address (added new properties)
* added OKTMO
* fix test
  • Loading branch information
Velhron authored Jan 21, 2021
1 parent 11c60f7 commit 0e853eb
Show file tree
Hide file tree
Showing 11 changed files with 217 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/Model/Request/Find/OktmoRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Velhron\DadataBundle\Model\Request\Find;

class OktmoRequest extends FindRequest
{
}
9 changes: 9 additions & 0 deletions src/Model/Request/Suggest/OktmoRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Velhron\DadataBundle\Model\Request\Suggest;

class OktmoRequest extends SuggestRequest
{
}
5 changes: 5 additions & 0 deletions src/Model/Request/Suggest/PartyRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ class PartyRequest extends SuggestRequest
* @var array Приоритет города при ранжировании
*/
protected $locations_boost;

/**
* @var array Ограничение по коду ОКВЭД
*/
protected $okved;
}
48 changes: 48 additions & 0 deletions src/Model/Response/Suggest/OktmoResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace Velhron\DadataBundle\Model\Response\Suggest;

class OktmoResponse extends SuggestResponse
{
/**
* @var string Код ОКТМО
*/
public $oktmo;

/**
* @var string Тип муниципального района
*/
public $areaType;

/**
* @var string Код муниципального района
*/
public $areaCode;

/**
* @var string Название муниципального района
*/
public $area;

/**
* @var string Тип муниципального поселения
*
* 1 — городское поселение
* 2 — сельское поселение
* 3 — межселенная территория в составе муниципального района
* 4 — внутригородской район городского округа
*/
public $subareaType;

/**
* @var string Код муниципального поселения
*/
public $subareaCode;

/**
* @var string Название муниципального поселения
*/
public $subarea;
}
10 changes: 10 additions & 0 deletions src/Model/Response/Suggest/PartyResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ class PartyResponse extends SuggestResponse
*/
public $managers;

/**
* @var array Правопредшественники (только для юр. лиц)
*/
public $predecessors;

/**
* @var array Правопреемники (только для юр. лиц)
*/
public $successors;

/**
* @var string Уставной капитал компании
*/
Expand Down
10 changes: 10 additions & 0 deletions src/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ services:
response: Velhron\DadataBundle\Model\Response\Suggest\Okpd2Response
url: '%velhron_dadata.base_suggestions_url%/suggest/okpd2'

- name: 'suggestOktmo'
request: Velhron\DadataBundle\Model\Request\Suggest\OktmoRequest
response: Velhron\DadataBundle\Model\Response\Suggest\OktmoResponse
url: '%velhron_dadata.base_suggestions_url%/suggest/oktmo'

- name: 'findAddress'
request: Velhron\DadataBundle\Model\Request\Find\AddressRequest
response: Velhron\DadataBundle\Model\Response\Suggest\AddressResponse
Expand Down Expand Up @@ -152,6 +157,11 @@ services:
response: Velhron\DadataBundle\Model\Response\Find\AffiliatedPartyResponse
url: '%velhron_dadata.base_suggestions_url%/findAffiliated/party'

- name: 'findOktmo'
request: Velhron\DadataBundle\Model\Request\Find\OktmoRequest
response: Velhron\DadataBundle\Model\Response\Suggest\OktmoResponse
url: '%velhron_dadata.base_suggestions_url%/findById/oktmo'

- name: 'geolocateAddress'
request: Velhron\DadataBundle\Model\Request\Geolocate\AddressRequest
response: Velhron\DadataBundle\Model\Response\Suggest\AddressResponse
Expand Down
38 changes: 37 additions & 1 deletion src/Service/DadataSuggest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Velhron\DadataBundle\Model\Response\Suggest\FnsUnitResponse;
use Velhron\DadataBundle\Model\Response\Suggest\MetroResponse;
use Velhron\DadataBundle\Model\Response\Suggest\Okpd2Response;
use Velhron\DadataBundle\Model\Response\Suggest\OktmoResponse;
use Velhron\DadataBundle\Model\Response\Suggest\Okved2Response;
use Velhron\DadataBundle\Model\Response\Suggest\PartyResponse;
use Velhron\DadataBundle\Model\Response\Suggest\PostalUnitResponse;
Expand Down Expand Up @@ -95,6 +96,7 @@ public function suggestAddress(string $query, array $options = []): array
/**
* Подсказки по организациям.
*
* Возвращает только базовые поля.
* Ищет компании и индивидуальных предпринимателей:
* - по ИНН, ОГРН и КПП;
* - названию (полному и краткому);
Expand Down Expand Up @@ -349,6 +351,23 @@ public function suggestOkpd2(string $query, array $options = []): array
return $this->handle('suggestOkpd2', $query, $options);
}

/**
* Подсказки по справочнику "Муниципальные образования (ОКТМО)".
*
* Общероссийский классификатор территорий муниципальных образований.
*
* @param string $query Текст запроса
* @param array $options Дополнительные параметры запроса
*
* @return OktmoResponse[]
*
* @throws DadataException|InvalidConfigException
*/
public function suggestOktmo(string $query, array $options = []): array
{
return $this->handle('suggestOktmo', $query, $options);
}

/**
* Адрес по коду КЛАДР или ФИАС.
*
Expand Down Expand Up @@ -401,7 +420,7 @@ public function findDelivery(string $query, array $options = []): array
*
* Находит компанию или индивидуального предпринимателя по ИНН, КПП, ОГРН.
* Возвращает реквизиты компании, учредителей, руководителей, сведения о налоговой, ПФР и ФСС, финансы, лицензии,
* реестр МСП и другую информацию о компании.
* реестр МСП и другую информацию о компании. Возвращает все доступные сведения о компании.
*
* @param string $query Текст запроса
* @param array $options Дополнительные параметры запроса
Expand Down Expand Up @@ -471,4 +490,21 @@ public function findAffiliatedParty(string $query, array $options = []): array
{
return $this->handle('findAffiliatedParty', $query, $options);
}

/**
* Муниципальные образования (ОКТМО) по идентификатору.
*
* Общероссийский классификатор территорий муниципальных образований.
*
* @param string $query Текст запроса
* @param array $options Дополнительные параметры запроса
*
* @return OktmoResponse[]
*
* @throws DadataException|InvalidConfigException
*/
public function findOktmo(string $query, array $options = []): array
{
return $this->handle('findOktmo', $query, $options);
}
}
10 changes: 10 additions & 0 deletions src/Traits/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,16 @@ trait Address
*/
public $block;

/**
* @var string Подъезд
*/
public $entrance;

/**
* @var string Этаж
*/
public $floor;

/**
* @var string Тип квартиры (сокращенный)
*/
Expand Down
32 changes: 32 additions & 0 deletions tests/Service/DadataSuggestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,17 @@ public function testSuggestOkpd2(): void
$this->assertEquals('S.95.23.10.133', $result[0]->idx);
}

public function testSuggestOktmo(): void
{
$service = $this->createService(__DIR__.'/../mocks/Suggest/oktmo.json');
$result = $service->suggestOktmo('5462342');

$this->assertEquals('54623422', $result[0]->oktmo);
$this->assertEquals('Колпнянский', $result[0]->area);
$this->assertEquals('54623000', $result[1]->areaCode);
$this->assertEquals('Ярищенское', $result[1]->subarea);
}

public function testFindAddress(): void
{
$service = $this->createService(__DIR__.'/../mocks/Find/address.json');
Expand Down Expand Up @@ -250,6 +261,15 @@ public function testFindAffiliatedParty(): void
$this->assertEquals('45286560000', $result[0]->okato);
}

public function testFindOktmo(): void
{
$service = $this->createService(__DIR__.'/../mocks/Find/oktmo.json');
$result = $service->findOktmo('54623425');

$this->assertEquals('54623425', $result[0]->value);
$this->assertEquals('54623000', $result[0]->areaCode);
}

public function suggestDataProvider(): array
{
return [
Expand Down Expand Up @@ -349,6 +369,12 @@ public function suggestDataProvider(): array
'калоши',
__DIR__.'/../mocks/Suggest/okpd2.json',
],
[
'suggestOktmo',
'/suggest/oktmo',
'5462342',
__DIR__.'/../mocks/Suggest/oktmo.json',
],
[
'findAddress',
'/findById/address',
Expand Down Expand Up @@ -391,6 +417,12 @@ public function suggestDataProvider(): array
'7736207543',
__DIR__.'/../mocks/Find/affiliatedParty.json',
],
[
'findOktmo',
'/findById/oktmo',
'54623425',
__DIR__.'/../mocks/Find/oktmo.json',
],
];
}

Expand Down
17 changes: 17 additions & 0 deletions tests/mocks/Find/oktmo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"suggestions": [
{
"value": "54623425",
"unrestricted_value": "54623425",
"data": {
"oktmo": "54623425",
"area_type": "1",
"area_code": "54623000",
"area": "Колпнянский",
"subarea_type": "2",
"subarea_code": "54623425",
"subarea": "Ярищенское"
}
}
]
}
30 changes: 30 additions & 0 deletions tests/mocks/Suggest/oktmo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"suggestions": [
{
"value": "54623422",
"unrestricted_value": "54623422",
"data": {
"oktmo": "54623422",
"area_type": "1",
"area_code": "54623000",
"area": "Колпнянский",
"subarea_type": "2",
"subarea_code": "54623422",
"subarea": "Ушаковское"
}
},
{
"value": "54623425",
"unrestricted_value": "54623425",
"data": {
"oktmo": "54623425",
"area_type": "1",
"area_code": "54623000",
"area": "Колпнянский",
"subarea_type": "2",
"subarea_code": "54623425",
"subarea": "Ярищенское"
}
}
]
}

0 comments on commit 0e853eb

Please sign in to comment.