Really, this should be it, for the passing income.
[capital-apms-progress.git] / process / one-off / chgphone.p
blob64471e2590432f51f5d59acb98f797080882d581
1 &ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12
2 &ANALYZE-RESUME
3 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS Procedure
4 /*--------------------------------------------------------------------------
5 ------------------------------------------------------------------------*/
7 {inc/ofc-this.i}
8 {inc/ofc-set.i "Country-Code" "c-this-country"}
9 {inc/ofc-set.i "STD-Code" "c-this-std"}
11 {inc/persndtl.i}
13 DEF VAR phone-string AS CHAR NO-UNDO FORMAT "X(16)".
14 DEF VAR cc LIKE PhoneDetail.cCountryCode NO-UNDO.
15 DEF VAR cs LIKE PhoneDetail.cStdCode NO-UNDO.
16 DEF VAR ph LIKE PhoneDetail.Number NO-UNDO.
17 DEF VAR nice-phone AS CHAR NO-UNDO FORMAT "X(24)".
19 DEFINE FRAME default-frame WITH DOWN NO-BOX WIDTH 109.
20 FORM
21 Person.Company COLUMN-LABEL "Company" FORMAT "X(10)"
22 Person.LastName COLUMN-LABEL "Last Name" FORMAT "X(10)"
23 PhoneDetail.CountryCode COLUMN-LABEL "Ctry" FORMAT ">>>9"
24 PhoneDetail.STDCode COLUMN-LABEL "STD" FORMAT ">>>9"
25 PhoneDetail.Number FORMAT "X(20)"
26 cc COLUMN-LABEL "Ctry" FORMAT "X(4)"
27 cs COLUMN-LABEL "STD" FORMAT "X(4)"
28 ph FORMAT "X(12)"
29 nice-phone
30 WITH FRAME default-frame.
32 /* _UIB-CODE-BLOCK-END */
33 &ANALYZE-RESUME
36 &ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
38 /* ******************** Preprocessor Definitions ******************** */
40 &Scoped-define PROCEDURE-TYPE Procedure
44 /* _UIB-PREPROCESSOR-BLOCK-END */
45 &ANALYZE-RESUME
49 /* *********************** Procedure Settings ************************ */
51 &ANALYZE-SUSPEND _PROCEDURE-SETTINGS
52 /* Settings for THIS-PROCEDURE
53 Type: Procedure
54 Allow:
55 Frames: 0
56 Add Fields to: Neither
57 Other Settings: CODE-ONLY COMPILE
59 &ANALYZE-RESUME _END-PROCEDURE-SETTINGS
61 /* ************************* Create Window ************************** */
63 &ANALYZE-SUSPEND _CREATE-WINDOW
64 /* DESIGN Window definition (used by the UIB)
65 CREATE WINDOW Procedure ASSIGN
66 HEIGHT = .25
67 WIDTH = 40.
68 /* END WINDOW DEFINITION */
70 &ANALYZE-RESUME
75 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Procedure
78 /* *************************** Main Block *************************** */
79 DEF VAR w1 AS WIDGET-HANDLE NO-UNDO.
80 DEF VAR prev-window AS WIDGET-HANDLE NO-UNDO.
82 CREATE WINDOW w1
83 ASSIGN TITLE = "Converting Phone Numbers"
84 WIDTH-CHARS = 110
85 HEIGHT-CHARS = 17
86 STATUS-AREA = no
87 MESSAGE-AREA = yes.
89 prev-window = CURRENT-WINDOW.
90 CURRENT-WINDOW = w1.
91 VIEW FRAME default-frame IN WINDOW w1.
92 DO WITH FRAME default-frame:
93 RUN convert-phones.
94 END.
95 CURRENT-WINDOW = prev-window.
96 DELETE WIDGET w1.
98 /* _UIB-CODE-BLOCK-END */
99 &ANALYZE-RESUME
102 /* ********************** Internal Procedures *********************** */
104 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE convert-phones Procedure
105 PROCEDURE convert-phones :
106 /*------------------------------------------------------------------------------
107 Purpose:
108 ------------------------------------------------------------------------------*/
109 DEF VAR i AS INT NO-UNDO.
110 DEF VAR digits AS INT NO-UNDO.
112 FOR EACH Person NO-LOCK,
113 EACH PhoneDetail EXCLUSIVE-LOCK OF Person
114 WHERE PhoneDetail.Number <> ""
115 BY Person.Company:
117 phone-string = "".
119 IF c-this-country = "64" AND PhoneDetail.cCountryCode = "61" AND PhoneDetail.cSTDCode = "2" THEN DO:
120 /* Correct major fuck-up ! */
121 IF PhoneDetail.CountryCode > 0 THEN
122 phone-string = phone-string + "+" + STRING( PhoneDetail.CountryCode ) + " ".
123 END.
124 ELSE IF PhoneDetail.cCountryCode <> "" THEN
125 phone-string = phone-string + "+" + PhoneDetail.cCountryCode + " ".
126 ELSE IF PhoneDetail.CountryCode = 0 AND PhoneDetail.STDCode > 200 THEN
127 phone-string = phone-string + "+1 ".
128 ELSE IF PhoneDetail.CountryCode > 0 THEN
129 phone-string = phone-string + "+" + STRING( PhoneDetail.CountryCode ) + " ".
131 IF c-this-country = "64" AND PhoneDetail.cCountryCode = "61" AND PhoneDetail.cSTDCode = "2" THEN DO:
132 /* Correct major fuck-up ! */
133 IF PhoneDetail.STDCode > 0 THEN
134 phone-string = phone-string + "(" + STRING( PhoneDetail.STDCode ) + ") ".
135 END.
136 ELSE IF PhoneDetail.cSTDCode <> "" THEN
137 phone-string = phone-string + "(" + PhoneDetail.cSTDCode + ") ".
138 ELSE IF PhoneDetail.STDCode = 65 THEN
139 phone-string = phone-string + "+" + STRING( PhoneDetail.STDCode ) + " () ".
140 ELSE IF PhoneDetail.STDCode > 0 THEN
141 phone-string = phone-string + "(" + STRING( PhoneDetail.STDCode ) + ") ".
143 phone-string = phone-string + PhoneDetail.Number.
145 RUN split-phone( phone-string, OUTPUT cc, OUTPUT cs, OUTPUT ph).
148 IF cc = "64" AND
149 (cs = "6" OR cs = "4" OR cs = "3" OR cs = "21" OR cs = "25" OR cs = "9" OR cs = "7")
150 THEN NEXT.
151 IF cc = "61" AND (cs = "2" OR cs = "3" OR cs = "6" OR cs = "7") THEN NEXT.
154 IF cc = "6" AND cs = "4" THEN cc = "64".
155 IF cc = "2" AND cs = "5" THEN ASSIGN cc = "64" cs = "25" .
157 /* Probably US number if (6xx) style */
158 IF LENGTH(cs) = 3 AND SUBSTR(cs,1,1) = "6" THEN cc = "1".
159 IF cc = "64" AND cs = "1" AND LENGTH( ENTRY(1,ph," ")) = 3 THEN
160 ASSIGN cc = "1" cs = ENTRY(1,ph," ") ph = SUBSTR(ph,5) .
162 /* someone left the country code of some UK numbers */
163 IF cc = "64" AND cs = "131" THEN ASSIGN cc = "44" .
164 IF cc = "64" AND cs = "171" THEN ASSIGN cc = "44" .
166 /* someone left the country code of a Chengdu number */
167 IF cc = "64" AND cs = "28" THEN ASSIGN cc = "86" .
169 /* hong kong numbers have often had the same problem */
170 IF cc = "64" AND cs = "852" THEN ASSIGN cc = cs cs = "" .
171 IF cc = "85" AND cs = "2" THEN ASSIGN cc = cs cs = "" .
173 /* Australian numbers frequently miss the code, especially mobiles */
174 IF cc = "64" AND cs = "14" THEN ASSIGN cc = "61".
175 IF cc = "64" AND cs = "15" THEN ASSIGN cc = "61".
176 IF cc = "64" AND cs = "18" THEN ASSIGN cc = "61".
177 IF cc = "64" AND SUBSTR(cs, 1, 2) = "41" THEN ASSIGN cc = "61".
179 /* for NZ all STD codes are single unless they begin with 2,8 or 9 */
180 IF cc = "64" AND LENGTH(cs) > 1 THEN DO:
181 IF cs <> "25" AND cs <> "21" AND cs <> "800" AND cs <> "900" AND cs <> "131" THEN ASSIGN
182 ph = SUBSTR( cs, 2) + " " + ph
183 cs = SUBSTR( cs, 1, 1).
184 END.
186 /* for OZ all STD codes are single unless they begin with 1 or 4 */
187 IF cc = "61" AND LENGTH(cs) > 1 THEN DO:
188 IF SUBSTR( cs, 1, 1) <> "1" AND SUBSTR( cs, 1, 1) <> "4" AND SUBSTR( cs, 1, 1) <> "5" THEN ASSIGN
189 ph = SUBSTR( cs, 2) + " " + ph
190 cs = SUBSTR( cs, 1, 1).
191 END.
193 /* someone seems to have left off the country code entering some melbourne #'s */
194 IF cc = "64" and cs = "3" AND SUBSTR( ph, 1, 2) = "96" THEN
195 cc = "61".
197 /* No "2" on it's own in NZ - it's bound to be sydney */
198 IF cs = "2" AND cc = "64" THEN cc = "61".
200 /* trim off any redundant area code */
201 IF cc <> "64" AND SUBSTR( ph, 1, 3) = cc + cs THEN ph = TRIM( SUBSTR( ph, 4 )).
203 digits = 0.
204 DO i = 1 TO LENGTH(ph):
205 IF SUBSTR(ph,i,1) >= "0" AND SUBSTR(ph,i,1) <= "9" THEN digits = digits + 1.
206 END.
208 IF cc = "64" AND cs = "9" AND digits = 8 AND SUBSTRING( ph, 1, 1) = "9" THEN
209 ph = SUBSTR( ph, 2).
211 IF cc = "61" AND digits < 6 AND LENGTH(cs) > 4 THEN ASSIGN
212 ph = SUBSTR(cs,5) + " " + ph
213 digits = digits + LENGTH(cs) - 4.
214 cs = SUBSTR(cs,1,4).
216 IF cc = "61" AND digits > 8 AND cs = "2" THEN ASSIGN
217 cs = SUBSTR(ph, 1, (IF SUBSTR(ph,3,2) = "00" THEN 4 ELSE 2) )
218 ph = SUBSTR(ph,(IF SUBSTR(ph,3,2) = "00" THEN 5 ELSE 3))
219 digits = digits - (IF SUBSTR(ph,3,2) = "00" THEN 4 ELSE 2) .
221 /* all Sydney and Melbourne numbers have had a "9" prefixed to them recently. */
222 IF cc = "61" AND (cs = "2" OR cs = "3") AND SUBSTR(ph, 1, 1) <> "9"
223 AND SUBSTR(ph, 1, 1) <> "1" AND digits = 7 THEN
224 ph = "9" + ph.
227 DISPLAY Person.Company
228 Person.LastName
229 PhoneDetail.CountryCode
230 PhoneDetail.STDCode
231 PhoneDetail.Number FORMAT "X(14)"
235 WITH FRAME default-frame.
236 RUN combine-phone( cc, cs, ph, OUTPUT nice-phone ).
237 UPDATE nice-phone WITH FRAME default-frame.
238 DOWN WITH FRAME default-frame.
240 PhoneDetail.cCountryCode = cc.
241 PhoneDetail.cSTDCode = cs.
242 PhoneDetail.Number = ph.
243 END.
245 END PROCEDURE.
247 /* _UIB-CODE-BLOCK-END */
248 &ANALYZE-RESUME