How to auto generate `Ref number` on Invoice Form


#1

I have Invoice Form in my POS System.
And I would like to auto generate Ref number + 1 base on the latest one.
Ex:
1- Latest: INV001, -> INV002
2- Latest: IVN001-BB005, -> IVN001-BB006
3- Latest: BB005CC002DD -> BB005CC003DD


#2

Easiest way is to just set it on the document before you insert


#3

could example?
(how to replace last of string)


#4

Now work fine with

String.prototype.replaceLast = function(what, replacement) {
    var pcs = this.split(what);
    var lastPc = pcs.pop();
    return pcs.join(what) + replacement + lastPc;
};
----
str.replaceLast(what, replacement)

#5

If the number to change will be in a consistent/know/given location you could do :

someIdString[locationtoreplace] = parseInt(someIdString[locationtoreplace])++;