/** * <p>Lazy getter for balanceAtAllDirtyCheck.</p> * @param pAddParam additional param * @return BalanceAtAllDirtyCheck * @throws Exception - an exception **/ public final synchronized BalanceAtAllDirtyCheck lazyGetBalanceAtAllDirtyCheck( final Map<String, Object> pAddParam) throws Exception { if (this.balanceAtAllDirtyCheck == null) { BalanceAtAllDirtyCheck balLoc = new BalanceAtAllDirtyCheck(); balLoc.setItsId(1L); this.balanceAtAllDirtyCheck = getSrvOrm() .retrieveEntity(pAddParam, balLoc); if (this.balanceAtAllDirtyCheck == null) { getSrvOrm().insertEntity(pAddParam, balLoc); balLoc.setIsNew(false); this.balanceAtAllDirtyCheck = getSrvOrm() .retrieveEntity(pAddParam, balLoc); } } return this.balanceAtAllDirtyCheck; }
calCurrYear.set(Calendar.MILLISECOND, 0); Calendar calStBl = Calendar.getInstance(new Locale("en", "US")); calStBl.setTime(this.balanceAtAllDirtyCheck.getDateBalanceStoreStart()); calStBl.set(Calendar.MONTH, 0); calStBl.set(Calendar.DAY_OF_MONTH, 1); if (calCurrYear.getTime().getTime() < calStBl.getTime().getTime() || this.balanceAtAllDirtyCheck .getLeastAccountingEntryDate() .getTime() < this.balanceAtAllDirtyCheck .getDateBalanceStoreStart().getTime()) { this.balanceAtAllDirtyCheck .setCurrentBalanceDate(initDate); this.balanceAtAllDirtyCheck .setDateBalanceStoreStart(initDate); evalDateBalanceStoreStart(pAddParam); recalculateAll(pAddParam, pDateFor, false); } else if (datePeriodStartFor.getTime() > this.balanceAtAllDirtyCheck .getCurrentBalanceDate().getTime() || this.balanceAtAllDirtyCheck .getLeastAccountingEntryDate() .getTime() < this.balanceAtAllDirtyCheck .getCurrentBalanceDate().getTime()) { recalculateAll(pAddParam, pDateFor, false);
.getDateBalanceStoreStart(); Date leastAccountingEntryDate = lazyGetBalanceAtAllDirtyCheck() .getLeastAccountingEntryDate(); if (dateBalanceStoreStart.getTime() == 157766400000L && leastAccountingEntryDate.getTime() == 157766400000L) { cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); lazyGetBalanceAtAllDirtyCheck().setDateBalanceStoreStart(cal.getTime()); } else if (dateBalanceStoreStart.getTime() == 157766400000L && leastAccountingEntryDate.getTime() > 157766400000L) { lazyGetBalanceAtAllDirtyCheck().setDateBalanceStoreStart( evalDatePeriodStartFor(leastAccountingEntryDate)); return lazyGetBalanceAtAllDirtyCheck().getDateBalanceStoreStart();
/** * <p>Handle new accounting entry is created to check dirty. * This is implementation of dirty check for all accounts.</p> * @param pAcc account * @param pSubaccId subaccount ID * @param pDateAt date at * @throws Exception - an exception **/ @Override public final synchronized void handleNewAccountEntry(final Account pAcc, final Long pSubaccId, final Date pDateAt) throws Exception { if (lazyGetBalanceAtAllDirtyCheck().getLeastAccountingEntryDate() .getTime() > pDateAt.getTime()) { getLogger().debug(SrvBalanceStd.class, SrvBalanceStd.class.getSimpleName() + ": changing least last entry date from " + lazyGetBalanceAtAllDirtyCheck().getLeastAccountingEntryDate() + " to " + pDateAt); lazyGetBalanceAtAllDirtyCheck().setLeastAccountingEntryDate(pDateAt); } }
if (this.balanceAtAllDirtyCheck.getIsPeriodChanged()) { getLogger().info(null, SrvBalanceStd.class, "deleting all stored balances cause period has changed"); getSrvDatabase().executeDelete(BalanceAt.class.getSimpleName() .toUpperCase(), null); this.balanceAtAllDirtyCheck.setIsPeriodChanged(false); if (this.balanceAtAllDirtyCheck.getLeastAccountingEntryDate() .getTime() < this.balanceAtAllDirtyCheck .getCurrentBalanceDate().getTime()) { this.balanceAtAllDirtyCheck.getDateBalanceStoreStart()); getLogger().info(null, SrvBalanceStd.class, "recalculating balances from start " + date + " <- " + this.balanceAtAllDirtyCheck.getDateBalanceStoreStart()); } else { this.balanceAtAllDirtyCheck.getCurrentBalanceDate()); getLogger().info(null, SrvBalanceStd.class, "recalculating balances from current end " + date + " <- " + this.balanceAtAllDirtyCheck.getCurrentBalanceDate()); if (lastBalanceStoredDate.getTime() > pDateFor.getTime()) { this.balanceAtAllDirtyCheck .setCurrentBalanceDate(lastBalanceStoredDate); } else { this.balanceAtAllDirtyCheck.setCurrentBalanceDate(pDateFor); .setLeastAccountingEntryDate(this.balanceAtAllDirtyCheck
/** * <p>Evaluate period of stored balances according settings, * if it's changed then it switch on "current balances are dirty".</p> * @param pAddParam additional param * @return pPeriod EPeriod e.g. MONTHLY * @throws Exception - an exception **/ @Override public final synchronized EPeriod evalBalanceStorePeriod( final Map<String, Object> pAddParam) throws Exception { if (!lazyGetBalanceAtAllDirtyCheck(pAddParam).getBalanceStorePeriod() .equals(getSrvAccSettings().lazyGetAccSettings(pAddParam) .getBalanceStorePeriod())) { getLogger().info(null, SrvBalanceStd.class, "changing period from " + this.balanceAtAllDirtyCheck .getBalanceStorePeriod() + " to " + getSrvAccSettings() .lazyGetAccSettings(pAddParam).getBalanceStorePeriod()); this.balanceAtAllDirtyCheck .setBalanceStorePeriod(getSrvAccSettings().lazyGetAccSettings(pAddParam) .getBalanceStorePeriod()); this.balanceAtAllDirtyCheck.setIsPeriodChanged(true); this.balanceAtAllDirtyCheck .setCurrentBalanceDate(initDate); getSrvOrm() .updateEntity(pAddParam, this.balanceAtAllDirtyCheck); } return this.balanceAtAllDirtyCheck.getBalanceStorePeriod(); }
/** * <p>Recalculate if need for all balances for all dates less * or equals pDateFor, this method is always invoked by report ledger.</p> * @param pDateFor date for * @throws Exception - an exception **/ @Override public final synchronized void recalculateAllIfNeed( final Date pDateFor) throws Exception { evalBalanceStorePeriod(); //must be before evalDateBalanceStoreStart!!! evalDateBalanceStoreStart(); Date datePeriodStartFor = evalDatePeriodStartFor(pDateFor); if (datePeriodStartFor.getTime() > lazyGetBalanceAtAllDirtyCheck() .getCurrentBalanceDate().getTime() || lazyGetBalanceAtAllDirtyCheck() .getLeastAccountingEntryDate() .getTime() < lazyGetBalanceAtAllDirtyCheck() .getCurrentBalanceDate().getTime()) { recalculateAll(pDateFor, false); } }
/** * <p>Lazy getter for balanceAtAllDirtyCheck.</p> * @return BalanceAtAllDirtyCheck * @throws Exception - an exception **/ public final synchronized BalanceAtAllDirtyCheck lazyGetBalanceAtAllDirtyCheck() throws Exception { if (this.balanceAtAllDirtyCheck == null) { this.balanceAtAllDirtyCheck = getSrvOrm() .retrieveEntityById(BalanceAtAllDirtyCheck.class, 1L); if (this.balanceAtAllDirtyCheck == null) { this.balanceAtAllDirtyCheck = new BalanceAtAllDirtyCheck(); this.balanceAtAllDirtyCheck.setItsId(1L); getSrvOrm().insertEntity(this.balanceAtAllDirtyCheck); } } return this.balanceAtAllDirtyCheck; }
if (lazyGetBalanceAtAllDirtyCheck().getIsPeriodChanged()) { getLogger().info(SrvBalanceStd.class, SrvBalanceStd.class.getSimpleName() + ": deleting all stored balances cause period has changed"); getSrvDatabase().executeDelete(BalanceAt.class.getSimpleName() .toUpperCase(), null); lazyGetBalanceAtAllDirtyCheck().setIsPeriodChanged(false); if (lazyGetBalanceAtAllDirtyCheck().getLeastAccountingEntryDate() .getTime() < lazyGetBalanceAtAllDirtyCheck() .getCurrentBalanceDate().getTime()) { .getDateBalanceStoreStart()); getLogger().info(SrvBalanceStd.class, SrvBalanceStd.class.getSimpleName() + ": recalculating balances from start " + date + " <- " + lazyGetBalanceAtAllDirtyCheck().getDateBalanceStoreStart()); } else { .getCurrentBalanceDate()); getLogger().info(SrvBalanceStd.class, SrvBalanceStd.class.getSimpleName() + ": recalculating balances from current end " + date + " <- " + lazyGetBalanceAtAllDirtyCheck().getCurrentBalanceDate()); if (lastBalanceStoredDate.getTime() > pDateFor.getTime()) { lazyGetBalanceAtAllDirtyCheck() .setCurrentBalanceDate(lastBalanceStoredDate); } else { lazyGetBalanceAtAllDirtyCheck().setCurrentBalanceDate(pDateFor); .setLeastAccountingEntryDate(lazyGetBalanceAtAllDirtyCheck()
/** * <p>Evaluate period of stored balances according settings, * if it's changed then it switch on "current balances are dirty".</p> * @return pPeriod EPeriod e.g. MONTHLY * @throws Exception - an exception **/ @Override public final synchronized EPeriod evalBalanceStorePeriod() throws Exception { if (!lazyGetBalanceAtAllDirtyCheck().getBalanceStorePeriod() .equals(getSrvAccSettings().lazyGetAccSettings() .getBalanceStorePeriod())) { getLogger().info(SrvBalanceStd.class, SrvBalanceStd.class.getSimpleName() + ": changing period from " + lazyGetBalanceAtAllDirtyCheck() .getBalanceStorePeriod() + " to " + getSrvAccSettings() .lazyGetAccSettings().getBalanceStorePeriod()); lazyGetBalanceAtAllDirtyCheck() .setBalanceStorePeriod(getSrvAccSettings().lazyGetAccSettings() .getBalanceStorePeriod()); lazyGetBalanceAtAllDirtyCheck().setIsPeriodChanged(true); lazyGetBalanceAtAllDirtyCheck() .setCurrentBalanceDate(new Date(157766400000L)); } return lazyGetBalanceAtAllDirtyCheck().getBalanceStorePeriod(); }
final Map<String, Object> pAddParam) throws Exception { Date dateBalanceStoreStart = lazyGetBalanceAtAllDirtyCheck(pAddParam) .getDateBalanceStoreStart(); Date leastAccountingEntryDate = this.balanceAtAllDirtyCheck .getLeastAccountingEntryDate(); if (dateBalanceStoreStart.getTime() == this.initDateLong && leastAccountingEntryDate.getTime() == this.initDateLong) { cal.set(Calendar.MILLISECOND, 0); this.balanceAtAllDirtyCheck .setDateBalanceStoreStart(cal.getTime()); getSrvOrm() .updateEntity(pAddParam, this.balanceAtAllDirtyCheck); cal.set(Calendar.MILLISECOND, 0); this.balanceAtAllDirtyCheck .setDateBalanceStoreStart(cal.getTime()); } else { this.balanceAtAllDirtyCheck.setDateBalanceStoreStart( evalDatePeriodStartFor(pAddParam, new Date(dateFirstEntryLong))); .updateEntity(pAddParam, this.balanceAtAllDirtyCheck); return this.balanceAtAllDirtyCheck.getDateBalanceStoreStart();
/** * <p>Handle new accounting entry is created to check dirty. * This is implementation of dirty check for all accounts.</p> * @param pAddParam additional param * @param pAcc account * @param pSubaccId subaccount ID * @param pDateAt date at * @throws Exception - an exception **/ @Override public final synchronized void handleNewAccountEntry( final Map<String, Object> pAddParam, final Account pAcc, final Long pSubaccId, final Date pDateAt) throws Exception { if (lazyGetBalanceAtAllDirtyCheck(pAddParam).getLeastAccountingEntryDate() .getTime() > pDateAt.getTime()) { if (getLogger().getIsShowDebugMessagesFor(getClass())) { getLogger().debug(null, SrvBalanceStd.class, "changing least last entry date from " + this.balanceAtAllDirtyCheck .getLeastAccountingEntryDate() + " to " + pDateAt); } this.balanceAtAllDirtyCheck .setLeastAccountingEntryDate(pDateAt); getSrvOrm() .updateEntity(pAddParam, this.balanceAtAllDirtyCheck); } }
"null_not_accepted"); if (!lazyGetBalanceAtAllDirtyCheck(pAddParam).getBalanceStorePeriod() .equals(pPeriod)) { getLogger().info(null, SrvBalanceStd.class, "changing period from " + this.balanceAtAllDirtyCheck .getBalanceStorePeriod() + " to " + pPeriod); this.balanceAtAllDirtyCheck.setBalanceStorePeriod(pPeriod); if (!getSrvAccSettings().lazyGetAccSettings(pAddParam) .getBalanceStorePeriod().equals(pPeriod)) { .setCurrentBalanceDate(initDate); this.balanceAtAllDirtyCheck.setIsPeriodChanged(true); getSrvOrm() .updateEntity(pAddParam, this.balanceAtAllDirtyCheck);
"null_not_accepted"); if (!lazyGetBalanceAtAllDirtyCheck().getBalanceStorePeriod() .equals(pPeriod)) { getLogger().info(SrvBalanceStd.class, SrvBalanceStd.class.getSimpleName() + ": changing period from " + lazyGetBalanceAtAllDirtyCheck() .getBalanceStorePeriod() + " to " + pPeriod); lazyGetBalanceAtAllDirtyCheck().setBalanceStorePeriod(pPeriod); if (!getSrvAccSettings().lazyGetAccSettings() .getBalanceStorePeriod().equals(pPeriod)) { .setCurrentBalanceDate(new Date(157766400000L)); lazyGetBalanceAtAllDirtyCheck().setIsPeriodChanged(true); getSrvOrm().updateEntity(lazyGetBalanceAtAllDirtyCheck());