importPackage(Packages.java.lang);
importPackage(Packages.java.util);
importPackage(Packages.ru.intertrust.cmj.af.so);
importPackage(Packages.ru.intertrust.cmj.rest.tuning);
importPackage(Packages.ru.intertrust.cmj.af.misc);
importPackage(Packages.ru.intertrust.cmj.af.utils);
importPackage(Packages.ru.intertrust.cmj.af.tuning.impl);
importClass(Packages.ru.intertrust.cmj.rest.tuning.TuningHelper);
importClass(Packages.java.lang.System);
importClass(Packages.ru.intertrust.cmj.tunable.object.common.TunableObjectHelper);
importClass(Packages.ru.intertrust.cmj.af.core.AFSession);
importClass(Packages.ru.intertrust.cmj.tunable.object.TunableObjectApplication);
importClass(Packages.ru.intertrust.cmj.tunable.object.AnyTunableObject);
importClass(Packages.ru.intertrust.cmj.af.core.AFCMDomino);
importClass(Packages.org.springframework.util.StringUtils);
importClass(Packages.ru.intertrust.cmj.af.so.SOApplication);
//Функция вызывается при изменении поля, в котором установлен флаг recalc = "true"
function recalc(object, changedField) {
if (changedField == "Correspondent") {
// Получение tn-объекта
var tuning = object.tuning();
//Обнуление полей
object.tuning().getValues().put("Phone", null);
object.tuning().getValues().put("SendAddress", null);
if (object.tuning().getValues().get('Correspondent') != null && object.tuning().getValues().get('Correspondent').getValue() != null) { //Поле Корреспондент не пустое
var correspondent = object.tuning().getValues().get('Correspondent').getValue(); //значение из поля Корреспондент
var emplAddrs = new ArrayList();
var emplPhones = new ArrayList(); Карта AFInstance текушего объекта
var values = tuning.getValues();
// Схема текущего объекта
var schema = tuning.getSchema();
// Название измененного поля
if (changedField == "Correspondent") {
// Обнуление полей
values.put("Index", null); //Индекс
values.put("Address", null); //Адрес
values.put("Recipient", null); //ФИО получателя
values.put("Phone", null); //Телефон
if (values.get('Correspondent') != null && values.get('Correspondent').getValue() != null) { // Поле Корреспондент не пустое
var correspondent = values.get('Correspondent').getValue(); // Значение из поля Корреспондент
if (correspondent.getAddress() != ""null) {
emplAddrs.add(correspondent.getAddress()); //заполняем адресПолучение изtn-объекта бородыкорреспондента
var }
if (correspondent.originalData().getType() == SOBeard.Type.NONSYS_ORGANIZATION) { appTNObject = AFSession.get().getApplication(TunableObjectApplication.class);
if (correspondent.originalData().getParty().addressInfo().legal().getAddress()var correspondentObject = appTNObject.getEntityByUNID(AFCMDomino.ormUnidToTNUnid(correspondent.getUNID()));
if (correspondentObject != ""null) {
emplAddrs.add(person.originalData().getParty().addressInfo().legal().getAddress());
}
}
// Формирование списка адресов
var emplAddrs = new ArrayList();
// Почтовый/физический адрес
if (!emplAddrscorrespondent.isEmptygetAddress() != "") {
TuningHelper.processProperty(object.tuning().getValues(), "all_address", emplAddrs, object.tuningadd().getSchema().getProperty("all_address"correspondent.getAddress());
}
var// fio = new ArrayList();
Юридический адрес
fio.add(personif (correspondent.originalData().getFullNamegetType());
== SOBeard.Type.NONSYS_ORGANIZATION) {
var fioValue = new AFInstanceArrayImpl(object.tuningif (correspondent.originalData().getSchemagetParty(), fio);
object.tuning.addressInfo().getValueslegal().putgetAddress() != "Recipient",) fioValue);
{
var appTNObject = AFSession.getemplAddrs.add(correspondent.originalData().getApplicationgetParty(TunableObjectApplication.class);
var objectBeard = appTNObject.getEntityByUNID(AFCMDomino.ormUnidToTNUnid(person.getUNID()));
var phoneH = objectBeard.tuning().getValues().get("phoneHouse");
.addressInfo().legal().getAddress()); //заполняем адрес для несистемных организаций
}
}
// Формирование списка телефонов
var phoneWemplPhones = objectBeard.tuning().getValues().get("phoneWork");
new ArrayList();
// Карта объектов AFInstance корреспондента
var phoneMcorrespondentValue = objectBeardcorrespondentObject.tuning().getValues().get("phoneMobil");
var phonephoneH = objectBeard.tuning().getValues()correspondentValue.get("phonephoneHouse");
emplPhones.add(phoneHvar phoneW = correspondentValue.get("phoneWork");
var phoneM = correspondentValue.get("phoneMobil");
emplPhones.add(phoneWvar phone = correspondentValue.get("phone");
emplPhones.add(phoneMphoneH);
if (phoneemplPhones.add(phoneW);
emplPhones.add(phoneM);
if (phone != null && phone.getValues() != null) {
emplPhones.addAll(phone.getValues());
}
// Вычисление телефона по умолчанию
var phoneValue;
if (phoneM != null) {
phoneValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("phoneMobil"));
phoneM);
} else if (phoneW != null) {
phoneValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("phoneWork")phoneW);
} else if (phoneH != null) {
phoneValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("phoneHouse")phoneM);
} else if (phone != null && objectBeard.tuning()phone.getValues().get("phone").getValues() ! != null) {
phoneValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("phone").getValues().get(0));
}
// Получатель
ifvar (phoneValuerecipientValue != new nullArrayList() {;
TuningHelperrecipientValue.processPropertyadd(objectcorrespondent.tuningoriginalData().getValues(), "Phone", phoneValue, object.tuning().getSchema().getProperty("Phone"getFullName());
}
if (!emplPhonescorrespondent.isEmptyoriginalData()) {
TuningHelper.processProperty(object.tuning.getType().toString().getValuesequals(), "allPRIVATE_phone", emplPhones, object.tuning().getSchema().getProperty("all_phone"));
}
if (objectBeard != null) {
if (person.originalData().getType().toString().equals("PRIVATE_HUMAN")) {
HUMAN")) { // В качестве корреспондента выбрано 'Частное лицо'
var indexValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("sendIndex")); // Индекс
var countryValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("country")); // Страна
var indexValueregionValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues()correspondentValue.get("sendIndexregion")); // Регион
//var phoneValuedistrictValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().correspondentValue.get("phoneHousedistrict")); // Населенный пункт
var countryValuecityValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues()correspondentValue.get("countrycity")); // Город
var regionValuestreetValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues()correspondentValue.get("regionstreet")); // Улица
var districtValuehouseValue = TunableObjectHelper.getAFInstanceValue(objectBeardcorrespondentValue.tuning().getValues().get("districtget("house")); // Дом
var cityValuestructureValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues()correspondentValue.get("citystructure")); // Корпус
var streetValuehousingValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues()correspondentValue.get("streethousing")); // Строение
var houseValueroomValue = TunableObjectHelper.getAFInstanceValue(objectBeardcorrespondentValue.tuning().getValues().get("houseget("room")); // Комната
var//Формирование structureValueадреса = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("structure"));
по умолчанию
var housingValueaddressValue = TunableObjectHelper.getAFInstanceValue(objectBeardStringUtils.tuninghasLength().getValues().get("housing"));
var roomValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("room"));
var addressValue =countryValue) ? countryValue + ', ' : "") + (StringUtils.hasLength(countryValueregionValue) ? countryValueregionValue + ', ' : "") + (StringUtils.hasLength(regionValuedistrictValue) ? regionValue + ', ' : "") + (StringUtils.hasLength(districtValue) ? districtValue + ', ' : "") + (StringUtils.hasLength(cityValue) ? cityValue + ', ' : "") + (StringUtils.hasLength(streetValue) ? streetValue + ', ' : "") + (StringUtils.hasLength(houseValue) ? houseValue + ', ' : "") + (StringUtils.hasLength(structureValue) ? structureValue + ', ' : "") + (StringUtils.hasLength(housingValue) ? housingValue + ', ' : "") + (StringUtils.hasLength(roomValue) ? roomValue : "");
TuningHelper.processProperty(object.tuning().getValues(), "Index", indexValue, object.tuning().getSchema().getProperty("Index"));
TuningHelper.processProperty(object.tuning().getValues(), "SendAddress", addressValue, object.tuning().getSchema().getProperty("SendAddress"));
//TuningHelper.processProperty(object.tuning().getValues(), "Phone", phoneValue, object.tuning().getSchema().getProperty("Phone"));
} else if (person.originalData().getType().toString().equals("SYS_ORGANIZATION")) { // В качестве корреспондента выбрана 'Системная организация'
var addressValue = correspondent.originalData().getParty().getOrganizationDescription().addressInfo().post().getAddress(); //Адрес
var indexValue = correspondent.originalData().getParty().getOrganizationDescription().addressInfo().post().getZipCode(); //Индекс
} else { // if (person.originalData().getType().toString().equals("SYS_ORGANIZATION")) {
В качестве корреспондента выбрана 'Не системная организация'
var indexValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("jSendIndex")); //Индекс
var addressValuecountryValue = personTunableObjectHelper.originalDatagetAFInstanceValue()correspondentValue.getPartyget("jcountryName").getOrganizationDescription().addressInfo().post().getAddress();
); //Страна
var indexValueregionValue = personTunableObjectHelper.originalDatagetAFInstanceValue()correspondentValue.getParty().getOrganizationDescription().addressInfo().post().getZipCode();
get("region")); //Регион
TuningHelper.processProperty(object.tuning().getValues(), "SendAddress", addressValue, object.tuning().getSchema().getProperty("SendAddress"));
TuningHelper.processProperty(object.tuning().getValues(), "Index", indexValue, object.tuning().getSchema().getProperty("Index"));
} else {
var districtValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("jDistrict")); //Населенный пункт
var cityValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("jCity")); //Город
var streetValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("jStreet")); //Улица
var indexValuehouseValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues()correspondentValue.get("jSendIndexjHouse")); //Дом
var countryValuestructureValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues()correspondentValue.get("jcountryNamejStructure")); //Корпус
var regionValuehousingValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues()correspondentValue.get("regionjHousing")); //Строение
//Формирование адреса по умолчанию
var districtValueaddressValue = TunableObjectHelper.getAFInstanceValue(objectBeardStringUtils.tuninghasLength().getValues().get("jDistrict"));
var cityValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("jCity"));
var streetValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("jStreet"));
var houseValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("jHouse"));
var structureValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("jStructure"));
var housingValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("jHousing")countryValue) ? countryValue + ', ' : "") + (StringUtils.hasLength(regionValue) ? regionValue + ', ' : "") + (StringUtils.hasLength(districtValue) ? districtValue + ', ' : "") + (StringUtils.hasLength(cityValue) ? cityValue + ', ' : "") + (StringUtils.hasLength(streetValue) ? streetValue + ', ' : "") + (StringUtils.hasLength(houseValue) ? houseValue + ', ' : "") + (StringUtils.hasLength(structureValue) ? structureValue + ', ' : "") + (StringUtils.hasLength(housingValue) ? housingValue : "");
}
// Запись в поле 'Список адресов'
if (!emplAddrs.isEmpty()) {
TunableObjectHelper.putAFInstanceValue(tuning, "all_address", emplAddrs);
var addressValue = (StringUtils.hasLength(countryValue) ? countryValue + ', ' : "") + (StringUtils.hasLength(regionValue) ? regionValue + ', ' : "") + (StringUtils.hasLength(districtValue) ? districtValue + ', ' : "") + (StringUtils.hasLength(cityValue) ? cityValue + ', ' : "") + (StringUtils.hasLength(streetValue) ? streetValue + ', ' : "") + (StringUtils.hasLength(houseValue) ? houseValue + ', ' : "") + (StringUtils.hasLength(structureValue) ? structureValue + ', ' : "") + (StringUtils.hasLength(housingValue) ? housingValue : "");
TuningHelper.processProperty(object.tuning().getValues(), "Index", indexValue, object.tuning().getSchema().getProperty("Index"));
TuningHelper.processProperty(object.tuning().getValues(), "SendAddress", addressValue, object.tuning().getSchema().getProperty("SendAddress"));
}
}
if (person.originalData().getType().toString().equals("SYS_ORGANIZATION")) {
object.tuning().put("isSysOrg", TuningHelper.createPropertyValue(true, object.tuning().getSchema().getProperty("isSysOrg")));
}
if (person.originalData().getType().toString().equals("NONSYS_ORGANIZATION")) {
object.tuning().put("isSysOrg", TuningHelper.createPropertyValue(false, object.tuning().getSchema().getProperty("isSysOrg")));
}
}
}
}}
// Запись в поле 'Список телефонов'
if (!emplPhones.isEmpty()) {
TunableObjectHelper.putAFInstanceValue(tuning, "all_phone", emplPhones);
}
//Запись остальных полей
TunableObjectHelper.putAFInstanceValue(tuning, "Recipient", recipientValue); //Получатель
TunableObjectHelper.putAFInstanceValue(tuning, "Index", indexValue); //Индекс
TunableObjectHelper.putAFInstanceValue(tuning, "Address", addressValue); //Адрес
TunableObjectHelper.putAFInstanceValue(tuning, "Phone", phoneValue); //Телефон
}
}
}
}
} |