Create unique value on a condition
I made a database for my invoices. At the moment I'm adding an option to create a credit note. I have a field where I can select 'paid', 'not paid' or 'credit note'. If the last one is selected, I should create a unique value in a field called 'credit note number' (first time I do this, it should be 13001, 13002 for the next time, ... - every year I start again, so next year it should be 14001, ...). No number needs to be created if I don't select 'credit note'.