Introduction to Dynamic Invoice Numbering in WinDev
Proper and dynamic invoice numbering is crucial for any invoicing management system. Consistent numbering ensures proper tracking, legal compliance, and helps maintain organized financial records. In this sixth part of the Easy_Fact series, we will delve into how to implement a flexible and customizable invoice numbering system in WinDev, which meets various requirements such as specific prefixes, sequential numbers, and year integration.
We’ve received numerous inquiries from our community about this issue, especially concerning how to generate invoice numbers that include specific digits and letters, and multiple prefixes. This guide aims to simplify this process and provide a practical, effective solution.
What you will learn in this tutorial:
- Understand the importance of correct invoice numbering.
- Create HFSQL queries to retrieve the highest existing invoice number.
- Automatically generate sequential invoice numbers.
- Integrate custom prefixes (such as FACT, PROFORMA, DEVIS) and the current year into the invoice number.
- Apply this logic within a WinDev invoice window.
These steps are an essential part of our tutorial series on building a complete invoicing management application using WinDev. To ensure a comprehensive understanding of all concepts, we strongly recommend following the previous parts of the series.
Watch the full tutorial in the video below:
Proposed Invoice Number Structure
Our numbering system aims to generate invoice numbers in a format like: FACT/003/2023 or PROFORMA/015/2023. To achieve this, two main steps are required:
- Retrieve the highest invoice number: We need to query the database to identify the largest sequential number currently in use for a given invoice type.
- Assemble the new number: Construct the new number by incrementing the retrieved number, adding a specific prefix (such as
FACT,PROFORMA,DEVIS,BON DE LIVRAISON,BON DE RÉCEPTION,BON DE COMMANDE), and integrating the current year.
Code for Invoice Number Generation
1. HFSQL Query to Retrieve the Highest Invoice Number
This query retrieves the highest invoice number from the Facture table. It can be adapted to retrieve numbers for specific invoice types if you have a TypeFacture field.
SELECT
MAX(Facture.Num_fact) AS le_maximum_Num_fact
FROM
Facture2. WinDev Logic for Invoice Numbering
This code is implemented in your invoice window, typically during window initialization or when creating a new invoice.
// Execute the query to retrieve the highest invoice number
HExécuteRequête(REQ_max_n_facture, hRequêteDéfaut)
// Determine the new sequential number
IF REQ_max_n_facture.le_maximum_Num_fact = 0 THEN
// If no previous invoices, start from 1
Facture.Num_fact = 1
ELSE
// Increment the existing highest number
Facture.Num_fact = REQ_max_n_facture.le_maximum_Num_fact + 1
END
// Construct the final invoice reference (e.g., FACT/001/2023)
// The prefix (e.g., "FACT/") is determined based on the current document type
// Complète(ChaîneInverse(Facture.Num_fact), 3, 0) ensures the number is formatted with three leading zeros (e.g., 001, 002)
Facture.Référence = "FACT/" + ChaîneInverse(Complète(ChaîneInverse(Facture.Num_fact), 3, 0)) + "/" + AnnéeEnCours()
// Update UI elements with the new data
FichierVersEcran()
// Set the window return value (as needed for your application)
MaFenêtre..ValeurRenvoyée = FauxCustomizing Prefixes
To generate different types of documents (invoices, proforma invoices, quotes, etc.), you will need to dynamically modify the "FACT/" part of the code above based on the type of document you are creating. You can use a variable, a selection field, or a parameter to pass the appropriate prefix.
- Invoice:
"FACT/" - Proforma Invoice:
"PROFORMA/" - Quote:
"DEVIS/" - Delivery Note:
"BL/" - Receipt Note:
"BR/" - Purchase Order:
"BC/"
Conclusion
By implementing this logic, you can create a robust and flexible invoice numbering system within your WinDev application. This not only ensures the uniqueness of each document but also enhances professionalism and aids in efficient financial record management. Feel free to adapt these solutions to meet the specific requirements of your project.