diff --git a/ayanova/src/components/work-order-address.vue b/ayanova/src/components/work-order-address.vue index 5971fdde..cad41440 100644 --- a/ayanova/src/components/work-order-address.vue +++ b/ayanova/src/components/work-order-address.vue @@ -317,16 +317,16 @@ - + {{ $ay.t("SelectAlternateAddress") }} - + {{ alternateAddresses }} - {{ + {{ $ay.t("OK") }} @@ -368,6 +368,9 @@ export default { close() { this.openDialog = false; }, + closeSelect() { + this.openSelectDialog = false; + }, form() { return window.$gz.form; @@ -499,9 +502,55 @@ async function populateAlternateAddresses(vm) { //find all the addressible objects, get their addresses and push into list //at top should be customer, headoffice, then units vm.alternateAddresses = []; + const ispostal = vm.selectType == 2; const wo = vm.value; if (wo.customerId != null) { - res = await window.$gz.api.get(`customer/address/${wo.customerId}`); + let res = await window.$gz.api.get(`customer/address/${wo.customerId}`); + if (res.data) { + //customer first + if (ispostal) { + vm.alternateAddresses.push({ + name: res.data.customerpost.name, + viz: formatAddress(res.data.customerpost).postal, + src: res.data + }); + //headoffice if present + if (res.data.headofficepost) { + vm.alternateAddresses.push({ + name: res.data.headofficepost.name, + viz: formatAddress(res.data.headofficepost).postal, + src: res.data + }); + } + } else { + vm.alternateAddresses.push({ + name: res.data.customerphys.name, + viz: formatAddress(res.data.customerphys).physical, + src: res.data + }); + } + } + } + //Unit addresses + //Units only have physical addresses + if (!ispostal) { + let unitIdList = []; + vm.value.items.forEach(i => { + i.units.forEach(async u => { + if (u.id != null && !unitIdList.includes(u.id)) { + unitIdList.push(u.id); + //get address + let res = await window.$gz.api.get(`unit/address/${u.id}`); + if (res.data) { + vm.alternateAddresses.push({ + name: res.data.unit.name, + viz: formatAddress(res.data.unit).physical, + src: res.data + }); + } + } + }); + }); } } @@ -523,7 +572,13 @@ function formatAddress(o) { ret.physical += o.region + " "; } if (!window.$gz.util.stringIsNullOrEmpty(o.country)) { - ret.physical += o.country; + ret.physical += o.country + " "; + } + if (!window.$gz.util.stringIsNullOrEmpty(o.latitude)) { + ret.physical += ", lat " + o.latitude; + } + if (!window.$gz.util.stringIsNullOrEmpty(o.longitude)) { + ret.physical += ", long " + o.longitude; } //Postal