/** * <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); } }
"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)) { getSrvAccSettings().lazyGetAccSettings() .setBalanceStorePeriod(pPeriod); getSrvAccSettings().saveEntity(null, getSrvAccSettings() .lazyGetAccSettings(), false); lazyGetBalanceAtAllDirtyCheck() .setCurrentBalanceDate(new Date(157766400000L)); lazyGetBalanceAtAllDirtyCheck().setIsPeriodChanged(true); getSrvOrm().updateEntity(lazyGetBalanceAtAllDirtyCheck());
/** * <p>Evaluate Trial Balance query.</p> * @param pDate date of balance * @return query of balance * @throws Exception - an exception **/ public final synchronized String evalQueryBalance( final Date pDate) throws Exception { if (this.queryBalance == null) { String flName = "/" + "accounting" + "/" + "balance" + "/" + "queryBalance.sql"; this.queryBalance = loadString(flName); } String query = queryBalance.replace(":DATE1", String.valueOf(evalDatePeriodStartFor(pDate).getTime())); query = query.replace(":DATE2", String.valueOf(pDate.getTime())); return query; }
/** * <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); } }
public final synchronized void recalculateAll( final Date pDateFor, final boolean pIsPrepareNeed) throws Exception { getLogger().info(SrvBalanceStd.class, SrvBalanceStd.class.getSimpleName() + ": recalculation start BalanceAtAllDirtyCheck was " + lazyGetBalanceAtAllDirtyCheck()); if (pIsPrepareNeed) { evalBalanceStorePeriod(); //must be before evalDateBalanceStoreStart!!! evalDateBalanceStoreStart(); 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()) { date = evalDateNextPeriodStart(lazyGetBalanceAtAllDirtyCheck() .getDateBalanceStoreStart()); getLogger().info(SrvBalanceStd.class, SrvBalanceStd.class.getSimpleName() + ": recalculating balances from start " + date + " <- " + lazyGetBalanceAtAllDirtyCheck().getDateBalanceStoreStart()); } else { date = evalDateNextPeriodStart(lazyGetBalanceAtAllDirtyCheck() .getCurrentBalanceDate());
final Map<String, Object> pAddParam, final Date pDateFor) throws Exception { evalBalanceStorePeriod(pAddParam); evalDateBalanceStoreStart(pAddParam); Date datePeriodStartFor = evalDatePeriodStartFor(pAddParam, pDateFor); Calendar calCurrYear = Calendar.getInstance(new Locale("en", "US")); calCurrYear.setTime(getSrvAccSettings().lazyGetAccSettings(pAddParam) .getCurrentAccYear()); calCurrYear.set(Calendar.MONTH, 0); this.balanceAtAllDirtyCheck .setDateBalanceStoreStart(initDate); evalDateBalanceStoreStart(pAddParam); recalculateAll(pAddParam, pDateFor, false); } else if (datePeriodStartFor.getTime() > this.balanceAtAllDirtyCheck .getCurrentBalanceDate().getTime() .getTime() < this.balanceAtAllDirtyCheck .getCurrentBalanceDate().getTime()) { recalculateAll(pAddParam, pDateFor, false);
final Map<String, Object> pAddParam, final Date pDate) throws Exception { recalculateAllIfNeed(pDate); List<TrialBalanceLine> result = new ArrayList<TrialBalanceLine>(); String query = evalQueryBalance(pDate); IRecordSet<RS> recordSet = null; try { recordSet = getSrvDatabase().retrieveRecords(query); if (recordSet.moveToFirst()) { do { String accName = getSrvDatabase().getSrvRecordRetriever() .getString(recordSet.getRecordSet(), "ITSNAME"); String accNumber = getSrvDatabase().getSrvRecordRetriever() .getString(recordSet.getRecordSet(), "ITSNUMBER"); String subaccName = getSrvDatabase().getSrvRecordRetriever() .getString(recordSet.getRecordSet(), "SUBACC"); Double debit = getSrvDatabase().getSrvRecordRetriever() .getDouble(recordSet.getRecordSet(), "DEBIT"); Double credit = getSrvDatabase().getSrvRecordRetriever() .getDouble(recordSet.getRecordSet(), "CREDIT"); if (debit != 0 || credit != 0) { tbl.setSubaccName(subaccName); tbl.setDebit(BigDecimal.valueOf(debit).setScale( getSrvAccSettings().lazyGetAccSettings().getBalancePrecision(), getSrvAccSettings().lazyGetAccSettings().getRoundingMode())); tbl.setCredit(BigDecimal.valueOf(credit).setScale( getSrvAccSettings().lazyGetAccSettings().getBalancePrecision(), getSrvAccSettings().lazyGetAccSettings().getRoundingMode()));
/** * <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(); }
/** * <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); } }
IRecordSet<RS> recordSet = null; try { recordSet = getSrvDatabase().retrieveRecords(pQuery); if (recordSet.moveToFirst()) { do { String accName = getSrvDatabase().getSrvRecordRetriever() .getString(recordSet.getRecordSet(), "ITSNAME"); String accId = getSrvDatabase().getSrvRecordRetriever() .getString(recordSet.getRecordSet(), "ACCID"); Long subaccId = getSrvDatabase().getSrvRecordRetriever() .getLong(recordSet.getRecordSet(), "SUBACCID"); Integer subaccType = getSrvDatabase().getSrvRecordRetriever() .getInteger(recordSet.getRecordSet(), "SUBACCTYPE"); String accNumber = getSrvDatabase().getSrvRecordRetriever() .getString(recordSet.getRecordSet(), "ITSNUMBER"); String subaccName = getSrvDatabase().getSrvRecordRetriever() .getString(recordSet.getRecordSet(), "SUBACC"); Double debit = getSrvDatabase().getSrvRecordRetriever() .getDouble(recordSet.getRecordSet(), "DEBIT"); Double credit = getSrvDatabase().getSrvRecordRetriever() .getDouble(recordSet.getRecordSet(), "CREDIT"); if (debit != 0 || credit != 0) { tbl.setSubaccName(subaccName); tbl.setDebit(BigDecimal.valueOf(debit).setScale( getSrvAccSettings().lazyGetAccSettings().getCostPrecision(), getSrvAccSettings().lazyGetAccSettings().getRoundingMode())); tbl.setCredit(BigDecimal.valueOf(credit).setScale( getSrvAccSettings().lazyGetAccSettings().getCostPrecision(),
Date dateBalanceStoreStart = lazyGetBalanceAtAllDirtyCheck() .getDateBalanceStoreStart(); Date leastAccountingEntryDate = lazyGetBalanceAtAllDirtyCheck() .getLeastAccountingEntryDate(); if (dateBalanceStoreStart.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>Evaluate start of period nearest to pDateFor. * Tested in beige-common org.beigesoft.test.CalendarTest.</p> * @param pDateFor date for * @return Start of period nearest to pDateFor * @throws Exception - an exception **/ @Override public final synchronized Date evalDatePeriodStartFor( final Date pDateFor) throws Exception { if (!(evalBalanceStorePeriod().equals(EPeriod.MONTHLY) || evalBalanceStorePeriod().equals(EPeriod.WEEKLY) || evalBalanceStorePeriod().equals(EPeriod.DAILY))) { throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER, "stored_balance_period_must_be_dwm"); } Calendar cal = Calendar.getInstance(); cal.setTime(pDateFor); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); //Daily is ready if (evalBalanceStorePeriod().equals(EPeriod.MONTHLY)) { cal.set(Calendar.DAY_OF_MONTH, 1); } else if (evalBalanceStorePeriod().equals(EPeriod.WEEKLY)) { cal.set(Calendar.DAY_OF_WEEK, 1); } return cal.getTime(); }
/** * <p>Get SrvBalanceStd in lazy mode.</p> * @return SrvBalanceStd - SrvBalanceStd * @throws Exception - an exception */ public final synchronized SrvBalanceStd<RS> lazyGetSrvBalanceStd() throws Exception { if (this.srvBalanceStd == null) { this.srvBalanceStd = new SrvBalanceStd<RS>(factoryAppBeans .lazyGetSrvOrm(), factoryAppBeans.lazyGetSrvDatabase(), lazyGetSrvAccSettings(), factoryAppBeans.lazyGetLogger()); } return this.srvBalanceStd; }
/** * <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; }
IRecordSet<RS> recordSet = null; try { recordSet = getSrvDatabase().retrieveRecords(pQuery); if (recordSet.moveToFirst()) { do { String accName = getSrvDatabase().getSrvRecordRetriever() .getString(recordSet.getRecordSet(), "ITSNAME"); String accId = getSrvDatabase().getSrvRecordRetriever() .getString(recordSet.getRecordSet(), "ACCID"); Long subaccId = getSrvDatabase().getSrvRecordRetriever() .getLong(recordSet.getRecordSet(), "SUBACCID"); Integer subaccType = getSrvDatabase().getSrvRecordRetriever() .getInteger(recordSet.getRecordSet(), "SUBACCTYPE"); String accNumber = getSrvDatabase().getSrvRecordRetriever() .getString(recordSet.getRecordSet(), "ITSNUMBER"); String subaccName = getSrvDatabase().getSrvRecordRetriever() .getString(recordSet.getRecordSet(), "SUBACC"); Double debit = getSrvDatabase().getSrvRecordRetriever() .getDouble(recordSet.getRecordSet(), "DEBIT"); Double credit = getSrvDatabase().getSrvRecordRetriever() .getDouble(recordSet.getRecordSet(), "CREDIT"); TrialBalanceLine tbl = new TrialBalanceLine();
final Map<String, Object> pAddParam, final Date pDateFor, final boolean pIsPrepareNeed) throws Exception { getLogger().info(null, SrvBalanceStd.class, "recalculation start BalanceAtAllDirtyCheck was " + lazyGetBalanceAtAllDirtyCheck(pAddParam)); if (pIsPrepareNeed) { evalBalanceStorePeriod(pAddParam); evalDateBalanceStoreStart(pAddParam); getLogger().info(null, SrvBalanceStd.class, "deleting all stored balances cause period has changed"); getSrvDatabase().executeDelete(BalanceAt.class.getSimpleName() .toUpperCase(), null); this.balanceAtAllDirtyCheck.setIsPeriodChanged(false); date = evalDateNextPeriodStart(pAddParam, this.balanceAtAllDirtyCheck.getDateBalanceStoreStart()); getLogger().info(null, SrvBalanceStd.class, "recalculating balances from start " + date + " <- " + this.balanceAtAllDirtyCheck.getDateBalanceStoreStart()); } else { date = evalDateNextPeriodStart(pAddParam, this.balanceAtAllDirtyCheck.getCurrentBalanceDate()); getLogger().info(null, SrvBalanceStd.class, "recalculating balances from current end " + date + " <- " + this.balanceAtAllDirtyCheck.getCurrentBalanceDate());
final Map<String, Object> pAddParam, final Date pDate) throws Exception { recalculateAllIfNeed(pAddParam, pDate); List<TrialBalanceLine> result = new ArrayList<TrialBalanceLine>(); String query = evalQueryBalance(pAddParam, pDate); IRecordSet<RS> recordSet = null; try { recordSet = getSrvDatabase().retrieveRecords(query); if (recordSet.moveToFirst()) { do { tbl.setSubaccName(subaccName); tbl.setDebit(BigDecimal.valueOf(debit).setScale( getSrvAccSettings().lazyGetAccSettings(pAddParam) .getBalancePrecision(), getSrvAccSettings() .lazyGetAccSettings(pAddParam).getRoundingMode())); tbl.setCredit(BigDecimal.valueOf(credit).setScale( getSrvAccSettings().lazyGetAccSettings(pAddParam) .getBalancePrecision(), getSrvAccSettings() .lazyGetAccSettings(pAddParam).getRoundingMode())); if (tbl.getDebit().doubleValue() != 0
/** * <p>Evaluate Trial Balance query.</p> * @param pAddParam additional param * @param pDate date of balance * @return query of balance * @throws Exception - an exception **/ public final synchronized String evalQueryBalance( final Map<String, Object> pAddParam, final Date pDate) throws Exception { if (this.queryBalance == null) { String flName = "/" + "accounting" + "/" + "balance" //+ "/" + "queryBalance.sql"; fast query cause error due changing subacc name + "/" + "queryBalanceSl.sql"; this.queryBalance = loadString(flName); } String query = queryBalance.replace(":DATE1", String.valueOf(evalDatePeriodStartFor(pAddParam, pDate).getTime())); query = query.replace(":DATE2", String.valueOf(pDate.getTime())); return query; }
IRecordSet<RS> recordSet = null; try { recordSet = getSrvDatabase().retrieveRecords(pQuery); if (recordSet.moveToFirst()) { do { tbl.setSubaccName(subaccName); tbl.setDebit(BigDecimal.valueOf(debit).setScale( getSrvAccSettings().lazyGetAccSettings(pAddParam) .getCostPrecision(), getSrvAccSettings() .lazyGetAccSettings(pAddParam).getRoundingMode())); tbl.setCredit(BigDecimal.valueOf(credit).setScale( getSrvAccSettings().lazyGetAccSettings(pAddParam) .getCostPrecision(), getSrvAccSettings() .lazyGetAccSettings(pAddParam).getRoundingMode())); if (tbl.getDebit().doubleValue() != 0
if (!(evalBalanceStorePeriod().equals(EPeriod.MONTHLY) || evalBalanceStorePeriod().equals(EPeriod.WEEKLY) || evalBalanceStorePeriod().equals(EPeriod.DAILY))) { throw new ExceptionWithCode(ExceptionWithCode.WRONG_PARAMETER, "stored_balance_period_must_be_dwm"); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); if (evalBalanceStorePeriod().equals(EPeriod.DAILY)) { cal.add(Calendar.DATE, 1); } else if (evalBalanceStorePeriod().equals(EPeriod.MONTHLY)) { cal.add(Calendar.MONTH, 1); cal.set(Calendar.DAY_OF_MONTH, 1); } else if (evalBalanceStorePeriod().equals(EPeriod.WEEKLY)) { cal.add(Calendar.DAY_OF_YEAR, 7); cal.set(Calendar.DAY_OF_WEEK, 1);