Electronic invoice generation method and device, electronic equipment and computer program product
By identifying the business scenarios of transaction data and adjusting templates to generate target electronic invoices, the problems of high maintenance costs and insufficient flexibility caused by relying on third-party tools in the existing technology are solved, and efficient and accurate electronic invoice generation is achieved.
Patent Information
- Application Number
- CN202510182688.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-18
- Publication Date
- 2025-05-13
AI Technical Summary
The existing electronic invoice generation system relies on third-party tools, resulting in high maintenance costs, compatibility issues, insufficient flexibility, weak data processing capabilities, stability and security threats. User operations are cumbersome, and data errors or irregular formats are prone to occur.
By receiving transaction data, determining the target business scenario, filtering matching predefined templates from the preset template library, identifying transaction data, obtaining data characteristics, and adjusting the template based on the features to generate target electronic invoices.
It improves the efficiency and quality of electronic invoice generation, reduces the possibility of human error, improves the convenience of user experience and workflow, and ensures the accuracy and compliance of invoice information.
Smart Images

Figure CN119991234A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of electronic invoices, and in particular to a method and device for generating electronic invoices, an electronic device and a computer program product. Background Art
[0002] In the field of electronic invoice management, with the advancement of e-commerce and digital transformation, electronic invoices have become an important part of the daily operations of enterprises and institutions.
[0003] However, the current electronic invoice generation system has the following problems: (1) The current electronic invoice generation system relies on third-party tools (e.g., OFD (Open Fixed-layout (1) The current electronic invoice generation system generally uses fixed-format document (i.e., open fixed-format document) file editing tools, which usually require additional purchase and maintenance costs and may have inconsistent version updates, thereby increasing maintenance costs and compatibility issues; (2) The current electronic invoice generation system generally uses fixed-format templates, which are difficult to meet the special needs of different industries and business scenarios, resulting in insufficient flexibility and inability to adjust according to actual changes in the invoice content; (3) The current electronic invoice generation system lacks effective data processing capabilities, especially when processing large amounts of data or data in special formats, which is prone to errors or output formats that do not comply with the regulations; (4) Due to the use of third-party tools, the overall stability and security of the current electronic invoice generation system are threatened to a certain extent. Once a problem occurs with the third-party tool, it may affect the normal operation of the entire electronic invoice system; (5) Users need to manually adjust the template and input information during use, which is cumbersome and prone to data errors or irregular formats caused by misoperation; (6) Electronic invoices must comply with new standards and technical specifications, but the current electronic invoice generation system may not be able to keep up with these changes in a timely manner, resulting in the generated electronic invoices not meeting the latest requirements.
[0004] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention
[0005] The embodiments of the present invention provide a method and device for generating an electronic invoice, an electronic device and a computer program product, so as to at least solve the technical problem that the electronic invoice cannot be accurately generated in the related art.
[0006] According to one aspect of an embodiment of the present invention, there is provided a method for generating an electronic invoice, comprising: receiving transaction data, and determining a target business scenario involved in the transaction data; screening a target predefined template matching the target business scenario from a preset template library, the preset template library comprising: a plurality of predefined templates, each predefined template being associated with a business scenario; identifying the transaction data to obtain data features, and based on the data features, adjusting the target predefined template to obtain a target template; and generating a target electronic invoice based on the transaction data and the target template.
[0007] Furthermore, before receiving the transaction data, it also includes: defining a corresponding predefined template for each business scenario, the predefined template at least including: a business scenario name, a basic field set, and a remark box; and building a preset template library based on the predefined templates corresponding to all business scenarios.
[0008] Furthermore, the transaction data is key-value structured data, and the steps of identifying the transaction data and obtaining data features include: identifying the primary key and the key value corresponding to the primary key in the transaction data; determining the key value length and key value type of each key value; and determining the data features based on the key value length and key value type of all primary keys and the key values corresponding to the primary keys.
[0009] Furthermore, based on the data characteristics, the target predefined template is adjusted to obtain the target template, including: based on the primary key, adjusting the basic fields in the target predefined template, the primary key and the basic fields correspond one to one; based on the key value length and key value type of the key value corresponding to the primary key, determining the filling rule of the basic field corresponding to the primary key; based on all the basic fields and the filling rule of each basic field, obtaining the target template.
[0010] Furthermore, based on the transaction data and the target template, the step of generating a target electronic invoice includes: based on each basic field in the target template, determining from the transaction data the key value to be filled corresponding to each basic field; for each basic field, filling in the key value to be filled based on the filling rule of the basic field; determining the remark data from the transaction data, and adjusting the remark box on the target template based on the remark data to obtain the target remark box; filling the remark data into the target remark box to obtain the target electronic invoice.
[0011] Furthermore, based on the remark data, the remark box on the target template is adjusted to obtain the target remark box, including: determining the total number of characters based on the remark data; determining the printing area based on the remark box, and determining the expected number of characters in the remark box; determining the character density based on the printing area, the number of printed characters per unit area, and the expected number of characters; determining the number of remark box pages based on the total number of characters and the character density, and adjusting the remark box based on the number of remark box pages to obtain the target remark box.
[0012] Furthermore, after the target electronic invoice is generated based on the transaction data and the target template, it also includes: format verification and filling detection of the target electronic invoice; when the format verification and filling detection of the target electronic invoice are passed, the target electronic invoice is sent to the customer terminal.
[0013] According to another aspect of an embodiment of the present invention, there is also provided an electronic invoice generation device, comprising: a receiving unit, used to receive transaction data, and determine a target business scenario involved in the transaction data; a screening unit, used to screen a target predefined template matching the target business scenario from a preset template library, the preset template library comprising: a plurality of predefined templates, each predefined template being associated with a business scenario; an identification unit, used to identify the transaction data, obtain data features, and adjust the target predefined template based on the data features to obtain a target template; and a generation unit, used to generate a target electronic invoice based on the transaction data and the target template.
[0014] Furthermore, the generating device also includes: a first definition module, used to define a corresponding predefined template for each business scenario before receiving transaction data, the predefined template including at least: a business scenario name, a basic field set, and a remark box; a first construction module, used to construct a preset template library based on the predefined templates corresponding to all business scenarios.
[0015] Furthermore, the transaction data is key-value structured data, and the identification unit includes: a first identification module, used to identify primary keys and key values corresponding to the primary keys in the transaction data; a first determination module, used to determine the key value length and key value type of each key value; and a second determination module, used to determine data features based on the key value lengths and key value types of all primary keys and key values corresponding to the primary keys.
[0016] Furthermore, the identification unit also includes: a first adjustment module, used to adjust the basic fields in the target predefined template based on the primary key, and the primary key corresponds to the basic fields one by one; a third determination module, used to determine the filling rules of the basic fields corresponding to the primary key based on the key value length and key value type of the key value corresponding to the primary key; a first acquisition module, used to obtain the target template based on all basic fields and the filling rules of each basic field.
[0017] Furthermore, the generation unit includes: a fourth determination module, used to determine the key value to be filled corresponding to each basic field from the transaction data based on each basic field in the target template; a first filling module, used to fill the key value to be filled for each basic field based on the filling rule of the basic field; a second adjustment module, used to determine the remark data from the transaction data, and adjust the remark box on the target template based on the remark data to obtain the target remark box; a second filling module, used to fill the remark data into the target remark box to obtain the target electronic invoice.
[0018] Furthermore, the second adjustment module includes: a first determination submodule, used to determine the total number of characters based on the remark data; a second determination submodule, used to determine the printing area based on the remark box, and determine the expected number of characters in the remark box; a third determination submodule, used to determine the character density based on the printing area, the number of printed characters per unit area and the expected number of characters; a fourth determination submodule, used to determine the number of remark box pages based on the total number of characters and the character density, and adjust the remark box based on the number of remark box pages to obtain a target remark box.
[0019] Furthermore, the generating device also includes: a first verification module, which is used to perform format verification and filling detection on the target electronic invoice after generating the target electronic invoice based on the transaction data and the target template; a first sending module, which is used to send the target electronic invoice to the customer terminal if the format verification and filling detection of the target electronic invoice are passed.
[0020] According to another aspect of an embodiment of the present invention, a computer program product is also provided, including a non-volatile computer-readable storage medium, the non-volatile computer-readable storage medium storing a computer program, and when the computer program is executed by a processor, any one of the above-mentioned methods for generating an electronic invoice is implemented.
[0021] According to another aspect of an embodiment of the present invention, there is also provided an electronic device, comprising one or more processors and a memory, wherein the memory is used to store one or more programs, wherein when the one or more programs are executed by one or more processors, the one or more processors implement any one of the above-mentioned methods for generating electronic invoices.
[0022] In the present invention, transaction data is received, and the target business scenario involved in the transaction data is determined, a target predefined template matching the target business scenario is screened from a preset template library, the transaction data is identified, data features are obtained, and based on the data features, the target predefined template is adjusted to obtain a target template, and a target electronic invoice is generated based on the transaction data and the target template, thereby solving the technical problem in the related art that electronic invoices cannot be accurately generated.
[0023] In the present invention, by identifying the business scenario of transaction data, a matching target predefined template can be screened out from a preset template library, and then according to the data features of the identified transaction data, the target predefined template can be automatically adjusted to obtain the best target template, and then the transaction data is filled into the target template, so that the target electronic invoice can be efficiently and accurately generated. In this way, not only the efficiency of electronic invoice generation is improved, but also the accuracy and compliance of invoice information are ensured, thereby achieving the technical effect of efficiently and accurately generating electronic invoices. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0025] Figure 1 is a flow chart of an optional method for generating an electronic invoice according to an embodiment of the present invention;
[0026] Figure 2 is a schematic diagram of an optional OFD electronic invoice generation process according to an embodiment of the present invention;
[0027] Figure 3 is a schematic diagram of an optional electronic invoice generation device according to an embodiment of the present invention;
[0028] Figure 4 The present invention is a hardware structure block diagram of an electronic device (or mobile device) for a method for generating an electronic invoice according to an embodiment of the present invention. DETAILED DESCRIPTION
[0029] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0030] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0031] It should be noted that the relevant information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) collected and involved in the present invention are all information and data authorized by the user or fully authorized by all parties, and the collection, storage, use, processing, transmission, provision, disclosure and application of relevant data are in compliance with the relevant laws, regulations and standards of the relevant regions, necessary confidentiality measures are taken, and public order and good customs are not violated, and corresponding operation entrances are provided for users to choose to authorize or refuse. For example, an interface is set between the system and the relevant users or organizations. Before obtaining relevant information, it is necessary to send an acquisition request to the aforementioned user or organization through the interface, and obtain relevant information after receiving the consent information fed back by the aforementioned user or organization.
[0032] The present invention provides a dynamic adaptive OFD electronic invoice generation method, which can ensure efficient and standardized generation of standard OFD electronic invoices. The present invention can improve the efficiency and quality of electronic invoice generation and reduce the possibility of human error through the design of an adaptive template library, intelligent data analysis and template matching mechanism, and OFD generation technology. In addition, the automatic generation feature also improves the user experience and the convenience of the workflow.
[0033] The present invention is described in detail below in conjunction with various embodiments.
[0034] Embodiment 1
[0035] According to an embodiment of the present invention, an embodiment of a method for generating an electronic invoice is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0036] Figure 1 is a flow chart of an optional method for generating an electronic invoice according to an embodiment of the present invention, such as Figure 1 As shown, the method comprises the following steps:
[0037] Step S101, receiving transaction data, and determining the target business scenario involved in the transaction data.
[0038] In an embodiment of the present invention, an electronic invoice generation system is proposed, and the electronic invoice generation system can be used to execute the electronic invoice generation method.
[0039] In the embodiment of the present invention, the electronic invoice generation system can receive transaction data generated by the transaction system, which refers to the original data generated in the transaction activity and used to record the transaction facts, transaction amount, transaction time, commodity information, service content, etc. of the two parties to the transaction. In the electronic invoice generation system, the transaction data is the basis for generating electronic invoices.
[0040] Then, the electronic invoice generation system determines the specific business scenario for generating electronic invoices by receiving transaction data and analyzing the attributes of the data, thereby providing direction for subsequent template selection and data processing.
[0041] Here, business scenarios refer to the specific transaction business scenarios involved in transaction data. Different business scenarios may correspond to different invoice templates and data processing rules. For example, business scenarios such as retail business, catering services, and accommodation services each have specific invoice requirements and information fields.
[0042] For example, the electronic invoice generation system receives transaction data about accommodation services, and by analyzing the product description (such as "accommodation fee"), transaction amount, transaction time and other information in the data, it determines that this is transaction data for an accommodation business scenario, and then selects an appropriate accommodation service invoice template for the transaction.
[0043] Step S102: Filter a target predefined template that matches a target business scenario from a preset template library, wherein the preset template library includes: a plurality of predefined templates, each predefined template being associated with a business scenario.
[0044] In an embodiment of the present invention, an adaptive template library (i.e., a preset template library) is pre-established. The adaptive template library is a library containing a variety of predefined OFD electronic invoice format file templates (predefined templates), wherein each template is carefully designed for specific business scenarios and data features (i.e., each predefined template is associated with a business scenario). In this way, a variety of template choices are provided to meet the personalized needs of different users.
[0045] In an embodiment of the present invention, a matching target predefined template can be screened from a preset template library according to a target business scenario involved in the received transaction data, so as to ensure that the subsequently generated electronic invoice has a correct format and information structure.
[0046] For example, the electronic invoice generation system will select a predefined template related to accommodation services from a preset template library. The template may contain specific information fields such as hotel name, check-in and check-out time, room type, room charge details, etc.
[0047] Step S103, identifying the transaction data to obtain data features, and adjusting the target predefined template based on the data features to obtain a target template.
[0048] In an embodiment of the present invention, transaction data is a key-value structure data, and the transaction data can be identified to identify the data type, length and structure of each key value in the transaction data, thereby obtaining the data characteristics of the transaction data. For example, the data type of the key value of the primary key A in the transaction data is character type, the length is 10, and the structure is Chinese plus English. Then, according to the data characteristics of the transaction data, the layout, field size, font, filling rules, etc. of the predefined template are adjusted to meet the filling requirements of the data to obtain the target template. In this way, it is ensured that the transaction data can be accurately filled into the template while ensuring the visual presentation and readability of the invoice. By adjusting the template, the system can process data of different types and lengths, thereby generating a standard and beautiful electronic invoice.
[0049] For example, the electronic invoice generation system recognizes that the amount of the "accommodation fee" item in the transaction data is long and may contain multiple digits after the decimal point. Therefore, the width and font size of the "amount" field in the target predefined template are adjusted to ensure that even when the amount is long, it can be displayed correctly and does not overflow.
[0050] Step S104, generating a target electronic invoice based on the transaction data and the target template.
[0051] In an embodiment of the present invention, an electronic invoice file (ie, a target electronic invoice) conforming to a standard format is created based on transaction data and an adjusted target template, and the file can be recognized and processed by an electronic invoice management system.
[0052] For example, the system uses OFD file generation technology to fill transaction data (such as buyer and seller information and accommodation fee details) into the adjusted target template to generate an OFD format electronic invoice, which can be verified, stored and sent to the relevant parties by the system.
[0053] In this embodiment, the electronic invoice generation system can efficiently and accurately generate electronic invoices that are suitable for different business scenarios, reduce human intervention, improve the degree of automation, and at the same time ensure the standardization and aesthetics of the invoices.
[0054] In summary, by identifying the business scenarios of transaction data, we can filter out matching target predefined templates from the preset template library, and then automatically adjust the target predefined template according to the data features of the identified transaction data to obtain the best target template. After that, the transaction data is filled into the target template, and the target electronic invoice can be generated efficiently and accurately. In this way, not only the efficiency of electronic invoice generation is improved, but also the accuracy and compliance of invoice information are ensured, achieving the technical effect of efficiently and accurately generating electronic invoices, thereby solving the technical problem that electronic invoices cannot be accurately generated in related technologies.
[0055] In order to improve the accuracy of constructing a preset template library, in the method for generating an electronic invoice provided in Example 1 of the present application, before receiving transaction data, a corresponding predefined template is defined for each business scenario, and the predefined template includes at least: a business scenario name, a basic field set, and a remark box; based on the predefined templates corresponding to all business scenarios, a preset template library is constructed.
[0056] In an embodiment of the present invention, the business scenario name is an identifier of the template, which enables the system to quickly match the correct template according to the business information contained in the data when receiving the transaction data, thereby improving the processing speed and accuracy. Therefore, a clear name can be given to each business scenario, such as "catering services", "retail sales", "accommodation services", etc., to ensure that the business type can be quickly identified during the template management and selection process. The basic field set is the core part of the predefined template, which is used to ensure that the basic information of the invoice is comprehensive and standardized, so that the generated electronic invoice can meet the relevant standards. Therefore, a set of basic fields can be determined for each business scenario, including but not limited to the purchaser information, the seller information, the details of the goods or services, the amount, the tax rate, the issue date, etc. The remark box can improve the flexibility of the template and can carry more customized information, such as the special requirements of the buyer and seller, bank information, additional terms of the transaction, etc., so that the invoice can reflect more business details and meet the needs of complex transaction scenarios. Therefore, a variable remark box can be reserved in the predefined template to record special instructions or additional information that may exist in the transaction process.
[0057] In the embodiment of the present invention, a corresponding predefined template can be defined for each business scenario, and each predefined template at least includes: business scenario name, basic field set, remark box, etc., wherein the basic field set includes: multiple basic fields, such as invoice number, invoice date, purchaser information, seller information, project name, etc. Then, based on the predefined templates defined for all business scenarios, a comprehensive preset template library is constructed, which stores all predefined templates by category, so that the system can call them when generating electronic invoices.
[0058] For example, create a database or file system to store the predefined templates defined above. Each template will be assigned a unique ID (identifier) associated with the business scenario name. In this way, the construction of the preset template library provides a comprehensive template resource pool for the system, enabling the system to quickly filter out the most suitable template based on the received transaction data, thereby improving the efficiency and accuracy of invoice generation.
[0059] In this embodiment, by defining predefined templates in various business scenarios in detail and building a preset template library, not only the processing efficiency of the system is improved, but also the accuracy and comprehensiveness of electronic invoices are ensured, and finally the goal of quickly generating high-quality, standard-compliant OFD electronic invoices in different business scenarios is achieved. This not only solves the problem of fixed templates and poor adaptability in related technologies, but also provides users with a more personalized service experience and improves the level of electronic invoice management.
[0060] Optionally, the transaction data is key-value structured data. In order to improve the accuracy of determining data features, in the method for generating an electronic invoice provided in the first embodiment of the present application, the primary key and the key value corresponding to the primary key in the transaction data are identified; the key value length and key value type of each key value are determined; and the data features are determined based on the key value lengths and key value types of all primary keys and the key values corresponding to the primary keys.
[0061] In an embodiment of the present invention, transaction data is key-value structured data. After receiving the transaction data, the primary key in the data and its corresponding key value can be identified. The primary key is usually used to uniquely identify each entity or record in the data, and the key value is the detailed information or attribute value corresponding to the primary key. For example, using a data parsing algorithm, according to predefined key-value pair rules, the transaction data is read one by one, the primary key is identified, and their corresponding key values are extracted. In this way, by identifying the primary key and the key value, the various fields in the transaction data can be organized and accessed more systematically, providing a clear data structure for subsequent data feature analysis and template adjustment.
[0062] Each key value identified is then further analyzed to determine its key value length (i.e., the number of characters in the data) and key value type (e.g., string, numeric, date, etc.). For example, "invoiceCode" may be a string of 20 characters, while "amount" may be a numeric type with a variable length and two decimal places. In this way, by analyzing the length and type of the key value, the nature of the data can be better understood, which will directly affect the layout and formatting of the fields in the template, ensuring that there will be no overflow or format errors when filling in the data.
[0063] In an embodiment of the present invention, after completing the analysis of all key values, the key value lengths and key value types of all primary keys and their key values can be combined to determine the data characteristics of the entire transaction data. Data characteristics may include the overall complexity of the data, the distribution of data fields, the length and type of key data, etc. For example, if "buyerName" and "sellerName" both exceed the conventional length, the system will adjust the name box size in the template to accommodate the needs of long names. In this way, the determination of data characteristics is the key basis for the system to intelligently adjust the template, which can help the system identify special needs in transaction data, thereby making reasonable layout and formatting decisions to ensure that the generated electronic invoice is not only accurate in information, but also has a reasonable format and is easy to read.
[0064] In this embodiment, through sophisticated data structure analysis and layout adjustment, an effective solution is provided for processing complex key-value structure data in the process of electronic invoice generation, which not only improves the accuracy of data processing and the aesthetics of the layout, but also further enhances the automation and intelligence of the system, which is of great significance to improving the efficiency of electronic invoice management and user experience.
[0065] In order to accurately obtain the target template, in the method for generating an electronic invoice provided in Example 1 of the present application, based on the primary key, the basic fields in the target predefined template are adjusted, and the primary key corresponds to the basic fields one by one; based on the key value length and key value type of the key value corresponding to the primary key, the filling rules of the basic fields corresponding to the primary key are determined; based on all the basic fields and the filling rules of each basic field, the target template is obtained.
[0066] In an embodiment of the present invention, after identifying and parsing the primary key in the transaction data, the basic fields in the target predefined template can be adjusted to ensure that they can accurately carry the transaction information. The system matches the primary key with the basic fields at the corresponding position in the predefined template, for example, the primary key "invoiceCode" corresponds to the "invoice code" field in the template, and the primary key "buyerName" corresponds to the "buyer name" field. In this way, it can be ensured that each basic field in the template can correspond to the primary key in the transaction data, so that it can be accurately located when filling in the data to avoid wrong filling or missing filling. Then, the key value corresponding to the primary key can be further analyzed, including the length and type of the key value, to determine the filling rules for each basic field. For example, if the key value "invoiceCode" is a string of fixed length, then the filling rules of the "invoice code" field may include a fixed width text box; if the key value "amount" is a value that may have decimals, then the filling rules of the "amount" field need to consider the formatting of the value and the alignment of the decimal point. In this embodiment, the determination of the filling rule can ensure that the display of data in the template is both compliant with the specification and easy to read, while also being able to handle various data types and lengths to avoid format errors or layout confusion.
[0067] In the embodiment of the present invention, the target predefined template is adjusted based on all basic fields and their filling rules, thereby obtaining an adjusted target template. The adjustment includes but is not limited to: adjusting the size, position, font of the field, and adding necessary line break and paging rules. In this way, through this series of adjustments, the target template can better adapt to the characteristics of transaction data, ensuring that after filling in the data, the electronic invoice is not only complete and accurate in content, but also has a reasonable and beautiful layout.
[0068] In this embodiment, by adjusting the template and determining the filling rules based on the primary key and its key-value characteristics, personalized and refined control of electronic invoice generation is achieved, which not only improves the system's ability to process complex transaction data, but also improves the efficiency and quality of generating electronic invoices.
[0069] In order to improve the accuracy of generating a target electronic invoice, in the method for generating an electronic invoice provided in Example 1 of the present application, based on each basic field in the target template, the key value to be filled in corresponding to each basic field is determined from the transaction data; for each basic field, the key value to be filled in is filled in based on the filling rule of the basic field; the remark data is determined from the transaction data, and based on the remark data, the remark box on the target template is adjusted to obtain the target remark box; the remark data is filled into the target remark box to obtain the target electronic invoice.
[0070] In an embodiment of the present invention, the basic fields in the target template, such as "invoiceCode", "buyerName", "sell lerName", etc., can be compared one by one to find the key values corresponding to these basic fields from the transaction data. For example, through data matching and mapping, the template fields are compared with the fields in the transaction data to find matches. In this way, it can be ensured that each basic field in the template can obtain the corresponding key value in the transaction data, thereby ensuring the integrity and accuracy of the electronic invoice. Then, according to the previously determined basic field filling rules, the key values to be filled in the transaction data are accurately filled into the corresponding positions in the template. For example, the filling rules for the "amount" field may include ensuring that the numerical format is correct, retaining two decimal places, etc. In this way, by following the filling rules to fill in the data, an electronic invoice with standardized format and accurate information can be generated, avoiding the problem of invoice non-compliance caused by incorrect data format.
[0071] In an embodiment of the present invention, remark data, such as special requirements of the buyer and seller, additional terms, etc., can be extracted from the transaction data. These remark data may be contained in specific fields in the key-value structure data. If the remark data is determined, the remark box on the target template can be adjusted according to the length and content of the remark data to ensure that its size and position can accommodate and clearly display all the remark information. In this way, it is ensured that the electronic invoice can fully reflect the transaction details, especially those special circumstances that require additional explanations, thereby improving the practical value of the invoice and the integrity of information transmission. Afterwards, the remark data is filled into the adjusted target remark box to complete the generation of the electronic invoice. In this way, by correctly filling the remark data into the remark box, the electronic invoice can fully and accurately reflect all important information of the transaction, including special terms or requirements, and meet the comprehensive requirements of the transaction parties for the content of the invoice.
[0072] In order to accurately obtain the target remark box, in the method for generating an electronic invoice provided in Example 1 of the present application, the total number of characters is determined based on the remark data; the printing area is determined based on the remark box, and the expected number of characters in the remark box is determined; the character density is determined based on the printing area, the number of printed characters per unit area, and the expected number of characters; the number of remark box pages is determined based on the total number of characters and the character density, and the remark box is adjusted based on the number of remark box pages to obtain the target remark box.
[0073] In an embodiment of the present invention, the remark data in the transaction data can be completely collected, including all texts that need to be displayed in the invoice remark column. Then, the total number of characters of these remark data is counted. For example, if the remark contains detailed requirements of the buyer and seller, additional terms, etc., the number of characters of all these information can be summed up. In this embodiment, determining the total number of characters of the remark data helps to plan the size of the remark box and the number of pages in the subsequent process, ensuring that the remark data can be fully displayed on the electronic invoice.
[0074] In the embodiment of the present invention, the actual printing area of the remark box is calculated according to the position and size (width, height) of the remark box on the target template. At the same time, based on the size and format of the remark box, the number of characters that the remark box can accommodate (i.e., the expected number of characters) can be estimated.
[0075] In this embodiment, the calculation of the print area usually needs to take into account factors such as the width (W) and height (H) of the note box in the template design, the horizontal margin (M_w) and the vertical margin (M_h) of the note box, so as to ensure the accuracy of the calculation result. The determination of the expected number of characters helps to evaluate whether the filling space of the note information is sufficient. In this way, by calculating the print area and the expected number of characters of the note box, the display requirements of the note data can be evaluated, providing a basis for subsequent adjustments.
[0076] In an embodiment of the present invention, the character density D of the remark box can be calculated based on the actual printing area of the remark box ((W-2M_w)\t imes(H-2M_h)), that is, the value of the width minus the horizontal margins on the left and right sides multiplied by the value of the height minus the vertical margins on the top and bottom sides), the number of printed characters A per unit area set by the template (which is a fixed value that depends on the font size and style), and the expected number of characters N. The character density calculation formula is as follows: D = \frac{N}{(W-2M_w)\t imes(H-2M_h)}\div A, where D is the character density, N is the expected number of characters, W and H are the width and height of the remark box, respectively, M_w and M_h are the horizontal and vertical margins of the remark box, and A is the number of printed characters per unit area. The calculation of character density helps the system understand the display efficiency of the remark information in a limited space and provides key data for determining the number of pages in the remark box.
[0077] In the embodiment of the present invention, the total number of pages that the remark data needs to occupy in the remark box (i.e., the number of remark box pages P) can be determined by using the determined total number of characters and character density. The calculation formula for the number of remark box pages is as follows: P = \lcei l\frac{C_{total}}{D}\rcei l, where P represents the number of remark box pages, C_{total} represents the total number of characters, D represents the character density, and \lcei l\rcei l represents the rounding up function.
[0078] In this embodiment, if the total number of characters in the remark data exceeds the expected number of characters in a single remark box, the required number of pages can be automatically calculated and the layout of the remark box can be adjusted accordingly to meet the needs of multi-page display. For example, add automatic page break logic to the remark box and adjust the page margins to ensure that the remark information on each page is clearly displayed and the layout is beautiful. In this way, the determination of the number of pages in the remark box and the adjustment of the layout ensure that even if the amount of remark information is large, it can be reasonably distributed on the electronic invoice, avoiding information overflow or layout confusion, and maintaining the professionalism and readability of the invoice.
[0079] In this embodiment, it can ensure that the remark information can not only be displayed completely and in a standardized manner, but also the format can be automatically adjusted according to the amount of information, thereby avoiding processing problems caused by the remark information being too long or the format not matching.
[0080] In order to ensure the integrity, correctness and security of the target electronic invoice sent, in the electronic invoice generation method provided in Example 1 of the present application, after the target electronic invoice is generated based on the transaction data and the target template, the target electronic invoice is subjected to format verification and filling detection; if the format verification and filling detection of the target electronic invoice are passed, the target electronic invoice is sent to the customer terminal.
[0081] In an embodiment of the present invention, after the electronic invoice is generated, the format of the electronic invoice can be verified to check whether the invoice complies with the prescribed OFD file standard format, including whether the invoice code, invoice number, buyer and seller information, commodity or service description, amount, tax rate, tax amount, price and tax total, and remarks and other information are correctly presented in the prescribed format and position. Format verification involves checking the structure, font, line spacing, margins, page layout and other aspects of the invoice. In this way, it can be ensured that the format of the electronic invoice fully complies with the standard, avoiding invalidation or rejection of the invoice due to format problems.
[0082] In the embodiment of the present invention, it is also necessary to perform filling detection on the electronic invoice to ensure that all key information in the transaction data has been correctly and completely filled into the target electronic invoice. The filling detection includes checking whether key fields such as invoice code, invoice number, amount, tax rate, etc. have been filled, and whether the filled information is consistent with the transaction data without omissions or errors. In this way, the accuracy of the information in the electronic invoice is ensured, and inaccurate or unusable invoices caused by missing or incorrect data are prevented.
[0083] In the embodiment of the present invention, if the target electronic invoice passes the format verification and filling detection, the invoice can be sent to the designated client terminal in a secure manner. For example, it can be transmitted through multiple channels such as email, mobile application or internal enterprise system, while ensuring the data security during the transmission process, such as using encryption technology to prevent information leakage. In this way, it can ensure that the electronic invoice is securely sent to the client terminal, ensuring that the client can receive the invoice in a timely and accurate manner, while also protecting the privacy and security of the invoice information.
[0084] In this embodiment, the standardization and security of electronic invoice generation and delivery can be improved through strict format verification, filling detection and secure sending processes.
[0085] Another optional specific implementation is described in detail below.
[0086] In an embodiment of the present invention, an electronic invoice generation system is proposed, including: a data input module, a preprocessing module, a data analysis module, a template library management module, an adaptive adjustment module, a data filling module, a formatting and page break processing module, an OFD generation module, a verification module, and an output module.
[0087] The data input module is used to receive electronic bill data (ie, transaction data) from an external system (ie, a transaction system).
[0088] The preprocessing module is used to clean the received data, remove invalid information and ensure data quality.
[0089] The data analysis module is used to analyze the type, length and structure of the data, providing a basis for subsequent template selection.
[0090] The template library management module is used to store and manage various predefined OFD electronic invoice templates.
[0091] The adaptive adjustment module is used to dynamically adjust templates and application rules according to the data analysis results of the data analysis module.
[0092] The data filling module is used to accurately fill the analyzed data according to the selected template.
[0093] The formatting and page break processing module is used to handle long text and paging issues to ensure the correct document format.
[0094] The OFD generation module is used to convert the filled data into an OFD file that complies with the standard.
[0095] The verification module is used to verify the integrity, correctness and security of the generated OFD file.
[0096] The output module is used to output the verified OFD file to the target location or send it to the user.
[0097] Figure 2 is a schematic diagram of an optional OFD electronic invoice generation process according to an embodiment of the present invention, such as Figure 2 As shown, the following process is included:
[0098] (1) Collect transaction data;
[0099] (2) Clean the received data, remove invalid information, and ensure data quality;
[0100] (3) Analyze the type, length and structure of the preprocessed data to obtain analysis results;
[0101] (4) Select a suitable OFD template;
[0102] (5) Dynamically adjust templates and application rules based on analysis results;
[0103] (6) Accurately fill in the data according to the adjusted template;
[0104] (7) Dealing with long text and paging issues;
[0105] (8) Convert the filled data into an OFD file that complies with the standard;
[0106] (9) Verify the integrity, correctness and security of the generated OFD file;
[0107] (10) Send the verified OFD file to the user.
[0108] In the embodiment of the present invention, by adopting the unified OFD electronic invoice standard, it is helpful to promote the standardized development of the entire industry and reduce disputes and regulatory difficulties caused by non-standard electronic invoices. In addition, by quickly generating and distributing electronic invoices, it promotes the instant transmission of business information and the efficient use of resources. In addition, since the dependence on external software is reduced, the cost of purchasing and using third-party invoice generation tools can be saved, and the automated data processing and template matching process shortens the invoice production time and improves work efficiency.
[0109] In the embodiment of the present invention, through the adaptive mechanism, the template and application rules can be flexibly adjusted according to the real-time data volume and content characteristics, effectively avoiding the fixed parameter restrictions, making the system more flexible and efficient. In addition, through the pre-set template library and analysis algorithm, the complex decision-making process can be completed in a very short time, which not only speeds up the processing speed of invoices, but also ensures the standardization of the output. In addition, the integration of functions such as automatic page breaking and processing of long texts solves difficult-to-handle edge cases (i.e., electronic invoices may contain very long text or information that needs to be displayed across multiple pages), thereby improving overall reliability and practicality.
[0110] The following is a detailed description in conjunction with another embodiment.
[0111] Embodiment 2
[0112] The electronic invoice generation device provided in this embodiment includes multiple implementation units, each of which corresponds to each implementation step in the above-mentioned embodiment 1.
[0113] Figure 3 is a schematic diagram of an optional electronic invoice generation device according to an embodiment of the present invention, such as Figure 3 As shown, the generating device may include: a receiving unit 30 , a screening unit 31 , an identifying unit 32 , and a generating unit 33 .
[0114] The receiving unit 30 is used to receive transaction data and determine the target business scenario involved in the transaction data;
[0115] A screening unit 31 is used to screen a target predefined template matching a target business scenario from a preset template library, wherein the preset template library includes: a plurality of predefined templates, each predefined template is associated with a business scenario;
[0116] The identification unit 32 is used to identify the transaction data, obtain data features, and adjust the target predefined template based on the data features to obtain a target template;
[0117] The generating unit 33 is used to generate a target electronic invoice based on the transaction data and the target template.
[0118] The above-mentioned generation device can identify the business scenarios of transaction data, filter out matching target predefined templates from a preset template library, and then automatically adjust the target predefined template according to the data features of the identified transaction data to obtain the best target template. Thereafter, the transaction data is filled into the target template, and the target electronic invoice can be generated efficiently and accurately. In this way, not only the efficiency of electronic invoice generation is improved, but also the accuracy and compliance of invoice information are ensured, achieving the technical effect of efficiently and accurately generating electronic invoices, thereby solving the technical problem that electronic invoices cannot be accurately generated in related technologies.
[0119] Optionally, the generating device also includes: a first definition module, used to define a corresponding predefined template for each business scenario before receiving transaction data, the predefined template including at least: a business scenario name, a basic field set, and a remark box; a first construction module, used to construct a preset template library based on the predefined templates corresponding to all business scenarios.
[0120] Optionally, the transaction data is key-value structured data, and the identification unit includes: a first identification module, used to identify primary keys and key values corresponding to the primary keys in the transaction data; a first determination module, used to determine the key value length and key value type of each key value; and a second determination module, used to determine data features based on the key value lengths and key value types of all primary keys and key values corresponding to the primary keys.
[0121] Optionally, the identification unit also includes: a first adjustment module, used to adjust the basic fields in the target predefined template based on the primary key, and the primary key corresponds to the basic fields one by one; a third determination module, used to determine the filling rules of the basic fields corresponding to the primary key based on the key value length and key value type of the key value corresponding to the primary key; a first acquisition module, used to obtain the target template based on all basic fields and the filling rules of each basic field.
[0122] Optionally, the generation unit includes: a fourth determination module, used to determine the key value to be filled in corresponding to each basic field in the target template from the transaction data based on each basic field in the target template; a first filling module, used to fill the key value to be filled in for each basic field based on the filling rule of the basic field; a second adjustment module, used to determine the remark data from the transaction data, and adjust the remark box on the target template based on the remark data to obtain the target remark box; a second filling module, used to fill the remark data into the target remark box to obtain the target electronic invoice.
[0123] Optionally, the second adjustment module includes: a first determination submodule, used to determine the total number of characters based on the remark data; a second determination submodule, used to determine the printing area based on the remark box, and determine the expected number of characters in the remark box; a third determination submodule, used to determine the character density based on the printing area, the number of printed characters per unit area and the expected number of characters; a fourth determination submodule, used to determine the number of remark box pages based on the total number of characters and the character density, and adjust the remark box based on the number of remark box pages to obtain a target remark box.
[0124] Optionally, the generating device also includes: a first verification module, used to perform format verification and filling detection on the target electronic invoice after generating the target electronic invoice based on the transaction data and the target template; a first sending module, used to send the target electronic invoice to the customer terminal if the format verification and filling detection of the target electronic invoice are passed.
[0125] The above-mentioned generating device may also include a processor and a memory. The above-mentioned receiving unit 30, screening unit 31, identification unit 32, generating unit 33, etc. are all stored in the memory as program units, and the processor executes the above-mentioned program units stored in the memory to realize corresponding functions.
[0126] The processor includes a kernel, which retrieves the corresponding program unit from the memory. One or more kernels can be set, and the target electronic invoice is generated based on the transaction data and the target template by adjusting the kernel parameters.
[0127] The above-mentioned memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one storage chip.
[0128] The present invention also provides a computer program product, which, when executed on a data processing device, is suitable for executing a program that initializes the following method steps: receiving transaction data, and determining a target business scenario involved in the transaction data, screening a target predefined template that matches the target business scenario from a preset template library, identifying the transaction data, obtaining data features, and adjusting the target predefined template based on the data features to obtain a target template, and generating a target electronic invoice based on the transaction data and the target template.
[0129] According to another aspect of an embodiment of the present invention, a computer program product is also provided, including a non-volatile computer-readable storage medium, the non-volatile computer-readable storage medium storing a computer program, and when the computer program is executed by a processor, any one of the above-mentioned methods for generating an electronic invoice is implemented.
[0130] According to another aspect of an embodiment of the present invention, there is also provided an electronic device, comprising one or more processors and a memory, wherein the memory is used to store one or more programs, wherein when the one or more programs are executed by one or more processors, the one or more processors implement the above-mentioned method for generating electronic invoices.
[0131] Figure 4 FIG. 1 is a hardware structure block diagram of an electronic device (or mobile device) for generating an electronic invoice according to an embodiment of the present invention. Figure 4 As shown, the electronic device may include one or more processors (e.g., Figure 4 The processor 402a, processor 402b, ..., processor 402n, etc., which may include but are not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA, etc.), a memory 404 for storing data. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the I / O interface), a network interface, a keyboard, a power supply and / or a camera. It can be understood by those skilled in the art that Figure 4 The structure shown is only for illustration and does not limit the structure of the above electronic device. Figure 4 More or fewer components as shown, or with Figure 4 Different configurations are shown.
[0132] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0133] The embodiments or examples of the present disclosure are not exhaustive, but are only illustrative of some embodiments or examples, and are not intended to be specific limitations on the scope of protection of the present disclosure. In the absence of contradiction, each step in a certain embodiment or example can be implemented as an independent example, and the steps can be combined arbitrarily. For example, the scheme after removing some steps in a certain embodiment or example can also be implemented as an independent example, and the order of the steps in a certain embodiment or example can be arbitrarily exchanged. In addition, the optional methods or optional examples in a certain embodiment or example can be combined arbitrarily; in addition, the various embodiments or examples can be combined arbitrarily, for example, some or all steps of different embodiments or examples can be combined arbitrarily, and a certain embodiment or example can be combined arbitrarily with the optional methods or optional examples of other embodiments or examples.
[0134] In the above embodiments of the present invention, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0135] In the several embodiments provided by the present invention, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units can be a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0136] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0137] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0138] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk and other media that can store program codes.
[0139] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A method for generating an electronic invoice, characterized in that: include: Receiving transaction data and determining a target business scenario involved in the transaction data; Filtering a target predefined template matching the target business scenario from a preset template library, wherein the preset template library includes: a plurality of predefined templates, each of which is associated with a business scenario; Identifying the transaction data to obtain data features, and adjusting the target predefined template based on the data features to obtain a target template; A target electronic invoice is generated based on the transaction data and the target template.
2. The generation method according to claim 1, characterized in that: Before receiving transaction data, it also includes: Defining a corresponding predefined template for each business scenario, wherein the predefined template at least includes: a business scenario name, a basic field set, and a remark box; The preset template library is constructed based on the predefined templates corresponding to all the business scenarios.
3. The generation method according to claim 1, characterized in that: The transaction data is key-value structure data, and the step of identifying the transaction data and obtaining data features includes: Identify a primary key in the transaction data and a key value corresponding to the primary key; Determine the key length and key type of each key value; The data feature is determined based on the key value lengths and the key value types of all the primary keys and the key values corresponding to the primary keys.
4. The generation method according to claim 3, characterized in that: The step of adjusting the target predefined template based on the data feature to obtain the target template includes: Based on the primary key, adjusting the basic fields in the target predefined template, wherein the primary key corresponds to the basic fields one by one; Determine a filling rule for the basic field corresponding to the primary key based on the key value length and the key value type of the key value corresponding to the primary key; The target template is obtained based on all the basic fields and the filling rule of each of the basic fields.
5. The generation method according to claim 1, characterized in that: The step of generating a target electronic invoice based on the transaction data and the target template includes: Based on each basic field in the target template, determining a key value to be filled corresponding to each basic field from the transaction data; For each of the basic fields, filling the key value to be filled based on the filling rule of the basic field; Determining remark data from the transaction data, and adjusting a remark box on the target template based on the remark data to obtain a target remark box; Fill the remark data into the target remark box to obtain the target electronic invoice.
6. The generation method according to claim 5, characterized in that: The step of adjusting the remark box on the target template based on the remark data to obtain the target remark box includes: Based on the remark data, determining the total number of characters; Based on the remark box, determining a printing area, and determining an expected number of characters of the remark box; Determining character density based on the printing area, the number of printed characters per unit area, and the expected number of characters; The number of remark box pages is determined based on the total number of characters and the character density, and the remark box is adjusted based on the number of remark box pages to obtain the target remark box.
7. The generation method according to claim 1, characterized in that: After generating a target electronic invoice based on the transaction data and the target template, the method further includes: Performing format verification and filling detection on the target electronic invoice; When the format verification and the padding detection of the target electronic invoice are both passed, the target electronic invoice is sent to the customer terminal.
8. An electronic invoice generation device, characterized in that: include: A receiving unit, configured to receive transaction data and determine a target business scenario involved in the transaction data; A screening unit, configured to screen a target predefined template matching the target business scenario from a preset template library, wherein the preset template library comprises: a plurality of predefined templates, each of which is associated with a business scenario; an identification unit, configured to identify the transaction data, obtain data features, and adjust the target predefined template based on the data features to obtain a target template; A generating unit is used to generate a target electronic invoice based on the transaction data and the target template.
9. A computer program product, characterized in that The invention comprises a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method for generating an electronic invoice according to any one of claims 1 to 7 is implemented.
10. An electronic device, characterized in that: The invention comprises one or more processors and a memory, wherein the memory is used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the method for generating an electronic invoice as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Structured document information labeling method and device and electronic equipment
CN111695518A
Bill identification method and device, computer equipment and storage medium
CN117558020A
Electronic certificate data processing method and device, computer equipment and storage medium
CN118052218A
Invoicing method and system of multi-invoice-type invoices, electronic equipment and medium
CN119130573A
Automatic processing method and device and electronic equipment
CN119296126A