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) {
// Получение tn-объекта
var tuning = object.tuning();
// Карта 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 != null) {
// Получение tn-объекта корреспондента
var appTNObject = AFSession.get().getApplication(TunableObjectApplication.class);
var correspondentObject = appTNObject.getEntityByUNID(AFCMDomino.ormUnidToTNUnid(correspondent.getUNID()));
if (correspondentObject != null) {
// Формирование списка адресов
var emplAddrs = new ArrayList();
// Почтовый/физический адрес
if (correspondent.getAddress() != "") {
emplAddrs.add(correspondent.getAddress());
}
// Юридический адрес
if (correspondent.originalData().getType() == SOBeard.Type.NONSYS_ORGANIZATION) {
if (correspondent.originalData().getParty().addressInfo().legal().getAddress() != "") {
emplAddrs.add(correspondent.originalData().getParty().addressInfo().legal().getAddress()); //заполняем адрес для несистемных организаций
}
}
// Формирование списка телефонов
var emplPhones = new ArrayList();
// Карта объектов AFInstance корреспондента
var correspondentValue = correspondentObject.tuning().getValues();
var phoneH = correspondentValue.get("phoneHouse");
var phoneW = correspondentValue.get("phoneWork");
var phoneM = correspondentValue.get("phoneMobil");
var phone = correspondentValue.get("phone");
emplPhones.add(phoneH);
emplPhones.add(phoneW);
emplPhones.add(phoneM);
if (phone != null && phone.getValues() != null) {
emplPhones.addAll(phone.getValues());
}
// Вычисление телефона по умолчанию
var phoneValue;
if (phoneM != null) {
phoneValue = TunableObjectHelper.getAFInstanceValue(phoneM);
} else if (phoneW != null) {
phoneValue = TunableObjectHelper.getAFInstanceValue(phoneW);
} else if (phoneH != null) {
phoneValue = TunableObjectHelper.getAFInstanceValue(phoneM);
} else if (phone != null && phone.getValues() != null) {
phoneValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning()phone.getValues().get("phoneMobil"0));
}
// Получатель
}var recipientValue else= ifnew ArrayList(phoneW != null) {
);
phoneValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuningrecipientValue.add(correspondent.originalData().getValues().get("phoneWork"getFullName());
} else if (phoneH != null) {
phoneValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuningif (correspondent.originalData().getType().getValuestoString().getequals("phoneHousePRIVATE_HUMAN"));
{ // В качестве корреспондента выбрано 'Частное лицо'
}var else if (phone != null && objectBeard.tuning().getValues()indexValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("phonesendIndex").getValues(); != null) {// Индекс
phoneValue var countryValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues()correspondentValue.get("phonecountry")).getValues(); // Страна
var regionValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get(0"region")); // Регион
}
ifvar (phoneValuedistrictValue != null) {
TuningHelper.processProperty(object.tuning().getValues(), "Phone", phoneValue, object.tuning().getSchema().getProperty("Phone"));
}
if (!emplPhones.isEmpty()) {
TuningHelper.processProperty(object.tuning().getValues(), "all_phone", emplPhones, object.tuning().getSchema().getProperty("all_phone"));
}
if (objectBeard != null) {
if (person.originalData().getType().toString().equals("PRIVATE_HUMAN")) {
TunableObjectHelper.getAFInstanceValue(correspondentValue.get("district")); // Населенный пункт
var cityValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("city")); // Город
var streetValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("street")); // Улица
var houseValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("house")); // Дом
var structureValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("structure")); // Корпус
var housingValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("housing")); // Строение
var indexValueroomValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().correspondentValue.get("sendIndexroom")); // Комната
//varФормирование phoneValueадреса = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("phoneHouse"));
по умолчанию
var countryValueaddressValue = TunableObjectHelper.getAFInstanceValue(objectBeardStringUtils.tuninghasLength().getValues().get("country"));
var regionValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("region"));
var districtValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("district"));
var cityValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("city"));
var streetValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("street"));
var houseValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("house"));
var structureValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("structure"));
var housingValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("housing"));
var roomValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("room"));
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 + ', ' : "") + (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")) {
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 + ', ' : "") + (StringUtils.hasLength(roomValue) ? roomValue : "");
} 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 { // В качестве корреспондента выбрана 'Не системная организация'
var indexValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("jSendIndex")); //Индекс
var countryValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("jcountryName")); //Страна
var regionValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("region")); //Регион
var districtValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("jDistrict")); //Населенный пункт
var cityValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("jCity")); //Город
var streetValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("jStreet")); //Улица
var houseValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("jHouse")); //Дом
var structureValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("jStructure")); //Корпус
var housingValue = TunableObjectHelper.getAFInstanceValue(correspondentValue.get("jHousing")); //Строение
//Формирование адреса по умолчанию
var addressValue = person.originalData().getParty().getOrganizationDescription().addressInfo().post().getAddress();
var indexValue = person.originalData().getParty().getOrganizationDescription().addressInfo().post().getZipCode();
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 indexValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("jSendIndex"));
var countryValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("jcountryName"));
var regionValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().getValues().get("region"));
var districtValue = TunableObjectHelper.getAFInstanceValue(objectBeard.tuning().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"));
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")));
}
}
}
} (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 : "");
}
// Запись в поле 'Список адресов'
if (!emplAddrs.isEmpty()) {
TunableObjectHelper.putAFInstanceValue(tuning, "all_address", emplAddrs);
}
// Запись в поле 'Список телефонов'
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); //Телефон
}
}
}
}
} |