1 &ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12
3 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS Include
4 /*--------------------------------------------------------------------------
5 ------------------------------------------------------------------------*/
7 DEF VAR ctc-office-country-code
LIKE PhoneDetail.cCountryCode
NO-UNDO.
8 DEF VAR ctc-office-std-code
LIKE PhoneDetail.cSTDCode
NO-UNDO.
9 DEF VAR ctc-office-isd-prefix
AS CHAR NO-UNDO INITIAL "00".
10 DEF VAR ctc-office-country-name
AS CHAR NO-UNDO INITIAL "".
14 FIND OfficeSettings
OF Office
WHERE OfficeSettings.SetName
= "Country-Code" NO-LOCK NO-ERROR.
15 IF AVAILABLE OfficeSettings
THEN ctc-office-country-code
= OfficeSettings.SetValue.
17 FIND OfficeSettings
OF Office
WHERE OfficeSettings.SetName
= "STD-Code" NO-LOCK NO-ERROR.
18 IF AVAILABLE OfficeSettings
THEN ctc-office-std-code
= OfficeSettings.SetValue.
20 FIND OfficeSettings
OF Office
WHERE OfficeSettings.SetName
= "ISD-Prefix" NO-LOCK NO-ERROR.
21 IF AVAILABLE(OfficeSettings
) THEN ctc-office-isd-prefix
= OfficeSettings.SetValue.
23 FIND OfficeSettings
OF Office
WHERE OfficeSettings.SetName
= "Country" NO-LOCK NO-ERROR.
24 IF AVAILABLE(OfficeSettings
) THEN ctc-office-country-name
= OfficeSettings.SetValue.
26 {inc
/ofc-set.i
"Address-Priority" "ctc-address-priority-list"}
27 {inc
/ofc-set.i
"Phone-Priority" "ctc-phone-priority-list"}
29 /* _UIB-CODE-BLOCK-END
*/
33 &ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
35 /* ******************** Preprocessor Definitions
******************** */
39 /* _UIB-PREPROCESSOR-BLOCK-END
*/
43 /* ************************ Function Prototypes
********************** */
45 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD get-address Include
46 FUNCTION get-address
RETURNS CHARACTER
47 ( INPUT person-code
AS INT, INPUT postal-type
AS CHAR ) FORWARD.
49 /* _UIB-CODE-BLOCK-END
*/
52 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD get-best-address Include
53 FUNCTION get-best-address
RETURNS CHARACTER
54 ( INPUT person-code
AS INT, INPUT type-list
AS CHAR ) FORWARD.
56 /* _UIB-CODE-BLOCK-END
*/
59 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD get-best-phone Include
60 FUNCTION get-best-phone
RETURNS CHARACTER
61 ( INPUT person-code
AS INT, INPUT type-list
AS CHAR ) FORWARD.
63 /* _UIB-CODE-BLOCK-END
*/
66 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD get-fullname Include
67 FUNCTION get-fullname
RETURNS CHARACTER
68 ( INPUT person-code
AS INT ) FORWARD.
70 /* _UIB-CODE-BLOCK-END
*/
73 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD get-phone-no Include
74 FUNCTION get-phone-no
RETURNS CHARACTER
75 ( INPUT person-code
AS INT, INPUT phone-type
AS CHAR ) FORWARD.
77 /* _UIB-CODE-BLOCK-END
*/
80 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD non-null Include
81 FUNCTION non-null
RETURNS CHARACTER
82 ( INPUT s
AS CHAR ) FORWARD.
84 /* _UIB-CODE-BLOCK-END
*/
88 /* *********************** Procedure Settings
************************ */
90 &ANALYZE-SUSPEND _PROCEDURE-SETTINGS
91 /* Settings for
THIS-PROCEDURE
95 Add Fields to
: Neither
96 Other Settings
: INCLUDE-ONLY
98 &ANALYZE-RESUME _END-PROCEDURE-SETTINGS
100 /* ************************* Create Window
************************** */
102 &ANALYZE-SUSPEND _CREATE-WINDOW
103 /* DESIGN Window definition
(used by the UIB
)
104 CREATE WINDOW Include
ASSIGN
107 /* END WINDOW DEFINITION
*/
114 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Include
117 /* *************************** Main Block
*************************** */
119 /* _UIB-CODE-BLOCK-END
*/
123 /* ************************ Function Implementations
***************** */
125 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION get-address Include
126 FUNCTION get-address
RETURNS CHARACTER
127 ( INPUT person-code
AS INT, INPUT postal-type
AS CHAR ) :
128 /*------------------------------------------------------------------------------
129 Purpose
: Return a formatted address string for the address of the
131 ------------------------------------------------------------------------------*/
132 DEF VAR address-line
AS CHAR NO-UNDO INITIAL "".
133 DEF VAR address
AS CHAR NO-UNDO INITIAL "".
135 DEF BUFFER PD
FOR PostalDetail.
136 FIND PD
WHERE PD.PersonCode
= person-code
137 AND PD.PostalType
= postal-type
NO-LOCK NO-ERROR.
138 IF NOT AVAILABLE PD
THEN RETURN ?.
140 address-line
= non-null
(PD.State
).
141 address-line
= TRIM( address-line
+ (IF PD.Zip
= ?
OR PD.ZIp
= "" THEN "" ELSE " " + PD.Zip
)).
142 IF address-line
<> "" THEN
143 address-line
= TRIM( non-null
( PD.City
) + ", " + address-line
, ", ") .
145 address-line
= non-null
( PD.City
).
147 address
= address
+ non-null
( TRIM(PD.Address
) ).
148 address
= address
+ non-null
( "~n" + address-line
).
151 IF PD.Country
<> ctc-office-country-name
THEN address-line
= PD.Country.
153 address
= address
+ non-null
( "~n" + TRIM(address-line
) ).
155 /* replace any bizarro stuff we got from doing a dump and reload
*/
156 address
= TRIM(REPLACE(address
, "~r", "")).
157 DO WHILE INDEX( address
, ",~n") > 0:
158 address
= REPLACE( address
, ",~n", "~n").
160 DO WHILE INDEX( address
, "~n ") > 0:
161 address
= REPLACE( address
, "~n ", "~n").
163 DO WHILE INDEX( address
, " ~n") > 0:
164 address
= REPLACE( address
, " ~n", "~n").
166 DO WHILE INDEX( address
, "~n~n") > 0:
167 address
= REPLACE( address
, "~n~n", "~n").
174 /* _UIB-CODE-BLOCK-END
*/
178 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION get-best-address Include
179 FUNCTION get-best-address
RETURNS CHARACTER
180 ( INPUT person-code
AS INT, INPUT type-list
AS CHAR ) :
181 /*------------------------------------------------------------------------------
184 ------------------------------------------------------------------------------*/
185 DEF VAR n
AS INT NO-UNDO.
186 DEF VAR i
AS INT NO-UNDO.
188 IF type-list
= ?
OR type-list
= "" THEN type-list
= ctc-address-priority-list.
189 n
= NUM-ENTRIES( type-list
).
191 FIND PostalDetail
WHERE PostalDetail.PersonCode
= person-code
192 AND PostalDetail.PostalType
= ENTRY(i
,type-list
)
194 IF AVAILABLE(PostalDetail
) THEN
195 RETURN get-address
( person-code
, PostalDetail.PostalType
).
198 FIND FIRST PostalDetail
WHERE PostalDetail.PersonCode
= person-code
NO-LOCK NO-ERROR.
199 IF AVAILABLE(PostalDetail
) THEN
200 RETURN get-address
( person-code
, PostalDetail.PostalType
).
206 /* _UIB-CODE-BLOCK-END
*/
210 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION get-best-phone Include
211 FUNCTION get-best-phone
RETURNS CHARACTER
212 ( INPUT person-code
AS INT, INPUT type-list
AS CHAR ) :
213 /*------------------------------------------------------------------------------
216 ------------------------------------------------------------------------------*/
217 DEF VAR n
AS INT NO-UNDO.
218 DEF VAR i
AS INT NO-UNDO.
220 IF type-list
= ?
OR type-list
= "" THEN type-list
= ctc-phone-priority-list.
221 n
= NUM-ENTRIES( type-list
).
223 FIND PhoneDetail
WHERE PhoneDetail.PersonCode
= person-code
224 AND PhoneDetail.PhoneType
= ENTRY(i
,type-list
)
226 IF AVAILABLE(PhoneDetail
) THEN
227 RETURN get-phone-no
( person-code
, PhoneDetail.PhoneType
).
230 FIND FIRST PhoneDetail
WHERE PhoneDetail.PersonCode
= person-code
NO-LOCK NO-ERROR.
231 IF AVAILABLE(PhoneDetail
) THEN
232 RETURN get-phone-no
( person-code
, PhoneDetail.PhoneType
).
238 /* _UIB-CODE-BLOCK-END
*/
242 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION get-fullname Include
243 FUNCTION get-fullname
RETURNS CHARACTER
244 ( INPUT person-code
AS INT ) :
245 /*------------------------------------------------------------------------------
248 ------------------------------------------------------------------------------*/
250 IF AVAILABLE(Person
) AND Person.PersonCode
= person-code
THEN
251 RETURN TRIM( non-null
(Person.FirstName
) + ' '
+ non-null
(Person.LastName
) ).
253 DEF BUFFER AltPerson
FOR Person.
254 FIND AltPerson
WHERE AltPerson.PersonCode
= person-code
NO-LOCK NO-ERROR.
255 IF AVAILABLE(AltPerson
) THEN
256 RETURN TRIM( non-null
(AltPerson.FirstName
) + ' '
+ non-null
(AltPerson.LastName
) ).
258 RETURN ?.
/* no such person
*/
262 /* _UIB-CODE-BLOCK-END
*/
266 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION get-phone-no Include
267 FUNCTION get-phone-no
RETURNS CHARACTER
268 ( INPUT person-code
AS INT, INPUT phone-type
AS CHAR ) :
269 /*------------------------------------------------------------------------------
270 Purpose
: return a formatted phone number of this type for this person
271 ------------------------------------------------------------------------------*/
272 DEF VAR country-part
AS CHAR NO-UNDO INITIAL "".
273 DEF VAR std-part
AS CHAR NO-UNDO INITIAL "".
274 DEF VAR c-country
AS CHAR NO-UNDO.
275 DEF VAR c-std
AS CHAR NO-UNDO.
276 DEF VAR phone-no
AS CHAR NO-UNDO.
278 /* might avoid unnecessary read
*/
279 IF AVAILABLE(PhoneDetail
) AND PhoneDetail.PersonCode
= person-code
280 AND PhoneDetail.PhoneType
= phone-type
THEN ASSIGN
281 c-country
= non-null
(PhoneDetail.cCountryCode
)
282 c-std
= non-null
(PhoneDetail.cSTDCode
)
283 phone-no
= non-null
(PhoneDetail.Number
).
285 DEF BUFFER AltPD
FOR PhoneDetail.
286 FIND AltPD
WHERE AltPD.PersonCode
= person-code
287 AND AltPD.PhoneType
= phone-type
NO-LOCK NO-ERROR.
288 IF AVAILABLE(AltPD
) THEN ASSIGN
289 c-country
= non-null
(AltPD.cCountryCode
)
290 c-std
= non-null
(AltPD.cSTDCode
)
291 phone-no
= non-null
(AltPD.Number
).
296 IF c-country
<> "" AND c-country
<> ctc-office-country-code
THEN
297 country-part
= "+" + c-country
+ " ".
299 IF c-country
<> ctc-office-country-code
OR c-std
<> ctc-office-std-code
THEN
300 std-part
= "(" + c-std
+ ") ".
302 RETURN country-part
+ std-part
+ phone-no .
306 /* _UIB-CODE-BLOCK-END
*/
310 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION non-null Include
311 FUNCTION non-null
RETURNS CHARACTER
312 ( INPUT s
AS CHAR ) :
313 /*------------------------------------------------------------------------------
314 Purpose
: Return a null-string if the input is ?
315 ------------------------------------------------------------------------------*/
316 IF s
<> ?
THEN RETURN s.
321 /* _UIB-CODE-BLOCK-END
*/