Skip to Content
Technical Articles
Author's profile photo Sergiu Iatco

Application which checks VAT split status of 5000 Romanian companies.

: Application which checks automatically VAT split status of 5000 Romanian companies.

Ro: Aplicatie care verifica automat 5000 de furnizorii care aplica plata defalcata TVA.

Dear All,

This post is for Romania only. The post refers to “Legea 275/2017, OG 23/2017 plata defalcata TVA”.

ANAF has published short instructions on how to find the VAT split status of a company here.

I have provided on stackoverflow a complete working program code in Python for a single request here.

Maybe later I will extend the code for CSV upload and saving…

I am back with code and instructions for querying VAT split status using a list in CSV format.

The easy way for beginners to run the Python code is to install Anaconda (next, next, finish) and run Jupyter notebook (ipynb extension). Anaconda is an absolutely FREE open-source distribution of Python which works on Windows, macOs, and Linux. Jupyter notebook runs directly in your preferred Chrome, Firefox, Microsoft Edge, or other browsers.

You can find VAT split status readme instructions here, tutorial here pdf and complete code here ipynb. Further, you can easily figure out that you can add other fields in which ANAF webservice returns to perform also other checks.

However, If you need all fields which ANAF webservice returns, run this code here ipynb.

Maybe first of all you want to get a quick idea of how a script looks like and run a quick test for a single request here ipynb or quick tutorial here pdf.

You can also execute a quick test for a single request without installing anything using mybinder here. Wait for Starting repository, then from the menu open Kernel / Restart & Run All.

Running a list of 5000 to 10000 companies will take about one hour depending on the server load. Further, if you want to improve performance you may adapt the code to include in a request maximum of 500 elements at once instead of a single element(company).

SAP central note  2538317 “VAT split payment mechanism in Romania” does not provide a report to check and generate vendors’ VAT split status and VAT IBAN account. To solve this issue you can create an ABAP report which extracts data from the following tables: Vendor master data(LFA1, LFB1, LFBK, TIBAN), Vendor Open Items(BSIK), Purchasing Contracts and Purchasing Orders (EKKO, EKPO, EKET).

You may insist on the integration of the entire process of checking and updating vendor master data with the help of SAP RFC. Python supports SAP RFC and fortunately, you can start with studying the following blog here.

 

Update 01 March 2021.

Request data direct from SAP.  Consider security risks and access to the internet.

*&---------------------------------------------------------------------*
*& Report ZAPI_TVA_Romania
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZAPI_TVA_Romania.
* https://stackoverflow.com/questions/24322222/sap-fm-http-post-to-send-a-message-to-push-notification-server

start-of-selection.
  perform start.

form start.

  data: lv_status type i,
        lv_error_occurred type flag,
        lv_error_msg type string,
        lv_response_body type string.

  perform send_json using
        'https://webservicesp.anaf.ro/PlatitorTvaRest/api/v5/ws/tva'
        '[{"cui": "10874881", "data": "2017-12-22"}]'

    changing lv_status lv_response_body
             lv_error_occurred
             lv_error_msg.

* Show result
  format color col_heading.
  write: / 'Response status:', lv_status.
  if lv_error_occurred = 'X'.
    format color col_negative.
    write: / 'Error occurred:', lv_error_msg.
  endif.
  format color col_normal.
  write: / 'Response:', lv_response_body.

lv_json = lv_response_body.

* https://wiki.scn.sap.com/wiki/display/Snippets/One+more+ABAP+to+JSON+Serializer+and+Deserializer

endform.                    "start

form send_json using iv_url type string
                     iv_json_data type string
        changing cv_status type i
                 cv_response_body type string
                 cv_error_occurred type flag
                 cv_error_msg type string.


  data: lo_client type ref to if_http_client.

  clear: cv_error_msg,
         cv_status,
         cv_error_occurred,
         cv_error_msg.

  if iv_url is initial.
* No URL passed
    message e349(sbds) into cv_error_msg.
    cv_error_occurred = 'X'.
    return.
  endif.

  call method cl_http_client=>create_by_url
    exporting
      url                = iv_url
    importing
      client             = lo_client
    exceptions
      argument_not_found = 1
      plugin_not_active  = 2
      internal_error     = 3
      others             = 4.
  if sy-subrc ne 0.
    message id sy-msgid type sy-msgty number sy-msgno
      with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
     into cv_error_msg.
    cv_error_occurred = 'X'.
    return.
  endif.

  lo_client->request->set_cdata( iv_json_data ).
  lo_client->request->set_content_type( 'application/json' ).
  lo_client->request->set_method( 'POST' ).
  call method lo_client->send
    exceptions
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3
      others                     = 4.
  if sy-subrc ne 0.
    lo_client->get_last_error( importing message = cv_error_msg ).
    cv_error_occurred = 'X'.
    return.
  endif.

  lo_client->receive( exceptions others = 1 ).
  if sy-subrc ne 0.
    lo_client->get_last_error( importing message = cv_error_msg ).
    cv_error_occurred = 'X'.
    return.
  endif.

  cv_response_body = lo_client->response->get_cdata( ).
  lo_client->response->get_status( importing code = cv_status ).

endform.

 

Expected results.

 

Further solution to security and internet concerns could be a developed API (FastAPI) exposed to LAN and the internet.

Enjoy!

Sergiu Iatco

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.