I have extended the current auto-number generation with some additional element like adding company name or static prefix etc. which is working perfectly.
Now I want to reset the auto-number to specific number that we want to for which gave done the as follows:
My number generation program in a service is as follows:
public long getNextDocNumberWithPrefix(String docName, String companyCode, String plantCode, @Nullable FinancialYear financialYear) {
SEQ_PREFIX = "";
SEQ_PREFIX2 = "";
SEQ_MID = "";
TOTAL_DIGIT = 0;
EXCLUDE_PREFIX = false;
String year="";
if(financialYear ==null){
long coCo = Long.valueOf(companyCode);
financialYear = inteaccUtilService.getFinancialYearCurrent(inteaccUtilService.getCompanyFinancialYearCurrent(coCo));
}else {
financialYear = inteaccEntityDataService.getEntityById(FinancialYear.class, financialYear.getUuid(), "financialYearFrom-view");
}
year = financialYear.getYearFrom().toString();
UniqueNumbersAPI numbersBean = AppBeans.get(UniqueNumbersAPI.NAME);
SEQ_PREFIX = getPrefix(docName, companyCode, plantCode, year);
SEQ_PREFIX2 = SEQ_PREFIX;
if(SEQ_PREFIX.equalsIgnoreCase("")){
SEQ_PREFIX = docName;
}
Long number = numbersBean.getNextNumber(SEQ_PREFIX);
if(SEQ_PREFIX2.equalsIgnoreCase(""))
SEQ_PREFIX="";
//generate number with fixed digits
int n1 = SEQ_PREFIX.length();
int n3 = number.toString().length();
int n2 = TOTAL_DIGIT-n1-n3;
for(int i=0; i<n2;i++){
SEQ_MID = SEQ_MID+"0";
}
long seqNumber = new Long(0);
if(EXCLUDE_PREFIX==true){
seqNumber = number;
}else {
seqNumber = Long.valueOf(SEQ_PREFIX.concat(SEQ_MID).concat(number.toString()));
}
return seqNumber;
}
The structure of Entity “NumberGenerationRule” that is used to maintain different unique number generation:
create table ERP_NUMBER_GENERATION_RULE (
ID uuid,
VERSION integer not null,
CREATE_TS timestamp,
CREATED_BY varchar(50),
UPDATE_TS timestamp,
UPDATED_BY varchar(50),
DELETE_TS timestamp,
DELETED_BY varchar(50),
--
NAME varchar(255),
DOC_NUMBER_IDENTIFIER bigint,
NUMBER_PREFIX1 varchar(50),
NUMBER_PREFIX2 varchar(50),
NUMBER_PREFIX3 varchar(50),
TOTAL_NUMBER_OF_DIGIT integer,
EXCLUDE_PREFIX_KEEP_UNIQUENESS boolean,
MANUAL_NUMBER_GENERATION boolean,
COMPANY_GROUP_ID uuid,
RESET_AUTO_NUMBER boolean,
AUTO_NUMBER_NEXT_NEW bigint,
--
primary key (ID)
)
NumberGenerationEntityListener
void updateAutoNumber(NumberGenerationRule entity){
if(entity.getResetAutoNumber()==true){
uniqueNumbersAPI.setCurrentNumber(entity.getName(),entity.getAutoNumberNextNew());
}
}
Now when I reset, it reset works but the number generated is not changed.
What could be the reason?