controle Sequence for BL
This commit is contained in:
@@ -611,4 +611,52 @@ public class StockMoveController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// controler les sequences pour les livraisons client => bloc si ne sont pas séquentielle
|
||||||
|
public void controleSequenceBL(ActionRequest request, ActionResponse response) throws AxelorException {
|
||||||
|
|
||||||
|
StockMove stockMove = request.getContext().asType(StockMove.class);
|
||||||
|
|
||||||
|
|
||||||
|
if(stockMove.getTypeSelect() == StockMoveRepository.TYPE_OUTGOING &&
|
||||||
|
stockMove.getIsReversion() == false && stockMove.getPartner().getId() != 853){
|
||||||
|
|
||||||
|
int currentYear = Beans.get(AppBaseService.class).getTodayDateTime().getYear();
|
||||||
|
String[] splityear = Integer.toString(currentYear).split("20");
|
||||||
|
String year ="BL"+splityear[1];
|
||||||
|
Query q =
|
||||||
|
JPA.em()
|
||||||
|
.createQuery(
|
||||||
|
" select stockMoveSeq from StockMove where stockMoveSeq like ?1 and stockMoveSeq != ?2"+
|
||||||
|
" and LENGTH(stock_move_seq) = 9 and partner != 853 and is_reversion = false "+
|
||||||
|
" ORDER BY stockMoveSeq DESC",
|
||||||
|
String.class);
|
||||||
|
q.setParameter(1, year + "%" );
|
||||||
|
q.setParameter(2, stockMove.getStockMoveSeq());
|
||||||
|
|
||||||
|
|
||||||
|
if (q.getResultList().size() > 0) {
|
||||||
|
List<String> squences = q.getResultList();
|
||||||
|
String maxNumberString = squences.get(0);
|
||||||
|
String[] a = maxNumberString.split(year);
|
||||||
|
Integer maxNumber = Integer.parseInt(a[1]);
|
||||||
|
|
||||||
|
String originNumberString = stockMove.getStockMoveSeq();
|
||||||
|
String[] b = originNumberString.split(year);
|
||||||
|
Integer originNumber = Integer.parseInt(b[1]);
|
||||||
|
|
||||||
|
|
||||||
|
Integer nextNumber = maxNumber+1;
|
||||||
|
String padding = "00000".substring(nextNumber.toString().length()) + nextNumber.toString();
|
||||||
|
if(nextNumber != originNumber && originNumber > nextNumber){
|
||||||
|
throw new AxelorException(
|
||||||
|
stockMove,
|
||||||
|
TraceBackRepository.CATEGORY_CONFIGURATION_ERROR,
|
||||||
|
"please correct current sequence to: "+year+padding
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user