/**** * Before Save. * - Set Name * @param newRecord new * @return save */ protected override bool BeforeSave(bool newRecord) { if (GetC_Location_ID() == 0) { return(false); } // Set New Name if (!newRecord) { return(true); } MLocation address = GetLocation(true); _uniqueName = GetName(); if (_uniqueName != null && _uniqueName.Equals(".")) // default { _uniqueName = null; } _unique = 0; MakeUnique(address); // Check uniqueness MBPartnerLocation[] locations = GetForBPartner(GetCtx(), GetC_BPartner_ID(), Get_TrxName()); bool unique = locations.Length == 0; while (!unique) { unique = true; for (int i = 0; i < locations.Length; i++) { MBPartnerLocation location = locations[i]; if (location.GetC_BPartner_Location_ID() == Get_ID()) { continue; } if (_uniqueName.Equals(location.GetName())) { MakeUnique(address); unique = false; break; } } } SetName(_uniqueName); return(true); }
/** * Create BP Location from Lead * @return error message */ private String CreateBPLocation() { if (GetC_BPartner_Location_ID() != 0 || GetC_Country_ID() == 0) // mandatory { return(null); } // Something to save if ((GetAddress1() != null && GetAddress1().Length > 0) || (GetPostal() != null && GetPostal().Length > 0) || (GetCity() != null && GetCity().Length > 0) || (GetRegionName() != null && GetRegionName().Length > 0) ) { ; } else { log.Fine("No BP Location Info to save"); return(null); } // Address MLocation location = new MLocation(GetCtx(), GetC_Country_ID(), GetC_Region_ID(), GetCity(), Get_TrxName()); location.SetAddress1(GetAddress1()); location.SetAddress2(GetAddress2()); location.SetPostal(GetPostal()); location.SetPostal_Add(GetPostal_Add()); location.SetRegionName(GetRegionName()); if (location.Save()) { MBPartnerLocation bpl = new MBPartnerLocation(_bp); bpl.SetC_Location_ID(location.GetC_Location_ID()); bpl.SetPhone(GetPhone()); bpl.SetPhone2(GetPhone2()); bpl.SetFax(GetFax()); bpl.SetC_SalesRegion_ID(GetC_SalesRegion_ID()); if (bpl.Save()) { SetC_BPartner_Location_ID(bpl.GetC_BPartner_Location_ID()); } } return(null); }
/**** * Before Save. * - Set Name * @param newRecord new * @return save */ protected override bool BeforeSave(bool newRecord) { if (GetC_Location_ID() == 0) { return(false); } if (VAdvantage.Utility.Env.IsModuleInstalled("VA077_")) { // Error if Customer Location No is not unique if (GetVA077_LocNo() != null) { string sql = @"SELECT C_BPartner_ID, VA077_IsMailAdd FROM C_BPartner_Location WHERE VA077_LocNo = '" + GetVA077_LocNo() + "' AND C_BPartner_Location_ID !=" + GetC_BPartner_Location_ID(); DataSet ds = DB.ExecuteDataset(sql, null, Get_Trx()); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows.Count == 1) { int PartnerID = Util.GetValueOfInt(ds.Tables[0].Rows[0]["C_BPartner_ID"]); bool value = Util.GetValueOfString(ds.Tables[0].Rows[0]["VA077_IsMailAdd"]).Equals("Y") ? true : false; if (value.Equals(IsVA077_IsMailAdd()) || PartnerID != GetC_BPartner_ID()) { log.SaveError("VA077_UniqueLocNo", ""); return(false); } } else { log.SaveError("VA077_UniqueLocNo", ""); return(false); } } } } // change by amit // Set New Name //if (!newRecord) // return true; if (Util.GetValueOfString(Get_ValueOld("Name")) == GetName() && Util.GetValueOfInt(Get_ValueOld("C_Location_ID")) == GetC_Location_ID()) { return(true); } MLocation address = GetLocation(true); _uniqueName.Append(GetName()); //if (_uniqueName != null && _uniqueName.Equals(".")) // default change by amit _uniqueName.Clear(); _unique = 0; // Changes Done By Vivek on 10/12/2015 //Set City Name at Name Field if (GetName() == ".") { MakeUnique(address); } //else Set Manually Edited Name by User at name field else { SetName(GetName()); return(true); } //if (Util.GetValueOfString(Get_ValueOld("Name")) != GetName()) //{ // _uniqueName = GetName(); // SetName(_uniqueName); // return true; //} //MakeUnique(address); // Check uniqueness MBPartnerLocation[] locations = GetForBPartner(GetCtx(), GetC_BPartner_ID(), Get_TrxName()); bool unique = locations.Length == 0; while (!unique) { unique = true; for (int i = 0; i < locations.Length; i++) { MBPartnerLocation location = locations[i]; if (location.GetC_BPartner_Location_ID() == Get_ID()) { continue; } if (_uniqueName.Equals(location.GetName())) { MakeUnique(address); unique = false; break; } } } SetName(_uniqueName.ToString()); return(true); }
/// <summary> /// Set BPartner /// </summary> /// <param name="bp">partner</param> /// <param name="isSOTrx">SO</param> public void SetBPartner(MBPartner bp, bool isSOTrx) { SetC_BPartner_ID(bp.GetC_BPartner_ID()); MBPartnerLocation[] locations = bp.GetLocations(false); // Location if (locations.Length == 1) { SetC_BPartner_Location_ID(locations[0].GetC_BPartner_Location_ID()); } else { for (int i = 0; i < locations.Length; i++) { MBPartnerLocation location = locations[i]; if (!location.IsActive()) { continue; } if ((location.IsPayFrom() && isSOTrx) || (location.IsRemitTo() && !isSOTrx)) { SetC_BPartner_Location_ID(location.GetC_BPartner_Location_ID()); break; } } } if (GetC_BPartner_Location_ID() == 0) { String msg = "@C_BPartner_ID@ " + bp.GetName(); if (isSOTrx) { msg += " @No@ @IsPayFrom@"; } else { msg += " @No@ @IsRemitTo@"; } throw new ArgumentException(msg); } // User with location MUser[] users = MUser.GetOfBPartner(GetCtx(), bp.GetC_BPartner_ID()); if (users.Length == 1) { SetAD_User_ID(users[0].GetAD_User_ID()); } else { for (int i = 0; i < users.Length; i++) { MUser user = users[i]; if (user.GetC_BPartner_Location_ID() == GetC_BPartner_Location_ID()) { SetAD_User_ID(users[i].GetAD_User_ID()); break; } } } // int SalesRep_ID = bp.GetSalesRep_ID(); if (SalesRep_ID != 0) { SetSalesRep_ID(SalesRep_ID); } }
/**** * Before Save. * - Set Name * @param newRecord new * @return save */ protected override bool BeforeSave(bool newRecord) { if (GetC_Location_ID() == 0) { return(false); } // change by amit // Set New Name //if (!newRecord) // return true; if (Util.GetValueOfString(Get_ValueOld("Name")) == GetName() && Util.GetValueOfInt(Get_ValueOld("C_Location_ID")) == GetC_Location_ID()) { return(true); } MLocation address = GetLocation(true); _uniqueName = GetName(); //if (_uniqueName != null && _uniqueName.Equals(".")) // default change by amit _uniqueName = null; _unique = 0; // Changes Done By Vivek on 10/12/2015 //Set City Name at Name Field if (GetName() == ".") { MakeUnique(address); } //else Set Manually Edited Name by User at name field else { SetName(GetName()); return(true); } //if (Util.GetValueOfString(Get_ValueOld("Name")) != GetName()) //{ // _uniqueName = GetName(); // SetName(_uniqueName); // return true; //} //MakeUnique(address); // Check uniqueness MBPartnerLocation[] locations = GetForBPartner(GetCtx(), GetC_BPartner_ID(), Get_TrxName()); bool unique = locations.Length == 0; while (!unique) { unique = true; for (int i = 0; i < locations.Length; i++) { MBPartnerLocation location = locations[i]; if (location.GetC_BPartner_Location_ID() == Get_ID()) { continue; } if (_uniqueName.Equals(location.GetName())) { MakeUnique(address); unique = false; break; } } } SetName(_uniqueName); return(true); }
/// <summary> /// Set BPartner /// </summary> /// <param name="bp">partner</param> /// <param name="isSOTrx">SO</param> public void SetBPartner(MBPartner bp, bool isSOTrx) { SetC_BPartner_ID(bp.GetC_BPartner_ID()); MBPartnerLocation[] locations = GetLocations(); // Location for (int i = 0; i < locations.Length; i++) { MBPartnerLocation location = locations[i]; if (!location.IsActive()) { continue; } if ((location.IsPayFrom() && isSOTrx) || (location.IsRemitTo() && !isSOTrx)) { SetC_BPartner_Location_ID(location.GetC_BPartner_Location_ID()); break; } } //} if (GetC_BPartner_Location_ID() == 0) { String msg = "@C_BPartner_ID@ " + bp.GetName(); if (isSOTrx) { msg += " @No@ @IsPayFrom@"; } else { msg += " @No@ @IsRemitTo@"; } //throw new ArgumentException(msg); log.SaveInfo("", msg); return; } // User with location // Change done by mohit to pick users sorted by date updated. 7 May 2019. MUser[] users = GetOfBPartner(GetCtx(), bp.GetC_BPartner_ID()); if (users.Length == 1) { if (users[0].IsEmail() || users[0].GetNotificationType() == MUser.NOTIFICATIONTYPE_EMail || users[0].GetNotificationType() == MUser.NOTIFICATIONTYPE_EMailPlusNotice || users[0].GetNotificationType() == MUser.NOTIFICATIONTYPE_EMailPlusFaxEMail) { SetAD_User_ID(users[0].GetAD_User_ID()); } } else { for (int i = 0; i < users.Length; i++) { MUser user = users[i]; if (user.GetC_BPartner_Location_ID() == GetC_BPartner_Location_ID() && (user.IsEmail() || user.GetNotificationType() == MUser.NOTIFICATIONTYPE_EMail || user.GetNotificationType() == MUser.NOTIFICATIONTYPE_EMailPlusNotice || user.GetNotificationType() == MUser.NOTIFICATIONTYPE_EMailPlusFaxEMail)) { SetAD_User_ID(users[i].GetAD_User_ID()); break; } } } // int SalesRep_ID = bp.GetSalesRep_ID(); if (SalesRep_ID != 0) { SetSalesRep_ID(SalesRep_ID); } }