Coder Social home page Coder Social logo

anaf-php's Introduction

ANAF PHP

GitHub Workflow Status (main) Total Downloads Latest Version License


ANAF PHP is a PHP API client that allows you to interact with the ANAF Web Services.

Get Started

Requires PHP 8.1+

First, install ANAF via the Composer package manager:

composer require andalisolutions/anaf-php

Then, you can create ANAF client in two ways:

/*
 * 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 package.

TODO

  • Obtaining public information in the financial statements/annual accounting reports related to economic agents. (Docs)
  • Get info about companies using TAX IDENTIFICATION NUMBER (CUI/Vat Number). (Docs)
  • Get info about taxpayers who are registered in the Register of farmers who apply the special regime (Docs)
  • Get info about taxpayers who are registered in the Register of religious entities/units (Docs)
  • Accessing the functionalities offered by the SPV (Docs)
  • The national system regarding the electronic invoice RO e-Factura (Docs)
  • The integrated electronic system RO e-Transport (Docs)

Usage

Balance Sheet Resource

Get public information in the financial statements/annual accounting reports related to economic agents

$balanceSheet = $client()->balanceSheet()->create([
    'cui' => '12345678',
    'an' => 2019,
]);

$balanceSheet->year;
$balanceSheet->tax_identification_number;
$balanceSheet->company_name;
$balanceSheet->activity_code;
$balanceSheet->activity_name;
$balanceSheet->indicators; // array
$balanceSheet->indicators['AVERAGE_NUMBER_OF_EMPLOYEES']->value;
$balanceSheet->indicators['NET_LOSS']->value;
$balanceSheet->indicators['NET_PROFIT']->value;
$balanceSheet->indicators['GROSS_LOSS']->value;
$balanceSheet->indicators['GROSS_PROFIT']->value;
$balanceSheet->indicators['TOTAL_EXPENSES']->value;
$balanceSheet->indicators['TOTAL_INCOME']->value;
$balanceSheet->indicators['NET_TURNOVER']->value;
$balanceSheet->indicators['HERITAGE_OF_THE_KINGDOM']->value;
$balanceSheet->indicators['PAID_SUBSCRIBED_CAPITAL']->value;
$balanceSheet->indicators['CAPITAL_TOTAL']->value;
$balanceSheet->indicators['PROVISIONS']->value;
$balanceSheet->indicators['ADVANCE_INCOME']->value;
$balanceSheet->indicators['LIABILITIES']->value;
$balanceSheet->indicators['PREPAYMENTS']->value;
$balanceSheet->indicators['HOME_AND_BANK_ACCOUNTS']->value;
$balanceSheet->indicators['DEBT']->value;
$balanceSheet->indicators['INVENTORIES']->value;
$balanceSheet->indicators['CURRENT_ASSETS']->value;
$balanceSheet->indicators['FIXED_ASSETS']->value;

$balanceSheet->toArray(); // ['year' => '', 'tax_identification_number' => '', 'company_name' => '' ...]

For balance sheets, the indicators may vary depending on the type of company, as specified by ANAF. I recommend you to use var_dump to observe the type of indicators. The vast majority of companies have the indicators from the example above

Info Resource

Get info about the company or multiple companies.

$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; 

/* Accessible information in general data */
$companyInfo->generalData->companyName;
$companyInfo->generalData->address;
$companyInfo->generalData->registrationNumber;
$companyInfo->generalData->phone;
$companyInfo->generalData->fax;
$companyInfo->generalData->postalCode;
$companyInfo->generalData->document;
$companyInfo->generalData->registrationStatus;
$companyInfo->generalData->registrationDate;
$companyInfo->generalData->activityCode;
$companyInfo->generalData->bankAccount;
$companyInfo->generalData->roInvoiceStatus;
$companyInfo->generalData->authorityName;
$companyInfo->generalData->formOfOwnership;
$companyInfo->generalData->organizationalForm;
$companyInfo->generalData->legalForm;

$companyInfo->vatRegistration;

/* Accessible information in vat registration */
$companyInfo->vatRegistration->status;
//vatPeriods is an array from ANAF v8
$companyInfo->vatRegistration->vatPeriods[0]->startDate
$companyInfo->vatRegistration->vatPeriods[0]->stopDate;
$companyInfo->vatRegistration->vatPeriods[0]->stopEffectiveDate;
$companyInfo->vatRegistration->vatPeriods[0]->message;

$companyInfo->vatAtCheckout;

