Really, this should be it, for the passing income.
[capital-apms-progress.git] / inc / contacts.i
blob41896e94846f62a35ca365cb6b0488e531ff5ed7
1 &ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12
2 &ANALYZE-RESUME
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 "".
12 {inc/ofc-this.i}
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 */
30 &ANALYZE-RESUME
33 &ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
35 /* ******************** Preprocessor Definitions ******************** */
39 /* _UIB-PREPROCESSOR-BLOCK-END */
40 &ANALYZE-RESUME
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 */
50 &ANALYZE-RESUME
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 */
57 &ANALYZE-RESUME
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 */
64 &ANALYZE-RESUME
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 */
71 &ANALYZE-RESUME
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 */
78 &ANALYZE-RESUME
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 */
85 &ANALYZE-RESUME
88 /* *********************** Procedure Settings ************************ */
90 &ANALYZE-SUSPEND _PROCEDURE-SETTINGS
91 /* Settings for THIS-PROCEDURE
92 Type: Include
93 Allow:
94 Frames: 0
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
105 HEIGHT = .1
106 WIDTH = 40.
107 /* END WINDOW DEFINITION */
109 &ANALYZE-RESUME
114 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Include
117 /* *************************** Main Block *************************** */
119 /* _UIB-CODE-BLOCK-END */
120 &ANALYZE-RESUME
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
130 specified type.
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, ", ") .
144 ELSE
145 address-line = non-null( PD.City ).
147 address = address + non-null( TRIM(PD.Address) ).
148 address = address + non-null( "~n" + address-line ).
150 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").
159 END.
160 DO WHILE INDEX( address, "~n ") > 0:
161 address = REPLACE( address, "~n ", "~n").
162 END.
163 DO WHILE INDEX( address, " ~n") > 0:
164 address = REPLACE( address, " ~n", "~n").
165 END.
166 DO WHILE INDEX( address, "~n~n") > 0:
167 address = REPLACE( address, "~n~n", "~n").
168 END.
170 RETURN address.
172 END FUNCTION.
174 /* _UIB-CODE-BLOCK-END */
175 &ANALYZE-RESUME
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 /*------------------------------------------------------------------------------
182 Purpose:
183 Notes:
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 ).
190 DO i = 1 TO n:
191 FIND PostalDetail WHERE PostalDetail.PersonCode = person-code
192 AND PostalDetail.PostalType = ENTRY(i,type-list)
193 NO-LOCK NO-ERROR.
194 IF AVAILABLE(PostalDetail) THEN
195 RETURN get-address( person-code, PostalDetail.PostalType ).
196 END.
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 ).
202 RETURN "".
204 END FUNCTION.
206 /* _UIB-CODE-BLOCK-END */
207 &ANALYZE-RESUME
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 /*------------------------------------------------------------------------------
214 Purpose:
215 Notes:
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 ).
222 DO i = 1 TO n:
223 FIND PhoneDetail WHERE PhoneDetail.PersonCode = person-code
224 AND PhoneDetail.PhoneType = ENTRY(i,type-list)
225 NO-LOCK NO-ERROR.
226 IF AVAILABLE(PhoneDetail) THEN
227 RETURN get-phone-no( person-code, PhoneDetail.PhoneType ).
228 END.
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 ).
234 RETURN "".
236 END FUNCTION.
238 /* _UIB-CODE-BLOCK-END */
239 &ANALYZE-RESUME
242 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION get-fullname Include
243 FUNCTION get-fullname RETURNS CHARACTER
244 ( INPUT person-code AS INT ) :
245 /*------------------------------------------------------------------------------
246 Purpose:
247 Notes:
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 */
260 END FUNCTION.
262 /* _UIB-CODE-BLOCK-END */
263 &ANALYZE-RESUME
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).
284 ELSE DO:
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).
292 ELSE
293 RETURN ?.
294 END.
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 .
304 END FUNCTION.
306 /* _UIB-CODE-BLOCK-END */
307 &ANALYZE-RESUME
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.
317 RETURN "".
319 END FUNCTION.
321 /* _UIB-CODE-BLOCK-END */
322 &ANALYZE-RESUME