Make date field wider to accommodate 10 digits properly.
[capital-apms-progress.git] / process / bkoldbnz.p
bloba55a4d3a8dc5c54c277e09c88cc1dec869d34cf5
1 &ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12
2 &ANALYZE-RESUME
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.
11 preview = (ENTRY( 1, report-options) = "Yes").
12 in-file = ENTRY( 2, report-options).
13 create-receipts = (ENTRY( 3, report-options) = "Yes").
15 /* MESSAGE preview in-file create-receipts. */
17 /* page control */
18 DEF VAR prt-ctrl AS CHAR NO-UNDO.
19 DEF VAR cols AS INT NO-UNDO.
20 DEF VAR rows AS INT NO-UNDO.
21 DEF VAR user-name AS CHAR FORMAT "X(20)" NO-UNDO.
22 {inc/username.i "user-name"}
24 /* page header */
25 &SCOPED-DEFINE page-width 205
26 &SCOPED-DEFINE with-clause NO-BOX USE-TEXT NO-LABELS WIDTH {&page-width}
28 DEF VAR timeStamp AS CHAR FORMAT "X(54)" NO-UNDO.
29 timeStamp = STRING( TODAY, "99/99/9999") + ", " + STRING( TIME, "HH:MM:SS") + " for " + user-name.
30 DEF VAR hline2 AS CHAR FORMAT "X({&page-width})" NO-UNDO.
31 DEF VAR hline3 AS CHAR FORMAT "X({&page-width})" NO-UNDO.
32 hline2 = "Statement Processing for BNZ CMS".
33 hline2 = SUBSTRING( STRING("","X({&page-width})"), 1, INTEGER(({&page-width} - LENGTH(hline2) ) / 2)) + hline2.
34 hline3 = "Presented Cheques" + (IF create-receipts THEN " and Receipts Batch Creation" ELSE "").
35 hline3 = SUBSTRING( STRING("","X({&page-width})"), 1, INTEGER(({&page-width} - LENGTH(hline3) ) / 2)) + hline3.
37 DEFINE FRAME heading-frame WITH 1 DOWN {&with-clause} PAGE-TOP.
38 FORM HEADER
39 timeStamp "Page " + STRING( PAGE-NUMBER ) TO {&page-width} SKIP (1)
40 hline2 FORMAT "X({&page-width})"
41 hline3 FORMAT "X({&page-width})"
42 SKIP (2) " Date Account Number Type Cheque Reference 1 Reference 2 Amount || Import Program Action taken"
43 WITH FRAME heading-frame.
45 /* _UIB-CODE-BLOCK-END */
46 &ANALYZE-RESUME
49 &ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
51 /* ******************** Preprocessor Definitions ******************** */
53 &Scoped-define PROCEDURE-TYPE Procedure
57 /* _UIB-PREPROCESSOR-BLOCK-END */
58 &ANALYZE-RESUME
62 /* *********************** Procedure Settings ************************ */
64 &ANALYZE-SUSPEND _PROCEDURE-SETTINGS
65 /* Settings for THIS-PROCEDURE
66 Type: Procedure
67 Allow:
68 Frames: 0
69 Add Fields to: Neither
70 Other Settings: CODE-ONLY COMPILE
72 &ANALYZE-RESUME _END-PROCEDURE-SETTINGS
74 /* ************************* Create Window ************************** */
76 &ANALYZE-SUSPEND _CREATE-WINDOW
77 /* DESIGN Window definition (used by the UIB)
78 CREATE WINDOW Procedure ASSIGN
79 HEIGHT = .42
80 WIDTH = 40.29.
81 /* END WINDOW DEFINITION */
83 &ANALYZE-RESUME
87 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _INCLUDED-LIB Procedure
88 /* ************************* Included-Libraries *********************** */
90 {inc/method/m-impcsv.i}
91 {inc/method/m-txtrep.i}
93 /* _UIB-CODE-BLOCK-END */
94 &ANALYZE-RESUME
98 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Procedure
101 /* *************************** Main Block *************************** */
103 RUN make-control-string ( "PCL", "reset,landscape,tm,2,a4,lm,6,courier,cpi,18,lpi,9",
104 OUTPUT prt-ctrl, OUTPUT rows, OUTPUT cols ).
106 RUN output-control-file ( prt-ctrl ).
107 OUTPUT TO VALUE(txtrep-print-file) KEEP-MESSAGES PAGE-SIZE VALUE(rows).
109 VIEW FRAME heading-frame.
111 RUN present-cheques.
113 OUTPUT CLOSE.
114 RUN view-output-file ( preview ).
116 /* _UIB-CODE-BLOCK-END */
117 &ANALYZE-RESUME
120 /* ********************** Internal Procedures *********************** */
122 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE convert-bnz-date Procedure
123 PROCEDURE convert-bnz-date :
124 /*------------------------------------------------------------------------------
125 Purpose:
126 ------------------------------------------------------------------------------*/
127 DEF INPUT PARAMETER v-date AS CHAR NO-UNDO.
128 DEF OUTPUT PARAMETER i-date AS DATE NO-UNDO.
130 DEF VAR dd AS INT NO-UNDO.
131 DEF VAR mm AS INT NO-UNDO.
132 DEF VAR yy AS INT NO-UNDO.
134 ASSIGN i-date = DATE( v-date ) NO-ERROR.
135 IF i-date > (TODAY - 1000) THEN RETURN.
137 /* otherwise make sure there aren't going to be problems with the year 2000 */
138 dd = INT( ENTRY( 1, v-date, "/")).
139 mm = INT( ENTRY( 2, v-date, "/")).
140 yy = INT( ENTRY( 3, v-date, "/")).
141 IF yy < 100 THEN yy = yy + 1900.
142 IF yy < 1990 THEN yy = yy + 100.
143 i-date = DATE( mm, dd, yy).
145 END PROCEDURE.
147 /* _UIB-CODE-BLOCK-END */
148 &ANALYZE-RESUME
151 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE create-payment-transaction Procedure
152 PROCEDURE create-payment-transaction :
153 /*------------------------------------------------------------------------------
154 Purpose:
155 ------------------------------------------------------------------------------*/
156 MESSAGE "Payment transaction creation not yet written!"
157 VIEW-AS ALERT-BOX ERROR.
158 RETURN.
159 END PROCEDURE.
161 /* _UIB-CODE-BLOCK-END */
162 &ANALYZE-RESUME
165 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE mark-as-presented Procedure
166 PROCEDURE mark-as-presented :
167 /*------------------------------------------------------------------------------
168 Purpose:
169 ------------------------------------------------------------------------------*/
170 DEF INPUT PARAMETER bkacct AS CHAR NO-UNDO.
171 DEF INPUT PARAMETER chqnum AS INT NO-UNDO.
172 DEF INPUT PARAMETER indate AS CHAR NO-UNDO.
173 DEF INPUT PARAMETER amount AS DEC NO-UNDO.
175 DEF VAR cheque-no AS INT NO-UNDO.
176 DEF VAR prdate AS DATE NO-UNDO.
178 RUN convert-bnz-date( indate, OUTPUT prdate ).
180 bkacct = REPLACE( bkacct, "-", "").
181 FIND FIRST BankAccount WHERE BankAccount.BankAccount = bkacct NO-LOCK NO-ERROR.
182 IF NOT AVAILABLE(BankAccount) THEN DO:
183 bkacct = SUBSTRING( bkacct, 1, 13) + "0" + SUBSTRING( bkacct, 14, 2).
184 FIND FIRST BankAccount WHERE BankAccount.BankAccount BEGINS bkacct NO-LOCK NO-ERROR.
185 IF NOT AVAILABLE(BankAccount) THEN DO:
186 PUT UNFORMATTED "No bank account available with account code " STRING( bkacct, "XX-XXXX-XXXXXXX-XXX") .
187 RETURN.
188 END.
189 END.
191 cheque-no = INTEGER( chqnum ).
192 FIND Cheque WHERE Cheque.BankAccountCode = BankAccount.BankAccountCode
193 AND Cheque.ChequeNo = cheque-no EXCLUSIVE-LOCK NO-ERROR.
194 IF NOT AVAILABLE(Cheque) THEN DO:
195 PUT UNFORMATTED "Cheque " cheque-no " presented for " TRIM(STRING( amount, ">>>,>>>,>>9.99")) " but no record of issue - ignored!".
196 RETURN.
197 END.
199 IF amount <> Cheque.Amount THEN DO:
200 PUT UNFORMATTED "Cheque " cheque-no " issued for " TRIM(STRING( Cheque.Amount, ">>>,>>>,>>9.99"))
201 " but presented for " TRIM(STRING( amount, ">>>,>>>,>>9.99")).
202 MESSAGE "Cheque" STRING( cheque-no, "999999") "issued for" STRING( Cheque.Amount )
203 "but presented for" STRING( amount ) SKIP(1)
204 "Cheque not marked as presented!"
205 VIEW-AS ALERT-BOX WARNING TITLE "Error in presented amount!".
206 RETURN.
207 END.
209 PUT UNFORMATTED "Cheque record updated".
211 ASSIGN Cheque.DatePresented = prdate
212 Cheque.PresentedAmount = amount.
214 END PROCEDURE.
216 /* _UIB-CODE-BLOCK-END */
217 &ANALYZE-RESUME
220 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE present-cheques Procedure
221 PROCEDURE present-cheques :
222 /*------------------------------------------------------------------------------
223 Purpose: Mark cheques in BNZ export file as presented.
224 ------------------------------------------------------------------------------*/
225 DEF VAR bk-acct AS CHAR NO-UNDO.
226 DEF VAR tr-amnt AS DEC NO-UNDO. /* amount */
227 DEF VAR tr-cheque AS INT NO-UNDO. /* cheque no */
228 DEF VAR tr-type AS INT NO-UNDO.
229 DEF VAR tr-type2 AS CHAR NO-UNDO.
230 DEF VAR tr-date AS CHAR NO-UNDO. /* date presented */
232 DEF VAR tr-text AS CHAR NO-UNDO.
233 DEF VAR tr-payee AS CHAR NO-UNDO.
234 DEF VAR in-line AS CHAR NO-UNDO.
235 DEF VAR i AS INT NO-UNDO.
236 DEF VAR pos AS INT NO-UNDO.
238 INPUT FROM VALUE( in-file ).
239 REPEAT:
240 csv-clear-fields().
241 IF csv-import-line() = ? THEN LEAVE. /* file processed */
242 IF LENGTH( csv-get-field(1) ) > 3 THEN NEXT.
244 tr-type = to-number( csv-get-field(1) ).
245 IF tr-type = 5 OR tr-type = 6 OR tr-type = 8 OR tr-type = 9 THEN NEXT.
247 bk-acct = csv-get-field(3).
248 tr-cheque = to-number( csv-get-field(5) ).
249 tr-date = csv-get-field(11).
250 tr-type2 = csv-get-field(13).
251 tr-amnt = to-number( csv-get-field(4)).
253 tr-text = csv-get-field(7) + " " + csv-get-field(8) + " " + csv-get-field(9).
254 tr-payee = csv-get-field(10).
256 PUT UNFORMATTED STRING( tr-date, "X(10)") " "
257 STRING( bk-acct, "X(19)") " "
258 STRING( tr-type, ">9") " "
259 STRING( tr-type2, "XX") " "
260 (IF tr-cheque > 0 THEN STRING( tr-cheque, "999999") ELSE FILL(" ",6)) " "
261 STRING( tr-text, "X(36)") " "
262 STRING( tr-payee, "X(36)") " "
263 STRING( tr-amnt, ">>>,>>>,>>9.99CR") " || ".
265 IF tr-type = 3 AND tr-cheque > 0 AND tr-amnt < 0 THEN DO:
266 RUN mark-as-presented( bk-acct, tr-cheque, tr-date, - tr-amnt ) .
267 END.
268 ELSE IF SUBSTRING(tr-text, 1, 8) = "RENTAL, " AND create-receipts THEN DO:
269 RUN create-payment-transaction.
270 END.
271 PUT UNFORMATTED " " SKIP.
272 END.
273 INPUT CLOSE.
275 END PROCEDURE.
277 /* _UIB-CODE-BLOCK-END */
278 &ANALYZE-RESUME