Add blank column, rename column.
[capital-apms-progress.git] / process / report / contacts.p
blob151375e797090520953f78fa987fb63df3a4ce0f
1 &ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12
2 &ANALYZE-RESUME
3 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS Procedure
4 /*--------------------------------------------------------------------------
5 ------------------------------------------------------------------------*/
7 &IF DEFINED(UIB_IS_RUNNING) &THEN
8 DEF VAR report-options AS CHAR NO-UNDO INITIAL "".
9 &ELSE
10 DEF INPUT PARAMETER report-options AS CHAR NO-UNDO.
11 &ENDIF
13 DEF VAR ctype-list AS CHAR NO-UNDO.
14 DEF VAR ptype-list AS CHAR NO-UNDO.
15 DEF VAR phtype-list AS CHAR NO-UNDO INIT "BUS,FAX,MOB".
16 DEF VAR include-types AS LOGI NO-UNDO INIT Yes.
17 DEF VAR merge-list AS LOGI NO-UNDO INIT No.
18 DEF VAR page-per-tenant AS LOGI NO-UNDO INIT No.
19 DEF VAR entity-type AS CHAR NO-UNDO INIT "".
20 DEF VAR entity-code AS INT NO-UNDO.
21 DEF VAR entity-to AS INT NO-UNDO.
22 DEF VAR entity-description AS CHAR NO-UNDO.
24 DEF VAR preview AS LOGI NO-UNDO INIT No.
25 DEF VAR user-name AS CHAR NO-UNDO.
26 DEF VAR timeStamp AS CHAR FORMAT "X(44)" NO-UNDO.
27 DEF VAR out-line AS CHAR NO-UNDO.
29 DEF TEMP-TABLE ListContact NO-UNDO
30 FIELD PersonCode AS INT
31 FIELD Company AS CHAR
32 FIELD LastName AS CHAR
33 FIELD Address AS CHAR
34 FIELD ContactType AS CHAR
35 FIELD Phone AS CHAR EXTENT 3
36 FIELD JobTitle AS CHAR
37 FIELD Department AS CHAR
38 INDEX XPKListContact IS UNIQUE PRIMARY PersonCode
39 INDEX XAK1ListContact Company Lastname.
41 /* _UIB-CODE-BLOCK-END */
42 &ANALYZE-RESUME
45 &ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
47 /* ******************** Preprocessor Definitions ******************** */
49 &Scoped-define PROCEDURE-TYPE Procedure
50 &Scoped-define DB-AWARE no
54 /* _UIB-PREPROCESSOR-BLOCK-END */
55 &ANALYZE-RESUME
59 /* *********************** Procedure Settings ************************ */
61 &ANALYZE-SUSPEND _PROCEDURE-SETTINGS
62 /* Settings for THIS-PROCEDURE
63 Type: Procedure
64 Allow:
65 Frames: 0
66 Add Fields to: Neither
67 Other Settings: CODE-ONLY COMPILE
69 &ANALYZE-RESUME _END-PROCEDURE-SETTINGS
71 /* ************************* Create Window ************************** */
73 &ANALYZE-SUSPEND _CREATE-WINDOW
74 /* DESIGN Window definition (used by the UIB)
75 CREATE WINDOW Procedure ASSIGN
76 HEIGHT = 20.35
77 WIDTH = 32.57.
78 /* END WINDOW DEFINITION */
80 &ANALYZE-RESUME
82 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _INCLUDED-LIB Procedure
83 /* ************************* Included-Libraries *********************** */
85 {inc/method/m-txtrep.i}
86 {inc/persndtl.i}
87 {inc/null.i}
89 /* _UIB-CODE-BLOCK-END */
90 &ANALYZE-RESUME
96 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Procedure
99 /* *************************** Main Block *************************** */
100 {inc/username.i "user-name"}
101 timeStamp = STRING( TODAY, "99/99/9999") + ", " + STRING( TIME, "HH:MM:SS") + " for " + user-name.
103 RUN parse-parameters.
105 OUTPUT TO VALUE(txtrep-print-file) KEEP-MESSAGES PAGE-SIZE 0.
107 RUN pclrep-start( preview, "reset,landscape,tm,2,a4,lm,6,courier,cpi,18,lpi,9").
109 IF merge-list THEN
110 RUN merge-contacts.
111 ELSE IF entity-type <> "" THEN
112 RUN entity-contacts.
113 ELSE
114 RUN contact-listing.
116 OUTPUT CLOSE.
118 RUN pclrep-finish.
120 /* _UIB-CODE-BLOCK-END */
121 &ANALYZE-RESUME
124 /* ********************** Internal Procedures *********************** */
126 &IF DEFINED(EXCLUDE-clear-list-contacts) = 0 &THEN
128 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE clear-list-contacts Procedure
129 PROCEDURE clear-list-contacts :
130 /*------------------------------------------------------------------------------
131 Purpose:
132 ------------------------------------------------------------------------------*/
133 FOR EACH ListContact:
134 DELETE ListContact.
135 END.
136 END PROCEDURE.
138 /* _UIB-CODE-BLOCK-END */
139 &ANALYZE-RESUME
141 &ENDIF
143 &IF DEFINED(EXCLUDE-contact-listing) = 0 &THEN
145 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE contact-listing Procedure
146 PROCEDURE contact-listing :
147 /*------------------------------------------------------------------------------
148 Purpose:
149 ------------------------------------------------------------------------------*/
150 DEF VAR use-contact-type AS LOGI NO-UNDO.
152 FOR EACH ContactType NO-LOCK:
154 use-contact-type = LOOKUP( ContactType.ContactType, ctype-list ) <> 0.
155 IF NOT include-types THEN use-contact-type = NOT use-contact-type.
156 IF NOT use-contact-type THEN NEXT.
157 RUN each-contact-type.
159 END.
161 END PROCEDURE.
163 /* _UIB-CODE-BLOCK-END */
164 &ANALYZE-RESUME
166 &ENDIF
168 &IF DEFINED(EXCLUDE-each-contact) = 0 &THEN
170 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE each-contact Procedure
171 PROCEDURE each-contact :
172 /*------------------------------------------------------------------------------
173 Purpose:
174 ------------------------------------------------------------------------------*/
175 DEF INPUT PARAMETER ct-type AS CHAR NO-UNDO.
176 DEF INPUT PARAMETER person-code AS INT NO-UNDO.
178 DEF BUFFER Psn FOR Person.
179 DEF BUFFER Ctc FOR Contact.
180 DEF VAR phone-no AS CHAR EXTENT 3 NO-UNDO.
181 DEF VAR contact-types AS CHAR NO-UNDO.
182 DEF VAR i AS INT NO-UNDO.
184 FIND Psn WHERE Psn.PersonCode = person-code NO-LOCK NO-ERROR.
185 IF NOT AVAILABLE(Psn) THEN RETURN.
187 IF entity-type <> "" THEN
188 phone-no[1] = get-phone-nos( Psn.PersonCode ).
189 ELSE DO i = 1 TO NUM-ENTRIES( phtype-list ):
190 FIND PhoneDetail WHERE
191 PhoneDetail.PersonCode = Psn.PersonCode AND
192 PhoneDetail.PhoneType = ENTRY( i, phtype-list )
193 NO-LOCK NO-ERROR.
195 phone-no[i] = "".
196 IF AVAILABLE PhoneDetail THEN
197 RUN combine-phone( PhoneDetail.cCountryCode, PhoneDetail.cSTDCode, PhoneDetail.Number,
198 OUTPUT phone-no[i] ).
199 END.
201 contact-types = "".
202 FOR EACH Ctc WHERE Ctc.PersonCode = Psn.PersonCode:
203 contact-types = contact-types + Ctc.ContactType + ", ".
204 END.
205 contact-types = TRIM(contact-types, ", ").
207 out-line = SPC( 2 ) + STRING(person-code,">>>>9 ")
208 + STRING( null-str(ct-type,"?"), "X(4)") + SPC( 2 )
209 + STRING( null-str(Psn.FirstName, ""), "X(15)" ) + SPC( 1 )
210 + STRING( null-str(Psn.LastName, ""), "X(15)" ) + SPC( 1 ) .
212 IF entity-type <> "" THEN
213 out-line = out-line
214 + STRING( null-str(phone-no[1], ""), "X(92)" ) + SPC( 1 )
215 + STRING( null-str(Psn.JobTitle, ""), "X(40)" ) + SPC( 1 ).
216 ELSE
217 out-line = out-line
218 + STRING( null-str(phone-no[1], ""), "X(20)" ) + SPC( 1 )
219 + STRING( null-str(phone-no[2], ""), "X(20)" ) + SPC( 1 )
220 + STRING( null-str(phone-no[3], ""), "X(20)" ) + SPC( 1 )
221 + STRING( null-str(Psn.JobTitle, ""), "X(40)" ) + SPC( 1 )
222 + STRING( null-str(contact-types, ""), "X(40)" ) .
225 RUN pclrep-line( "courier,Fixed,cpi,18,lpi,9,Normal", out-line ).
227 END PROCEDURE.
229 /* _UIB-CODE-BLOCK-END */
230 &ANALYZE-RESUME
232 &ENDIF
234 &IF DEFINED(EXCLUDE-each-contact-type) = 0 &THEN
236 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE each-contact-type Procedure
237 PROCEDURE each-contact-type :
238 /*------------------------------------------------------------------------------
239 Purpose:
240 ------------------------------------------------------------------------------*/
242 RUN clear-list-contacts.
243 FOR EACH Contact OF ContactType NO-LOCK:
244 RUN make-list-contact( Contact.ContactType, Contact.PersonCode, ? ).
245 END.
247 IF NOT CAN-FIND( FIRST ListContact) THEN RETURN.
248 RUN pclrep-line( "Helvetica,Point,12,Bold,Proportional", ContactType.Description + " (" + ContactType.ContactType + ")" ).
249 RUN pclrep-line( ?, "" ).
251 RUN output-list-contacts.
252 RUN pclrep-line( ?, "" ).
254 END PROCEDURE.
256 /* _UIB-CODE-BLOCK-END */
257 &ANALYZE-RESUME
259 &ENDIF
261 &IF DEFINED(EXCLUDE-each-entity) = 0 &THEN
263 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE each-entity Procedure
264 PROCEDURE each-entity :
265 /*------------------------------------------------------------------------------
266 Purpose:
267 ------------------------------------------------------------------------------*/
268 IF NOT( page-per-tenant ) THEN DO:
269 RUN pclrep-line( "Helvetica,Point,12,Bold,Proportional", entity-description + " (" + entity-type + STRING(entity-code) + ")" ).
270 RUN pclrep-line( ?, "" ).
271 END.
273 FOR EACH Tenant WHERE Tenant.EntityType = entity-type
274 AND Tenant.EntityCode = entity-code
275 AND Tenant.Active NO-LOCK:
276 RUN each-tenant.
277 END.
278 IF NOT( page-per-tenant ) THEN DO:
279 RUN pclrep-page-break.
280 END.
282 END PROCEDURE.
284 /* _UIB-CODE-BLOCK-END */
285 &ANALYZE-RESUME
287 &ENDIF
289 &IF DEFINED(EXCLUDE-each-tenant) = 0 &THEN
291 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE each-tenant Procedure
292 PROCEDURE each-tenant :
293 /*------------------------------------------------------------------------------
294 Purpose:
295 ------------------------------------------------------------------------------*/
296 DEF VAR person-address AS CHAR NO-UNDO.
297 DEF VAR tenant-name AS CHAR NO-UNDO.
299 IF page-per-tenant THEN DO:
300 RUN pclrep-line( "Helvetica,Point,12,Bold,Proportional", entity-description + " (" + entity-type + STRING(entity-code) + ")" ).
301 RUN pclrep-line( ?, "" ).
302 END.
304 RUN clear-list-contacts.
305 tenant-name = (IF Tenant.LegalName <> "" THEN Tenant.LegalName ELSE Tenant.Name).
306 RUN process/getaddr.p( "PERSON", Tenant.BillingContact, ptype-list, OUTPUT person-address ).
307 person-address = TRIM( TRIM( REPLACE( REPLACE( person-address, CHR(13), ""), "~n", "," ), "," ) ).
309 RUN make-list-contact( "ACCT", Tenant.BillingContact, person-address ).
310 RUN make-list-contact( "PROP", Tenant.PropertyContact, person-address ).
311 RUN make-list-contact( "AH-1", Tenant.AH1Contact, person-address ).
312 RUN make-list-contact( "AH-2", Tenant.AH2Contact, person-address ).
313 FOR EACH EntityContact WHERE EntityContact.EntityType = "T"
314 AND EntityContact.EntityCode = Tenant.TenantCode NO-LOCK:
315 RUN make-list-contact( EntityContact.EntityContactType, EntityContact.PersonCode, person-address).
316 END.
318 IF NOT CAN-FIND( FIRST ListContact) THEN RETURN.
320 RUN pclrep-line( "Helvetica,Point,8,Normal,Proportional", tenant-name + (IF person-address <> "" THEN ", " + person-address ELSE "") ).
321 RUN pclrep-line( ?, "" ).
323 RUN output-list-contacts.
324 RUN pclrep-line( ?, "" ).
326 IF page-per-tenant THEN DO:
327 RUN pclrep-page-break.
328 END.
330 END PROCEDURE.
332 /* _UIB-CODE-BLOCK-END */
333 &ANALYZE-RESUME
335 &ENDIF
337 &IF DEFINED(EXCLUDE-entity-contacts) = 0 &THEN
339 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE entity-contacts Procedure
340 PROCEDURE entity-contacts :
341 /*------------------------------------------------------------------------------
342 Purpose:
343 ------------------------------------------------------------------------------*/
344 DEF VAR entity-from AS INT NO-UNDO.
346 IF entity-type = "P" THEN DO:
347 entity-from = entity-code.
348 FOR EACH Property WHERE Property.PropertyCode >= entity-from
349 AND Property.PropertyCode <= entity-to
350 AND Property.Active NO-LOCK:
351 entity-description = Property.Name.
352 entity-code = Property.PropertyCode .
353 RUN each-entity.
354 END.
355 END.
356 ELSE DO:
357 RUN each-entity.
358 END.
360 END PROCEDURE.
362 /* _UIB-CODE-BLOCK-END */
363 &ANALYZE-RESUME
365 &ENDIF
367 &IF DEFINED(EXCLUDE-inst-page-footer) = 0 &THEN
369 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE inst-page-footer Procedure
370 PROCEDURE inst-page-footer :
371 /*------------------------------------------------------------------------------
372 Purpose: Print any page footer
373 ------------------------------------------------------------------------------*/
375 END PROCEDURE.
377 /* _UIB-CODE-BLOCK-END */
378 &ANALYZE-RESUME
380 &ENDIF
382 &IF DEFINED(EXCLUDE-inst-page-header) = 0 &THEN
384 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE inst-page-header Procedure
385 PROCEDURE inst-page-header :
386 /*------------------------------------------------------------------------------
387 Purpose: Print any page header
388 ------------------------------------------------------------------------------*/
390 RUN pclrep-line( "univers,Point,7,bold,proportional", TimeStamp).
391 RUN pclrep-line( "univers,Point,12,bold,proportional", FILL( " ", 45) + "Contact Listing").
393 IF merge-list THEN DO:
394 RUN pclrep-line( "", "").
395 RUN pclrep-line( "courier,Fixed,cpi,18,lpi,9,Bold", "Contact Types: " + ctype-list ).
396 END.
398 RUN pclrep-line( "", "").
399 out-line = SPC( 6 ) +
400 STRING( "First Name", "X(15)" ) + SPC( 3 ) +
401 STRING( "Last Name", "X(15)" ) + SPC( 3 ).
403 IF entity-type <> "" THEN
404 out-line = out-line + STRING( "Phone Nos.", "X(92)" ) + SPC( 1 )
405 + STRING( "Position title", "X(41)" ) + "~n" .
406 ELSE
407 out-line = out-line + STRING( "Business", "X(20)" ) + SPC( 1 ) +
408 STRING( "Facsimile", "X(20)" ) + SPC( 1 ) +
409 STRING( "Mobile", "X(18)" ) + SPC( 1 ) +
410 STRING( "Position title", "X(41)" )
411 + "Contact types~n" .
413 RUN pclrep-line( "courier,Fixed,cpi,18,lpi,9,Bold", out-line ).
416 END PROCEDURE.
418 /* _UIB-CODE-BLOCK-END */
419 &ANALYZE-RESUME
421 &ENDIF
423 &IF DEFINED(EXCLUDE-make-list-contact) = 0 &THEN
425 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE make-list-contact Procedure
426 PROCEDURE make-list-contact :
427 /*------------------------------------------------------------------------------
428 Purpose:
429 ------------------------------------------------------------------------------*/
430 DEF INPUT PARAMETER contact-type AS CHAR NO-UNDO.
431 DEF INPUT PARAMETER person-code AS INT NO-UNDO.
432 DEF INPUT PARAMETER person-address AS CHAR NO-UNDO.
434 IF NOT CAN-DO( ctype-list, contact-type ) THEN RETURN.
435 FIND FIRST Person WHERE Person.PersonCode = person-code NO-LOCK NO-ERROR.
436 IF AVAILABLE(Person) THEN DO:
437 IF TRIM(null-str(Person.Company,"")) = ""
438 AND TRIM(null-str(Person.FirstName,"")) = ""
439 AND null-str(Person.LastName,"") = ""
440 THEN RETURN.
442 FIND ListContact WHERE ListContact.PersonCode = Person.PersonCode NO-ERROR.
443 IF AVAILABLE(ListContact) THEN RETURN.
444 CREATE ListContact.
445 ListContact.PersonCode = Person.PersonCode.
446 ListContact.LastName = Person.LastName.
447 ListContact.ContactType = contact-type.
448 IF person-address = ? THEN DO:
449 RUN process/getaddr.p( "PERSON", Person.PersonCode, ptype-list, OUTPUT person-address ).
450 person-address = TRIM( TRIM( REPLACE( REPLACE( person-address, CHR(13), ""), "~n", ", " ), ", " ) ).
451 IF person-address = ? THEN person-address = "".
452 END.
453 ListContact.Address = person-address.
454 ListContact.Company = null-str( Person.Company, "")
455 + (IF ListContact.Address <> "" THEN ", " ELSE "")
456 + ListContact.Address.
458 IF entity-type <> "" AND AVAILABLE(Tenant) THEN
459 ListContact.Company = "T" + STRING(Tenant.TenantCode) + " - " + ListContact.Company.
460 END.
462 END PROCEDURE.
464 /* _UIB-CODE-BLOCK-END */
465 &ANALYZE-RESUME
467 &ENDIF
469 &IF DEFINED(EXCLUDE-merge-contacts) = 0 &THEN
471 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE merge-contacts Procedure
472 PROCEDURE merge-contacts :
473 /*------------------------------------------------------------------------------
474 Purpose:
475 ------------------------------------------------------------------------------*/
476 DEF VAR use-contact-type AS LOGI NO-UNDO.
477 DEF VAR person-address AS CHAR NO-UNDO.
479 FOR EACH Contact NO-LOCK:
480 IF CAN-FIND(FIRST ListContact WHERE ListContact.PersonCode = Contact.PersonCode ) THEN NEXT.
481 use-contact-type = LOOKUP( Contact.ContactType, ctype-list ) <> 0.
482 IF NOT include-types THEN use-contact-type = NOT use-contact-type.
483 IF NOT use-contact-type THEN NEXT.
485 RUN make-list-contact( "", Contact.PersonCode, ? ).
486 END.
488 RUN output-list-contacts.
490 END PROCEDURE.
492 /* _UIB-CODE-BLOCK-END */
493 &ANALYZE-RESUME
495 &ENDIF
497 &IF DEFINED(EXCLUDE-output-list-contacts) = 0 &THEN
499 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE output-list-contacts Procedure
500 PROCEDURE output-list-contacts :
501 /*------------------------------------------------------------------------------
502 Purpose:
503 ------------------------------------------------------------------------------*/
505 FOR EACH ListContact, FIRST Person WHERE ListContact.PersonCode=Person.PersonCode
506 BREAK BY ListContact.Company:
507 IF FIRST-OF( ListContact.Company ) THEN
508 RUN pclrep-line( "Helvetica,Point,8,Normal,Proportional", ListContact.Company ).
510 RUN each-contact( ListContact.ContactType, ListContact.PersonCode ).
512 IF LAST-OF( ListContact.Company ) THEN RUN pclrep-line( ?, "" ).
513 END.
516 END PROCEDURE.
518 /* _UIB-CODE-BLOCK-END */
519 &ANALYZE-RESUME
521 &ENDIF
523 &IF DEFINED(EXCLUDE-parse-parameters) = 0 &THEN
525 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE parse-parameters Procedure
526 PROCEDURE parse-parameters :
527 /*------------------------------------------------------------------------------
528 Purpose:
529 Parameters: <none>
530 Notes:
531 ------------------------------------------------------------------------------*/
533 DEF VAR i AS INT NO-UNDO.
534 DEF VAR token AS CHAR NO-UNDO.
536 {inc/showopts.i "report-options"}
538 DO i = 1 TO NUM-ENTRIES( report-options, "~n" ):
539 token = ENTRY( i, report-options, "~n" ).
541 CASE ENTRY( 1, token ):
542 WHEN "ContactTypes" THEN ctype-list = SUBSTR( token, INDEX( token, "," ) + 1 ).
543 WHEN "PostalTypes" THEN ptype-list = SUBSTR( token, INDEX( token, "," ) + 1 ).
544 WHEN "Exclude" THEN include-types = ENTRY( 2, token ) <> "Yes".
545 WHEN "Preview" THEN preview = Yes.
546 WHEN "Merge" THEN merge-list = Yes.
547 WHEN "PagePerTenant" THEN page-per-tenant = Yes.
548 WHEN "Entity" THEN DO:
549 entity-type = ENTRY( 2, token ).
550 entity-code = INT( ENTRY( 3,token )).
551 IF NUM-ENTRIES(token) = 4 THEN
552 entity-to = INT( ENTRY( 4,token )).
553 ELSE
554 entity-to = entity-code.
555 IF entity-to < entity-code THEN entity-to = entity-code.
556 END.
557 END CASE.
558 END.
560 CASE entity-type:
561 WHEN "P" THEN DO:
562 FIND Property WHERE Property.PropertyCode = entity-code NO-LOCK.
563 entity-description = Property.Name.
564 END.
565 WHEN "L" THEN DO:
566 FIND Company WHERE Company.CompanyCode = entity-code NO-LOCK.
567 entity-description = Company.LegalName .
568 END.
569 OTHERWISE DO:
570 entity-type = "".
571 END.
572 END CASE.
574 END PROCEDURE.
576 /* _UIB-CODE-BLOCK-END */
577 &ANALYZE-RESUME
579 &ENDIF