Create custom invoice number

0
Hi, I'm quite new to Mendix and recently completed the introduction course. For learning purposes I want to create a tiny app for invoicing. I was wondering how to create a custom invoice number where the user can configure which invoice number to start from for instance 2018-12345. Thank you in advance.
asked
1 answers
1

Hi Roger,

You can do this using a Before Commit event and an autonumber attribute.

 

if you start with a domain model along the lines of this. Where the number attribute will hold the invoice number and an attribute of type autonumber (will be the second number in the invoice number).

 

For the autonumber attribute you can define which number you want to start from.

 

Then you can add a Before Commit event handler and build a microflow similar to this.

 

The exclusive split uses the "isNew" function but you can also just check for empty on the invoice number attribute. The change object would build the string for your invoice number. You could use something along the lines of this.

formatDateTime([%CurrentDateTime%],'yyyy') + '-' + $Invoice/AutoNumber

 

 

Here is some documentation on event handlers and autonumbers

https://docs.mendix.com/refguide/event-handlers

https://docs.mendix.com/refguide/attributes

 

 

Edit:

for the exclusive split, just add the code that i put in the annotation. isNew will return a boolean and you can set the true/false paths. 

 

For your second question, since the number has to restart each year, then you wouldnt be able to use an autonumber to generate the number. You would have to build a table that would hold some kind of configuration for this.

If its just incremental and the number starts over from 1 (or some othere number) after the new year, then you can handle that logic in the before commit (or use an after commit event). If you change the autonumber attribute to an integer, you can retrieve the highest number from the database.

You would  have to retrieve from database the first object where

year = the invoice year

use a sort on the integer attribute descending. 

This will retrieve the last invoice number that was created, and then you can just add 1 to increment it.

 

If its more complicated then that, then you would have to create a configuration table, retrieve the configuration, and then do whatever logic necessary to set the invoice number. 

 

 

answered