Add missing brackets.
[capital-apms-progress.git] / process / getaddr.p
blobad972669375bee25f716df82b35fe135d05d623a
1 &ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12
2 &ANALYZE-RESUME
3 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS Procedure
4 /*--------------------------------------------------------------------------
5 File :
6 Purpose :
8 Syntax :
10 Description :
12 Author(s) :
13 Created :
14 Notes :
15 ------------------------------------------------------------------------*/
16 /* This .W file was created with the Progress UIB. */
17 /*----------------------------------------------------------------------*/
19 /* *************************** Definitions ************************** */
21 DEF INPUT PARAMETER report-options AS CHAR NO-UNDO.
22 DEF INPUT PARAMETER entity-code LIKE AcctTran.EntityCode NO-UNDO.
23 DEF INPUT PARAMETER type-list AS CHAR NO-UNDO.
24 DEF OUTPUT PARAMETER address AS CHAR NO-UNDO.
26 /* _UIB-CODE-BLOCK-END */
27 &ANALYZE-RESUME
30 &ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
32 /* ******************** Preprocessor Definitions ******************** */
34 &Scoped-define PROCEDURE-TYPE Procedure
38 /* _UIB-PREPROCESSOR-BLOCK-END */
39 &ANALYZE-RESUME
43 /* *********************** Procedure Settings ************************ */
45 &ANALYZE-SUSPEND _PROCEDURE-SETTINGS
46 /* Settings for THIS-PROCEDURE
47 Type: Procedure
48 Allow:
49 Frames: 0
50 Add Fields to: Neither
51 Other Settings: CODE-ONLY COMPILE
53 &ANALYZE-RESUME _END-PROCEDURE-SETTINGS
55 /* ************************* Create Window ************************** */
57 &ANALYZE-SUSPEND _CREATE-WINDOW
58 /* DESIGN Window definition (used by the UIB)
59 CREATE WINDOW Procedure ASSIGN
60 HEIGHT = .17
61 WIDTH = 40.
62 /* END WINDOW DEFINITION */
64 &ANALYZE-RESUME
69 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Procedure
72 /* *************************** Main Block *************************** */
74 DEF VAR person-code LIKE Person.PersonCode NO-UNDO.
75 DEF VAR entity-type AS CHAR NO-UNDO.
76 DEF VAR address-type AS CHAR NO-UNDO.
77 DEF VAR other-options AS CHAR NO-UNDO.
78 /* DEF VAR opt-person-name AS LOGICAL NO-UNDO. */
79 DEF VAR opt-person-name AS CHAR INIT "" NO-UNDO. /* Stolen for attn line */
80 DEF VAR entity-name AS CHAR NO-UNDO.
81 DEF VAR state-line AS CHAR NO-UNDO.
82 DEF VAR country-line AS CHAR NO-UNDO.
83 DEF VAR i AS INT NO-UNDO.
84 DEF BUFFER pd FOR PostalDetail.
86 {inc/ofc-this.i}
87 {inc/ofc-set.i "Country" "office-country"}
88 {inc/ofc-set.i "Address-Attention" "address-attention"}
89 {inc/ofc-set.i "Address-Priority" "priority-list"}
90 IF type-list = ? OR type-list = "" THEN type-list = priority-list.
92 entity-type = ENTRY( 1, report-options).
93 IF NUM-ENTRIES( report-options ) > 1 THEN DO:
94 opt-person-name = ENTRY( 2, report-options).
95 /* other-options = ENTRY( 2, report-options).
96 opt-person-name = INDEX( other-options, "N" ) <> 0. */
97 END.
99 CASE entity-type:
101 WHEN "T" THEN DO:
102 FIND Tenant WHERE Tenant.TenantCode = entity-code NO-LOCK NO-ERROR.
103 IF AVAILABLE Tenant THEN ASSIGN
104 entity-name = Tenant.Name
105 person-code = Tenant.BillingContact.
106 END.
108 WHEN "C" THEN DO:
109 FIND Creditor WHERE Creditor.CreditorCode = entity-code NO-LOCK NO-ERROR.
110 IF AVAILABLE Creditor THEN ASSIGN
111 entity-name = Creditor.Name
112 person-code = Creditor.PaymentContact.
113 END.
115 WHEN "PERSON" THEN DO:
116 entity-name = "".
117 person-code = entity-code.
118 END.
119 END.
120 IF entity-name = ? THEN entity-name = "".
121 i = 0.
122 DO WHILE NOT AVAILABLE PD AND i < NUM-ENTRIES( type-list ).
124 i = i + 1.
125 FIND PD WHERE
126 PD.PersonCode = person-code AND
127 PD.PostalType = ENTRY( i, type-list ) NO-LOCK NO-ERROR.
129 END.
131 IF NOT AVAILABLE PD THEN
132 FIND FIRST PD WHERE PD.PersonCode = person-code NO-LOCK NO-ERROR.
134 address = "".
135 RUN cat-non-null( entity-name ).
137 /* Inject the user entered attn line if it exists. Dont know what the
138 lookup is for but two attns will appear if I dont check it */
139 IF LOOKUP( address-type, address-attention) = 0 AND opt-person-name <> "" THEN
140 RUN cat-non-null( "~nAttn: " + opt-person-name ).
142 IF AVAILABLE(PD) THEN DO:
144 state-line = IF PD.State = ? THEN "" ELSE PD.State.
145 state-line = IF PD.Zip = ? THEN state-line
146 ELSE state-line + " " + PD.Zip.
148 RUN cat-non-null( "~n" + TRIM(PD.Address) ).
149 RUN cat-non-null( "~n" + TRIM(PD.City) ).
150 IF TRIM(state-line) <> "" THEN RUN cat-non-null( ", " + TRIM(state-line) ).
152 country-line = "".
153 IF PD.Country <> office-country THEN country-line = PD.Country.
155 RUN cat-non-null( "~n" + TRIM(country-line) ).
157 address-type = PD.PostalType.
158 IF LOOKUP( address-type, address-attention) > 0 THEN DO:
159 FIND Person WHERE Person.PersonCode = person-code NO-LOCK.
160 IF entity-name <> (Person.FirstName + " " + Person.LastName)
161 AND TRIM(Person.FirstName + Person.LastName) <> "" THEN DO:
162 RUN cat-non-null( "~nAttn: ").
163 RUN cat-non-null( Person.PersonTitle + " ").
164 RUN cat-non-null( Person.FirstName + " " ).
165 RUN cat-non-null( Person.LastName ).
166 END.
167 END.
169 END.
170 address = TRIM(REPLACE(address, "~r", "")).
171 DO WHILE INDEX( address, ",~n") > 0:
172 address = REPLACE( address, ",~n", "~n").
173 END.
174 DO WHILE INDEX( address, "~n ") > 0:
175 address = REPLACE( address, "~n ", "~n").
176 END.
177 DO WHILE INDEX( address, " ~n") > 0:
178 address = REPLACE( address, " ~n", "~n").
179 END.
180 DO WHILE INDEX( address, "~n~n") > 0:
181 address = REPLACE( address, "~n~n", "~n").
182 END.
184 /* _UIB-CODE-BLOCK-END */
185 &ANALYZE-RESUME
188 /* ********************** Internal Procedures *********************** */
190 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE cat-non-null Procedure
191 PROCEDURE cat-non-null :
192 /*------------------------------------------------------------------------------
193 Purpose: concatenate the string onto address only if it is non-null
194 ------------------------------------------------------------------------------*/
195 DEF INPUT PARAMETER s2 AS CHAR NO-UNDO.
197 IF s2 = ? OR TRIM(s2) = "" THEN RETURN.
198 address = address + s2.
199 END PROCEDURE.
201 /* _UIB-CODE-BLOCK-END */
202 &ANALYZE-RESUME