/// <summary> /// Parent Constructor /// </summary> /// <param name="client">client</param> /// <param name="name">name</param> public MOrg(MClient client, String name) : this(client.GetCtx(), 0, client.Get_Trx()) { SetAD_Client_ID(client.GetAD_Client_ID()); SetValue(name); SetName(name); }
/// <summary> /// /// </summary> /// <param name="client"></param> /// <param name="currency"></param> public MAcctSchema(MClient client, KeyNamePair currency) : this(client.GetCtx(), 0, client.Get_TrxName()) { SetClientOrg(client); SetC_Currency_ID(currency.GetKey()); SetName(client.GetName() + " " + GetGAAP() + "/" + Get_ColumnCount() + " " + currency.GetName()); } // MAcctSchema
/// <summary> /// Parent Constructor /// </summary> /// <param name="client">parent</param> /// <param name="Supervisor_ID">admin</param> public MAcctProcessor(MClient client, int Supervisor_ID) : this(client.GetCtx(), 0, client.Get_TrxName()) { SetClientOrg(client); SetName(client.GetName() + " - " + Msg.Translate(GetCtx(), "C_AcctProcessor_ID")); SetSupervisor_ID(Supervisor_ID); }
/// <summary> /// Parent Constructor /// </summary> /// <param name="parent"></param> /// <param name="Supervisor_ID"></param> public MRequestProcessor(MClient parent, int Supervisor_ID) : this(parent.GetCtx(), 0, parent.Get_TrxName()) { SetClientOrg(parent); SetName(parent.GetName() + " - " + Msg.Translate(GetCtx(), "R_RequestProcessor_ID")); SetSupervisor_ID(Supervisor_ID); }
/// <summary> ///Full Constructor /// </summary> /// <param name="client">client</param> /// <param name="Name">name</param> /// <param name="ElementType">type</param> /// <param name="AD_Tree_ID">tree</param> public MElement(MClient client, string name, string elementType, int AD_Tree_ID) : this(client.GetCtx(), 0, client.Get_TrxName()) { SetClientOrg(client); SetName(name); SetElementType(elementType); // A SetAD_Tree_ID(AD_Tree_ID); SetIsNaturalAccount(ELEMENTTYPE_Account.Equals(elementType)); }
} // get /// <summary> /// Get active Web Stores of Clieny /// </summary> /// <param name="client">client</param> /// <returns>array of web stores</returns> public static MStore[] GetOfClient(MClient client) { //ArrayList<MStore> list = new ArrayList<MStore>(); List <MStore> list = new List <MStore>(); String sql = "SELECT * FROM W_Store WHERE AD_Client_ID=@Param1 AND IsActive='Y'"; SqlParameter[] Param = new SqlParameter[1]; DataTable dt = null; IDataReader idr = null; try { Param[0] = new SqlParameter("@Param1", client.GetAD_Client_ID()); idr = DataBase.DB.ExecuteReader(sql, Param, client.Get_TrxName()); dt = new DataTable(); dt.Load(idr); idr.Close(); foreach (DataRow dr in dt.Rows) { list.Add(new MStore(client.GetCtx(), dr, client.Get_TrxName())); } } //PreparedStatement pstmt = null; //try //{ // pstmt = DataBase.prepareStatement (sql, client.get_TrxName()); // pstmt.setInt (1, client.getAD_Client_ID()); // ResultSet rs = pstmt.executeQuery (); // while (rs.next ()) // list.add (new MStore (client.getCtx(), rs, client.get_TrxName())); // rs.close (); // pstmt.close (); // pstmt = null; //} catch (Exception e) { if (idr != null) { idr.Close(); } _log.Log(Level.SEVERE, sql, e); } finally { dt = null; if (idr != null) { idr.Close(); } } // MStore[] retValue = new MStore[list.Count]; //list.toArray (retValue); retValue = list.ToArray(); return(retValue); } // getOfClient
/// <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 + ")"); }
/// <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()); }
/// <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()); }
/// <summary> /// Prepare - e.g., get Parameters. /// </summary> protected override void Prepare() { ProcessInfoParameter[] para = GetParameter(); foreach (ProcessInfoParameter element in para) { String name = element.GetParameterName(); if (element.GetParameter() == null) { ; } else if (name.Equals("A_Asset_Group_ID")) { _A_Asset_Group_ID = element.GetParameterAsInt(); } else if (name.Equals("M_Product_ID")) { _M_Product_ID = element.GetParameterAsInt(); } else if (name.Equals("C_BPartner_ID")) { _C_BPartner_ID = element.GetParameterAsInt(); } else if (name.Equals("A_Asset_ID")) { _A_Asset_ID = element.GetParameterAsInt(); } else if (name.Equals("GuaranteeDate")) { _GuaranteeDate = (DateTime?)element.GetParameter(); } else if (name.Equals("NoGuarantee_MailText_ID")) { _NoGuarantee_MailText_ID = element.GetParameterAsInt(); } else if (name.Equals("AttachAsset")) { _AttachAsset = "Y".Equals(element.GetParameter()); } else { log.Log(Level.SEVERE, "Unknown Parameter: " + name); } } if (_GuaranteeDate == null) { _GuaranteeDate = DateTime.Now; //( new Timestamp (System.currentTimeMillis()); } // _client = VAdvantage.Model.MClient.Get(GetCtx()); } // prepare
} // authenticateAsset /// <summary> /// Find Client /// </summary> /// <param name="client">client name</param> /// <returns>AD_Client_ID</returns> private int FindClient(String client) { if (_clients == null) { _clients = MClient.GetAll(GetCtx()); } for (int i = 0; i < _clients.Length; i++) { if (client.ToLower().Equals(_clients[i].GetValue().ToLower()))// client.equalsIgnoreCase (_clients[i].GetValue()))) { return(_clients[i].GetAD_Client_ID()); } } return(0); } // findClient
/// <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); }
/// <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); }
/// <summary> ///Get client /// </summary> /// <param name="ctx">context</param> /// <param name="AD_Client_ID">id</param> /// <returns>client</returns> public static MClient Get(Ctx ctx, int AD_Client_ID) { int key = AD_Client_ID; MClient client = (MClient)s_cache[key]; if (client != null) { return(client); } client = new MClient(ctx, AD_Client_ID, null); if (AD_Client_ID == 0) { client.Load((Trx)null); } s_cache.Add(key, client); return(client); }
} // MClientInfo /// <summary> ///Parent Constructor /// </summary> /// <param name="client">client</param> /// <param name="AD_Tree_Org_ID">org tree</param> /// <param name="AD_Tree_BPartner_ID">bp tree</param> /// <param name="AD_Tree_Project_ID">project tree</param> /// <param name="AD_Tree_SalesRegion_ID">sr tree</param> /// <param name="AD_Tree_Product_ID">product tree</param> /// <param name="AD_Tree_Campaign_ID">campaign tree</param> /// <param name="AD_Tree_Activity_ID">activity tree</param> /// <param name="trxName">transaction</param> public MClientInfo(MClient client, int AD_Tree_Org_ID, int AD_Tree_BPartner_ID, int AD_Tree_Project_ID, int AD_Tree_SalesRegion_ID, int AD_Tree_Product_ID, int AD_Tree_Campaign_ID, int AD_Tree_Activity_ID, Trx trxName) : base(client.GetCtx(), 0, trxName) { //super(client.getCtx(), 0, trxName); SetAD_Client_ID(client.GetAD_Client_ID()); // to make sure SetAD_Org_ID(0); SetIsDiscountLineAmt(false); // SetAD_Tree_Menu_ID(10); // HARDCODED // SetAD_Tree_Org_ID(AD_Tree_Org_ID); SetAD_Tree_BPartner_ID(AD_Tree_BPartner_ID); SetAD_Tree_Project_ID(AD_Tree_Project_ID); SetAD_Tree_SalesRegion_ID(AD_Tree_SalesRegion_ID); SetAD_Tree_Product_ID(AD_Tree_Product_ID); SetAD_Tree_Campaign_ID(AD_Tree_Campaign_ID); SetAD_Tree_Activity_ID(AD_Tree_Activity_ID); // SetMatchRequirementI(MATCHREQUIREMENTI_None); SetMatchRequirementR(MATCHREQUIREMENTR_None); _createNew = true; }
/// <summary> /// Get all clients /// </summary> /// <param name="ctx">context</param> /// <returns>clients</returns> public static MClient[] GetAll(Ctx ctx) { List <MClient> list = new List <MClient>(); String sql = "SELECT * FROM AD_Client"; try { DataSet ds = DataBase.DB.ExecuteDataset(sql, null, null); foreach (DataRow dr in ds.Tables[0].Rows) { MClient client = new MClient(ctx, dr, null); list.Add(client); } } catch (Exception e) { s_log.Log(Level.SEVERE, sql, e); } MClient[] RetValue = new MClient[list.Count()]; RetValue = list.ToArray(); return(RetValue); } // getAll
/// <summary> /// Parent Constructor /// </summary> /// <param name="client">parent</param> public MCalendar(MClient client) : base(client.GetCtx(), 0, client.Get_TrxName()) { SetClientOrg(client); SetName(client.GetName() + " " + Utility.Msg.Translate(client.GetCtx(), "C_Calendar_ID")); }
} // 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); }
/// <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 }