/* Accessible information in vat at checkout */
$companyInfo->vatAtCheckout->startDate;
$companyInfo->vatAtCheckout->stopDate;
$companyInfo->vatAtCheckout->updateDate;
$companyInfo->vatAtCheckout->publishDate;
$companyInfo->vatAtCheckout->updatedType;
$companyInfo->vatAtCheckout->status;


$companyInfo->inactiveState;

/* Accessible information in inactive state */
$companyInfo->inactiveState->inactivationDate;
$companyInfo->inactiveState->reactivationDate;
$companyInfo->inactiveState->publishDate;
$companyInfo->inactiveState->deletionDate;
$companyInfo->inactiveState->status;


$companyInfo->splitVat;

/* Accessible information in split tva */
$companyInfo->splitVat->startDate;
$companyInfo->splitVat->stopDate;
$companyInfo->splitVat->status;

$companyInfo->hqAddress;

/* Accessible information in hq address */
$companyInfo->hqAddress->street;
$companyInfo->hqAddress->no;
$companyInfo->hqAddress->city;
$companyInfo->hqAddress->cityCode;
$companyInfo->hqAddress->county;
$companyInfo->hqAddress->countyCode;
$companyInfo->hqAddress->countyShort;
$companyInfo->hqAddress->country;
$companyInfo->hqAddress->details;
$companyInfo->hqAddress->postalCode;

$companyInfo->fiscalAddress;

/* Accessible information in fiscal address */
$companyInfo->fiscalAddress->street;
$companyInfo->fiscalAddress->no;
$companyInfo->fiscalAddress->city;
$companyInfo->fiscalAddress->cityCode;
$companyInfo->fiscalAddress->county;
$companyInfo->fiscalAddress->countyCode;
$companyInfo->fiscalAddress->countyShort;
$companyInfo->fiscalAddress->country;
$companyInfo->fiscalAddress->details;
$companyInfo->fiscalAddress->postalCode;

// You can use all resources as array
$companyInfo->toArray(); // ["general_data" => ["tax_identification_number" => '', "company_name" => ''...]..]
// or
$companyInfo->generalData->toArray(); // ['tax_identification_number' => '', 'company_name' => ''...]

Ngo Resource

Checking NGO taxpayers who are registered in the Register of religious entities/units

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

$entityInfo->taxIdentificationNumber;
$entityInfo->searchDate;
$entityInfo->entityName;
$entityInfo->address;
$entityInfo->phone;
$entityInfo->postalCode;
$entityInfo->document;
$entityInfo->registrationStatus;
$entityInfo->startDate;
$entityInfo->endDate;
$entityInfo->status;

// You can use all resources as array
$entityInfo->toArray(); // ["tax_identification_number" => '', "entity_name" => ''...]

eFactura Resource

Upload Resource

Upload an XML (eFactura) file to the SPV

TODO: improve error handling

$upload = $authorizedClient->efactura()->upload(
    xml_path: $pathToXmlFile,
    taxIdentificationNumber: '12345678',
    //standard: UploadStandard::UBL, // default value is UBL
    //extern: false, // default value is false
    //selfInvoice: false, // default value is false
);
$upload->responseDate, // 202401011640
$upload->executionStatus,
$upload->uploadIndex,

Status Resource

TODO: implement status from here

Messages Resource

TODO: implement paginated messages from here Get the list of available messages

$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,

Get a file from the SPV identified by the id received from the messages endpoint

$file = $authorizedClient->efactura()->download([
    'id' => '12345678',
]);

$file->getContent(); // string - You can save/download the content to a file

Validate Resource

TODO: implement validate from here

XmlToPdf Resource

Convert XML eFactura to PDF. For this endpoint you need to use unauthenticated client

/*
 * $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

ANAF PHP is an open-sourced software licensed under the MIT license.

anaf-php's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

anaf-php's Issues

proxy

Cum setez un proxy prin care sa treaca conexiunea catre anaf?

Class Anaf not found

Although installed with composer, the answer is Uncaught „Error: Class "Anaf" not found in...”.
print_r(get_declared_classes()) doesn't show Anaf class.

Testing & Integration Questions

HI, first of all, thank you for such an amazing work of making usage of governmental web service easy and accessible! But before the integration I had couple of questions:

  1. It is mentioned that this is charged API. Where I can find price and conditions?
  2. Before integrating I wanted to try ANAF API in Postman (https://static.anaf.ro/static/10/Anaf/Informatii_R/doc_WS_V6.txt) but when I try to POST I get either 404, or 200, but with <title>Mentenanta sistem</title>.

Tho, I am trying without any authorisation, is there a token I need to obtain (could find any clear info).

Many thanks in advance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.