// إنشاء العنوان
if (Data.parmCity() || Data.parmAddressDetail() || Data.parmBuildingNumber() || Data.parmDistrict())
{
DirPartyPostalAddressView postalAddressView;
DirPartyLocation partyLocationLocal;
DirPartyLocationRole partyLocationRole;
LogisticsLocationRole locationRole;
LogisticsAddressCountryRegion countryRegion;
CompanyInfo companyInfo;
RecId locationRecId;
str street = '';
// الحصول على شركة العميل
companyInfo = CompanyInfo::find();
if (companyInfo.DataArea != Data.parmCompany())
{
select firstonly companyInfo
where companyInfo.DataArea == Data.parmCompany();
}
// بناء الشارع
if (Data.parmAddressDetail())
{
street = Data.parmAddressDetail();
}
if (Data.parmBuildingNumber())
{
street = street ? strFmt("%1, %2", street, Data.parmBuildingNumber()) : Data.parmBuildingNumber();
}
if (Data.parmDistrict() && Data.parmDistrict() != 'NA')
{
street = street ? strFmt("%1, %2", street, Data.parmDistrict()) : Data.parmDistrict();
}
street = strLRTrim(street);
// الحصول على الدولة الافتراضية
select firstonly countryRegion;
// تجهيز PostalAddressView
postalAddressView.clear();
postalAddressView.initValue();
postalAddressView.Street = street;
postalAddressView.City = Data.parmCity();
postalAddressView.IsPrimary = NoYes::Yes;
if (countryRegion.RecId)
{
postalAddressView.CountryRegionId = countryRegion.CountryRegionId;
}
// إنشاء العنوان
dirParty.createOrUpdatePostalAddress(postalAddressView);
debugStep = "16. Address created";
// البحث عن PartyLocation
select firstonly partyLocationLocal
where partyLocationLocal.Party == custTable.Party
&& partyLocationLocal.IsPrimary == NoYes::Yes
&& partyLocationLocal.IsPostalAddress == NoYes::Yes;
if (partyLocationLocal.RecId)
{
// إضافة الأدوار
locationRole = LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Delivery);
if (locationRole.RecId)
{
select firstonly partyLocationRole
where partyLocationRole.PartyLocation == partyLocationLocal.RecId
&& partyLocationRole.LocationRole == locationRole.RecId;
if (!partyLocationRole.RecId)
{
partyLocationRole.clear();
partyLocationRole.initValue();
partyLocationRole.PartyLocation = partyLocationLocal.RecId;
partyLocationRole.LocationRole = locationRole.RecId;
partyLocationRole.insert();
}
}
locationRole = LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Invoice);
if (locationRole.RecId)
{
select firstonly partyLocationRole
where partyLocationRole.PartyLocation == partyLocationLocal.RecId
&& partyLocationRole.LocationRole == locationRole.RecId;
if (!partyLocationRole.RecId)
{
partyLocationRole.clear();
partyLocationRole.initValue();
partyLocationRole.PartyLocation = partyLocationLocal.RecId;
partyLocationRole.LocationRole = locationRole.RecId;
partyLocationRole.insert();
}
}
locationRole = LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Business);
if (locationRole.RecId)
{
select firstonly partyLocationRole
where partyLocationRole.PartyLocation == partyLocationLocal.RecId
&& partyLocationRole.LocationRole == locationRole.RecId;
if (!partyLocationRole.RecId)
{
partyLocationRole.clear();
partyLocationRole.initValue();
partyLocationRole.PartyLocation = partyLocationLocal.RecId;
partyLocationRole.LocationRole = locationRole.RecId;
partyLocationRole.insert();
}
}
debugStep = "17. Address roles added";
}
}