/** * Is standard Period Open for Document Base Type - does not check Orgs * * @param ctx context * @param DateAcct date * @param DocBaseType base type * @return true if open * @deprecated use new isOpen */ @Deprecated public static boolean isOpenOld(Ctx ctx, Timestamp DateAcct, String DocBaseType) { if (DateAcct == null) { s_log.warning("No DateAcct"); return false; } if (DocBaseType == null) { s_log.warning("No DocBaseType"); return false; } MPeriod period = MPeriod.getOfOrg(ctx, 0, DateAcct); if (period == null) { s_log.warning("No Period for " + DateAcct + " (" + DocBaseType + ")"); return false; } String error = period.isOpen(DocBaseType, DateAcct); if (error != null) s_log.warning(error + " - " + period.getName()); return error == null; } // isOpen
/** * Load Invoice Line. * * @param bs bank statement 4 amounts AMTTYPE_Payment AMTTYPE_Statement2 AMTTYPE_Charge * AMTTYPE_Interest * @return DocLine Array */ private DocLine[] loadLines(final MBankStatement bs) { ArrayList<DocLine> list = new ArrayList<DocLine>(); MBankStatementLine[] lines = bs.getLines(false); for (int i = 0; i < lines.length; i++) { MBankStatementLine line = lines[i]; DocLine_BankStatement docLine = new DocLine_BankStatement(line, this); // Set Date Acct if (i == 0) setDateAcct(line.getDateAcct()); MPeriod period = MPeriod.get(getCtx(), line.getDateAcct(), line.getAD_Org_ID()); if (period != null && period.isOpen(DOCTYPE_BankStatement, line.getDateAcct(), bs.getAD_Org_ID())) { docLine.setC_Period_ID(period.getC_Period_ID()); } // list.add(docLine); } // Return Array DocLine[] dls = new DocLine[list.size()]; list.toArray(dls); return dls; } // loadLines
/** * Is standard Period Open for specified orgs for the client. For best performance, ensure that * the list of orgs does not contain duplicates. * * @param ctx * @param AD_Client_ID * @param orgs * @param DateAcct accounting date * @param DocBaseType document base type * @return error message or null */ public static String isOpen( Ctx ctx, int AD_Client_ID, ArrayList<Integer> orgs, Timestamp DateAcct, String DocBaseType) { if (DateAcct == null) return "@NotFound@ @DateAcct@"; if (DocBaseType == null) return "@NotFound@ @DocBaseType@"; MAcctSchema as = MClient.get(ctx, AD_Client_ID).getAcctSchema(); if (as == null) return "@NotFound@ @C_AcctSchema_ID@ for AD_Client_ID=" + AD_Client_ID; if (as.isAutoPeriodControl()) { if (as.isAutoPeriodControlOpen(DateAcct)) return null; else return "@PeriodClosed@ - @AutoPeriodControl@"; } // Get all Calendars in line with Organizations MClientInfo clientInfo = MClientInfo.get(ctx, AD_Client_ID, null); ArrayList<Integer> orgCalendars = new ArrayList<Integer>(); ArrayList<Integer> calendars = new ArrayList<Integer>(); for (int org : orgs) { MOrgInfo orgInfo = MOrgInfo.get(ctx, org, null); int C_Calendar_ID = orgInfo.getC_Calendar_ID(); if (C_Calendar_ID == 0) C_Calendar_ID = clientInfo.getC_Calendar_ID(); orgCalendars.add(C_Calendar_ID); if (!calendars.contains(C_Calendar_ID)) calendars.add(C_Calendar_ID); } // Should not happen if (calendars.size() == 0) return "@NotFound@ @C_Calendar_ID@"; // For all Calendars get Periods for (int i = 0; i < calendars.size(); i++) { int C_Calendar_ID = calendars.get(i); MPeriod period = MPeriod.getOfCalendar(ctx, C_Calendar_ID, DateAcct); // First Org for Calendar int AD_Org_ID = 0; for (int j = 0; j < orgCalendars.size(); j++) { if (orgCalendars.get(j) == C_Calendar_ID) { AD_Org_ID = orgs.get(j); break; } } if (period == null) { MCalendar cal = MCalendar.get(ctx, C_Calendar_ID); String date = DisplayType.getDateFormat(DisplayTypeConstants.Date).format(DateAcct); if (cal != null) return "@NotFound@ @C_Period_ID@: " + date + " - " + MOrg.get(ctx, AD_Org_ID).getName() + " -> " + cal.getName(); else return "@NotFound@ @C_Period_ID@: " + date + " - " + MOrg.get(ctx, AD_Org_ID).getName() + " -> C_Calendar_ID=" + C_Calendar_ID; } String error = period.isOpen(DocBaseType, DateAcct); if (error != null) return error + " - " + MOrg.get(ctx, AD_Org_ID).getName() + " -> " + MCalendar.get(ctx, C_Calendar_ID).getName(); } return null; // open } // isOpen