/** * Parent Constructor * * @param client client * @param name */ public MOrg(MClient client, String name) { this(client.getCtx(), 0, client.get_TrxName()); setAD_Client_ID(client.getAD_Client_ID()); setValue(name); setName(name); } // MOrg
/** * Create 12 Standard Periods from the specified start date. Creates also Period Control from * DocType. * * @see DocumentTypeVerify#createPeriodControls(Properties, int, SvrProcess, String) * @param locale locale * @param startDate first day of the calendar year * @param dateFormat SimpleDateFormat pattern for generating the period names. * @return true if created */ public boolean createStdPeriods(Locale locale, Timestamp startDate, String dateFormat) { if (locale == null) { MClient client = MClient.get(getCtx()); locale = client.getLocale(); } if (locale == null && Language.getLoginLanguage() != null) locale = Language.getLoginLanguage().getLocale(); if (locale == null) locale = Env.getLanguage(getCtx()).getLocale(); // SimpleDateFormat formatter; if (dateFormat == null || dateFormat.equals("")) dateFormat = "MMM-yy"; formatter = new SimpleDateFormat(dateFormat, locale); // int year = getYearAsInt(); GregorianCalendar cal = new GregorianCalendar(locale); if (startDate != null) { cal.setTime(startDate); if (cal.get(Calendar.YEAR) != year) // specified start date takes precedence in setting year year = cal.get(Calendar.YEAR); } else { cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, 0); cal.set(Calendar.DAY_OF_MONTH, 1); } cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); // for (int month = 0; month < 12; month++) { Timestamp start = new Timestamp(cal.getTimeInMillis()); String name = formatter.format(start); // get last day of same month cal.add(Calendar.MONTH, 1); cal.add(Calendar.DAY_OF_YEAR, -1); Timestamp end = new Timestamp(cal.getTimeInMillis()); // MPeriod period = MPeriod.findByCalendar(getCtx(), start, getC_Calendar_ID(), get_TrxName()); if (period == null) { period = new MPeriod(this, month + 1, name, start, end); } else { period.setC_Year_ID(this.getC_Year_ID()); period.setPeriodNo(month + 1); period.setName(name); period.setStartDate(start); period.setEndDate(end); } period.saveEx(get_TrxName()); // Creates Period Control // get first day of next month cal.add(Calendar.DAY_OF_YEAR, 1); } return true; } // createStdPeriods
public static MPasswordRule getRules(Properties ctx, String trxName) { MClient system = MClient.get(ctx, 0); int pwdruleID = system.getAD_PasswordRule_ID(); MPasswordRule pass = null; if (pwdruleID > 0) pass = new MPasswordRule(ctx, pwdruleID, trxName); return pass; }
/** * Parent Constructor * * @param client client * @param currency currency */ public MAcctSchema(MClient client, KeyNamePair currency) { this(client.getCtx(), 0, client.get_TrxName()); setClientOrg(client); setC_Currency_ID(currency.getKey()); StringBuilder msgset = new StringBuilder() .append(client.getName()) .append(" ") .append(getGAAP()) .append("/") .append(get_ColumnCount()) .append(" ") .append(currency.getName()); setName(msgset.toString()); } // MAcctSchema
/** * Find Client * * @param client client name * @return AD_Client_ID */ private int findClient(String client) { if (m_clients == null) m_clients = MClient.getAll(getCtx()); for (int i = 0; i < m_clients.length; i++) { if ((client.equalsIgnoreCase(m_clients[i].getValue()))) return m_clients[i].getAD_Client_ID(); } return 0; } // findClient
/** * Is Period Open for Doc Base Type * * @param DocBaseType document base type * @param dateAcct accounting date * @return error message or null */ public String isOpen(String DocBaseType, Timestamp dateAcct) { if (!isActive()) { s_log.warning("Period not active: " + getName()); return "@C_Period_ID@ <> @IsActive@"; } MAcctSchema as = MClient.get(getCtx(), getAD_Client_ID()).getAcctSchema(); if (as != null && as.isAutoPeriodControl()) { if (!as.isAutoPeriodControlOpen(dateAcct)) return "@PeriodClosed@ - @AutoPeriodControl@"; // We are OK Timestamp today = new Timestamp(System.currentTimeMillis()); if (isInPeriod(today) && as.getC_Period_ID() != getC_Period_ID()) { as.setC_Period_ID(getC_Period_ID()); as.save(); } return null; } // Standard Period Control if (DocBaseType == null) { log.warning(getName() + " - No DocBaseType"); return "@NotFound@ @DocBaseType@"; } MPeriodControl pc = getPeriodControl(DocBaseType); if (pc == null) { log.warning(getName() + " - Period Control not found for " + DocBaseType); return "@NotFound@ @C_PeriodControl_ID@: " + DocBaseType; } log.fine(getName() + ": " + DocBaseType); if (pc.isOpen()) return null; return "@PeriodClosed@ - @C_PeriodControl_ID@ (" + DocBaseType + ", " + dateAcct + ")"; } // isOpen
/** * Is standard Period closed for all Document Base Types * * @param ctx context for AD_Client * @param DateAcct accounting date * @return true if closed */ public static boolean isClosed(Ctx ctx, Timestamp DateAcct) { if (DateAcct == null) return false; MAcctSchema as = MClient.get(ctx, ctx.getAD_Client_ID()).getAcctSchema(); if (as.isAutoPeriodControl()) return !as.isAutoPeriodControlOpen(DateAcct); // Get all Calendars in line with Organizations MClientInfo cInfo = MClientInfo.get(ctx, ctx.getAD_Client_ID(), null); ArrayList<Integer> calendars = new ArrayList<Integer>(); MOrg[] orgs = MOrg.getOfClient(cInfo); for (MOrg org : orgs) { MOrgInfo info = MOrgInfo.get(ctx, org.getAD_Org_ID(), null); int C_Calendar_ID = info.getC_Calendar_ID(); if (C_Calendar_ID == 0) C_Calendar_ID = cInfo.getC_Calendar_ID(); if (!calendars.contains(C_Calendar_ID)) calendars.add(C_Calendar_ID); } // Should not happen if (calendars.size() == 0) throw new IllegalArgumentException("@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); // Period not found if (period == null) return false; if (!period.isClosed()) return false; } return true; // closed } // isClosed
/** * Add Node to correct tree * * @param ctx cpntext * @param treeType tree type * @param Record_ID id * @param trxName transaction * @return true if node added */ public static boolean addNode(Properties ctx, String treeType, int Record_ID, String trxName) { // TODO: Check & refactor this // Get Tree int AD_Tree_ID = 0; MClient client = MClient.get(ctx); I_AD_ClientInfo ci = client.getInfo(); if (TREETYPE_Activity.equals(treeType)) AD_Tree_ID = ci.getAD_Tree_Activity_ID(); else if (TREETYPE_BoM.equals(treeType)) throw new IllegalArgumentException("BoM Trees not supported"); else if (TREETYPE_BPartner.equals(treeType)) AD_Tree_ID = ci.getAD_Tree_BPartner_ID(); else if (TREETYPE_Campaign.equals(treeType)) AD_Tree_ID = ci.getAD_Tree_Campaign_ID(); else if (TREETYPE_ElementValue.equals(treeType)) throw new IllegalArgumentException("ElementValue cannot use this API"); else if (TREETYPE_Menu.equals(treeType)) AD_Tree_ID = ci.getAD_Tree_Menu_ID(); else if (TREETYPE_Organization.equals(treeType)) AD_Tree_ID = ci.getAD_Tree_Org_ID(); else if (TREETYPE_Product.equals(treeType)) AD_Tree_ID = ci.getAD_Tree_Product_ID(); else if (TREETYPE_ProductCategory.equals(treeType)) throw new IllegalArgumentException("Product Category Trees not supported"); else if (TREETYPE_Project.equals(treeType)) AD_Tree_ID = ci.getAD_Tree_Project_ID(); else if (TREETYPE_SalesRegion.equals(treeType)) AD_Tree_ID = ci.getAD_Tree_SalesRegion_ID(); if (AD_Tree_ID == 0) throw new IllegalArgumentException("No Tree found"); MTree_Base tree = MTree_Base.get(ctx, AD_Tree_ID, trxName); if (tree.get_ID() != AD_Tree_ID) throw new IllegalArgumentException("Tree found AD_Tree_ID=" + AD_Tree_ID); // Insert Tree in correct tree boolean saved = false; if (TREETYPE_Menu.equals(treeType)) { MTree_NodeMM node = new MTree_NodeMM(tree, Record_ID); saved = node.save(); } else if (TREETYPE_BPartner.equals(treeType)) { MTree_NodeBP node = new MTree_NodeBP(tree, Record_ID); saved = node.save(); } else if (TREETYPE_Product.equals(treeType)) { MTree_NodePR node = new MTree_NodePR(tree, Record_ID); saved = node.save(); } else { MTree_Node node = new MTree_Node(tree, Record_ID); saved = node.save(); } return saved; } // addNode
/** * Gets Material Management Policy. Tries: Product Category, Client (in this order) * * @return Material Management Policy */ public String getMMPolicy() { MProductCategory pc = MProductCategory.get(getCtx(), getM_Product_Category_ID()); String MMPolicy = pc.getMMPolicy(); if (MMPolicy == null || MMPolicy.length() == 0) MMPolicy = MClient.get(getCtx()).getMMPolicy(); return MMPolicy; }
/** * 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
/** * Parent Constructor * * @param client client * @param name name * @param treeType */ public MTree_Base(MClient client, String name, String treeType) { this(client.getCtx(), 0, client.get_TrxName()); setClientOrg(client); setName(name); setTreeType(treeType); } // MTree_Base