
Few people think when shopping in a store, how a cashier’s equipment works. In fact, this is a well-established mechanism, not only from a technical point of view, but also from the point of view of legislation. Everyone knows that the main thing is to get a check, but why a check is a fiscal document confirming the purchase - mostly only the entrepreneurs themselves know.
In this article we will share the experience of developing a cash register and tell you how everything is arranged from the inside.
Antique Cash Register')
1. System: iron + software at the cashier
The entire hardware and software system that is installed at the cashier’s workplace can be called a POS system or a POS terminal, from English Point of sale is a place of sale.
Consider how the POS system works. Since the fundamental difference between the system and the terminal is the location of the fiscal memory (FP) or the fiscal drive (FN): in the POS system it is built into the printing device, and in the POS terminal it is located in the computer unit.
Typical cash register. POS-system of the Russian company "SHTRIH-M"POS-system is a software and hardware complex that operates on the basis of a fiscal registrar. It usually consists of a POS computer, a monitor and keyboard, a receipt printer, a fiscal recorder, a customer display, a cash drawer and a bank card reader. A typical set of cash functions: accounting and holiday goods, receiving and issuing money, cancellation of the purchase.
The most interesting part of the POS system - the
fiscal registrar is the heart of the system and one of the classes of cash registers (CCM).
In the role of the fiscal registrar serves receipt printer with built-in fiscal memory. It receives information via a communication channel, processes it and prints it. Data on cash transactions can be stored in fiscal memory indefinitely until you need to reset them.
For the direct transfer of the fiscal registrar data to the tax service, the server of
the fiscal data operator is used - the CRF , a special legal entity that is responsible for receiving, processing, storing and transmitting the fiscal data to the tax service.
Last year, Russian entrepreneurs actively discussed the transition to online cash registers and sending checks to the tax office through the CRF in connection with the adoption of Law 54-FZ “On the use of cash registers”.
The role of OFD. Scheme from the article about 54- and transition to online cash registersThe FTS is the Federal Tax Service of the Russian Federation. In Kazakhstan, this function is performed by the State Revenue Committee of the Ministry of Finance. And in Belarus - the Ministry of Taxes and Duties.
There are several CRFs in the Russian Federation, and only one in Kazakhstan, Kazakhtelecom JSC.
2. Legislation: global online cash register control
Online control of retail operations is already in place in many countries: South Korea (2005), Sweden (2008), Canada (2010), Poland (2011), Croatia (2013). In 2015, this approach began to be introduced in Kazakhstan. And in Belarus, the deadline for connecting cash registers to the remote control system of revenue was postponed to July 1, 2018 (the same period is scheduled in Russia).
The use of online cash desks in Kazakhstan is governed by
Chapter 90 of the Tax Code . Since 2015, the transfer of checks to the tax on the Internet began sellers of fuel and alcohol. At the second stage - from 2016 - those who are engaged in the wholesale trade in various materials and equipment were connected to the system; retail of furniture, software and electronics; owners of hotels, restaurants, hairdressers and cinemas. Provided the third phase of the project.
We refer to laws for a reason, they describe the mandatory technical requirements for software and hardware systems for collecting and sending data to the tax system, which form the basis of those. tasks for development engineers. For example,
the order of the Minister of Finance of the Republic of Kazakhstan published a list of requirements for a cash register for transferring information about cash payments, which was very useful to us for developing a fiscal registrar.
3. Device and business logic of the fiscal registrar
Our development base device is a thermal receipt printer. Buildroot assembly system. Programming is on Qt.
The project required to develop:
1) technical task;
2) an exchange protocol with a POS computer, let's call it the POS-C protocol;
3) daemon application that controls the device:
- data exchange module with the CRF server using the CCP protocol (cash register equipment);
- data exchange module with a POS computer using the POS-C protocol;
- print management module;
- communication interface control module;
- module of interaction with the database;
- web server.
1) Module data exchange with the server OFD
The device is exchanged with the server using the TCP / IP protocol. In this interaction, the device is the client, and the CRF is the server. Protocol Buffers is used as the basis for encoding and decoding information transmitted via the CCT protocol.
Protocol Buffers (Protobuf) is a protocol for the serialization (transmission) of structured data proposed by Google as an effective binary alternative to the XML text format. Developers report that their Protocol Buffers is simpler, more compact and faster than XML, because it transmits binary data that is optimized for the minimum message size.
The format of messages in Protobuf is described in a special declarative language, which somewhat resembles the declaration of structures in the C ++ language. These declarations are saved to a file with the .proto extension and are compiled into source codes in the selected language using the protoc compiler.
The CCP protocol allows you to:
- receive service information, information about the cashier, nomenclature data;
- send the data of the fiscal receipt and cancel it;
- receive reports on the operations performed;
- control cash on hand (withdraw or deposit cash) and the status of the shift (open or close the shift);
- authorize the operator cashier.
2) Data exchange module with a POS computer
Communication with a POS computer is implemented using TCP / IP or HTTP protocols, depending on the settings in the web interface, via the USB Type-B port using USB over Ethernet technology. In this interaction, the device is the server, and the POS computer is the client. When using a TCP connection, the data is in XML format. And in the case of an HTTP connection, a POST request is used, the body of which is the same data as a TCP connection.
POS-C protocol allows:
- configure and test the connection with the OFD server;
- get information about the state of the device;
- control the peripheral of the device (print text, beep, open or close the cash drawer);
- print a fiscal receipt;
- print reports on the operations performed;
- control cash on hand (withdraw or deposit cash) and the status of the shift (open or close the shift).
3) Print Management Module
Interaction with the printing mechanism, sound emitter and the port of control of the cash drawer is carried out through
the Python-ESCPOS library , which implements the ESC / POS protocol.
ESC / P (Epson Standard Code for Printers) is a command language developed by Epson to control printers. ESC / POS is one of the ESC / P variants designed for use in POS equipment.
Types of printed documents:
- test print;
- test fiscal receipt;
- fiscal receipt;
- canceled fiscal receipt;
- reports (X-report, Z-report, full control tape, abbreviated control tape, cashier report, section report);
- depositing or withdrawing cash;
- opening shift;
- information about the state of the device;
- device test result;
- device registration receipt.
Testing the printer. Examples of checks4) Communication Interface Management Module
On board the device there is a DHCP server for the USB interface to communicate with the POS computer. And to connect to the OFD server, LAN, WiFi and GPRS interfaces can be used, switching between which is implemented by the ConnMan network connections management daemon. It allows you to configure connections for each interface so that in case of a connection failure on the active interface, quickly switch to another connection with a lower priority. Such a solution stabilizes the connection with the OFD server at points of sale with poor internet connection.
5) Database interaction module
Data storage is implemented using a compact
embedded SQLite DBMS and organized in the form of the following tables:
- data on the operations performed;
- authorization data;
- section settings;
- tax settings;
- cliché and basement check settings;
- informational messages from the OFD server.
6) Web server
To implement the web server
, the Wt, C ++ WebToolkit library was chosen due to the following advantages:
- this is a cross-platform free library with C ++ support;
- small size of a web server in C ++ and low resource consumption;
- ease of integration with existing desktop applications and C ++ libraries;
- No need to use HTML, CSS, JavaScript and other technologies, because can be programmed using widgets like Qt;
- security and cross-browser web applications.
WtDesigner turned out to be very useful for a quick start.
The purpose of the web interface:
- settings;
- view device status;
- Software Update.
Web interface4. Conclusion
Based on these technologies, we developed a device with a wealth of functions and settings via a web interface, support for various communication protocols with a POS computer, and the ability to update software.
And now it seems that the Promwad engineering team will never be able to just come to the store and buy something, without thinking about all these insides of the online cash registers, protocols for transmitting data, the requirements of the legislation, and printing the whole kitchen:
- Take the check, please!
- No, thanks! :-)
PS And finally, a minute of humor: British ufologists from the ArtAlienTV team found in the pictures of the Curiosity rover a thing resembling an old cash register.
