Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] - Preparations for v1.0 Release #16

Merged
merged 2 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/formats.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [8.1]
dependency-version: [prefer-lowest, prefer-stable]
php: [8.1, 8.2, 8.3]
dependency-version: [prefer-stable]

name: Formats P${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }}

Expand Down
53 changes: 32 additions & 21 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,50 @@
name: Tests
name: Formats

on: ['push', 'pull_request']

jobs:
ci:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [8.1, 8.2]
dependency-version: [prefer-lowest, prefer-stable]
php: [8.1, 8.2, 8.3]
dependency-version: [prefer-stable]

name: Tests P${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }}
name: Formats P${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }}

steps:

- name: Checkout
uses: actions/checkout@v4
- name: Checkout
uses: actions/checkout@v4

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.composer/cache/files
key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, mbstring, zip
tools: prestissimo
coverage: pcov

- name: Install Composer dependencies
run: composer update --${{ matrix.dependency-version }} --no-interaction --prefer-dist

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.composer/cache/files
key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
- name: Coding Style Checks
run: composer test:lint

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, mbstring, zip
coverage: none
- name: Refacto Checks
run: composer test:refacto

- name: Install Composer dependencies
run: composer update --${{ matrix.dependency-version }} --no-interaction --prefer-dist
- name: Type Checks
run: composer test:types

