/// <summary> /// Organization constructor /// </summary> /// <param name="org">org</param> public MOrgInfo(MOrg org) : base(org.GetCtx(), 0, org.Get_TrxName()) { SetClientOrg(org); SetDUNS("?"); SetTaxID("?"); }
/// <summary> /// Skip creating postings for this Org. /// Requires setOnlyOrgs (MReportTree requires MTree in Basis) /// </summary> /// <param name="AD_Org_ID"></param> /// <returns>true if to skip</returns> public bool IsSkipOrg(int AD_Org_ID) { if (GetAD_OrgOnly_ID() == 0) { return(false); } // Only Organization if (GetAD_OrgOnly_ID() == AD_Org_ID) { return(false); } if (_onlyOrg == null) { _onlyOrg = MOrg.Get(GetCtx(), GetAD_OrgOnly_ID()); } // Not Summary Only - i.e. skip it if (!_onlyOrg.IsSummary()) { return(true); } if (_onlyOrgs == null) { return(false); } for (int i = 0; i < _onlyOrgs.Length; i++) { if (AD_Org_ID == Utility.Util.GetValueOfInt(_onlyOrgs[i])) { return(false); } } return(true); }
} // setM_Product_ID /// <summary> /// Set (default) Locator based on qty. /// /// </summary> /// <param name="Qty">Qty quantity</param> public void SetM_Locator_ID(Decimal Qty) { // Locator established if (GetM_Locator_ID() != 0) { return; } // No Product if (GetM_Product_ID() == 0) { Set_ValueNoCheck("M_Locator_ID", null); return; } VAdvantage.Model.MOrg org = new VAdvantage.Model.MOrg(GetCtx(), GetAD_Org_ID(), Get_TrxName()); // Get existing Location int M_Locator_ID = VAdvantage.Model.MStorage.GetM_Locator_ID(org.GetM_Warehouse_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Qty, Get_TrxName()); // Get default Location if (M_Locator_ID == 0) { VAdvantage.Model.MProduct product = VAdvantage.Model.MProduct.Get(GetCtx(), GetM_Product_ID()); M_Locator_ID = VAdvantage.Model.MProductLocator.GetFirstM_Locator_ID(product, org.GetM_Warehouse_ID()); if (M_Locator_ID == 0) { VAdvantage.Model.MWarehouse wh = VAdvantage.Model.MWarehouse.Get(GetCtx(), org.GetM_Warehouse_ID()); M_Locator_ID = wh.GetDefaultM_Locator_ID(); } } base.SetM_Locator_ID(M_Locator_ID); } // setM_Locator_ID
/// <summary> /// Get Organizations Of Client /// </summary> /// <param name="po">persistent object</param> /// <returns>array of orgs</returns> public static MOrg[] GetOfClient(PO po) { List <MOrg> list = new List <MOrg>(); String sql = "SELECT * FROM AD_Org WHERE AD_Client_ID=" + po.GetAD_Client_ID() + " ORDER BY Value"; try { DataSet ds = DataBase.DB.ExecuteDataset(sql, null, null); if (ds.Tables.Count > 0) { DataRow dr = null; int totCount = ds.Tables[0].Rows.Count; for (int i = 0; i < totCount; i++) { dr = ds.Tables[0].Rows[i]; list.Add(new MOrg(po.GetCtx(), dr, null)); } } } catch (Exception e) { _log.Log(Level.SEVERE, sql, e); } MOrg[] retValue = new MOrg[list.Count]; retValue = list.ToArray(); return(retValue); }
} // MUserOrgAccess /// <summary> /// Organization Constructor /// </summary> /// <param name="org">org</param> /// <param name="AD_User_ID"> role</param> public MUserOrgAccess(MOrg org, int AD_User_ID) : this(org.GetCtx(), 0, org.Get_TrxName()) { //this (org.GetCtx(), 0, org.Get_TrxName()); SetClientOrg(org); SetAD_User_ID(AD_User_ID); } // MUserOrgAccess
/// <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> /// Organization Constructor /// </summary> /// <param name="org">org</param> public MWarehouse(MOrg org) : this(org.GetCtx(), 0, org.Get_TrxName()) { SetClientOrg(org); SetValue(org.GetValue()); SetName(org.GetName()); if (org.GetInfo() != null) { SetC_Location_ID(org.GetInfo().GetC_Location_ID()); } }
/// <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> /// Create Organizational Access for all Automatic Roles /// </summary> /// <param name="org">org</param> /// <returns>true if created</returns> public static bool CreateForOrg(MOrg org) { int counter = 0; MRole[] roles = MRole.GetOfClient(org.GetCtx()); for (int i = 0; i < roles.Length; i++) { if (!roles[i].IsManual()) { MRoleOrgAccess orgAccess = new MRoleOrgAccess(org, roles[i].GetAD_Role_ID()); if (orgAccess.Save()) { counter++; } } } _log.Info(org + " - created #" + counter); return(counter != 0); }
//Amit /** * Standard Constructor * @param ctx context * @param C_Cash_ID id * @param trxName transaction */ public MCash(Ctx ctx, int C_Cash_ID, Trx trxName) : base(ctx, C_Cash_ID, trxName) { if (C_Cash_ID == 0) { // setC_CashBook_ID (0); // FK SetBeginningBalance(Env.ZERO); SetEndingBalance(Env.ZERO); SetStatementDifference(Env.ZERO); SetDocAction(DOCACTION_Complete); SetDocStatus(DOCSTATUS_Drafted); // DateTime today = TimeUtil.GetDay(DateTime.Now); SetStatementDate(today); // @#Date@ SetDateAcct(today); // @#Date@ //String name = DisplayType.getDateFormat(DisplayType.Date).format(today) + " " + MOrg.Get(ctx, GetAD_Org_ID()).GetValue(); String name = String.Format("{0:d}", today) + " " + MOrg.Get(ctx, GetAD_Org_ID()).GetValue(); SetName(name); SetIsApproved(false); SetPosted(false); // N SetProcessed(false); } }
/// <summary> /// Get Org from Cache /// </summary> /// <param name="ctx">context</param> /// <param name="AD_Org_ID">id</param> /// <returns>MOrg</returns> public static MOrg Get(Ctx ctx, int AD_Org_ID) { int key = AD_Org_ID; MOrg retValue = null; if (cache.ContainsKey(key)) { retValue = (MOrg)cache[key]; } if (retValue != null) { return(retValue); } retValue = new MOrg(ctx, AD_Org_ID, null); if (AD_Org_ID == 0) { retValue.Load((Trx)null); } if (retValue.Get_ID() != AD_Org_ID) { cache.Add(key, retValue); } return(retValue); }
} // setC_Charge_ID /// <summary> /// Calculate Tax /// </summary> /// <param name="windowNo"></param> /// <param name="columnName"></param> private void SetTax(int windowNo, String columnName) { int C_Charge_ID = GetC_Charge_ID(); log.Fine("C_Charge_ID=" + C_Charge_ID); if (C_Charge_ID == 0) { SetAmt(windowNo, columnName); return; } // Check Partner Location int C_BPartner_Location_ID = GetC_BPartner_Location_ID(); log.Fine("BP_Location=" + C_BPartner_Location_ID); if (C_BPartner_Location_ID == 0) { SetAmt(windowNo, columnName); return; } // Dates DateTime?billDate = GetDateInvoiced(); log.Fine("Bill Date=" + billDate); DateTime?shipDate = billDate; log.Fine("Ship Date=" + shipDate); int AD_Org_ID = GetAD_Org_ID(); log.Fine("Org=" + AD_Org_ID); MOrg org = MOrg.Get(GetCtx(), AD_Org_ID); int M_Warehouse_ID = org.GetM_Warehouse_ID(); log.Fine("Warehouse=" + M_Warehouse_ID); Boolean isSOTrx = GetCtx().IsSOTrx(windowNo); // int C_Tax_ID = Tax.Get(GetCtx(), 0, C_Charge_ID, billDate, shipDate, AD_Org_ID, M_Warehouse_ID, C_BPartner_Location_ID, C_BPartner_Location_ID, isSOTrx); log.Info("Tax ID=" + C_Tax_ID + " - SOTrx=" + isSOTrx); if (C_Tax_ID == 0) { //ValueNamePair pp = CLogger.retrieveError(); //if (pp != null) //{ //p_changeVO.addError(pp.getValue()); //} //else //{ //p_changeVO.addError("Tax Error"); //} } else { base.SetC_Tax_ID(C_Tax_ID); } SetAmt(windowNo, columnName); }
/// <summary> /// Set Value and Description and Fully Qualified Flag for Combination /// </summary> public void SetValueDescription() { StringBuilder combi = new StringBuilder(); StringBuilder descr = new StringBuilder(); bool fullyQualified = true; // MAcctSchema as1 = new MAcctSchema(GetCtx(), GetC_AcctSchema_ID(), Get_TrxName()); // In Trx! MAcctSchemaElement[] elements = MAcctSchemaElement.GetAcctSchemaElements(as1); for (int i = 0; i < elements.Length; i++) { if (i > 0) { combi.Append(as1.GetSeparator()); descr.Append(as1.GetSeparator()); } MAcctSchemaElement element = elements[i]; String combiStr = "_"; // not defined String descrStr = "_"; if (MAcctSchemaElement.ELEMENTTYPE_Organization.Equals(element.GetElementType())) { if (GetAD_Org_ID() != 0) { MOrg org = new MOrg(GetCtx(), GetAD_Org_ID(), Get_TrxName()); // in Trx! combiStr = org.GetValue(); descrStr = org.GetName(); } else { combiStr = "*"; descrStr = "*"; fullyQualified = false; } } else if (MAcctSchemaElement.ELEMENTTYPE_Account.Equals(element.GetElementType())) { if (GetAccount_ID() != 0) { if (_accountEV == null) { _accountEV = new MElementValue(GetCtx(), GetAccount_ID(), Get_TrxName()); } combiStr = _accountEV.GetValue(); descrStr = _accountEV.GetName(); } else if (element.IsMandatory()) { //log.warning("Mandatory Element missing: Account"); fullyQualified = false; } } else if (MAcctSchemaElement.ELEMENTTYPE_SubAccount.Equals(element.GetElementType())) { if (GetC_SubAcct_ID() != 0) { X_C_SubAcct sa = new X_C_SubAcct(GetCtx(), GetC_SubAcct_ID(), Get_TrxName()); combiStr = sa.GetValue(); descrStr = sa.GetName(); } } else if (MAcctSchemaElement.ELEMENTTYPE_Product.Equals(element.GetElementType())) { if (GetM_Product_ID() != 0) { X_M_Product product = new X_M_Product(GetCtx(), GetM_Product_ID(), Get_TrxName()); combiStr = product.GetValue(); descrStr = product.GetName(); } else if (element.IsMandatory()) { //log.warning("Mandatory Element missing: Product"); fullyQualified = false; } } else if (MAcctSchemaElement.ELEMENTTYPE_BPartner.Equals(element.GetElementType())) { if (GetC_BPartner_ID() != 0) { X_C_BPartner partner = new X_C_BPartner(GetCtx(), GetC_BPartner_ID(), Get_TrxName()); combiStr = partner.GetValue(); descrStr = partner.GetName(); } else if (element.IsMandatory()) { //log.warning("Mandatory Element missing: Business Partner"); fullyQualified = false; } } else if (MAcctSchemaElement.ELEMENTTYPE_OrgTrx.Equals(element.GetElementType())) { if (GetAD_OrgTrx_ID() != 0) { MOrg org = new MOrg(GetCtx(), GetAD_OrgTrx_ID(), Get_TrxName()); // in Trx! combiStr = org.GetValue(); descrStr = org.GetName(); } else if (element.IsMandatory()) { //log.warning("Mandatory Element missing: Trx Org"); fullyQualified = false; } } else if (MAcctSchemaElement.ELEMENTTYPE_LocationFrom.Equals(element.GetElementType())) { if (GetC_LocFrom_ID() != 0) { MLocation loc = new MLocation(GetCtx(), GetC_LocFrom_ID(), Get_TrxName()); // in Trx! combiStr = loc.GetPostal(); descrStr = loc.GetCity(); } else if (element.IsMandatory()) { //log.warning("Mandatory Element missing: Location From"); fullyQualified = false; } } else if (MAcctSchemaElement.ELEMENTTYPE_LocationTo.Equals(element.GetElementType())) { if (GetC_LocTo_ID() != 0) { MLocation loc = new MLocation(GetCtx(), GetC_LocFrom_ID(), Get_TrxName()); // in Trx! combiStr = loc.GetPostal(); descrStr = loc.GetCity(); } else if (element.IsMandatory()) { //log.warning("Mandatory Element missing: Location To"); fullyQualified = false; } } else if (MAcctSchemaElement.ELEMENTTYPE_SalesRegion.Equals(element.GetElementType())) { if (GetC_SalesRegion_ID() != 0) { MSalesRegion loc = new MSalesRegion(GetCtx(), GetC_SalesRegion_ID(), Get_TrxName()); combiStr = loc.GetValue(); descrStr = loc.GetName(); } else if (element.IsMandatory()) { //log.warning("Mandatory Element missing: SalesRegion"); fullyQualified = false; } } else if (MAcctSchemaElement.ELEMENTTYPE_Project.Equals(element.GetElementType())) { if (GetC_Project_ID() != 0) { X_C_Project project = new X_C_Project(GetCtx(), GetC_Project_ID(), Get_TrxName()); combiStr = project.GetValue(); descrStr = project.GetName(); } else if (element.IsMandatory()) { //log.warning("Mandatory Element missing: Project"); fullyQualified = false; } } else if (MAcctSchemaElement.ELEMENTTYPE_Campaign.Equals(element.GetElementType())) { if (GetC_Campaign_ID() != 0) { X_C_Campaign campaign = new X_C_Campaign(GetCtx(), GetC_Campaign_ID(), Get_TrxName()); combiStr = campaign.GetValue(); descrStr = campaign.GetName(); } else if (element.IsMandatory()) { //log.warning("Mandatory Element missing: Campaign"); fullyQualified = false; } } else if (MAcctSchemaElement.ELEMENTTYPE_Activity.Equals(element.GetElementType())) { if (GetC_Activity_ID() != 0) { X_C_Activity act = new X_C_Activity(GetCtx(), GetC_Activity_ID(), Get_TrxName()); combiStr = act.GetValue(); descrStr = act.GetName(); } else if (element.IsMandatory()) { //log.warning("Mandatory Element missing: Campaign"); fullyQualified = false; } } else if (MAcctSchemaElement.ELEMENTTYPE_UserList1.Equals(element.GetElementType())) { if (GetUser1_ID() != 0) { MElementValue ev = new MElementValue(GetCtx(), GetUser1_ID(), Get_TrxName()); combiStr = ev.GetValue(); descrStr = ev.GetName(); } } else if (MAcctSchemaElement.ELEMENTTYPE_UserList2.Equals(element.GetElementType())) { if (GetUser2_ID() != 0) { MElementValue ev = new MElementValue(GetCtx(), GetUser2_ID(), Get_TrxName()); combiStr = ev.GetValue(); descrStr = ev.GetName(); } } else if (MAcctSchemaElement.ELEMENTTYPE_UserElement1.Equals(element.GetElementType())) { if (GetUserElement1_ID() != 0) { } } else if (MAcctSchemaElement.ELEMENTTYPE_UserElement2.Equals(element.GetElementType())) { if (GetUserElement2_ID() != 0) { } } combi.Append(combiStr); descr.Append(descrStr); } // Set Values base.SetCombination(combi.ToString()); base.SetDescription(descr.ToString()); if (fullyQualified != IsFullyQualified()) { SetIsFullyQualified(fullyQualified); _log.Fine("Combination=" + GetCombination() + " - " + GetDescription() + " - FullyQualified=" + fullyQualified); } }
/// <summary> /// Organization Constructor /// </summary> /// <param name="org">org</param> /// <param name="AD_Role_ID">role id</param> public MRoleOrgAccess(MOrg org, int AD_Role_ID) : this(org.GetCtx(), 0, org.Get_TrxName()) { SetClientOrg(org); SetAD_Role_ID(AD_Role_ID); }
/// <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 }