Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1.   public static String getDocumentNo(DocumentType docType, String strTableName, boolean updateNext) {
  2.     if (docType == null) {
  3.       return "";
  4.     }
  5.     Sequence seq = docType.getDocumentSequence();
  6.     if (seq == null && strTableName != null) {
  7.       OBCriteria<Sequence> obcSeq = OBDal.getInstance().createCriteria(Sequence.class);
  8.       obcSeq.add(Restrictions.eq(Sequence.PROPERTY_NAME, "DocumentNo_" + strTableName));
  9.       if (obcSeq != null && obcSeq.list().size() > 0) {
  10.         seq = obcSeq.list().get(0);
  11.       }
  12.     }
  13.     if (seq == null) {
  14.       return "";
  15.     }
  16.     String nextDocNumber = "";
  17.     if (seq.getPrefix() != null) {
  18.       nextDocNumber = seq.getPrefix();
  19.     }
  20.     nextDocNumber += seq.getNextAssignedNumber().toString();
  21.     if (seq.getSuffix() != null) {
  22.       nextDocNumber += seq.getSuffix();
  23.     }
  24.     if (updateNext) {
  25.       seq.setNextAssignedNumber(seq.getNextAssignedNumber() + seq.getIncrementBy());
  26.       try {
  27.         OBContext.setAdminMode(false);
  28.         OBDal.getInstance().save(seq);
  29.         OBDal.getInstance().flush();
  30.       } finally {
  31.         OBContext.restorePreviousMode();
  32.       }
  33.     }
  34.  
  35.     return nextDocNumber;
  36.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement