/// <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); } }
/// <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); } }