1 &ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12
3 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS Procedure
4 /*--------------------------------------------------------------------------
5 ------------------------------------------------------------------------*/
6 DEF INPUT PARAMETER report-options
AS CHAR NO-UNDO.
8 DEF VAR preview
AS LOGICAL NO-UNDO.
9 DEF VAR in-file
AS CHAR NO-UNDO.
10 DEF VAR create-receipts
AS LOGICAL NO-UNDO.
13 DEF VAR base-font
AS CHAR NO-UNDO INITIAL "courier,fixed,cpi,22,lpi,10,normal".
14 DEF VAR header-font
AS CHAR NO-UNDO INITIAL "helvetica,proportional,point,11,lpi,7,bold".
15 DEF VAR time-font
AS CHAR NO-UNDO INITIAL "helvetica,proportional,point,6,lpi,9,normal".
16 DEF VAR line
AS CHAR NO-UNDO.
18 DEF VAR bank-amount
AS DEC NO-UNDO INITIAL 0.0 .
19 DEF VAR bank-ec
AS INT NO-UNDO INITIAL ?.
20 DEF VAR bank-ac
AS DEC NO-UNDO INITIAL ?.
21 DEF VAR last-prdate
AS DATE NO-UNDO INITIAL ?.
23 DEF VAR user-name
AS CHAR FORMAT "X(20)" NO-UNDO.
24 {inc
/username.i
"user-name"}
25 DEF VAR timeStamp
AS CHAR FORMAT "X(54)" NO-UNDO.
26 timeStamp
= STRING( TODAY, "99/99/9999") + ", " + STRING( TIME, "HH:MM:SS") + " for " + user-name.
28 DEF VAR hline2
AS CHAR NO-UNDO.
29 DEF VAR hline3
AS CHAR NO-UNDO.
30 hline2
= "Statement Processing for ANZ Online".
31 hline3
= "Presented Cheques" + (IF create-receipts
THEN " and Receipts Batch Creation" ELSE "").
33 /* ensure NewBatch
& NewDocument are scoped to entire program */
34 FIND FIRST NewBatch
NO-LOCK NO-ERROR.
35 FIND PREV NewBatch
NO-LOCK NO-ERROR.
38 {inc
/ofc-acct.i
"DEBTORS" "sundry-debtors" "ERROR"}
39 {inc
/ofc-acct.i
"SUSPENSE-TENANT" "suspense-tenant-ac" "ERROR"}
40 DEF VAR suspense-tenant-ec
AS INT NO-UNDO.
41 suspense-tenant-ec
= OfficeControlAccount.EntityCode.
43 {inc
/ofc-set.i
"Receipts-Description" "receipts-description"}
45 /* _UIB-CODE-BLOCK-END
*/
49 &ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
51 /* ******************** Preprocessor Definitions
******************** */
53 &Scoped-define PROCEDURE-TYPE Procedure
57 /* _UIB-PREPROCESSOR-BLOCK-END
*/
61 /* ************************ Function Prototypes
********************** */
63 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD find-tenant-code Procedure
64 FUNCTION find-tenant-code
RETURNS INTEGER
65 ( INPUT t1
AS CHAR, INPUT t2
AS CHAR ) FORWARD.
67 /* _UIB-CODE-BLOCK-END
*/
71 /* *********************** Procedure Settings
************************ */
73 &ANALYZE-SUSPEND _PROCEDURE-SETTINGS
74 /* Settings for
THIS-PROCEDURE
78 Add Fields to
: Neither
79 Other Settings
: CODE-ONLY
COMPILE
81 &ANALYZE-RESUME _END-PROCEDURE-SETTINGS
83 /* ************************* Create Window
************************** */
85 &ANALYZE-SUSPEND _CREATE-WINDOW
86 /* DESIGN Window definition
(used by the UIB
)
87 CREATE WINDOW Procedure
ASSIGN
90 /* END WINDOW DEFINITION
*/
96 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _INCLUDED-LIB Procedure
97 /* ************************* Included-Libraries
*********************** */
99 {inc
/method
/m-impcsv.i
}
100 {inc
/method
/m-txtrep.i
}
102 /* _UIB-CODE-BLOCK-END
*/
107 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Procedure
110 /* *************************** Main Block
*************************** */
112 RUN pclrep-start
( preview
, "reset,landscape,tm,2,a4,lm,6," + base-font
).
113 OUTPUT TO VALUE(txtrep-print-file
) KEEP-MESSAGES PAGE-SIZE 0.
116 IF create-receipts
THEN RUN create-bank-transaction.
122 /* _UIB-CODE-BLOCK-END
*/
126 /* ********************** Internal Procedures
*********************** */
128 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE convert-bank-date Procedure
129 PROCEDURE convert-bank-date
:
130 /*------------------------------------------------------------------------------
132 ------------------------------------------------------------------------------*/
133 DEF INPUT PARAMETER v-date
AS CHAR NO-UNDO.
134 DEF OUTPUT PARAMETER i-date
AS DATE NO-UNDO.
136 DEF VAR dd
AS INT NO-UNDO.
137 DEF VAR mm
AS INT NO-UNDO.
138 DEF VAR yy
AS INT NO-UNDO.
140 ASSIGN i-date
= DATE( v-date
) NO-ERROR.
141 IF i-date
> (TODAY - 1000) THEN RETURN.
143 /* otherwise make sure there aren't going to be problems with the year
2000 */
144 dd
= INT( ENTRY( 1, v-date
, "/")).
145 mm
= INT( ENTRY( 2, v-date
, "/")).
146 yy
= INT( ENTRY( 3, v-date
, "/")).
149 DO WHILE yy
< SESSION:YEAR-OFFSET:
153 i-date
= DATE( mm
, dd
, yy
).
157 /* _UIB-CODE-BLOCK-END
*/
161 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE create-bank-transaction Procedure
162 PROCEDURE create-bank-transaction
:
163 /*------------------------------------------------------------------------------
165 ------------------------------------------------------------------------------*/
167 IF NOT AVAILABLE(NewBatch
) THEN RETURN.
168 IF bank-ec
= ?
THEN RETURN.
169 IF bank-ac
= ?
THEN RETURN.
170 IF last-prdate
= ?
THEN RETURN.
173 NewDocument.BatchCode
= NewBatch.BatchCode.
174 NewDocument.DocumentType
= "RCBK".
175 NewDocument.Reference
= STRING(NewBatch.BatchCode
) + "/" + STRING(NewDocument.DocumentCode
).
176 NewDocument.Description
= "Banking Summary " + STRING(last-prdate
, "99/99/9999").
179 NewAcctTrans.BatchCode
= NewBatch.BatchCode.
180 NewAcctTrans.DocumentCode
= NewDocument.DocumentCode.
181 NewAcctTrans.EntityType
= "L".
182 NewAcctTrans.EntityCode
= bank-ec.
183 NewAcctTrans.AccountCode
= bank-ac.
184 NewAcctTrans.Date
= last-prdate.
185 NewAcctTrans.Amount
= bank-amount.
189 /* _UIB-CODE-BLOCK-END
*/
193 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE create-receipt-transaction Procedure
194 PROCEDURE create-receipt-transaction
:
195 /*------------------------------------------------------------------------------
197 ------------------------------------------------------------------------------*/
198 DEF INPUT PARAMETER bkacct
AS CHAR NO-UNDO.
199 DEF INPUT PARAMETER tr-type
AS CHAR NO-UNDO.
200 DEF INPUT PARAMETER indate
AS CHAR NO-UNDO.
201 DEF INPUT PARAMETER text1
AS CHAR NO-UNDO.
202 DEF INPUT PARAMETER text2
AS CHAR NO-UNDO.
203 DEF INPUT PARAMETER amount
AS DEC NO-UNDO.
204 DEF OUTPUT PARAMETER result
AS CHAR NO-UNDO INITIAL "".
206 DEF VAR prdate
AS DATE NO-UNDO.
207 DEF VAR tenant-code
AS INT NO-UNDO.
208 DEF VAR tr-description
AS CHAR NO-UNDO.
209 DEF VAR tr-reference
AS CHAR NO-UNDO.
211 RUN convert-bank-date
( indate
, OUTPUT prdate
).
213 bkacct
= REPLACE( bkacct
, "-", "").
214 FIND FIRST BankAccount
WHERE BankAccount.BankAccount
= bkacct
NO-LOCK NO-ERROR.
215 IF NOT AVAILABLE(BankAccount
) THEN DO:
216 bkacct
= SUBSTRING( bkacct
, 1, 13) + "0" + SUBSTRING( bkacct
, 14, 2).
217 FIND FIRST BankAccount
WHERE BankAccount.BankAccount
BEGINS bkacct
NO-LOCK NO-ERROR.
218 IF NOT AVAILABLE(BankAccount
) THEN DO:
219 result
= "-->No bank account available with account code "
220 + STRING( bkacct
, "XX-XXXX-XXXXXXX-XXX") .
225 tenant-code
= find-tenant-code
( text1
, text2
).
226 IF tenant-code
= ?
THEN DO:
227 tr-description
= TRIM(text2
) + " " + TRIM(text1
).
228 tenant-code
= suspense-tenant-ec.
231 tr-description
= receipts-description.
233 FIND Tenant
WHERE Tenant.TenantCode
= tenant-code
NO-LOCK NO-ERROR.
234 IF NOT AVAILABLE(Tenant
) THEN DO:
235 /* should only occur if the suspense tenant doesn't exist
*/
236 result
= "-->Tenant " + STRING(tenant-code
,"99999") + " not on file.".
241 IF NOT AVAILABLE(NewBatch
) THEN DO:
243 NewBatch.BatchType
= "NORM".
244 NewBatch.Description
= "Automatic receipts " + STRING( TODAY, "99/99/9999").
247 NewDocument.BatchCode
= NewBatch.BatchCode.
248 NewDocument.DocumentType
= "RCPT".
249 NewDocument.Reference
= STRING(NewBatch.BatchCode
) + "/" + STRING(NewDocument.DocumentCode
).
250 NewDocument.Description
= NewBatch.Description.
254 NewAcctTrans.BatchCode
= NewBatch.BatchCode.
255 NewAcctTrans.DocumentCode
= NewDocument.DocumentCode.
256 NewAcctTrans.EntityType
= "T".
257 NewAcctTrans.EntityCode
= tenant-code.
258 NewAcctTrans.AccountCode
= sundry-debtors.
259 NewAcctTrans.Date
= prdate.
260 NewAcctTrans.Amount
= amount.
261 NewAcctTrans.Reference
= STRING(NewBatch.BatchCode
) + "/" + STRING(NewDocument.DocumentCode
) + "/" + STRING(NewAcctTrans.TransactionCode
).
262 NewAcctTrans.Description
= tr-description.
264 RUN match-exception
(tr-type
, text2
, text1
, OUTPUT result
).
266 last-prdate
= prdate.
267 bank-ec
= BankAccount.CompanyCode.
268 bank-ac
= BankAccount.AccountCode.
269 bank-amount
= bank-amount
+ amount.
272 result
= "Receipt from " + STRING( Tenant.Name
, "X(30)") + " "
273 + "T" + STRING( Tenant.TenantCode
, "99999") + "/" + Tenant.EntityType
+ STRING( Tenant.EntityCode
, "99999").
279 /* _UIB-CODE-BLOCK-END
*/
283 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE inst-page-header Procedure
284 PROCEDURE inst-page-header
:
285 /*------------------------------------------------------------------------------
287 ------------------------------------------------------------------------------*/
288 RUN pclrep-line
( time-font
, timeStamp
+ CHR(13) + FILL(" ",350) + "Page " + STRING(pclrep-page-number
)).
289 RUN pclrep-down-by
(1).
290 RUN pclrep-line
( header-font
, hline2
).
291 RUN pclrep-line
( header-font
, hline3
).
292 RUN pclrep-down-by
(0.5).
293 RUN pclrep-line
( base-font
, " Date Account Number Type Cheque Reference Name of Other Party Amount || Import Program Action taken").
294 RUN pclrep-down-by
(0.3).
298 /* _UIB-CODE-BLOCK-END
*/
302 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE mark-as-presented Procedure
303 PROCEDURE mark-as-presented
:
304 /*------------------------------------------------------------------------------
306 ------------------------------------------------------------------------------*/
307 DEF INPUT PARAMETER bkacct
AS CHAR NO-UNDO.
308 DEF INPUT PARAMETER chqnum
AS INT NO-UNDO.
309 DEF INPUT PARAMETER indate
AS CHAR NO-UNDO.
310 DEF INPUT PARAMETER amount
AS DEC NO-UNDO.
311 DEF OUTPUT PARAMETER result
AS CHAR NO-UNDO INITIAL "".
313 DEF VAR cheque-no
AS INT NO-UNDO.
314 DEF VAR prdate
AS DATE NO-UNDO.
316 RUN convert-bank-date
( indate
, OUTPUT prdate
).
318 bkacct
= REPLACE( bkacct
, "-", "").
319 FIND FIRST BankAccount
WHERE BankAccount.BankAccount
= bkacct
NO-LOCK NO-ERROR.
320 IF NOT AVAILABLE(BankAccount
) THEN DO:
321 bkacct
= SUBSTRING( bkacct
, 1, 13) + "0" + SUBSTRING( bkacct
, 14, 2).
322 FIND FIRST BankAccount
WHERE BankAccount.BankAccount
BEGINS bkacct
NO-LOCK NO-ERROR.
323 IF NOT AVAILABLE(BankAccount
) THEN DO:
324 result
= "-->No bank account available with account code "
325 + STRING( bkacct
, "XX-XXXX-XXXXXXX-XXX") .
330 cheque-no
= INTEGER( chqnum
).
331 FIND Cheque
WHERE Cheque.BankAccountCode
= BankAccount.BankAccountCode
332 AND Cheque.ChequeNo
= cheque-no
EXCLUSIVE-LOCK NO-ERROR.
333 IF NOT AVAILABLE(Cheque
) THEN DO:
334 result
= "-->Cheque" + STRING(cheque-no
,">999999")
335 + " presented for " + TRIM(STRING( amount
, ">>>,>>>,>>9.99"))
336 + " but no record of issue - ignored!".
340 IF amount
<> Cheque.Amount
THEN DO:
341 result
= "-->Cheque" + STRING(cheque-no
,">999999") + " issued for " + TRIM(STRING( Cheque.Amount
, ">>>,>>>,>>9.99"))
342 + " but presented for " + TRIM(STRING( amount
, ">>>,>>>,>>9.99")).
343 MESSAGE result
SKIP(1)
344 "Cheque not marked as presented!"
345 VIEW-AS ALERT-BOX WARNING TITLE "Error in presented amount!".
349 ASSIGN Cheque.DatePresented
= prdate
350 Cheque.PresentedAmount
= amount.
352 result
= "Cheque record updated".
356 /* _UIB-CODE-BLOCK-END
*/
360 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE match-exception Procedure
361 PROCEDURE match-exception
:
362 /*------------------------------------------------------------------------------
364 ------------------------------------------------------------------------------*/
365 DEF INPUT PARAMETER trn-type
AS CHAR NO-UNDO.
366 DEF INPUT PARAMETER other-party
AS CHAR NO-UNDO.
367 DEF INPUT PARAMETER ref-text
AS CHAR NO-UNDO.
368 DEF OUTPUT PARAMETER result
AS CHAR NO-UNDO.
370 FOR EACH BankImportException
WHERE BankAccount.BankAccountCode
= BankImportException.BankAccountCode
NO-LOCK:
371 IF trn-type
MATCHES BankImportException.TrnType
372 AND other-party
MATCHES BankImportException.Match1
373 AND ref-text
MATCHES BankImportException.Match2
375 IF BankImport.EntityType
= ?
OR BankImportException.EntityCode
= ?
376 OR BankImportException.AccountCode
= ?
THEN DO:
378 result
= "skipped - no transaction created.".
380 NewAcctTrans.EntityType
= BankImportException.EntityType .
381 NewAcctTrans.EntityCode
= BankImportException.EntityCode .
382 NewAcctTrans.AccountCode
= BankImportException.AccountCode .
383 NewAcctTrans.Description
= BankImportException.Description.
384 IF NewAcctTrans.Description
= ?
OR TRIM(NewAcctTrans.Description
) = "" THEN
385 NewAcctTrans.Description
= receipts-description.
387 result
= "Matched exception to " + BankImportException.EntityType
+ STRING(BankImportException.EntityCode
, "99999")
388 + "/" + STRING(BankImportException.AccountCode
,"9999.99")
389 + " - " + BankImportException.Description.
396 /* _UIB-CODE-BLOCK-END
*/
400 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE parse-parameters Procedure
401 PROCEDURE parse-parameters
:
402 /*------------------------------------------------------------------------------
404 ------------------------------------------------------------------------------*/
405 DEF VAR token
AS CHAR NO-UNDO.
406 DEF VAR i
AS INT NO-UNDO.
408 {inc
/showopts.i
"report-options"}
410 DO i
= 1 TO NUM-ENTRIES( report-options
, "~n" ):
411 token
= ENTRY( i
, report-options
, "~n" ).
413 CASE ENTRY( 1, token
):
414 WHEN "Preview" THEN preview
= Yes.
415 WHEN "CreateReceipts" THEN create-receipts
= Yes.
416 WHEN "FileName" THEN in-file
= SUBSTRING( token
, INDEX(token
,",") + 1).
423 /* _UIB-CODE-BLOCK-END
*/
427 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE present-cheques Procedure
428 PROCEDURE present-cheques
:
429 /*------------------------------------------------------------------------------
430 Purpose
: Mark cheques in BNZ export file as presented.
431 ------------------------------------------------------------------------------*/
432 DEF VAR bk-acct
AS CHAR NO-UNDO.
433 DEF VAR tr-amnt
AS DEC NO-UNDO.
/* amount
*/
434 DEF VAR tr-cheque
AS DEC NO-UNDO.
/* cheque no
*/
435 DEF VAR tr-type
AS INT NO-UNDO.
436 DEF VAR tr-type2
AS CHAR NO-UNDO.
437 DEF VAR tr-date
AS CHAR NO-UNDO.
/* date presented
*/
439 DEF VAR tr-text
AS CHAR NO-UNDO.
440 DEF VAR tr-payee
AS CHAR NO-UNDO.
441 DEF VAR in-line
AS CHAR NO-UNDO.
442 DEF VAR i
AS INT NO-UNDO.
443 DEF VAR pos
AS INT NO-UNDO.
444 DEF VAR result
AS CHAR NO-UNDO.
446 INPUT FROM VALUE( in-file
).
449 IF csv-import-line
() = ?
THEN LEAVE.
/* file processed
*/
450 IF LENGTH( csv-get-field
(1) ) > 3 THEN NEXT.
452 tr-type
= to-number
( csv-get-field
(1) ).
453 IF tr-type
<> 3 THEN NEXT.
455 /* We ignore field
2 (corporate ID
) */
456 bk-acct
= csv-get-field
(3).
457 tr-amnt
= to-number
( csv-get-field
(4)).
458 ASSIGN tr-cheque
= to-number
( csv-get-field
(5) ) NO-ERROR.
459 /* IF tr-cheque
> 9999999 OR tr-cheque
= 0 THEN tr-cheque
= 0.
*/
460 tr-type
= to-number
( csv-get-field
(6) ).
461 tr-type2
= csv-get-field
(7).
463 tr-text
= STRING( csv-get-field
(8), "X(12)") + STRING( csv-get-field
(9), "X(12)") + csv-get-field
(10).
464 tr-payee
= csv-get-field
(11).
465 tr-date
= csv-get-field
(12).
467 line
= STRING( tr-date
, "X(11)")
468 + STRING( bk-acct
, "X(20)")
469 + STRING( tr-type
, ">>9") + " "
470 + STRING( tr-type2
, "X(3)")
471 + (IF tr-cheque
> 0 AND tr-cheque
<= 9999999.0 THEN STRING( tr-cheque
, ">999999") ELSE FILL(" ",7)) + " "
472 + STRING( tr-text
, "X(37)")
473 + STRING( tr-payee
, "X(21)")
474 + STRING( tr-amnt
, ">>>,>>>,>>9.99CR")
477 IF LOOKUP( tr-type2
, "AP,DC,ET,DD") > 0 AND create-receipts
THEN
478 RUN create-receipt-transaction
( bk-acct
, tr-type2
, tr-date
, tr-text
, tr-payee
, tr-amnt
, OUTPUT result
).
479 ELSE IF tr-cheque
> 0 AND tr-cheque
<= 9999999
480 AND tr-amnt
< 0 AND tr-type2
<> "DD" THEN
481 RUN mark-as-presented
( bk-acct
, tr-cheque
, tr-date
, - tr-amnt
, OUTPUT result
) .
482 ELSE IF create-receipts
THEN /* treat as if receipt anyway
*/
483 RUN create-receipt-transaction
( bk-acct
, tr-type2
, tr-date
, tr-text
, tr-payee
, tr-amnt
, OUTPUT result
).
485 result
= "No action taken".
487 RUN pclrep-line
( base-font
, line
+ result
).
493 /* _UIB-CODE-BLOCK-END
*/
497 /* ************************ Function Implementations
***************** */
499 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION find-tenant-code Procedure
500 FUNCTION find-tenant-code
RETURNS INTEGER
501 ( INPUT t1
AS CHAR, INPUT t2
AS CHAR ) :
502 /*------------------------------------------------------------------------------
503 Purpose
: Figure the tenant code from bank statement references
504 ------------------------------------------------------------------------------*/
505 DEF VAR pos
AS INT NO-UNDO.
506 DEF VAR tc
AS INT NO-UNDO INITIAL ?.
509 pos
= R-INDEX( t1
, "T").
510 IF pos
> (LENGTH(t1
) - 7) THEN tc
= to-number
( SUBSTRING(t1
, pos
+ 1) ).
511 FIND Tenant
WHERE Tenant.TenantCode
= tc
NO-LOCK NO-ERROR.
512 IF NOT AVAILABLE(Tenant
) THEN tc
= ?.
513 IF tc
<> ?
THEN RETURN tc.
515 pos
= R-INDEX( t1
, " ").
516 IF pos
> (LENGTH(t1
) - 6) AND pos
< (LENGTH(t1
) - 4) THEN tc
= to-number
( SUBSTRING(t1
, pos
+ 1) ).
518 FIND Tenant
WHERE Tenant.TenantCode
= tc
NO-LOCK NO-ERROR.
519 IF NOT AVAILABLE(Tenant
) THEN tc
= ?.
525 /* _UIB-CODE-BLOCK-END
*/