/** * Get the first Date From date of the next period based on Accumulation * @param from date * @return first date of next period */ public DateTime?GetDateFromNext(DateTime?from) { if (from == null) { return(from); } DateTime?retValue = from; if (BALANCEACCUMULATION_Daily.Equals(GetBALANCEACCUMULATION())) { return(null); } if (BALANCEACCUMULATION_CalendarMonth.Equals(GetBALANCEACCUMULATION())) { retValue = TimeUtil.AddMonths(from, 1); retValue = TimeUtil.Trunc(retValue, TimeUtil.TRUNC_MONTH); } else if (BALANCEACCUMULATION_CalendarWeek.Equals(GetBALANCEACCUMULATION())) { retValue = TimeUtil.AddDays(from, 7); retValue = TimeUtil.Trunc(retValue, TimeUtil.TRUNC_WEEK); } else if (BALANCEACCUMULATION_PeriodOfAViennaCalendar.Equals(GetBALANCEACCUMULATION()) && GetC_Calendar_ID() != 0) { } return(retValue); }
/** * Get the first Date From date based on Accumulation * @param from date * @return first date */ public DateTime?GetDateFrom(DateTime?from) { if (from == null) { return(from); } if (BALANCEACCUMULATION_CalendarMonth.Equals(GetBALANCEACCUMULATION())) { return(TimeUtil.Trunc(from, TimeUtil.TRUNC_MONTH)); } else if (BALANCEACCUMULATION_CalendarWeek.Equals(GetBALANCEACCUMULATION())) { return(TimeUtil.Trunc(from, TimeUtil.TRUNC_WEEK)); } else if (BALANCEACCUMULATION_PeriodOfAViennaCalendar.Equals(GetBALANCEACCUMULATION()) && GetC_Calendar_ID() != 0) { MPeriod period = MPeriod.GetOfCalendar(GetCtx(), GetC_Calendar_ID(), from); if (period != null) { return(period.GetStartDate()); } } return(from); }
/** * Before Save - Check Calendar * @param newRecord new * @return true if it can be saved */ protected override Boolean BeforeSave(Boolean newRecord) { // Calendar if (BALANCEACCUMULATION_PeriodOfAViennaCalendar.Equals(GetBALANCEACCUMULATION())) { if (GetC_Calendar_ID() == 0) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "C_Calendar_ID")); return(false); } } else if (GetC_Calendar_ID() != 0) { SetC_Calendar_ID(0); } if (IsDefault()) { Boolean exists = false; String sql = "SELECT * FROM Fact_Accumulation " + " WHERE IsDefault = 'Y'" + " AND IsActive = 'Y' " + " AND AD_Client_ID = " + GetAD_Client_ID() + " AND Fact_Accumulation_ID <> " + GetFACT_ACCUMULATION_ID(); IDataReader idr = null; try { idr = DB.ExecuteReader(sql, null, Get_TrxName()); if (idr.Read()) { exists = true; } idr.Close(); } catch (Exception e) { log.Log(Level.SEVERE, sql, e); } finally { if (idr != null) { idr.Close(); idr = null; } } if (exists) { log.SaveError("DefaultExists", "Default Balance aggregation already exists"); return(false); } } if (!newRecord) { if (Is_ValueChanged("C_AcctSchema_ID") || Is_ValueChanged("BalanceAccumulation") || Is_ValueChanged("C_Calendar_ID") || Is_ValueChanged("IsActivity") || Is_ValueChanged("IsBudget") || Is_ValueChanged("IsBusinessPartner") || Is_ValueChanged("IsCampaign") || Is_ValueChanged("IsLocationFrom") || Is_ValueChanged("IsLocationTo") || Is_ValueChanged("IsProduct") || Is_ValueChanged("IsProject") || Is_ValueChanged("IsSalesRegion") || Is_ValueChanged("IsUserList1") || Is_ValueChanged("IsUserList2")) { Boolean exists = false; String sql = "SELECT * FROM Fact_Acct_Balance " + " WHERE Fact_Accumulation_ID = " + GetFACT_ACCUMULATION_ID(); IDataReader idr = null; try { idr = DB.ExecuteReader(sql, null, Get_TrxName()); if (idr.Read()) { exists = true; } idr.Close(); } catch (Exception e) { log.Log(Level.SEVERE, sql, e); } finally { if (idr != null) { idr.Close(); idr = null; } } if (exists) { log.SaveError("BalanceExists", "Updates not allowed when balances exists for the Aggregation"); return(false); } } } return(true); }