1 &ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12
3 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS Procedure
4 /*--------------------------------------------------------------------------
5 Report
: Merge duplicate Person records
6 Author
: Andrew McMillan
8 ------------------------------------------------------------------------*/
10 DEF INPUT PARAMETER report-options
AS CHAR NO-UNDO.
12 DEF VAR preview
AS LOGI
NO-UNDO INIT Yes.
13 DEF VAR person-code
AS INT NO-UNDO.
16 DEF VAR user-name
AS CHAR NO-UNDO.
17 {inc
/username.i
"user-name"}
18 DEF VAR timeStamp
AS CHAR FORMAT "X(44)" NO-UNDO.
19 timeStamp
= STRING( TODAY, "99/99/9999") + ", " + STRING( TIME, "HH:MM:SS") + " for " + user-name.
21 DEF VAR base-font
AS CHAR NO-UNDO INITIAL "fixed,courier,cpi,16,lpi,8,normal".
22 DEF VAR header1-font
AS CHAR NO-UNDO INITIAL "proportional,helv,point,13,lpi,6,bold".
23 DEF VAR header2-font
AS CHAR NO-UNDO INITIAL "proportional,helv,point,11,lpi,7,bold".
24 DEF VAR header3-font
AS CHAR NO-UNDO INITIAL "fixed,courier,cpi,13,lpi,7.5,bold".
26 DEF VAR records-merged
AS LOGI
NO-UNDO INITIAL No.
27 DEF VAR to-merge
AS INT NO-UNDO INITIAL 0.
29 DEF TEMP-TABLE ToMerge
NO-UNDO
30 FIELD PersonCode
AS INT.
32 DEF BUFFER MainPerson
FOR Person.
33 DEF BUFFER OtherPerson
FOR Person.
35 /* _UIB-CODE-BLOCK-END
*/
39 &ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
41 /* ******************** Preprocessor Definitions
******************** */
43 &Scoped-define PROCEDURE-TYPE Procedure
44 &Scoped-define DB-AWARE no
48 /* _UIB-PREPROCESSOR-BLOCK-END
*/
52 /* ************************ Function Prototypes
********************** */
54 &IF DEFINED(EXCLUDE-ask-merge-duplicates) = 0 &THEN
56 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD ask-merge-duplicates Procedure
57 FUNCTION ask-merge-duplicates
RETURNS LOGICAL
58 ( /* no parameter-definitions
*/ ) FORWARD.
60 /* _UIB-CODE-BLOCK-END
*/
66 /* *********************** Procedure Settings
************************ */
68 &ANALYZE-SUSPEND _PROCEDURE-SETTINGS
69 /* Settings for
THIS-PROCEDURE
73 Add Fields to
: Neither
74 Other Settings
: CODE-ONLY
COMPILE
76 &ANALYZE-RESUME _END-PROCEDURE-SETTINGS
78 /* ************************* Create Window
************************** */
80 &ANALYZE-SUSPEND _CREATE-WINDOW
81 /* DESIGN Window definition
(used by the UIB
)
82 CREATE WINDOW Procedure
ASSIGN
85 /* END WINDOW DEFINITION
*/
89 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _INCLUDED-LIB Procedure
90 /* ************************* Included-Libraries
*********************** */
94 {inc
/method
/m-txtrep.i
}
96 /* _UIB-CODE-BLOCK-END
*/
103 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Procedure
106 /* *************************** Main Block
*************************** */
108 OUTPUT TO VALUE(txtrep-print-file
) KEEP-MESSAGES PAGE-SIZE 0.
109 RUN pclrep-start
( preview
, "reset,portrait,tm,2,a4,lm,6," + base-font
).
114 IF to-merge
> 0 AND to-merge
< 100 AND ask-merge-duplicates
() THEN RUN merge-duplicates.
116 IF NOT(records-merged
) THEN RETURN "FAIL".
118 /* _UIB-CODE-BLOCK-END
*/
122 /* ********************** Internal Procedures
*********************** */
124 &IF DEFINED(EXCLUDE-change-pointers) = 0 &THEN
126 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE change-pointers Procedure
127 PROCEDURE change-pointers
:
128 /*------------------------------------------------------------------------------
130 ------------------------------------------------------------------------------*/
131 DEF INPUT PARAMETER from-code
AS INT NO-UNDO.
133 FIND OtherPerson
WHERE OtherPerson.PersonCode
= from-code
NO-LOCK NO-ERROR.
134 IF NOT AVAILABLE(OtherPerson
) THEN RETURN.
136 FOR EACH Approver
WHERE Approver.PersonCode
= from-code
EXCLUSIVE-LOCK:
137 Approver.PersonCode
= person-code.
140 FOR EACH Usr
WHERE Usr.PersonCode
= from-code
EXCLUSIVE-LOCK:
141 Usr.PersonCode
= person-code.
144 FOR EACH Property
WHERE Property.Manager
= from-code
EXCLUSIVE-LOCK:
145 Property.Manager
= person-code.
148 FOR EACH Property
WHERE Property.Administrator
= from-code
EXCLUSIVE-LOCK:
149 Property.Administrator
= person-code.
152 FOR EACH Guarantor
WHERE Guarantor.PersonCode
= from-code
EXCLUSIVE-LOCK:
153 Guarantor.PersonCode
= person-code.
156 FOR EACH Directorship
WHERE DirectorShip.PersonCode
= from-code
EXCLUSIVE-LOCK:
157 Directorship.PersonCode
= person-code.
160 FOR EACH BuildingEvent
WHERE BuildingEvent.PersonCode
= from-code
EXCLUSIVE-LOCK:
161 BuildingEvent.PersonCode
= person-code.
164 FOR EACH Scenario
WHERE Scenario.PersonCode
= from-code
EXCLUSIVE-LOCK:
165 Scenario.PersonCode
= person-code.
168 FOR EACH NewBatch
WHERE NewBatch.PersonCode
= from-code
EXCLUSIVE-LOCK:
169 NewBatch.PersonCode
= person-code.
172 FOR EACH Shareholder
WHERE Shareholder.PersonCode
= from-code
EXCLUSIVE-LOCK:
173 Shareholder.PersonCode
= person-code.
176 FOR EACH SubLease
WHERE SubLease.PersonCode
= from-code
EXCLUSIVE-LOCK:
177 SubLease.PersonCode
= person-code.
180 FOR EACH EntityContact
WHERE EntityContact.PersonCode
= from-code
EXCLUSIVE-LOCK:
181 EntityContact.PersonCode
= person-code.
182 IF EntityContact.EntityType
= "T" THEN RUN
183 fix-tenant
( EntityContact.EntityCode
, from-code
, person-code
).
184 ELSE IF EntityContact.EntityType
= "C" THEN
185 RUN fix-creditor
( EntityContact.EntityCode
, from-code
, person-code
).
188 FOR EACH Inspector
WHERE Inspector.PersonCode
= from-code
EXCLUSIVE-LOCK:
189 Inspector.PersonCode
= person-code.
192 FOR EACH Tenant
WHERE Tenant.Name
= OtherPerson.Company
NO-LOCK:
193 RUN fix-tenant
( Tenant.TenantCode
, from-code
, person-code
).
196 FOR EACH Creditor
WHERE Creditor.Name
= OtherPerson.Company
EXCLUSIVE-LOCK:
197 RUN fix-creditor
( Creditor.CreditorCode
, from-code
, person-code
).
200 FOR EACH PersonDetail
WHERE PersonDetail.PersonCode
= from-code
EXCLUSIVE-LOCK:
201 PersonDetail.PersonCode
= person-code.
206 /* _UIB-CODE-BLOCK-END
*/
211 &IF DEFINED(EXCLUDE-find-duplicates) = 0 &THEN
213 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE find-duplicates Procedure
214 PROCEDURE find-duplicates
:
215 /*------------------------------------------------------------------------------
217 ------------------------------------------------------------------------------*/
218 FIND MainPerson
WHERE MainPerson.PersonCode
= person-code
NO-LOCK NO-ERROR.
219 IF NOT AVAILABLE(MainPerson
) THEN DO:
220 RUN pclrep-line
( base-font
, "Person " + STRING(person-code
) + " not on file!").
223 IF MainPerson.FirstName
= "" OR MainPerson.LastName
= "" THEN DO:
224 RUN pclrep-line
( header2-font
, "Skipping " + STRING(MainPerson.PersonCode
) + " - "
226 + " - no first or no last name and is therefore not a person!"
228 RUN pclrep-down-by
( 0.6 ).
232 RUN pclrep-line
( header2-font
, "Merging to " + STRING(MainPerson.PersonCode
) + " - "
233 + MainPerson.Company
+ ", "
234 + combine-name
( MainPerson.PersonTitle
, MainPerson.FirstName
, MainPerson.MiddleName
, MainPerson.LastName
, MainPerson.NameSuffix
)
236 RUN pclrep-down-by
( 0.6 ).
238 FOR EACH OtherPerson
WHERE OtherPerson.LastName
= MainPerson.LastName
239 AND OtherPerson.FirstName
= MainPerson.FirstName
NO-LOCK:
240 IF RECID(OtherPerson
) = RECID(MainPerson
) THEN NEXT.
242 IF OtherPerson.Company
<> MainPerson.Company
THEN DO:
243 RUN pclrep-line
( base-font
, "Person " + STRING(OtherPerson.PersonCode
) + " company names differ: "
244 + combine-name
( OtherPerson.PersonTitle
, OtherPerson.FirstName
, OtherPerson.MiddleName
, OtherPerson.LastName
, OtherPerson.NameSuffix
) + ", " + OtherPerson.Company
245 + " (warning only - records will be merged anyway)" ).
248 IF OtherPerson.FirstName
<> MainPerson.FirstName
THEN DO:
249 RUN pclrep-line
( base-font
, "Person " + STRING(OtherPerson.PersonCode
) + " First names differ: "
250 + combine-name
( OtherPerson.PersonTitle
, OtherPerson.FirstName
, OtherPerson.MiddleName
, OtherPerson.LastName
, OtherPerson.NameSuffix
) ).
254 IF OtherPerson.MiddleName
<> MainPerson.MiddleName
THEN DO:
255 RUN pclrep-line
( base-font
, "Person " + STRING(OtherPerson.PersonCode
) + " middle names differ: "
256 + combine-name
( OtherPerson.PersonTitle
, OtherPerson.FirstName
, OtherPerson.MiddleName
, OtherPerson.LastName
, OtherPerson.NameSuffix
) ).
259 IF OtherPerson.NameSuffix
<> MainPerson.NameSuffix
THEN DO:
260 RUN pclrep-line
( base-font
, "Person " + STRING(OtherPerson.PersonCode
) + " name suffixes differ: "
261 + combine-name
( OtherPerson.PersonTitle
, OtherPerson.FirstName
, OtherPerson.MiddleName
, OtherPerson.LastName
, OtherPerson.NameSuffix
) ).
266 ToMerge.PersonCode
= OtherPerson.PersonCode.
268 RUN pclrep-line
( base-font
, "Code: " + STRING(STRING(OtherPerson.PersonCode
),"X(10)") + " "
269 + "Title: " + STRING(OtherPerson.JobTitle
, "X(50)") ).
270 RUN pclrep-line
( base-font
, "DOB: " + null-str
(STRING(OtherPerson.DateOfBirth
,"99/99/9999")," ") + " "
271 + "Dept: " + STRING(OtherPerson.Department
, "X(50)") ).
272 RUN pclrep-line
( base-font
, "Sex: " + null-str
(STRING(OtherPerson.Sex
,"Male/Female"),"Male") + " "
273 + "Office: " + STRING(OtherPerson.Office
, "X(50)") ).
274 RUN pclrep-line
( base-font
, "H'cap: " + null-str
(STRING(OtherPerson.GolfHandicap
,"->>9"),"N/A") + " "
275 + "Company: " + STRING(OtherPerson.Company
, "X(50)") ).
277 to-merge
= to-merge
+ 1.
281 RUN pclrep-down-by
( 1.4 ).
282 RUN pclrep-line
( base-font
, STRING(to-merge
) + " records found to merge" ).
283 RUN pclrep-down-by
( 2 ).
287 /* _UIB-CODE-BLOCK-END
*/
292 &IF DEFINED(EXCLUDE-fix-creditor) = 0 &THEN
294 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE fix-creditor Procedure
295 PROCEDURE fix-creditor
:
296 /*------------------------------------------------------------------------------
298 ------------------------------------------------------------------------------*/
299 DEF INPUT PARAMETER creditor-code
AS INT NO-UNDO.
300 DEF INPUT PARAMETER from-code
AS INT NO-UNDO.
301 DEF INPUT PARAMETER to-code
AS INT NO-UNDO.
303 FIND Creditor
WHERE Creditor.CreditorCode
= creditor-code
EXCLUSIVE-LOCK.
305 IF Creditor.PaymentContact
= from-code
THEN Creditor.PaymentContact
= to-code.
306 IF Creditor.OtherContact
= from-code
THEN Creditor.OtherContact
= to-code.
310 /* _UIB-CODE-BLOCK-END
*/
315 &IF DEFINED(EXCLUDE-fix-tenant) = 0 &THEN
317 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE fix-tenant Procedure
318 PROCEDURE fix-tenant
:
319 /*------------------------------------------------------------------------------
321 ------------------------------------------------------------------------------*/
322 DEF INPUT PARAMETER tenant-code
AS INT NO-UNDO.
323 DEF INPUT PARAMETER from-code
AS INT NO-UNDO.
324 DEF INPUT PARAMETER to-code
AS INT NO-UNDO.
326 FIND Tenant
WHERE Tenant.TenantCode
= tenant-code
EXCLUSIVE-LOCK.
327 IF Tenant.BillingContact
= from-code
THEN Tenant.BillingContact
= to-code.
328 IF Tenant.AH1Contact
= from-code
THEN Tenant.AH1Contact
= to-code.
329 IF Tenant.AH2Contact
= from-code
THEN Tenant.AH2Contact
= to-code.
330 IF Tenant.PropertyContact
= from-code
THEN Tenant.PropertyContact
= to-code.
334 /* _UIB-CODE-BLOCK-END
*/
339 &IF DEFINED(EXCLUDE-inst-page-footer) = 0 &THEN
341 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE inst-page-footer Procedure
342 PROCEDURE inst-page-footer
:
343 /*------------------------------------------------------------------------------
344 Purpose
: Print any page footer
345 ------------------------------------------------------------------------------*/
349 /* _UIB-CODE-BLOCK-END
*/
354 &IF DEFINED(EXCLUDE-inst-page-header) = 0 &THEN
356 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE inst-page-header Procedure
357 PROCEDURE inst-page-header
:
358 /*------------------------------------------------------------------------------
359 Purpose
: Print any page header
360 ------------------------------------------------------------------------------*/
362 RUN pclrep-line
( "univers,Point,7,bold,Proportional", TimeStamp
).
363 RUN pclrep-line
( "univers,Point,12,bold,Proportional",
364 SPC
(45) + "Merging Duplicate Person Records"
366 RUN pclrep-line
( "", "" ).
368 /* Put any column headers here
*/
372 /* _UIB-CODE-BLOCK-END
*/
377 &IF DEFINED(EXCLUDE-merge-duplicates) = 0 &THEN
379 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE merge-duplicates Procedure
380 PROCEDURE merge-duplicates
:
381 /*------------------------------------------------------------------------------
383 ------------------------------------------------------------------------------*/
387 DO TRANSACTION ON ERROR UNDO, NEXT to-merge-loop
:
388 RUN change-pointers
( ToMerge.PersonCode
).
389 RUN merge-information
( ToMerge.PersonCode
).
390 records-merged
= Yes.
396 /* _UIB-CODE-BLOCK-END
*/
401 &IF DEFINED(EXCLUDE-merge-information) = 0 &THEN
403 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE merge-information Procedure
404 PROCEDURE merge-information
:
405 /*------------------------------------------------------------------------------
406 Purpose
: Merge the fields from one person into another
407 ------------------------------------------------------------------------------*/
408 DEF INPUT PARAMETER from-code
AS INT NO-UNDO.
410 DEF BUFFER TgtContact
FOR Contact.
411 FOR EACH Contact
WHERE Contact.PersonCode
= from-code
EXCLUSIVE-LOCK:
412 FIND TgtContact
WHERE TgtContact.ContactType
= Contact.ContactType
413 AND TgtContact.PersonCode
= person-code
NO-LOCK NO-ERROR.
414 IF AVAILABLE(TgtContact
) THEN
417 Contact.PersonCode
= person-code.
420 DEF BUFFER TgtPhoneDetail
FOR PhoneDetail.
421 FOR EACH PhoneDetail
WHERE PhoneDetail.PersonCode
= from-code
NO-LOCK:
422 FIND TgtPhoneDetail
WHERE TgtPhoneDetail.PhoneType
= PhoneDetail.PhoneType
423 AND TgtPhoneDetail.PersonCode
= person-code
NO-LOCK NO-ERROR.
424 IF NOT AVAILABLE(TgtPhoneDetail
) THEN DO:
425 CREATE TgtPhoneDetail.
426 BUFFER-COPY PhoneDetail
TO TgtPhoneDetail
427 ASSIGN TgtPhoneDetail.PersonCode
= person-code.
431 DEF BUFFER TgtPostalDetail
FOR PostalDetail.
432 FOR EACH PostalDetail
WHERE PostalDetail.PersonCode
= from-code
NO-LOCK:
433 FIND TgtPostalDetail
WHERE TgtPostalDetail.PostalType
= PostalDetail.PostalType
434 AND TgtPostalDetail.PersonCode
= person-code
NO-LOCK NO-ERROR.
435 IF NOT AVAILABLE(TgtPostalDetail
) THEN DO:
436 CREATE TgtPostalDetail.
437 BUFFER-COPY PostalDetail
TO TgtPostalDetail
438 ASSIGN TgtPostalDetail.PersonCode
= person-code.
442 DEF BUFFER TgtPersonDetail
FOR PersonDetail.
443 FOR EACH PersonDetail
WHERE PersonDetail.PersonCode
= from-code
NO-LOCK:
444 FIND TgtPersonDetail
WHERE TgtPersonDetail.PersonDetailType
= PersonDetailType.PersonDetailType
445 AND TgtPersonDetail.PersonCode
= person-code
NO-LOCK NO-ERROR.
446 IF NOT AVAILABLE(TgtPersonDetail
) THEN DO:
447 CREATE TgtPersonDetail.
448 BUFFER-COPY PersonDetail
TO TgtPersonDetail
449 ASSIGN TgtPersonDetail.PersonCode
= person-code.
453 FIND MainPerson
EXCLUSIVE-LOCK WHERE MainPerson.PersonCode
= person-code.
454 FIND OtherPerson
EXCLUSIVE-LOCK WHERE OtherPerson.PersonCode
= from-code.
456 IF MainPerson.JobTitle
= "" THEN MainPerson.JobTitle
= null-str
(OtherPerson.JobTitle
,"").
457 IF MainPerson.Office
= "" THEN MainPerson.Office
= null-str
(OtherPerson.Office
,"").
458 IF MainPerson.Department
= "" THEN MainPerson.Department
= null-str
(OtherPerson.Department
,"").
459 IF MainPerson.Company
= "" THEN MainPerson.Company
= null-str
(OtherPerson.Company
,"").
461 IF MainPerson.PersonTitle
= "" THEN MainPerson.PersonTitle
= OtherPerson.PersonTitle .
462 IF MainPerson.FirstName
= "" THEN MainPerson.FirstName
= OtherPerson.FirstName .
463 IF MainPerson.MiddleNames
= "" THEN MainPerson.MiddleNames
= OtherPerson.MiddleNames .
464 IF MainPerson.LastName
= "" THEN MainPerson.LastName
= OtherPerson.LastName .
465 IF MainPerson.NameSuffix
= "" THEN MainPerson.NameSuffix
= OtherPerson.NameSuffix .
466 IF MainPerson.Initials
= "" THEN MainPerson.Initials
= OtherPerson.Initials .
467 IF MainPerson.Preferred
= "" THEN MainPerson.Preferred
= OtherPerson.Preferred .
468 IF MainPerson.SortOn
= "" THEN MainPerson.SortOn
= OtherPerson.SortOn .
469 IF MainPerson.Spouse
= "" THEN MainPerson.Spouse
= OtherPerson.Spouse .
471 IF MainPerson.Sex
= ?
THEN MainPerson.Sex
= OtherPerson.Sex .
472 IF MainPerson.GolfHandicap
= ?
THEN MainPerson.GolfHandicap
= OtherPerson.GolfHandicap.
473 IF MainPerson.DateOfBirth
= ?
THEN MainPerson.DateOfBirth
= OtherPerson.DateOfBirth .
475 IF MainPerson.LastModified
< OtherPerson.LastModified
THEN MainPerson.LastModified
= OtherPerson.LastModified.
476 IF MainPerson.LastValidated
< OtherPerson.LastValidated
THEN MainPerson.LastValidated
= OtherPerson.LastValidated.
478 IF MainPerson.Notes
= ?
THEN MainPerson.Notes
= OtherPerson.Notes.
480 /* append notes from otherperson to notes for mainperson
*/
483 OtherPerson.Company
= "9ZZZ-" + OtherPerson.Company.
484 OtherPerson.LastName
= "9ZZZ-" + OtherPerson.LastName.
488 /* _UIB-CODE-BLOCK-END
*/
493 &IF DEFINED(EXCLUDE-parse-parameters) = 0 &THEN
495 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE parse-parameters Procedure
496 PROCEDURE parse-parameters
:
497 /*------------------------------------------------------------------------------
499 ------------------------------------------------------------------------------*/
500 DEF VAR token
AS CHAR NO-UNDO.
501 DEF VAR i
AS INT NO-UNDO.
503 DO i
= 1 TO NUM-ENTRIES( report-options
, "~n" ):
504 token
= ENTRY( i
, report-options
, "~n" ).
506 CASE ENTRY( 1, token
):
507 WHEN "Preview" THEN preview
= Yes.
508 WHEN "PersonCode" THEN person-code
= INT( ENTRY(2,token
)).
515 /* _UIB-CODE-BLOCK-END
*/
520 /* ************************ Function Implementations
***************** */
522 &IF DEFINED(EXCLUDE-ask-merge-duplicates) = 0 &THEN
524 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION ask-merge-duplicates Procedure
525 FUNCTION ask-merge-duplicates
RETURNS LOGICAL
526 ( /* no parameter-definitions
*/ ) :
527 /*------------------------------------------------------------------------------
528 Purpose
: Ask the user whether we should merge the duplicates
530 ------------------------------------------------------------------------------*/
531 DEF VAR yes-do-it
AS LOGI
NO-UNDO INITIAL No.
533 MESSAGE "Merge duplicate records?" VIEW-AS ALERT-BOX
535 TITLE "Confirm Merge Records"
542 /* _UIB-CODE-BLOCK-END
*/