Beispiel #1
0
        /// <summary>
        /// Is Period Open for Doc Base Type in selected Organization
        /// </summary>
        /// <param name="DocBaseType">document base type</param>
        /// <param name="dateAcct">accounting date</param>
        /// <returns>error message or null</returns>
        /// <date>07-March-2011</date>
        /// <writer>raghu</writer>
        public String IsOpen(String DocBaseType, DateTime?dateAcct, int AD_Org_ID)
        {
            if (!IsActive())
            {
                _log.Warning("Period not active: " + GetName());
                return("@C_Period_ID@ <> @IsActive@");
            }

            MAcctSchema as1 = null;

            if (AD_Org_ID > 0)
            {
                as1 = MOrg.Get(GetCtx(), AD_Org_ID).GetAcctSchema();
            }
            else
            {
                as1 = MClient.Get(GetCtx(), GetAD_Client_ID()).GetAcctSchema();
            }
            if (as1 != null && as1.IsAutoPeriodControl())
            {
                if (!as1.IsAutoPeriodControlOpen(dateAcct))
                {
                    return("@PeriodClosed@ - @AutoPeriodControl@");
                }
                //	We are OK
                DateTime today = DateTime.Now.Date;
                if (IsInPeriod(today) && as1.GetC_Period_ID() != GetC_Period_ID())
                {
                    as1.SetC_Period_ID(GetC_Period_ID());
                    as1.Save();
                }
                return(null);
            }

            //	Standard Period Control
            if (DocBaseType == null)
            {
                log.Warning(GetName() + " - No DocBaseType");
                return("@NotFound@ @DocBaseType@");
            }
            MPeriodControl pc = GetPeriodControl(DocBaseType, AD_Org_ID);

            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 + ")");
        }
Beispiel #2
0
        /// <summary>
        /// Is Period Open for Doc Base Type
        /// </summary>
        /// <param name="docBaseType">document base type</param>
        /// <returns>true if open</returns>
        public bool IsOpen(String docBaseType)
        {
            if (!IsActive())
            {
                _log.Warning("Period not active: " + GetName());
                return(false);
            }

            MAcctSchema mas = MClient.Get(GetCtx(), GetAD_Client_ID()).GetAcctSchema();

            if (mas != null && mas.IsAutoPeriodControl())
            {
                //	if (as.getC_Period_ID() == getC_Period_ID())
                //		return true;
                DateTime today = DateTime.Now;// new DateTime(CommonFunctions.CurrentTimeMillis());
                DateTime first = TimeUtil.AddDays(today, -mas.GetPeriod_OpenHistory());
                DateTime last  = TimeUtil.AddDays(today, mas.GetPeriod_OpenFuture());
                //if (today.before(first))
                if (today < first)
                {
                    log.Warning("Today before first day - " + first);
                    return(false);
                }
                //if (today.after(last))
                if (today > last)
                {
                    log.Warning("Today after last day - " + first);
                    return(false);
                }
                //	We are OK
                if (IsInPeriod(today))
                {
                    mas.SetC_Period_ID(GetC_Period_ID());
                    mas.Save();
                }
                return(true);
            }

            //	Standard Period Control
            if (docBaseType == null)
            {
                log.Warning(GetName() + " - No DocBaseType");
                return(false);
            }
            MPeriodControl pc = GetPeriodControl(docBaseType);

            if (pc == null)
            {
                log.Warning(GetName() + " - Period Control not found for " + docBaseType);
                return(false);
            }
            log.Fine(GetName() + ": " + docBaseType);
            return(pc.IsOpen());
        }
