Ejemplo n.º 1
0
  /**
   * 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
Ejemplo n.º 2
0
  /**
   * Find standard Period of DateAcct based on Client Calendar
   *
   * @param ctx context
   * @param DateAcct date
   * @return active Period or null
   */
  public static MPeriod getOfOrg(Ctx ctx, int AD_Org_ID, Timestamp DateAcct) {
    int C_Calendar_ID = 0;
    if (AD_Org_ID != 0) {
      MOrgInfo info = MOrgInfo.get(ctx, AD_Org_ID, null);
      C_Calendar_ID = info.getC_Calendar_ID();
    }
    if (C_Calendar_ID == 0) {
      MClientInfo cInfo = MClientInfo.get(ctx);
      C_Calendar_ID = cInfo.getC_Calendar_ID();
    }

    return getOfCalendar(ctx, C_Calendar_ID, DateAcct);
  } //	get
Ejemplo n.º 3
0
 /**
  * Before Save
  *
  * @param newRecord new
  * @return true
  */
 protected boolean beforeSave(boolean newRecord) {
   if (getAD_Org_ID() != 0) setAD_Org_ID(0);
   if (super.getTaxCorrectionType() == null)
     setTaxCorrectionType(
         isDiscountCorrectsTax()
             ? TAXCORRECTIONTYPE_Write_OffAndDiscount
             : TAXCORRECTIONTYPE_None);
   checkCosting();
   //	Check Primary
   if (getAD_OrgOnly_ID() != 0) {
     MClientInfo info = MClientInfo.get(getCtx(), getAD_Client_ID());
     if (info.getC_AcctSchema1_ID() == getC_AcctSchema_ID()) setAD_OrgOnly_ID(0);
   }
   return true;
 } //	beforeSave
Ejemplo n.º 4
0
  /**
   * Get AccountSchema of Client
   *
   * @param ctx context
   * @param AD_Client_ID client or 0 for all
   * @param trxName optional trx
   * @return Array of AcctSchema of Client
   */
  public static MAcctSchema[] getClientAcctSchema(
      Properties ctx, int AD_Client_ID, String trxName) {
    //  Check Cache
    Integer key = new Integer(AD_Client_ID);
    if (s_schema.containsKey(key)) return (MAcctSchema[]) s_schema.get(key);

    //  Create New
    ArrayList<MAcctSchema> list = new ArrayList<MAcctSchema>();
    MClientInfo info = MClientInfo.get(ctx, AD_Client_ID, trxName);
    MAcctSchema as = MAcctSchema.get(ctx, info.getC_AcctSchema1_ID(), trxName);
    if (as.get_ID() != 0) list.add(as);

    ArrayList<Object> params = new ArrayList<Object>();
    StringBuilder whereClause =
        new StringBuilder("IsActive=? ")
            .append(
                " AND EXISTS (SELECT * FROM C_AcctSchema_GL gl WHERE C_AcctSchema.C_AcctSchema_ID=gl.C_AcctSchema_ID)")
            .append(
                " AND EXISTS (SELECT * FROM C_AcctSchema_Default d WHERE C_AcctSchema.C_AcctSchema_ID=d.C_AcctSchema_ID)");
    params.add("Y");
    if (AD_Client_ID != 0) {
      whereClause.append(" AND AD_Client_ID=?");
      params.add(AD_Client_ID);
    }

    List<MAcctSchema> ass =
        new Query(ctx, I_C_AcctSchema.Table_Name, whereClause.toString(), trxName)
            .setParameters(params)
            .setOrderBy(MAcctSchema.COLUMNNAME_C_AcctSchema_ID)
            .list();

    for (MAcctSchema acctschema : ass) {
      if (acctschema.get_ID() != info.getC_AcctSchema1_ID()) // 	already in list
      {
        if (acctschema.get_ID() != 0) list.add(acctschema);
      }
    }
    //  Save
    MAcctSchema[] retValue = new MAcctSchema[list.size()];
    list.toArray(retValue);
    s_schema.put(key, retValue);
    return retValue;
  } //  getClientAcctSchema
Ejemplo n.º 5
0
  /**
   * 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