Calendar c = TimeUtil.getCurrentCalendar();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
long id;
InvoiceIdCounter count = DaoFactory.getInvoiceIdCounterDao().perYear(year);
if (count==null) {
count = (InvoiceIdCounter)DaoFactory.getInvoiceIdCounterDao().newHandledObject();
count.setYear(year);
}
id = count.getCounter() + 1;
count.setCounter(id);
InvoiceIdImpl invId = (InvoiceIdImpl)DaoFactory.getInvoiceIdDao().newHandledObject();
invId.setReason(message);
invId.setIdent(formatIdent(id, year, month));