Beispiel #3
0
        /// <summary>
        /// Is used to check costing method belongs to PO costing method  like (Average PO, Weighted Average PO or Last PO)
        /// Firts we check costing method on Product category, if not found then we will check on Primary Accounting Schema
        /// </summary>
        /// <param name="ctx">current context</param>
        /// <param name="AD_Client_ID">Client reference</param>
        /// <param name="M_Product_ID">Product whom costing method is to be determine</param>
        /// <param name="trxName">Transaction</param>
        /// <returns>True/False</returns>
        public static bool IsPOCostingmethod(Ctx ctx, int AD_Client_ID, int M_Product_ID, Trx trxName)
        {
            MProductCategory pc = null;
            bool             isPOcostingMethod = false;
            string           costingMethod     = null;
            MClient          client            = MClient.Get(ctx, AD_Client_ID);
            MProduct         product           = MProduct.Get(ctx, M_Product_ID);

            if (product != null)
            {
                pc = MProductCategory.Get(product.GetCtx(), product.GetM_Product_Category_ID());
                if (pc != null)
                {
                    // check costing method from product category
                    costingMethod = pc.GetCostingMethod();
                    if (costingMethod == "C")
                    {
                        costingMethod = Util.GetValueOfString(DB.ExecuteScalar(@"SELECT costingmethod FROM M_CostElement WHERE M_CostElement_ID IN 
                                        (SELECT CAST(M_Ref_CostElement AS INTEGER) FROM M_CostElementLine WHERE M_CostElement_ID=" + pc.GetM_CostElement_ID() + @" )
                                        AND CostingMethod IS NOT NULL", null, trxName));
                    }
                }
                if (String.IsNullOrEmpty(costingMethod))
                {
                    // check costing method against primary accounting schema
                    MClientInfo clientInfo = MClientInfo.Get(ctx, AD_Client_ID);
                    MAcctSchema actSchema  = MAcctSchema.Get(ctx, clientInfo.GetC_AcctSchema1_ID());
                    if (actSchema != null)
                    {
                        costingMethod = actSchema.GetCostingMethod();
                        if (costingMethod == "C")
                        {
                            costingMethod = Util.GetValueOfString(DB.ExecuteScalar(@"SELECT costingmethod FROM M_CostElement WHERE M_CostElement_ID IN 
                                        (SELECT CAST(M_Ref_CostElement AS INTEGER) FROM M_CostElementLine WHERE M_CostElement_ID=" + actSchema.GetM_CostElement_ID() + @" )
                                        AND CostingMethod IS NOT NULL", null, trxName));
                        }
                    }
                }
            }
            if (costingMethod.Equals(COSTINGMETHOD_WeightedAveragePO) ||
                costingMethod.Equals(COSTINGMETHOD_AveragePO) ||
                costingMethod.Equals(COSTINGMETHOD_LastPOPrice))
            {
                isPOcostingMethod = true;
            }
            else
            {
                isPOcostingMethod = false;
            }

            return(isPOcostingMethod);
        }
        /// <summary>
        ///     Send RfQ, mail subject and body from mail template
        /// </summary>
        /// <returns>true if RfQ is sent per email.</returns>
        public bool SendRfQ()
        {
            try
            {
                MUser     to     = MUser.Get(GetCtx(), GetAD_User_ID());
                MClient   client = MClient.Get(GetCtx());
                MMailText mtext  = new MMailText(GetCtx(), GetRfQ().GetR_MailText_ID(), Get_TrxName());

                if (to.Get_ID() == 0 || to.GetEMail() == null || to.GetEMail().Length == 0)
                {
                    log.Log(Level.SEVERE, "No User or no EMail - " + to);
                    return(false);
                }

                // Check if mail template is set for RfQ window, if not then get from RfQ Topic window.
                if (mtext.GetR_MailText_ID() == 0)
                {
                    MRfQTopic mRfQTopic = new MRfQTopic(GetCtx(), GetRfQ().GetC_RfQ_Topic_ID(), Get_TrxName());
                    if (mRfQTopic.GetC_RfQ_Topic_ID() > 0)
                    {
                        mtext = new MMailText(GetCtx(), mRfQTopic.GetR_MailText_ID(), Get_TrxName());
                    }
                }

                //Replace the email template constants with tables values.
                StringBuilder message = new StringBuilder();
                mtext.SetPO(GetRfQ(), true);
                message.Append(mtext.GetMailText(true).Equals(string.Empty) ? "** No Email Body" : mtext.GetMailText(true));

                String subject = String.IsNullOrEmpty(mtext.GetMailHeader()) ? "** No Subject" : mtext.GetMailHeader();;

                EMail email = client.CreateEMail(to.GetEMail(), to.GetName(), subject, message.ToString());
                if (email == null)
                {
                    return(false);
                }
                email.AddAttachment(CreatePDF());
                if (EMail.SENT_OK.Equals(email.Send()))
                {
                    //SetDateInvited(new Timestamp(System.currentTimeMillis()));
                    SetDateInvited(DateTime.Now);
                    Save();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                log.Severe(ex.ToString());
                //MessageBox.Show("error--" + ex.ToString());
            }
            return(false);
        }
        /// <summary>
        /// This function is used to get Accounting Schema either binded on Organization or Primary Accounting SChema
        /// </summary>
        /// <param name="ctx">ctx</param>
        /// <param name="Ad_Client_ID">AD_Client_ID</param>
        /// <param name="AD_Org_ID">Org ID</param>
        /// <returns>C_AcctSchema ID</returns>
        public static int GetDefaultActSchema(Ctx ctx, int Ad_Client_ID, int AD_Org_ID)
        {
            MAcctSchema acctSchema = null;

            if (AD_Org_ID > 0)
            {
                acctSchema = MOrg.Get(ctx, AD_Org_ID).GetAcctSchema();
            }
            if (acctSchema == null)
            {
                acctSchema = MClient.Get(ctx, Ad_Client_ID).GetAcctSchema();
            }
            return(acctSchema.GetC_AcctSchema_ID());
        }
Beispiel #6
0
 /// <summary>
 ///     Send RfQ
 /// </summary>
 /// <returns>true if RfQ is sent per email.</returns>
 public bool SendRfQ()
 {
     try
     {
         MUser to = MUser.Get(GetCtx(), GetAD_User_ID());
         if (to.Get_ID() == 0 || to.GetEMail() == null || to.GetEMail().Length == 0)
         {
             log.Log(Level.SEVERE, "No User or no EMail - " + to);
             return(false);
         }
         MClient client = MClient.Get(GetCtx());
         //
         String message = GetDescription();
         if (message == null || message.Length == 0)
         {
             message = GetHelp();
         }
         else if (GetHelp() != null)
         {
             message += "\n" + GetHelp();
         }
         if (message == null)
         {
             message = GetName();
         }
         //
         EMail email = client.CreateEMail(to.GetEMail(), to.GetName(), "RfQ: " + GetName(), message);
         if (email == null)
         {
             return(false);
         }
         email.AddAttachment(CreatePDF());
         if (EMail.SENT_OK.Equals(email.Send()))
         {
             //SetDateInvited(new Timestamp(System.currentTimeMillis()));
             SetDateInvited(DateTime.Now);
             Save();
             return(true);
         }
     }
     catch (Exception ex)
     {
         log.Severe(ex.ToString());
         //MessageBox.Show("error--" + ex.ToString());
     }
     return(false);
 }
Beispiel #7
0
        /// <summary>
        /// Load active Countries (no summary).
        /// Set Default Language to Client Language
        /// </summary>
        /// <param name="ctx">Ctx</param>
        private static void LoadAllCountries(Ctx ctx)
        {
            MClient   client = MClient.Get(ctx);
            MLanguage lang   = MLanguage.Get(ctx, client.GetAD_Language());
            MCountry  usa    = null;
            //

            int countryID = Util.GetValueOfInt(ctx.Get("P|C_Country_ID"));

            s_countries = new CCache <String, MCountry>("C_Country", 250);
            String sql = "SELECT * FROM C_Country WHERE IsActive='Y' AND IsSummary='N'";

            try
            {
                DataSet ds = DataBase.DB.ExecuteDataset(sql, null, null);
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow  dr = ds.Tables[0].Rows[i];
                    MCountry c  = new MCountry(ctx, dr, null);
                    s_countries.Add(c.GetC_Country_ID().ToString(), c);
                    //	Country code of Client Language
                    if (lang != null && lang.GetCountryCode().Equals(c.GetCountryCode()) && _default == null)
                    {
                        _default = c;
                    }
                    else if (countryID == c.GetC_Country_ID())
                    {
                        _default = c;
                    }
                    if (c.GetC_Country_ID() == 100)             //	USA
                    {
                        usa = c;
                    }
                }
            }
            catch (Exception e)
            {
                _log.Log(Level.SEVERE, sql, e);
            }
            if (_default == null)
            {
                _default = usa;
            }
            _log.Fine("#" + s_countries.Size()
                      + " - Default=" + _default);
        }
Beispiel #8
0
        /// <summary>
        /// Is standard Period Open for specified orgs for the client. For best
        /// performance, ensure that the list of orgs does not contain duplicates.
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="AD_Client_ID"></param>
        /// <param name="orgs"></param>
        /// <param name="DateAcct">accounting date</param>
        /// <param name="DocBaseType">document base type</param>
        /// <returns>error message or null</returns>
        /// <date>07-March-2011</date>
        /// <writer>raghu</writer>
        public static String IsOpen(Ctx ctx, int AD_Client_ID, List <int> orgs, DateTime?DateAcct,
                                    String DocBaseType)
        {
            if (DateAcct == null)
            {
                return("@NotFound@ @DateAcct@");
            }
            if (DocBaseType == null)
            {
                return("@NotFound@ @DocBaseType@");
            }

            MAcctSchema as1 = MClient.Get(ctx, AD_Client_ID).GetAcctSchema();

            if (as1 == null)
            {
                return("@NotFound@ @C_AcctSchema_ID@ for AD_Client_ID=" + AD_Client_ID);
            }
            if (as1.IsAutoPeriodControl())
            {
                if (as1.IsAutoPeriodControlOpen(DateAcct))
                {
                    return(null);
                }
                else
                {
                    return("@PeriodClosed@ - @AutoPeriodControl@");
                }
            }

            //	Get all Calendars in line with Organizations
            MClientInfo clientInfo   = MClientInfo.Get(ctx, AD_Client_ID, null);
            List <int>  orgCalendars = new List <int>();
            List <int>  calendars    = new List <int>();

            foreach (int org in 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.Count == 0)
            {
                return("@NotFound@ @C_Calendar_ID@");
            }

            //	For all Calendars get Periods
            for (int i = 0; i < calendars.Count; i++)
            {
                int     C_Calendar_ID = calendars[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.Count; j++)
                {
                    if (orgCalendars[j] == C_Calendar_ID)
                    {
                        AD_Org_ID = orgs[j];
                        break;
                    }
                }
                if (period == null)
                {
                    MCalendar cal  = MCalendar.Get(ctx, C_Calendar_ID);
                    String    date = DisplayType.GetDateFormat(DisplayType.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
        }
Beispiel #9
0
        }       //	beforeSave

        /// <summary>
        ///	Create EMail from Request User
        /// </summary>
        /// <param name="toEMail">recipient</param>
        /// <param name="toName">tomail</param>
        /// <param name="subject">subject</param>
        /// <param name="message">message</param>
        /// <returns>Email</returns>
        public EMail CreateEMail(String toEMail, String toName,
                                 String subject, String message)
        {
            if (toEMail == null || toEMail.Length == 0)
            {
                _log.Warning("No To");
                return(null);
            }

            //
            EMail   email  = null;
            MClient client = MClient.Get(GetCtx(), GetAD_Client_ID());

            if (client.IsServerEMail() && Ini.IsClient())
            {
                //MessageBox.Show("Get Connection Problem");
                //Server server = CConnection.get().getServer();

                try
                {
                    //if (server != null)
                    if (!DataBase.DB.IsConnected())
                    {
                        email = CreateEMail(toEMail, toName, subject, message);
                    }

                    //{	//	See ServerBean
                    //    email = server.CreateEMail(GetCtx(), GetAD_Client_ID(),
                    //        toEMail, toName, subject, message);

                    //}
                    else
                    {
                        log.Log(Level.WARNING, "No AppsServer");
                    }
                }
                catch (Exception ex)
                {
                    log.Log(Level.SEVERE, GetName() + " - AppsServer error", ex);
                }
            }
            String from = GetWStoreEMail();

            if (from == null || from.Length == 0)
            {
                from = client.GetRequestEMail();
            }
            if (email == null)
            {
                email = new EMail(client,
                                  from, client.GetName(), toEMail, toName,
                                  subject, message);
            }
            //	Authorizetion
            if (client.IsSmtpAuthorization())
            {
                if (GetWStoreEMail() != null && GetWStoreUser() != null && GetWStoreUserPW() != null)
                {
                    email.CreateAuthenticator(GetWStoreUser(), GetWStoreUserPW());
                }
                else
                {
                    email.CreateAuthenticator(client.GetRequestUser(), client.GetRequestUserPW());
                }
            }
            //	Bcc
            email.AddBcc(from);
            //
            return(email);
        }