Add missing brackets.
[capital-apms-progress.git] / process / export / ctractor.p
blob8258aad3229e61cb9eaeb15201f341d54c9be4b1
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 ------------------------------------------------------------------------*/
17 /* *************************** Definitions ************************** */
19 DEF INPUT PARAMETER report-options AS CHAR NO-UNDO.
21 DEF VAR pty-list AS CHAR NO-UNDO.
22 DEF VAR file-name AS CHAR NO-UNDO.
23 DEF VAR vouchers-after AS DATE NO-UNDO.
24 DEF VAR cheques-after AS DATE NO-UNDO.
25 DEF VAR list-file AS CHAR NO-UNDO.
26 DEF VAR active-only AS LOGI NO-UNDO.
28 DEF VAR prp-selection AS CHAR NO-UNDO.
29 DEF VAR srv-selection AS CHAR NO-UNDO.
30 DEF VAR service-types AS CHAR NO-UNDO.
31 DEF VAR prp-sel-id AS CHAR NO-UNDO.
33 &GLOB EXTRA-FIELDS ~
34 Creditor.CreditorCode ~
35 Creditor.Name ~
36 Property.PropertyCode ~
37 Property.Name ~
38 ( IF AVAILABLE ServiceType THEN ServiceType.Description ELSE "" ) ~
39 ( IF AVAILABLE FrequencyType THEN FrequencyType.Description ELSE "" ) ~
40 Contract.FixedAmount ~
41 Contract.ContractReference
43 &GLOB EXTRA-HEADERS ~
44 "CreditorCode" ~
45 "CreditorName" ~
46 "PropertyCode" ~
47 "PropertyName" ~
48 "ServiceType" ~
49 "Frequency" ~
50 "Amount" ~
51 "Reference"
53 /* _UIB-CODE-BLOCK-END */
54 &ANALYZE-RESUME
57 &ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
59 /* ******************** Preprocessor Definitions ******************** */
61 &Scoped-define PROCEDURE-TYPE Procedure
65 /* _UIB-PREPROCESSOR-BLOCK-END */
66 &ANALYZE-RESUME
70 /* *********************** Procedure Settings ************************ */
72 &ANALYZE-SUSPEND _PROCEDURE-SETTINGS
73 /* Settings for THIS-PROCEDURE
74 Type: Procedure
75 Allow:
76 Frames: 0
77 Add Fields to: Neither
78 Other Settings: CODE-ONLY COMPILE
80 &ANALYZE-RESUME _END-PROCEDURE-SETTINGS
82 /* ************************* Create Window ************************** */
84 &ANALYZE-SUSPEND _CREATE-WINDOW
85 /* DESIGN Window definition (used by the UIB)
86 CREATE WINDOW Procedure ASSIGN
87 HEIGHT = .15
88 WIDTH = 40.
89 /* END WINDOW DEFINITION */
91 &ANALYZE-RESUME
95 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _INCLUDED-LIB Procedure
96 /* ************************* Included-Libraries *********************** */
98 {inc/method/m-expctc.i}
100 /* _UIB-CODE-BLOCK-END */
101 &ANALYZE-RESUME
105 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Procedure
108 /* *************************** Main Block *************************** */
110 DEF VAR i AS INT NO-UNDO.
112 RUN parse-parameters.
114 OUTPUT TO VALUE( file-name ).
116 RUN export-contact-header.
117 this-contact-type = "Contractor".
119 CASE list-file:
121 WHEN "CONTRACTOR" THEN DO:
122 IF prp-selection = "ALL" THEN
123 FOR EACH Property NO-LOCK:
124 RUN each-property.
125 END.
126 ELSE IF prp-selection = "MANAGER" THEN
127 FOR EACH Property NO-LOCK WHERE Property.Administrator = INT( prp-sel-id ):
128 RUN each-property.
129 END.
130 ELSE IF prp-selection = "REGION" THEN
131 FOR EACH Property NO-LOCK WHERE Property.Region = prp-sel-id:
132 RUN each-property.
133 END.
134 END.
136 END CASE.
138 OUTPUT CLOSE.
140 /* _UIB-CODE-BLOCK-END */
141 &ANALYZE-RESUME
144 /* ********************** Internal Procedures *********************** */
146 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE each-property Procedure
147 PROCEDURE each-property :
148 /*------------------------------------------------------------------------------
149 Purpose:
150 ------------------------------------------------------------------------------*/
152 FOR EACH Contract OF Property NO-LOCK WHERE
153 ( IF srv-selection = "ALL" THEN True ELSE LOOKUP( Contract.ServiceType, service-types ) <> 0 ),
155 FIRST Creditor NO-LOCK WHERE
156 ( Creditor.CreditorCode = Contract.CreditorCode ) AND
157 ( Creditor.Active OR (NOT active-only) ) AND
158 ( IF vouchers-after = ? THEN True ELSE CAN-FIND( FIRST Voucher OF Creditor WHERE
159 Voucher.CreatedDate >= vouchers-after )
160 ) AND
162 ( IF cheques-after = ? THEN True ELSE CAN-FIND( FIRST Cheque OF Creditor WHERE
163 Cheque.Date >= cheques-after )
166 FIND Person WHERE Person.PersonCode = Creditor.PaymentContact NO-LOCK NO-ERROR.
167 RUN export-contact.
169 END.
172 END PROCEDURE.
174 /* _UIB-CODE-BLOCK-END */
175 &ANALYZE-RESUME
178 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE parse-parameters Procedure
179 PROCEDURE parse-parameters :
180 /*------------------------------------------------------------------------------
181 Purpose:
182 Parameters: <none>
183 Notes:
184 ------------------------------------------------------------------------------*/
186 DEF VAR i AS INT NO-UNDO.
187 DEF VAR token AS CHAR NO-UNDO.
189 DO i = 1 TO NUM-ENTRIES( report-options, "~n" ):
190 token = ENTRY( i, report-options, "~n" ).
191 CASE ENTRY( 1, token ):
192 WHEN "FileName" THEN file-name = ENTRY( 2, token ).
193 WHEN "Address" THEN pty-list = SUBSTR( token, INDEX( token, "," ) + 1 ).
194 WHEN "Type" THEN list-file = ENTRY( 2, token ).
195 WHEN "VouchersAfter" THEN vouchers-after = DATE( ENTRY( 2, token ) ).
196 WHEN "ChequesAfter" THEN cheques-after = DATE( ENTRY( 2, token ) ).
197 WHEN "ActiveOnly" THEN active-only = ENTRY( 2, token ) = "Yes".
198 WHEN "Property" THEN
200 prp-selection = ENTRY( 2, token ).
201 IF prp-selection <> "ALL" THEN prp-sel-id = ENTRY( 3, token ).
202 END.
203 WHEN "ServiceType" THEN
205 srv-selection = ENTRY( 2, token ).
206 IF srv-selection <> "ALL" THEN service-types = SUBSTR( token, INDEX( token, "," ) + 1 ).
207 END.
209 WHEN "SplitAddress" THEN split-addresses = Yes.
210 WHEN "MakeUnique" THEN make-unique = Yes.
211 WHEN "CleanAddresses" THEN clean-addresses = Yes.
212 WHEN "IncludeNoMailout" THEN include-no-mailout = Yes.
213 END.
214 END.
216 END PROCEDURE.
218 /* _UIB-CODE-BLOCK-END */
219 &ANALYZE-RESUME
222 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE x-export-contact Procedure
223 PROCEDURE x-export-contact :
224 /*------------------------------------------------------------------------------
225 Purpose:
226 Parameters: <none>
227 Notes:
228 ------------------------------------------------------------------------------*/
230 DEF INPUT PARAMETER contact-type AS CHAR NO-UNDO.
232 DEF VAR person-address AS CHAR NO-UNDO.
233 DEF VAR phone-no AS CHAR EXTENT 4 NO-UNDO.
234 DEF VAR phone-list AS CHAR NO-UNDO INIT "HOME,BUS,MOB,FAX".
235 DEF VAR i AS INT NO-UNDO.
237 IF NOT AVAILABLE(Person) THEN RETURN.
238 RUN process/getaddr.p( "PERSON", Person.PersonCode, pty-list, OUTPUT person-address ).
240 DO i = 1 TO NUM-ENTRIES( phone-list ):
241 phone-no[i] = "".
242 FIND PhoneDetail WHERE PhoneDetail.PersonCode = Person.PersonCode
243 AND PhoneDetail.PhoneType = ENTRY( i, phone-list )
244 NO-LOCK NO-ERROR.
245 IF AVAILABLE( PhoneDetail ) THEN
246 phone-no[i] = get-phone-no( Person.PersonCode, ENTRY( i, phone-list ) ).
247 END.
249 DO i = 1 TO NUM-ENTRIES( pty-list ):
250 FIND PostalDetail WHERE
251 PostalDetail.PersonCode = Person.PersonCode AND
252 PostalDetail.PostalType = ENTRY( i, pty-list )
253 NO-LOCK NO-ERROR.
254 IF AVAILABLE(PostalDetail) THEN LEAVE.
255 END.
257 FIND FrequencyType OF Contract NO-LOCK NO-ERROR.
258 FIND ServiceType OF Contract NO-LOCK NO-ERROR.
260 EXPORT DELIMITER ","
261 contact-type
262 Person.PersonTitle
263 Person.FirstName
264 Person.LastName
265 Person.JobTitle
266 Person.Company
267 TRIM(REPLACE(person-address, "~r", ""))
268 (IF AVAILABLE(PostalDetail) THEN PostalDetail.City ELSE "")
269 phone-no[1]
270 phone-no[2]
271 phone-no[3]
272 phone-no[4]
275 END PROCEDURE.
277 /* _UIB-CODE-BLOCK-END */
278 &ANALYZE-RESUME
281 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE x-export-contact-header Procedure
282 PROCEDURE x-export-contact-header :
283 /*------------------------------------------------------------------------------
284 Purpose:
285 Parameters: <none>
286 Notes:
287 ------------------------------------------------------------------------------*/
289 EXPORT DELIMITER ","
290 "Type"
291 "Title"
292 "FirstName"
293 "LastName"
294 "JobTitle"
295 "Company"
296 "Address"
297 "City"
298 "HomePhone"
299 "WorkPhone"
300 "MobilePhone"
301 "Facsimile"
304 END PROCEDURE.
306 /* _UIB-CODE-BLOCK-END */
307 &ANALYZE-RESUME