📜 ⬆️ ⬇️

PHP contract generation system with 1C intergation

Hello, dear habrovchane. Not so long ago I had to solve the following problem. Develop a web application for the mass generation of model contracts for the supply of certain equipment or services provided. All data on goods is stored with 1C: trade management. This application is necessary for sales managers, as they often work out of the office, travel to customers, and draw up an agreement through the company's website is convenient enough for them. TK ends here. Since I am also a fifth year student, I decided to submit the same application to my diploma design.

When I received such a task, I really missed an article on the similarity of this one, where a similar solution would be described, I hope someone would find this useful.

At once I will make a reservation that in this article I describe the general ways of solving this problem, without going into the wilds of implementation.

To begin, we describe the ideology of the designed system.

')
The objectives that this system will achieve:

I divided this task into 2 main stages:
  1. transfer of data from 1C to the site database;
  2. creation of a contract in electronic form.

From the web-based tools with which you can solve this problem, I am familiar only with PHP and MySQL, so I looked for all solutions based on them.

Transfer data from 1C to the site database

This stage, perhaps, was the most difficult for me, since I had never seen the 1C before. After a brief study of the possibilities of importing and exporting data to 1C, I decided to use the following data translation scheme. In fact, I only needed the product range, so I unloaded it, using standard 1C tools, in an XML file. It is worth mentioning that 1C supports a very convenient standard for the exchange of commercial information CommerceML .
To parse this file, I used the SimpleXML extension, which is available in PHP since version 5 (you can learn a little about parsing xml with Russian tags here ). If anyone is interested, here is the XML file that is obtained when unloading the nomenclature from the 1C demonstration base into it.
Below you can see a part of the parser code.

$xml = new SimpleXMLElement($xmlstr);
foreach ($xml as $key=>$v)
{
$name=iconv("utf-8", "windows-1251", $v->);
$id=iconv("utf-8", "windows-1251", $v->);
$barcode=iconv("utf-8", "windows-1251", $v->);
$art=iconv("utf-8", "windows-1251", $v->);
$unit=iconv("utf-8", "windows-1251", $v->->->);
$gr=iconv("utf-8", "windows-1251", $v->->);
$tax_s=iconv("utf-8", "windows-1251", $v->->->);
$price=iconv("utf-8", "windows-1251", $v->->->);
}
$query = "INSERT INTO test (name,id,barcode,artikl,unit,gr,tax_type,tax_s,price) VALUES ('$name','$id','$barcode','$art','$unit','$gr','$tax_type','$tax_s','$price')"; mysql_query($query)or die(mysql_error());


Up to this point I have not worked with parsers, but it turned out to be not as scary as it seemed to me. It was necessary to convert to windows-1251 due to the fact that this application will be placed on the organization’s website, and the site’s database in this encoding may have an easier way to solve this problem, but I did so.

Create a contract in electronic form

After the nomenclature and something else has been transferred from 1C to the application database, you can think about the second part of the task.
Of course, before creating a contract, you must select the goods for which the contract is drawn up, but this part is not interesting.
As the format in which the generation will occur, the PDF format was chosen, in the first place, it was chosen because of cross-platform and machine independence, that is, it can be opened on any computer or mobile device and printed on almost any printing device. On the Internet, there are a large number of library reviews and PHP classes for working with PDF. In the end, I chose FPDF , the only problem of this class is that you need to sweat a bit over Cyrillic. I don’t think it’s worth to “litter” the code, as there are plenty of examples of using this class, including in Russian.
As a result of the work of this application, the following is obtained:
image
I also stuck a QR code on the contract (pulled here ), this is no longer a functional lotion, but just a way to show my teachers the possibilities of web technologies, although I read on the forums that 1C can work with ordinary 2D barcodes, so the idea is not meaningless, it needs only a little development.

The goal of the task was not only the creation of contracts, but also the creation of accountability of the work of each sales manager; now it is very easy to track any contract in the organization. It is easy to track which manager has concluded contracts, how many, and for how much, at what time interval. Statistics are presented in 2 ways: a chart and in tabular form.
Soon I plan to start bringing this application into a presentation, maybe I will try to make a module for Bitrix out of this case, in any case I want to try to develop this application a little more, with an increase in functionality and capabilities.

Thanks for attention! I would be grateful for constructive criticism.

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


All Articles