/// <summary>
        /// Process
        /// </summary>
        /// <returns>message</returns>
        protected override String DoIt()
        {
            MPeriod period = new MPeriod(GetCtx(), _C_Period_ID, Get_Trx());

            // Get all Document type related to Tenant
            MDocType[]    types     = MDocType.GetOfClient(GetCtx());
            int           count     = 0;
            List <String> baseTypes = new List <String>();
            ValueNamePair vp        = null;

            // Split multiselected organizations to get array
            if (!String.IsNullOrEmpty(orgs))
            {
                _AD_Org_ID = orgs.Split(',');
            }


            for (int i = 0; i < types.Length; i++)
            {
                MDocType type        = types[i];
                String   docBaseType = type.GetDocBaseType();
                if (baseTypes.Contains(docBaseType))
                {
                    continue;
                }

                // loop on multiple selected organizations
                for (int j = 0; j < _AD_Org_ID.Length; j++)
                {
                    MPeriodControl pc = new MPeriodControl(period, docBaseType);
                    pc.SetAD_Org_ID(Util.GetValueOfInt(_AD_Org_ID[j]));
                    if (pc.Save())
                    {
                        count++;
                    }
                    else
                    {
                        vp = VLogger.RetrieveError();
                        if (vp != null)
                        {
                            log.Severe(Msg.GetMsg(GetCtx(), "PeriodCtlNotSaved") + ", " + vp.GetName());
                        }
                        else
                        {
                            log.Severe(Msg.GetMsg(GetCtx(), "PeriodCtlNotSaved"));
                        }
                    }
                }
                baseTypes.Add(docBaseType);
            }

            log.Fine("PeriodControl #" + count);

            return(Msg.GetMsg(GetCtx(), "PeriodControlGenerated"));
        }
        /// <summary>
        ///	Process
        /// </summary>
        /// <returns>message</returns>
        protected override String DoIt()
        {
            //log.info("C_PeriodControl_ID=" + _C_PeriodControl_ID);
            MPeriodControl pc = new MPeriodControl(GetCtx(), _C_PeriodControl_ID, Get_TrxName());

            if (pc.Get_ID() == 0)
            {
                throw new Exception("@NotFound@  @C_PeriodControl_ID@=" + _C_PeriodControl_ID);
            }
            //	Permanently closed
            if (MPeriodControl.PERIODACTION_PermanentlyClosePeriod.Equals(pc.GetPeriodStatus()))
            {
                throw new Exception("@PeriodStatus@ = " + pc.GetPeriodStatus());
            }
            //	No Action
            if (MPeriodControl.PERIODACTION_NoAction.Equals(pc.GetPeriodAction()))
            {
                return("@OK@");
            }
            //	Open
            if (MPeriodControl.PERIODACTION_OpenPeriod.Equals(pc.GetPeriodAction()))
            {
                pc.SetPeriodStatus(MPeriodControl.PERIODSTATUS_Open);
            }
            //	Close
            if (MPeriodControl.PERIODACTION_ClosePeriod.Equals(pc.GetPeriodAction()))
            {
                pc.SetPeriodStatus(MPeriodControl.PERIODSTATUS_Closed);
            }
            //	Close Permanently
            if (MPeriodControl.PERIODACTION_PermanentlyClosePeriod.Equals(pc.GetPeriodAction()))
            {
                pc.SetPeriodStatus(MPeriodControl.PERIODSTATUS_PermanentlyClosed);
            }
            pc.SetPeriodAction(MPeriodControl.PERIODACTION_NoAction);
            Boolean ok = pc.Save();

            //	Reset Cache
            CacheMgt.Get().Reset("C_PeriodControl", 0);
            CacheMgt.Get().Reset("C_Period", pc.GetC_Period_ID());
            if (!ok)
            {
                return("@Error@");
            }
            return("@OK@");
        }
        }       //	createDocumentTypes

        /// <summary>
        ///
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="AD_Client_ID"></param>
        /// <param name="sp"></param>
        /// <param name="trxName"></param>
        public static void CreatePeriodControls(Ctx ctx, int AD_Client_ID, SvrProcess sp, Trx trxName)
        {
            _log.Info("AD_Client_ID=" + AD_Client_ID);

            //	Delete Duplicates
            //jz remove correlation ID  String sql = "DELETE FROM C_PeriodControl pc1 "
            String sql = "DELETE FROM C_PeriodControl "
                         + "WHERE (C_Period_ID, DocBaseType) IN "
                         + "(SELECT C_Period_ID, DocBaseType "
                         + "FROM C_PeriodControl pc2 "
                         + "GROUP BY C_Period_ID, DocBaseType "
                         + "HAVING COUNT(*) > 1)"
                         + " AND C_PeriodControl_ID NOT IN "
                         + "(SELECT MIN(C_PeriodControl_ID) "
                         + "FROM C_PeriodControl pc3 "
                         + "GROUP BY C_Period_ID, DocBaseType)";
            int no = DataBase.DB.ExecuteQuery(sql, null, trxName);

            _log.Info("Duplicates deleted #" + no);

            //	Insert Missing
            sql = "SELECT DISTINCT p.AD_Client_ID, p.AD_Org_ID, p.C_Period_ID, dt.DocBaseType "
                  + "FROM C_Period p"
                  + " FULL JOIN C_DocType dt ON (p.AD_Client_ID=dt.AD_Client_ID) "
                  + "WHERE p.AD_Client_ID='" + AD_Client_ID + "'"
                  + " AND NOT EXISTS"
                  + " (SELECT * FROM C_PeriodControl pc "
                  + "WHERE pc.C_Period_ID=p.C_Period_ID AND pc.DocBaseType=dt.DocBaseType)";
            IDataReader idr     = null;
            int         counter = 0;

            try
            {
                idr = DataBase.DB.ExecuteReader(sql, null, trxName);
                while (idr.Read())
                {
                    int    Client_ID   = Utility.Util.GetValueOfInt(idr[0].ToString());
                    int    Org_ID      = Utility.Util.GetValueOfInt(idr[1].ToString());     // Get Organization from Period
                    int    C_Period_ID = Utility.Util.GetValueOfInt(idr[2].ToString());
                    String DocBaseType = idr[3].ToString();
                    _log.Config("AD_Client_ID=" + Client_ID
                                + ", C_Period_ID=" + C_Period_ID + ", DocBaseType=" + DocBaseType);
                    //
                    MPeriodControl pc = new MPeriodControl(ctx, Client_ID, C_Period_ID, DocBaseType, trxName);
                    pc.SetAD_Org_ID(Org_ID);                // Set Organization of Period, on Period Control.
                    if (pc.Save())
                    {
                        counter++;
                        _log.Fine(pc.ToString());
                    }
                    else
                    {
                        _log.Warning("Not saved: " + pc);
                    }
                }
                idr.Close();
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                _log.Log(Level.SEVERE, sql, e);
            }

            if (sp != null)
            {
                sp.AddLog(0, null, (Decimal)counter, "@C_PeriodControl_ID@ @Created@");
            }
            _log.Info("Inserted #" + counter);
        }       //	createPeriodControls