📜 ⬆️ ⬇️

Use 54 FZ for the benefit of home bookkeeping

When the next edition of Federal Law number 54 "On the use of cash registers" came into force, most of the population met her negatively.

Something like this (18+, contains obscene language)


I was one of the few who jumped, clapped their hands and was generally happy as a child.
For the maintenance of accounting from a separate domestic work has become the most elementary business.

What for?


There will be no answer to the question "why do we need home accounting". If you do not know the answer, then you do not need it.

Also forget about the savings based on the analysis of accounting. The classic example of “you will see that a cup of coffee for 130 rubles eats up to 4,000 a month every day” is divorced from reality. If a person is not an idiot, he will see it without tedious bookkeeping.
')

The foundation


Let's start with the simple. Software for accounting.

There are a billion programs for home accounting.

I was superficially acquainted with the general trends and refused to use specialized software.
A high threshold of entry, limited support, the inability to expand on the one hand, and redundant functionality on the other, dubious prospects and the lifespan of software ...
In the end, my wife and I settled on Google Docs. We have been conducting bookkeeping since 2014, and during this time we have not failed (although the birth of a child has become a serious temptation) and have not regretted choosing a tool.

Everything looks very simple:
Three main sheets:
Categories - a list of categories for input validation
Current month - not to get lost
Current year - we drop here the current month

It looks like this (I think everything is clear from the screenshot):



Categories are automatically inserted from the corresponding sheet. If you enter something that is not in the list, the validator will curse.

I wanted to make tags, but in the end I refused this idea - objectively tagging is not at all simpler, and no need was found for this. Approximate destination category is enough.

This is what my list of categories looks like (it is not perfect, some of the categories duplicate each other, some of the categories are subcategories of others, but such a list has been formed over 4 years and covers our family needs for analyzing expenses):

Sheet: Categories
Site
Fruits
Vegetables
Spice
Petrol
Cultural holidays
Dessert
Products
Hygiene
Health
beauty
Auto
Job
Meat
Bedroom
Kitchen
Equipment
Presents
Entrance hall
Clothes, shoes
Games
Communal
Hobby
Soft
Cat
A fish
Taxi
Job
Phone
Equipment
Dishes
Household chemicals
Sport
Office
Taxes
Moto
Garden
Interior
Security
Cafe
Home maintenance and repair
Furniture
Sex
Travels
Buying a property
Drift
Drawing
Sculpture
Training
Ready meal
Smart House
Led
Children

Practice


In theory, bookkeeping looks very simple.

Well, what do we have to come home after the purchase and quickly enter the list of purchased goods into the document? A couple of packets of milk, a loaf of bread, cookies ...

The theory does not take into account trips to supermarkets, when products are bought at once in a bunch ...

And here it is - "a handful of nails":



One kind of footcloth is wildly demotivating. And entering with the union and counting items by category takes a long time. My wife and I sat down in the evenings and together we hammered in all the checks that had accumulated during the week.

Periodically, there was a desire to make text recognition check, to simplify the input.
But further thoughts did not go.

The reason is as simple as 5 kopecks: it takes time to write software. And at that moment it was obvious that the time spent on writing software capable of more or less qualitatively recognizing all checks and generating on their basis at least some useful data — about 10 years will overlap manual hammering in checks.

So it was until July 1, 2017. On this day, the “same” version of 54 FZ came into effect.
“That's it!”, I thought, “You can take the data from the check without hammering it in manually” ... And then we continued to hammer in the checks with our hands. Because inertia, laziness and conservatism.

In February 2018, my son was born ... This has greatly changed the priorities in business.

As a result - we did not find the time to keep accounts.

Checks have accumulated a huge amount.

Nail bucket


And here came the understanding that either I was doing automation, or I had to throw out all the checks, because I simply had no power to drive them.

Automation


It's time to talk about 54 FZ and what it gives us.

This law obliges sellers to conduct checks through the OFD (Fiscal Data Operator). If without clever words - all cash desks merge checks into the Internet.

And they can be accessed.

I don’t know how now, but when I understood, I couldn’t find any information about the protocol on the Internet.

Fortunately, the FTS have released their mobile application that can download checks.

Things are easy - we take a sniffer, put it on the phone and see what it sends an application for downloading data.

And it sends that
GET request to:
proverkacheka.nalog.ru : 9999 / v1 / inns / * / kkts / * / fss / {FN} / tickets / {FD}? fiscalSign = {FPD} & sendToEmail = no
The header contains the following required fields:
"Authorization": "Basic {BASE64 (phone: password)}"
Device-Id ":" {Any rubbish} "
"Device-OS": "Android 5.1" - most likely, you can also send rubbish, did not check.
"Version": "2"
"ClientVersion": "1.4.4.1"

The answer is in the form of json, I don’t see any sense in bringing the structure, it is simple and in practice it will be easily understood by the one to whom it will be relevant.

Link to sniffer
Links to the sniffer will not. I took the first one in Google. Everything worked fine, but I can't recommend it. It is worth remembering that in order to intercept https traffic, the application installs its certificates and is generally quite active in the phone. There is no certainty that the application does not contain malicious code. Therefore, if necessary - google and use it at your own peril and risk.

As you can see, the protocol requires a phone and a password to download the check.
I did not register, since it is easy to register through the official application and then use the phone and password to receive checks.

As I said above, writing automation software only makes sense if the costs of writing overlap with the gain from automation.

Therefore, I am a bit ashamed of the application code.

On the other hand, the application is written in a few hours and works great.

With the help of QZXing and a webcam, we scan the QR code, retrieve the OP, FD, FPD from it and make a request for the contents of the check.

By the way, the expensive webcam worked very poorly as a QR code scanner.

I was even a little upset and already wanted to recognize the application as unusable, since it took a few minutes to scan one code, which is completely unacceptable.
However, for the sake of experiment, I decided to try using a cheap Chinese webcam as a scanner ... And, oh, a miracle, she scans QR codes from checks without any problems! I did not expect this in any way ... I suppose the fact is that the Chinese webcam has a backlight, which is useless for normal use, but works well for close viewing of checks.

application


If you've suddenly read this far, you're probably interested in trying out the check reading software yourself.

Categories are stored in the categories.txt file.



Enter the phone number and password that received during registration in the official application.
Enter once, then it is saved locally in the application settings.

Click Request Bill, select the source of the video stream to scan a check and scan the receipt, or enter the data manually and click Manual to use the entered data.

If it is possible to recognize the data on the video stream, the window will automatically close and a request for a check will be sent.

What we have already entered is automatically substituted:



Fill in the fields: everything except the guarantee is mandatory.



Then click Generate Result and get the data in text form suitable for insertion into the table editor, this text is also placed in the clipboard.



Automation requires minimizing data entry. Therefore, everything that we have already entered is saved.
Buy something a second time - all fields of the goods will be already filled.

Everything entered is saved in the items.csv file

Sources of application hang on GitHub

There in the releases section you can pick up a build for Linux and Windows. Under the poppy, too, no problem going, but this is not for me.

UPD:
API authors have slightly changed its behavior.
1) Now it is necessary to first ask a valid check from the API, and only then request it. Otherwise, get invalid public API usage
2) Introduced a limit on the number of free requests from one user per day. Specially did not check, but the feeling of limitation in the region of 20 checks. In general, the restriction does not affect the home bookkeeping, so it may not be noticed.

Source: https://habr.com/ru/post/423633/


All Articles