- name: Unit Tests
run: composer test:unit
- name: Type Coverage
run: composer test:type-coverage min=90
121 changes: 110 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,36 @@ First, install ANAF via the [Composer](https://getcomposer.org/) package manager
composer require andalisolutions/anaf-php
```

Then, interact with ANAF's API:
Then, you can create `ANAF` client in two ways:

```php
$company = Anaf::for('TAX IDENTIFICATION NUMBER');
/*
* Client used for unauthenticated requests
*/
$client = Anaf::client();

/*
* Client used for authenticated requests
*/
$authorizedClient = Anaf::authorizedClient($apiKey);

/*
* Build a client with a specific base URI, staging and more. Example:
*/
$factoryClient = Anaf::factory()
->withApiKey($apiKey)
->staging()
->withBaseUri('https://webservicesp.anaf.ro')
->make();
```

#### You can obtain API key using [oauth2-anaf](https://github.com/andalisolutions/oauth2-anaf) package.
## TODO
- [x] Obtaining public information in the financial statements/annual accounting reports related to economic agents. ([Docs](https://static.anaf.ro/static/10/Anaf/Informatii_R/doc_WS_Bilant_V1.txt))
- [x] Get info about companies using `TAX IDENTIFICATION NUMBER` (CUI/Vat Number). ([Docs](https://static.anaf.ro/static/10/Anaf/Informatii_R/Servicii_web/doc_WS_V7.txt))
- [ ] Get info about taxpayers who are registered in the Register of farmers who apply the special regime ([Docs](https://static.anaf.ro/static/10/Anaf/Informatii_R/documentatie_SWRARG_v2.txt))
- [x] Get info about taxpayers who are registered in the Register of religious entities/units ([Docs](https://static.anaf.ro/static/10/Anaf/Informatii_R/index_cult_v2.html))
- [ ] Accessing the functionalities offered by the SPV ([Docs](https://static.anaf.ro/static/10/Anaf/Informatii_R/Prezentare_WS_SPV.txt))
- [ ] The national system regarding the electronic invoice RO e-Factura ([Docs](https://mfinante.gov.ro/static/10/eFactura/prezentare%20apeluri%20API%20E-factura.pdf))
- [x] Accessing the functionalities offered by the SPV ([Docs](https://static.anaf.ro/static/10/Anaf/Informatii_R/Prezentare_WS_SPV.txt))
- [x] The national system regarding the electronic invoice RO e-Factura ([Docs](https://mfinante.gov.ro/static/10/eFactura/prezentare%20apeluri%20API%20E-factura.pdf))
- [ ] The integrated electronic system RO e-Transport ([Docs](https://www.anaf.ro/anaf/internet/ANAF/servicii_online/servicii_web_anaf))


Expand All @@ -42,7 +59,11 @@ $company = Anaf::for('TAX IDENTIFICATION NUMBER');
### [Balance Sheet](https://static.anaf.ro/static/10/Anaf/Informatii_R/doc_WS_Bilant_V1.txt) Resource
Get public information in the financial statements/annual accounting reports related to economic agents
```php
$balanceSheet = $company->balanceSheet()->forYear('2021');
$balanceSheet = $client()->balanceSheet()->create([
'cui' => '12345678',
'an' => 2019,
]);

$balanceSheet->year;
$balanceSheet->tax_identification_number;
$balanceSheet->company_name;
Expand Down Expand Up @@ -76,9 +97,24 @@ _For balance sheets, the indicators may vary depending on the type of company, a

### [Info](https://static.anaf.ro/static/10/Anaf/Informatii_R/Servicii_web/doc_WS_V8.txt) Resource

Get info about the company using `TAX IDENTIFICATION NUMBER` (CUI/Vat Number)
Get info about the company or multiple companies.
```php
$companyInfo = $company->info()->get();
$companyInfo = $client->info()->create([
[
'cui' => '12345678',
'data' => '2021-01-01',
],
[
'cui' => '222222',
'data' => '2021-01-01',
]
]);

/*
* If you send one array, for one company, you will receive a CreateResponse object with the structure below.
* If you send multiple arrays, for multiple companies, you will receive a CreateResponses object with an array
* with CreateResponse objects.
*/

$companyInfo->generalData;

Expand All @@ -96,6 +132,9 @@ $companyInfo->generalData->activityCode;
$companyInfo->generalData->bankAccount;
$companyInfo->generalData->roInvoiceStatus;
$companyInfo->generalData->authorityName;
$companyInfo->generalData->formOfOwnership;
$companyInfo->generalData->organizationalForm;
$companyInfo->generalData->legalForm;

$companyInfo->vatRegistration;

Expand Down Expand Up @@ -174,9 +213,12 @@ $companyInfo->generalData->toArray(); // ['tax_identification_number' => '', 'co

Checking NGO taxpayers who are registered in the Register of religious entities/units
```php
$entity = Anaf::for('TAX IDENTIFICATION NUMBER');

$entityInfo = $entity->ngo()->get();
$entityInfo = $client->ngo()->create([
[
'cui' => '12345678',
'data' => '2021-01-01',
]
]);

$entityInfo->taxIdentificationNumber;
$entityInfo->searchDate;
Expand All @@ -194,6 +236,63 @@ $entityInfo->status;
$entityInfo->toArray(); // ["tax_identification_number" => '', "entity_name" => ''...]

```

### [eFactura](https://mfinante.gov.ro/web/efactura/informatii-tehnice) Resource

#### [Upload](https://mfinante.gov.ro/static/10/eFactura/upload.html) Resource
TODO: implement `upload` from [here](hhttps://mfinante.gov.ro/static/10/eFactura/upload.html)

#### [Status](https://mfinante.gov.ro/static/10/eFactura/upload.html) Resource
TODO: implement `status` from [here](https://mfinante.gov.ro/static/10/eFactura/staremesaj.html)

#### [Messages](https://mfinante.gov.ro/static/10/eFactura/listamesaje.html) Resource
TODO: implement `paginated messages` from [here](https://mfinante.gov.ro/static/10/eFactura/listamesaje.html#/EFacturaListaMesaje/getPaginatie)
Get the list of available messages
```php
$spvMessages = $authorizedClient->efactura()->messages([
'zile' => 30, // between 1 and 60
'cif' => '12345678',
]);

$spvMessages->messages; // array
$spvMessages->serial;
$spvMessages->taxIdentificationNumbers;
$spvMessages->title;

$message = $spvMessages->messages[0];
$message->creationDate,
$message->taxIdentificationNumber,
$message->solicitationId,
$message->details,
$message->type,
$message->id,
```

#### [Download - eFactura XML](https://mfinante.gov.ro/static/10/eFactura/descarcare.html) Resource
Get a file from the SPV identified by the `id` received from the messages endpoint
```php
$file = $authorizedClient->efactura()->download([
'id' => '12345678',
]);

$file->getContent(); // string - You can save/download the content to a file
```
#### [Validate](https://mfinante.gov.ro/static/10/eFactura/validare.html) Resource
TODO: implement `validate` from [here](https://mfinante.gov.ro/static/10/eFactura/validare.html)

#### [XmlToPdf](https://mfinante.gov.ro/static/10/eFactura/xmltopdf.html) Resource
Convert XML eFactura to PDF. For this endpoint you need to use unauthenticated client
```php
/*
* $xmlStandard can be one of the following: 'FACT1', 'FCN'.
* The default value is 'FACT1'
*/
$file = $client->efactura()->xmlToPdf($pathToXmlFile, $xmlStandard);
$file->getContent(); // string - You can save the pdf content to a file
```

TODO: implement `/transformare/{standard}/{novld}` from [here](https://mfinante.gov.ro/static/10/eFactura/xmltopdf.html#/EFacturaXmlToPdf/getPdfNoVld)

---

ANAF PHP is an open-sourced software licensed under the **[MIT license](https://opensource.org/licenses/MIT)**.
24 changes: 15 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@
],
"require": {
"php": "^8.1.0",
"ext-iconv": "*",
"guzzlehttp/guzzle": "^7.5.0",
"ext-iconv": "*"
"php-http/discovery": "^1.19"
},
"require-dev": {
"laravel/pint": "^1.3.0",
"laravel/pint": "^1.13.7",
"mockery/mockery": "^1.6",
"nunomaduro/collision": "^7.0.0",
"pestphp/pest": "^2.0.0",
"pestphp/pest-plugin-arch": "^2.0.0",
"pestphp/pest-plugin-mock": "^2.0.0",
"phpstan/phpstan": "^1.9.4",
"rector/rector": "^0.14.8",
"pestphp/pest": "^2.30.0",
"pestphp/pest-plugin-arch": "^2.5",
"pestphp/pest-plugin-type-coverage": "^2.7",
"phpstan/phpstan": "^1.10.54",
"rector/rector": "^0.18.13",
"spatie/ray": "^1.40",
"symfony/var-dumper": "^6.2.2"
},
"autoload": {
Expand All @@ -43,7 +46,8 @@
"sort-packages": true,
"preferred-install": "dist",
"allow-plugins": {
"pestphp/pest-plugin": true
"pestphp/pest-plugin": true,
"php-http/discovery": true
}
},
"scripts": {
Expand All @@ -52,12 +56,14 @@
"test:lint": "pint --test -v",
"test:refactor": "rector --dry-run",
"test:types": "phpstan analyse --ansi",
"test:type-coverage": "pest --type-coverage --min=90",
"test:unit": "pest --colors=always",
"test": [
"@test:lint",
"@test:refactor",
"@test:types",
"@test:unit"
"@test:unit",
"@test:type-coverage"
]
}
}
1 change: 0 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@
SetList::DEAD_CODE,
SetList::EARLY_RETURN,
SetList::TYPE_DECLARATION,
SetList::PRIVATIZATION,
]);
};
42 changes: 24 additions & 18 deletions src/Anaf.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,36 @@
declare(strict_types=1);

use Anaf\Client;
use Anaf\Enums\Transporter\ContentType;
use Anaf\Transporters\HttpTransporter;
use Anaf\ValueObjects\TaxIdentificationNumber;
use Anaf\ValueObjects\Transporter\BaseUri;
use Anaf\ValueObjects\Transporter\Headers;
use GuzzleHttp\Client as GuzzleClient;
use Anaf\Factory;

final class Anaf
class Anaf
{
/**
* Creates a new Anaf Client with the given Tax Identification Number (romanian CUI).
* Creates a new Anaf Authorized Client with the given api key.
*/
public static function for(string $taxIdentificationNumber): Client
public static function authorizedClient(string $apiKey): Client
{
$taxIdentificationNumber = TaxIdentificationNumber::from($taxIdentificationNumber);

$baseUri = BaseUri::from('webservicesp.anaf.ro');

$headers = Headers::withContentType(ContentType::JSON);

$client = new GuzzleClient();
return self::factory()
->withApiKey($apiKey)
->withBaseUri('api.anaf.ro')
->make();
}

$transporter = new HttpTransporter($client, $baseUri, $headers);
/**
* Creates a new Anaf Client for non-authorized requests.
*/
public static function client(): Client
{
return self::factory()
->withBaseUri('webservicesp.anaf.ro')
->make();
}

return new Client($transporter, $taxIdentificationNumber);
/**
* Creates a new factory instance to configure a custom Open AI Client
*/
public static function factory(): Factory
{
return new Factory();
}
}
Loading
Loading