Added capital works blank section. Synced calling screen.
[capital-apms-progress.git] / process / report / tr-l.p
blob16a6a33867f33d9ebca772904aca01e33f70c6c8
1 &ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12
2 &ANALYZE-RESUME
3 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS Procedure
4 /*--------------------------------------------------------------------------
5 File : tr-l.p
6 Purpose : Transactions by Ledger Account report
7 Author(s) : Andrew McMillan
8 ------------------------------------------------------------------------*/
10 DEF INPUT PARAMETER report-options AS CHAR NO-UNDO.
12 DEF VAR company-1 LIKE AcctTran.EntityCode NO-UNDO.
13 DEF VAR company-2 LIKE AcctTran.EntityCode NO-UNDO.
14 DEF VAR month-1 AS INTEGER FORMAT "9999" NO-UNDO.
15 DEF VAR month-2 AS INTEGER FORMAT "9999" NO-UNDO.
16 DEF VAR show-all AS LOGICAL NO-UNDO.
17 DEF VAR account-1 LIKE AcctTran.AccountCode NO-UNDO.
18 DEF VAR account-2 LIKE AcctTran.AccountCode NO-UNDO.
19 DEF VAR preview AS LOGICAL NO-UNDO.
20 DEF VAR earliest-date AS DATE NO-UNDO.
21 DEF VAR earliest-batch AS INT NO-UNDO.
22 DEF VAR export-fname AS CHAR NO-UNDO.
23 DEF VAR group-name AS CHAR NO-UNDO.
24 DEF VAR list-name AS CHAR NO-UNDO INITIAL ?.
25 DEF VAR show-relations AS LOGI NO-UNDO INITIAL Yes.
26 DEF VAR base-pattern AS CHAR NO-UNDO INITIAL ?.
27 DEF VAR account-pattern AS CHAR NO-UNDO INITIAL ?.
29 DEF VAR show-month-totals AS LOGICAL INITIAL no NO-UNDO.
30 DEF VAR show-opening-balances AS LOGICAL INITIAL Yes NO-UNDO.
31 DEF VAR no-show-zero AS LOGICAL INITIAL no NO-UNDO.
32 DEF VAR base-entity-type AS CHAR INITIAL "L" NO-UNDO. /* The basic entity we deal with */
33 DEF VAR sort-entity-type AS CHAR NO-UNDO. /* The sequence for output */
35 DEF VAR exclude-year-end AS LOGI NO-UNDO.
36 DEF VAR balances-only AS LOGI NO-UNDO.
37 RUN parse-parameters.
38 {inc/ofc-this.i}
39 {inc/ofc-set-l.i "Transactions-Show-ChequeNo" "show-cheque-no"}
41 DEF VAR consol-accounts AS CHAR INITIAL "" NO-UNDO.
42 IF list-name <> ? THEN DO:
43 FIND ConsolidationList NO-LOCK WHERE ConsolidationList.Name = list-name NO-ERROR.
44 END.
47 DEF VAR prt-ctrl AS CHAR NO-UNDO.
48 DEF VAR rows AS INT NO-UNDO.
49 DEF VAR cols AS INT NO-UNDO.
51 DEF VAR grand-total LIKE AcctTran.Amount INITIAL 0 NO-UNDO.
53 DEF VAR user-name AS CHAR NO-UNDO.
54 DEF VAR timeStamp AS CHAR FORMAT "X(54)" NO-UNDO.
55 DEF VAR dispReference AS CHARACTER COLUMN-LABEL "Reference" FORMAT "x(13)" NO-UNDO.
56 DEF VAR dispDescription AS CHARACTER NO-UNDO.
57 DEF VAR dispName AS CHARACTER FORMAT "X(80)" NO-UNDO.
59 DEF VAR money-length AS INT NO-UNDO INIT 19.
60 DEF VAR dispAmount AS CHARACTER FORMAT "X(19)" NO-UNDO.
62 DEF VAR last-month AS INT NO-UNDO INITIAL ?.
63 DEF VAR tr-this-month AS LOGICAL NO-UNDO.
64 DEF VAR tr-this-company AS LOGICAL NO-UNDO.
65 DEF VAR tr-this-account AS LOGICAL NO-UNDO.
66 DEF VAR company-total LIKE AcctTran.Amount NO-UNDO.
67 DEF VAR account-total LIKE AcctTran.Amount NO-UNDO.
69 DEF VAR m1-start AS DATE NO-UNDO.
70 DEF VAR m2-end AS DATE NO-UNDO.
72 FIND Month WHERE Month.MonthCode = month-1 NO-LOCK.
73 m1-start = Month.StartDate.
75 FIND Month WHERE Month.MonthCode = month-2 NO-LOCK.
76 m2-end = Month.EndDate.
78 &SCOPED-DEFINE page-width 126
79 DEF VAR hline2 AS CHAR FORMAT "X({&page-width})" NO-UNDO.
80 DEF VAR hline3 AS CHAR FORMAT "X({&page-width})" NO-UNDO.
81 hline2 = "Transactions for ".
82 IF AVAILABLE(ConsolidationList) THEN
83 hline2 = hline2 + "Consolidation List " + ConsolidationList.Name + " - " + ConsolidationList.Description.
84 ELSE IF company-1 = company-2 THEN DO:
85 FIND FIRST Company WHERE Company.CompanyCode = company-1 NO-LOCK NO-ERROR.
86 hline2 = hline2 + (IF AVAILABLE(Company) THEN Company.LegalName ELSE "Company not on file")
87 + " (L" + TRIM( STRING( company-1, ">>>>9")) + ")".
88 END.
89 ELSE
90 hline2 = hline2 + "Company " + TRIM(STRING(company-1,">>>>9")) + " to " + TRIM(STRING(company-2,">>>>9")).
92 hline2 = hline2 + ", from " + STRING( m1-start, "99/99/9999") +
93 " to " + STRING( m2-end, "99/99/9999")
94 + (IF earliest-date > DATE(1,1,1) THEN (" and dated after " + STRING(earliest-date,"99/99/9999")) ELSE "").
95 hline2 = SUBSTRING( STRING("","X({&page-width})"), 1, INTEGER(({&page-width} - LENGTH(hline2) ) / 2)) + hline2.
97 IF group-name = "" THEN DO:
98 hline3 = "Accounts " + STRING(account-1, "9999.99") + " to " + STRING(account-2, "9999.99").
99 IF account-pattern <> ? THEN hline3 = hline3 + " matching " + base-pattern .
100 END.
101 ELSE DO:
102 FIND AccountGroup WHERE AccountGroup.AccountGroupCode = group-name NO-LOCK.
103 hline3 = "Account group " + group-name + " - " + AccountGroup.Name.
104 END.
105 IF NOT show-opening-balances THEN hline3 = hline3 + " (opening balances not shown)".
106 hline3 = SUBSTRING( STRING("","X({&page-width})"), 1, INTEGER(({&page-width} - LENGTH(hline3) ) / 2)) + hline3.
108 /* define all the frames for the report */
109 &SCOPED-DEFINE with-clause NO-BOX USE-TEXT NO-LABELS WIDTH {&page-width}
111 DEFINE FRAME default-frame WITH DOWN {&with-clause}.
113 DEFINE FRAME heading-frame WITH 1 DOWN {&with-clause} PAGE-TOP.
114 FORM HEADER
115 timeStamp "Page " + STRING( PAGE-NUMBER ) TO {&page-width} SKIP (1)
116 hline2 FORMAT "X({&page-width})"
117 hline3 FORMAT "X({&page-width})"
118 SKIP (2) " Date Reference Amount Description" SPACE(40) "Related records"
119 WITH FRAME heading-frame.
121 DEFINE FRAME total-frame-1 WITH DOWN {&with-clause}.
122 FORM
123 SPACE(14)
124 dispReference
125 dispAmount
126 dispName
127 WITH FRAME total-frame-1.
129 DEFINE FRAME report-frame-1 WITH DOWN {&with-clause}.
130 FORM
131 SKIP(1)
132 dispName
133 WITH FRAME report-frame-1.
135 DEFINE FRAME report-frame-2 WITH DOWN {&with-clause}.
136 FORM " "
137 AcctTran.Date COLUMN-LABEL "Date" FORMAT "99/99/9999"
138 dispReference
139 /* dispAmount COLUMN-LABEL "Amount" */
140 dispDescription COLUMN-LABEL "Description" FORMAT "X(81)"
141 WITH FRAME report-frame-2.
143 {inc/ofc-this.i}
144 {inc/ofc-acct.i "IC-BASE" "ic-base"}
146 /* _UIB-CODE-BLOCK-END */
147 &ANALYZE-RESUME
150 &ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
152 /* ******************** Preprocessor Definitions ******************** */
154 &Scoped-define PROCEDURE-TYPE Procedure
155 &Scoped-define DB-AWARE no
159 /* _UIB-PREPROCESSOR-BLOCK-END */
160 &ANALYZE-RESUME
163 /* ************************ Function Prototypes ********************** */
165 &IF DEFINED(EXCLUDE-balance-is-zero) = 0 &THEN
167 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD balance-is-zero Procedure
168 FUNCTION balance-is-zero RETURNS LOGICAL
169 ( /* no parameter-definitions */ ) FORWARD.
171 /* _UIB-CODE-BLOCK-END */
172 &ANALYZE-RESUME
174 &ENDIF
176 &IF DEFINED(EXCLUDE-check-pattern-match) = 0 &THEN
178 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD check-pattern-match Procedure
179 FUNCTION check-pattern-match RETURNS LOGICAL
180 ( INPUT ac AS DEC ) FORWARD.
182 /* _UIB-CODE-BLOCK-END */
183 &ANALYZE-RESUME
185 &ENDIF
187 &IF DEFINED(EXCLUDE-format-big-money) = 0 &THEN
189 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD format-big-money Procedure
190 FUNCTION format-big-money RETURNS CHARACTER
191 ( INPUT amt AS DEC ) FORWARD.
193 /* _UIB-CODE-BLOCK-END */
194 &ANALYZE-RESUME
196 &ENDIF
198 &IF DEFINED(EXCLUDE-interco-outside-group) = 0 &THEN
200 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD interco-outside-group Procedure
201 FUNCTION interco-outside-group RETURNS LOGICAL
202 ( INPUT ac AS DEC ) FORWARD.
204 /* _UIB-CODE-BLOCK-END */
205 &ANALYZE-RESUME
207 &ENDIF
210 /* *********************** Procedure Settings ************************ */
212 &ANALYZE-SUSPEND _PROCEDURE-SETTINGS
213 /* Settings for THIS-PROCEDURE
214 Type: Procedure
215 Allow:
216 Frames: 0
217 Add Fields to: Neither
218 Other Settings: CODE-ONLY COMPILE
220 &ANALYZE-RESUME _END-PROCEDURE-SETTINGS
222 /* ************************* Create Window ************************** */
224 &ANALYZE-SUSPEND _CREATE-WINDOW
225 /* DESIGN Window definition (used by the UIB)
226 CREATE WINDOW Procedure ASSIGN
227 HEIGHT = 26.35
228 WIDTH = 35.72.
229 /* END WINDOW DEFINITION */
231 &ANALYZE-RESUME
233 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _INCLUDED-LIB Procedure
234 /* ************************* Included-Libraries *********************** */
236 {inc/method/m-txtrep.i}
238 /* _UIB-CODE-BLOCK-END */
239 &ANALYZE-RESUME
245 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Procedure
248 /* *************************** Main Block *************************** */
249 {inc/username.i "user-name"}
250 timeStamp = STRING( TODAY, "99/99/9999") + ", " + STRING( TIME, "HH:MM:SS") + " for " + user-name.
251 IF export-fname = "" THEN DO:
252 RUN make-control-string ( "PCL", "reset,portrait,tm,2,a4,lm,6,courier,cpi,18,lpi,9",
253 OUTPUT prt-ctrl, OUTPUT rows, OUTPUT cols ).
255 RUN output-control-file ( prt-ctrl ).
256 OUTPUT TO VALUE(txtrep-print-file) KEEP-MESSAGES PAGE-SIZE VALUE(rows).
258 VIEW FRAME heading-frame.
259 END.
260 ELSE DO:
261 OUTPUT TO VALUE(export-fname) KEEP-MESSAGES .
262 PUT UNFORMATTED '"Batch","Doc","Trn","Type","Entity","Account","Reference","Date","Amount","Narrative","Related records","Flag","Flagged By"' SKIP .
263 END.
265 IF sort-entity-type <> base-entity-type THEN DO:
266 IF group-name <> "" THEN DO:
267 FOR EACH ChartOfAccount OF AccountGroup NO-LOCK BY ChartOfAccount.AccountCode:
268 RUN each-account-by-account.
269 END.
270 END.
271 ELSE DO:
272 FOR EACH ChartOfAccount NO-LOCK
273 WHERE ChartOfAccount.AccountCode >= account-1 AND ChartOfAccount.AccountCode <= account-2
274 BY ChartOfAccount.AccountCode:
275 RUN each-account-by-account.
276 END.
277 END.
278 END.
279 ELSE IF AVAILABLE(ConsolidationList) THEN DO:
280 DEF VAR entry-no AS INT NO-UNDO INITIAL 0.
281 consol-accounts = STRING( ic-base, "9999.99").
282 ic-base = TRUNC( ic-base / 1000, 0 ) * 1000.
283 DO entry-no = 1 TO NUM-ENTRIES( ConsolidationList.CompanyList ):
284 consol-accounts = consol-accounts + "," + STRING( ic-base + DEC( ENTRY( entry-no, ConsolidationList.CompanyList)), "9999.99").
285 END.
286 DO entry-no = 1 TO NUM-ENTRIES( ConsolidationList.CompanyList ):
287 FIND Company NO-LOCK WHERE Company.CompanyCode = INT(ENTRY(entry-no, ConsolidationList.CompanyList)) NO-ERROR.
288 IF NOT AVAILABLE(Company) THEN NEXT.
289 RUN each-company-by-company.
290 END.
291 END.
292 ELSE DO:
293 FOR EACH Company NO-LOCK
294 WHERE Company.CompanyCode >= company-1 AND Company.CompanyCode <= company-2
295 BY Company.CompanyCode:
296 RUN each-company-by-company.
297 END.
298 END.
301 IF export-fname = "" THEN DO:
302 IF (company-1 = company-2 AND sort-entity-type = base-entity-type)
303 OR (account-1 = account-2 AND sort-entity-type <> base-entity-type)
304 THEN .
305 ELSE DO:
306 PUT SKIP (2).
307 dispName = "Entire report".
308 RUN disp-totals(grand-total).
309 END.
310 OUTPUT CLOSE.
311 RUN view-output-file( preview ).
312 END.
313 ELSE
314 OUTPUT CLOSE.
316 /* _UIB-CODE-BLOCK-END */
317 &ANALYZE-RESUME
320 /* ********************** Internal Procedures *********************** */
322 &IF DEFINED(EXCLUDE-disp-entity-account) = 0 &THEN
324 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE disp-entity-account Procedure
325 PROCEDURE disp-entity-account :
326 /*------------------------------------------------------------------------------
327 Purpose: Set the dispEntityName variable to the current account.
328 ------------------------------------------------------------------------------*/
329 dispName = STRING(ChartOfAccount.AccountCode, "9999.99") + ", " +
330 ChartOfAccount.Name.
331 END PROCEDURE.
333 /* _UIB-CODE-BLOCK-END */
334 &ANALYZE-RESUME
336 &ENDIF
338 &IF DEFINED(EXCLUDE-disp-entity-company) = 0 &THEN
340 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE disp-entity-company Procedure
341 PROCEDURE disp-entity-company :
342 /*------------------------------------------------------------------------------
343 Purpose: Set the dispEntityName variable to the current company.
344 ------------------------------------------------------------------------------*/
345 dispName = Company.LegalName +
346 " (" + STRING(Company.CompanyCode, "999") + ")".
347 END PROCEDURE.
349 /* _UIB-CODE-BLOCK-END */
350 &ANALYZE-RESUME
352 &ENDIF
354 &IF DEFINED(EXCLUDE-disp-month-totals) = 0 &THEN
356 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE disp-month-totals Procedure
357 PROCEDURE disp-month-totals :
358 /*------------------------------------------------------------------------------
359 Purpose:
360 ------------------------------------------------------------------------------*/
361 DEF INPUT PARAMETER month-code AS INT NO-UNDO.
362 DEF INPUT PARAMETER month-total AS DEC NO-UNDO.
363 DEF INPUT PARAMETER next-month-code AS INT NO-UNDO.
365 /* MESSAGE 1 show-month-totals tr-this-month month-code last-month month-total. */
366 IF NOT(show-month-totals) THEN RETURN.
368 DEF BUFFER MyMonth FOR Month.
370 IF month-code <> ? THEN DO:
371 IF tr-this-month THEN DO:
372 FIND MyMonth WHERE MyMonth.MonthCode = month-code NO-LOCK NO-ERROR.
373 dispName = "closing balance at " + STRING( MyMonth.EndDate, "99/99/9999").
374 RUN disp-totals( account-total ).
375 MESSAGE "".
376 END.
377 END.
379 tr-this-month = no.
380 last-month = next-month-code.
382 END PROCEDURE.
384 /* _UIB-CODE-BLOCK-END */
385 &ANALYZE-RESUME
387 &ENDIF
389 &IF DEFINED(EXCLUDE-disp-totals) = 0 &THEN
391 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE disp-totals Procedure
392 PROCEDURE disp-totals :
393 /*------------------------------------------------------------------------------
394 Purpose:
395 ------------------------------------------------------------------------------*/
396 DEF INPUT PARAMETER disp-total AS DECIMAL NO-UNDO.
398 IF export-fname <> "" THEN RETURN.
400 MESSAGE FILL(" ",30) " -------------".
401 dispReference = STRING( (IF dispName BEGINS "closin" THEN "" ELSE "Total"), "X(13)").
402 MESSAGE " " FILL(" ", 10) dispReference format-big-money(disp-total) dispName.
404 END PROCEDURE.
406 /* _UIB-CODE-BLOCK-END */
407 &ANALYZE-RESUME
409 &ENDIF
411 &IF DEFINED(EXCLUDE-display-headings-if-needed) = 0 &THEN
413 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE display-headings-if-needed Procedure
414 PROCEDURE display-headings-if-needed :
415 /*------------------------------------------------------------------------------
416 Purpose: If this is the first transaction for an account or company (or both)
417 we need to display the appropriate headings.
418 ------------------------------------------------------------------------------*/
420 IF export-fname <> "" THEN RETURN.
422 /* For the major sort sequence */
423 IF NOT tr-this-company AND sort-entity-type = "L" THEN DO:
424 IF company-1 <> company-2 THEN DO:
425 RUN disp-entity-company.
426 DISPLAY dispName WITH FRAME report-frame-1.
427 DOWN WITH FRAME report-frame-1.
428 END.
429 tr-this-company = yes.
430 END.
431 ELSE IF NOT tr-this-account AND sort-entity-type = "A" THEN DO:
432 RUN disp-entity-account.
433 DISPLAY dispName WITH FRAME report-frame-1.
434 DOWN WITH FRAME report-frame-1.
435 tr-this-account = yes.
436 END.
438 /* For the minor sort sequence */
439 IF NOT tr-this-company THEN DO:
440 RUN disp-entity-company.
441 DISPLAY dispName WITH FRAME report-frame-1.
442 DOWN WITH FRAME report-frame-1.
443 tr-this-company = yes.
444 END.
445 ELSE IF NOT tr-this-account THEN DO:
446 RUN disp-entity-account.
447 DISPLAY dispName WITH FRAME report-frame-1.
448 DOWN WITH FRAME report-frame-1.
449 tr-this-account = yes.
450 END.
452 END PROCEDURE.
454 /* _UIB-CODE-BLOCK-END */
455 &ANALYZE-RESUME
457 &ENDIF
459 &IF DEFINED(EXCLUDE-each-account) = 0 &THEN
461 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE each-account Procedure
462 PROCEDURE each-account :
463 /*------------------------------------------------------------------------------
464 Purpose: Display transactions for a single account
465 ------------------------------------------------------------------------------*/
466 IF account-pattern <> ? AND NOT check-pattern-match( ChartOfAccount.AccountCode ) THEN RETURN.
467 IF no-show-zero AND balance-is-zero() THEN RETURN.
468 IF show-opening-balances THEN RUN show-opening-balance.
470 IF ( ChartOfAccount.HighVolume AND (NOT show-all) ) OR balances-only THEN DO:
471 /* special treatment for high volume accounts */
472 RUN each-volume-account.
473 RETURN.
474 END.
476 tr-this-month = no.
477 FOR EACH AccountBalance NO-LOCK
478 WHERE AccountBalance.EntityType = base-entity-type
479 AND AccountBalance.EntityCode = Company.CompanyCode
480 AND AccountBalance.AccountCode = ChartOfAccount.AccountCode
481 AND AccountBalance.MonthCode >= month-1
482 AND AccountBalance.MonthCode <= month-2,
483 FIRST Month OF AccountBalance NO-LOCK
486 RUN disp-month-totals( last-month, account-total, AccountBalance.MonthCode ).
488 IF show-all THEN DO:
489 FOR EACH AcctTran NO-LOCK OF AccountBalance
490 WHERE AcctTran.Date >= earliest-date,
491 FIRST Document NO-LOCK OF AcctTran WHERE
492 ( IF exclude-year-end THEN Document.DocumentType <> "YEND" ELSE True )
493 BY AcctTran.EntityType BY AcctTran.EntityCode BY AcctTran.AccountCode
494 BY AcctTran.MonthCode BY AcctTran.Date
495 BY AcctTran.BatchCode BY AcctTran.DocumentCode BY AcctTran.TransactionCode
497 RUN each-transaction.
498 END.
499 END.
500 ELSE DO:
501 FOR EACH AcctTran NO-LOCK OF AccountBalance WHERE AcctTran.Date >= earliest-date,
502 FIRST Document NO-LOCK OF AcctTran
503 BY AcctTran.EntityType BY AcctTran.EntityCode BY AcctTran.AccountCode
504 BY AcctTran.MonthCode BY AcctTran.Date
505 BY AcctTran.BatchCode BY AcctTran.DocumentCode BY AcctTran.TransactionCode
507 RUN each-transaction.
508 END.
509 END.
510 END.
512 END PROCEDURE.
514 /* _UIB-CODE-BLOCK-END */
515 &ANALYZE-RESUME
517 &ENDIF
519 &IF DEFINED(EXCLUDE-each-account-by-account) = 0 &THEN
521 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE each-account-by-account Procedure
522 PROCEDURE each-account-by-account :
523 /*------------------------------------------------------------------------------
524 Purpose: Loop for all companies within an account
525 ------------------------------------------------------------------------------*/
527 ASSIGN
528 account-total = 0
529 tr-this-account = no
531 IF AVAILABLE(ConsolidationList) THEN DO:
532 DEF VAR entry-no AS INT NO-UNDO INITIAL 0.
533 DO entry-no = 1 TO NUM-ENTRIES( ConsolidationList.CompanyList ):
534 FIND Company NO-LOCK WHERE Company.CompanyCode = INT(ENTRY(entry-no, ConsolidationList.CompanyList)) NO-ERROR.
535 IF NOT AVAILABLE(Company) THEN NEXT.
537 ASSIGN company-total = 0
538 tr-this-company = no .
540 RUN each-account.
542 IF tr-this-company THEN DO:
543 RUN disp-entity-company.
544 RUN disp-totals( company-total ).
545 END.
546 END.
547 END.
548 ELSE DO:
549 FOR EACH Company NO-LOCK WHERE Company.CompanyCode >= company-1
550 AND Company.CompanyCode <= company-2
551 AND CAN-FIND( FIRST AccountBalance
552 WHERE AccountBalance.EntityType = base-entity-type
553 AND AccountBalance.EntityCode = Company.CompanyCode
554 AND AccountBalance.AccountCode = ChartOfAccount.AccountCode
555 AND AccountBalance.MonthCode <= month-2 ) :
556 ASSIGN company-total = 0
557 tr-this-company = no .
559 RUN each-account.
561 IF tr-this-company THEN DO:
562 RUN disp-entity-company.
563 RUN disp-totals( company-total ).
564 END.
565 END.
566 END.
568 IF tr-this-account THEN DO:
569 RUN disp-entity-account.
570 RUN disp-totals( account-total ).
571 grand-total = grand-total + account-total.
572 END.
574 END PROCEDURE.
576 /* _UIB-CODE-BLOCK-END */
577 &ANALYZE-RESUME
579 &ENDIF
581 &IF DEFINED(EXCLUDE-each-company-by-company) = 0 &THEN
583 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE each-company-by-company Procedure
584 PROCEDURE each-company-by-company :
585 /*------------------------------------------------------------------------------
586 Purpose: Loop for all accounts of company
587 ------------------------------------------------------------------------------*/
589 ASSIGN
590 company-total = 0
591 tr-this-company = no
594 IF group-name <> "" THEN DO:
595 FOR EACH ChartOfAccount OF AccountGroup NO-LOCK
596 WHERE CAN-FIND( FIRST AccountBalance
597 WHERE AccountBalance.EntityType = base-entity-type
598 AND AccountBalance.EntityCode = Company.CompanyCode
599 AND AccountBalance.AccountCode = ChartOfAccount.AccountCode
600 AND AccountBalance.MonthCode <= month-2 ) :
602 IF interco-outside-group( ChartOfAccount.AccountCode ) THEN NEXT.
604 ASSIGN account-total = 0
605 tr-this-account = no .
607 RUN each-account.
609 IF tr-this-account THEN DO:
610 RUN disp-entity-account.
611 RUN disp-totals( account-total ).
612 END.
613 END.
614 END.
615 ELSE DO:
616 FOR EACH ChartOfAccount NO-LOCK
617 WHERE ChartOfAccount.AccountCode >= account-1
618 AND ChartOfAccount.AccountCode <= account-2
619 AND CAN-FIND( FIRST AccountBalance
620 WHERE AccountBalance.EntityType = base-entity-type
621 AND AccountBalance.EntityCode = Company.CompanyCode
622 AND AccountBalance.AccountCode = ChartOfAccount.AccountCode
623 AND AccountBalance.MonthCode <= month-2 ) :
624 ASSIGN
625 account-total = 0
626 tr-this-account = no
629 RUN each-account.
631 IF tr-this-account THEN DO:
632 RUN disp-entity-account.
633 RUN disp-totals( account-total ).
634 END.
635 END.
636 END.
638 IF tr-this-company THEN DO:
639 RUN disp-entity-company.
640 RUN disp-totals( company-total ).
641 grand-total = grand-total + company-total.
642 END.
644 END PROCEDURE.
646 /* _UIB-CODE-BLOCK-END */
647 &ANALYZE-RESUME
649 &ENDIF
651 &IF DEFINED(EXCLUDE-each-transaction) = 0 &THEN
653 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE each-transaction Procedure
654 PROCEDURE each-transaction :
655 /*------------------------------------------------------------------------------
656 Purpose:
657 ------------------------------------------------------------------------------*/
658 IF AcctTran.BatchCode < earliest-batch THEN RETURN.
659 IF exclude-year-end THEN DO:
660 FIND Document OF AcctTran NO-LOCK.
661 IF Document.DocumentType = "YEND"
662 OR Document.Description BEGINS "Y/E Transfer to Ret"
663 OR Document.Description BEGINS "Y/E Accumulated P&L"
664 OR (AcctTran.EntityType = "P" AND Document.Description BEGINS "Y/E Clear Propacc Balance" )
665 THEN RETURN.
666 END.
668 RUN display-headings-if-needed.
670 dispReference = STRING( (IF (AcctTran.Reference = "") THEN (Document.Reference) ELSE (AcctTran.Reference) ), "X(12)" )
671 + ( IF (AcctTran.ClosingGroup > 0) THEN "*" ELSE " " ).
672 dispDescription = IF (AcctTran.Description = "") THEN (Document.Description) ELSE (AcctTran.Description).
673 tr-this-month = yes.
675 IF show-relations THEN DO:
676 IF SUBSTRING(dispReference, 1, 3) = "INV" THEN DO:
677 FIND Invoice WHERE Invoice.InvoiceNo = INT( SUBSTRING(dispReference, 4)) NO-LOCK NO-ERROR.
678 IF AVAILABLE(Invoice) THEN DO:
679 dispDescription = STRING( dispDescription, "X(51)").
680 IF Invoice.EntityType = "T" THEN DO:
681 FIND Tenant WHERE Tenant.TenantCode = Invoice.EntityCode NO-LOCK NO-ERROR.
683 dispDescription = dispDescription
684 + Invoice.EntityType + STRING(Invoice.EntityCode)
685 + (IF AVAILABLE(Tenant) THEN " " + Tenant.Name ELSE "").
686 END.
687 ELSE
688 dispDescription = dispDescription + Invoice.EntityType + STRING(Invoice.EntityCode).
689 END.
690 END.
691 ELSE IF SUBSTRING(dispReference, 1, 4) = "VCHR" THEN DO:
692 FIND Voucher WHERE Voucher.VoucherSeq = INT( SUBSTRING(dispReference, 5)) NO-LOCK NO-ERROR.
693 IF AVAILABLE(Voucher) THEN DO:
694 FIND Creditor OF Voucher NO-LOCK NO-ERROR.
695 dispDescription = STRING( dispDescription, "X(51)")
696 + (IF show-cheque-no THEN Voucher.BankAccountCode + STRING(Voucher.ChequeNo,"999999" + ", ") ELSE "")
697 + "C" + STRING(Voucher.CreditorCode)
698 + (IF AVAILABLE(Creditor) THEN " " + Creditor.Name ELSE "").
699 END.
700 END.
701 END.
703 IF export-fname <> "" THEN RUN export-transaction .
704 ELSE DO:
705 dispAmount = format-big-money( AcctTran.Amount ).
706 MESSAGE " " STRING(AcctTran.Date, "99/99/9999") dispReference dispAmount dispDescription.
707 /* DISPLAY
708 AcctTran.Date
709 dispReference
710 dispAmount
711 dispDescription
712 WITH FRAME report-frame-2.
714 DOWN WITH FRAME report-frame-2. */
715 END.
717 ASSIGN
718 account-total = account-total + AcctTran.Amount
719 company-total = company-total + AcctTran.Amount
722 END PROCEDURE.
724 /* _UIB-CODE-BLOCK-END */
725 &ANALYZE-RESUME
727 &ENDIF
729 &IF DEFINED(EXCLUDE-each-volume-account) = 0 &THEN
731 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE each-volume-account Procedure
732 PROCEDURE each-volume-account :
733 /*------------------------------------------------------------------------------
734 Purpose: Display balance only for a high-volume account
735 ------------------------------------------------------------------------------*/
736 DEF VAR transaction-total AS DECIMAL NO-UNDO.
738 transaction-total = 0.
739 FOR EACH AccountBalance NO-LOCK
740 WHERE AccountBalance.EntityType = base-entity-type
741 AND AccountBalance.EntityCode = Company.CompanyCode
742 AND AccountBalance.AccountCode = ChartOfAccount.AccountCode
743 AND AccountBalance.MonthCode >= month-1
744 AND AccountBalance.MonthCode <= month-2,
745 FIRST Month OF AccountBalance NO-LOCK
748 tr-this-month = no.
749 FOR EACH AcctTran NO-LOCK OF AccountBalance WHERE AcctTran.Date >= earliest-date
750 AND AcctTran.BatchCode >= earliest-batch,
751 FIRST Document NO-LOCK OF AcctTran WHERE
752 ( IF exclude-year-end THEN Document.DocumentType <> "YEND" ELSE True )
753 BY AcctTran.EntityType BY AcctTran.EntityCode BY AcctTran.AccountCode
754 BY AcctTran.MonthCode BY AcctTran.Date
755 BY AcctTran.BatchCode BY AcctTran.DocumentCode BY AcctTran.TransactionCode
757 ASSIGN
758 tr-this-month = yes
759 transaction-total = transaction-total + AcctTran.Amount
761 END.
762 END.
764 ASSIGN
765 account-total = account-total + transaction-total
766 company-total = company-total + transaction-total
769 RUN display-headings-if-needed.
771 IF export-fname = "" THEN DO:
772 dispAmount = format-big-money( transaction-total ).
773 MESSAGE " " STRING( m2-end, "99/99/9999") FILL(" ", 13) dispAmount "Sum of transactions in period".
774 END.
776 END PROCEDURE.
778 /* _UIB-CODE-BLOCK-END */
779 &ANALYZE-RESUME
781 &ENDIF
783 &IF DEFINED(EXCLUDE-export-transaction) = 0 &THEN
785 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE export-transaction Procedure
786 PROCEDURE export-transaction :
787 /*------------------------------------------------------------------------------
788 Purpose:
789 Parameters: <none>
790 Notes:
791 ------------------------------------------------------------------------------*/
792 DEF VAR FlagBy AS CHAR INITIAL "" NO-UNDO.
794 FIND Person WHERE Person.PersonCode = AcctTran.FlaggedBy NO-LOCK NO-ERROR.
795 IF AVAILABLE(Person) THEN
796 FlagBy = Person.FirstName + " " + Person.LastName.
798 PUT UNFORMATTED
799 AcctTran.BatchCode ','
800 AcctTran.DocumentCode ','
801 AcctTran.TransactionCode ',"'
802 AcctTran.EntityType '",'
803 AcctTran.EntityCode ','
804 AcctTran.AccountCode ',"'
805 dispReference '","'
806 AcctTran.Date '",'
807 AcctTran.Amount ',"'
808 TRIM( SUBSTRING(dispDescription,1,50)) '","'
809 TRIM( SUBSTRING(dispDescription,51)) '","'
810 AcctTran.FlagAttention '","'
811 FlagBy '"'
812 SKIP .
813 END PROCEDURE.
815 /* _UIB-CODE-BLOCK-END */
816 &ANALYZE-RESUME
818 &ENDIF
820 &IF DEFINED(EXCLUDE-parse-parameters) = 0 &THEN
822 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE parse-parameters Procedure
823 PROCEDURE parse-parameters :
824 /*------------------------------------------------------------------------------
825 Purpose:
826 ------------------------------------------------------------------------------*/
827 DEF VAR some-options AS CHAR NO-UNDO.
828 DEF VAR complex-options AS CHAR NO-UNDO.
829 DEF VAR pos AS INT NO-UNDO.
832 {inc/showopts.i "report-options"}
833 pos = INDEX( report-options, "~n").
834 IF pos = ? THEN pos = 0.
835 complex-options = SUBSTRING( report-options, pos + 1).
836 report-options = ENTRY( 1, report-options, "~n").
838 some-options = ENTRY( 1, report-options ).
839 company-1 = INTEGER( ENTRY( 2, report-options )).
840 company-2 = INTEGER( ENTRY( 3, report-options )).
841 month-1 = INTEGER( ENTRY( 4, report-options )).
842 month-2 = INTEGER( ENTRY( 5, report-options )).
843 show-all = (ENTRY( 6, report-options ) = "Yes").
844 account-1 = DECIMAL( ENTRY( 7, report-options )).
845 account-2 = DECIMAL( ENTRY( 8, report-options )).
846 preview = (ENTRY( 9, report-options ) = "Yes").
847 earliest-date = DATE(ENTRY(10, report-options )).
848 earliest-batch = INTEGER( ENTRY(11, report-options )).
849 export-fname = ENTRY(12, report-options ).
850 group-name = ENTRY(13, report-options ).
852 /* Now detail to the complex options string */
853 DEF VAR i AS INT NO-UNDO.
854 DEF VAR token AS CHAR NO-UNDO.
857 DO i = 1 TO NUM-ENTRIES( complex-options, "~n" ):
858 token = ENTRY( i, complex-options, "~n" ).
859 CASE( ENTRY( 1, token ) ):
860 WHEN "ConsolidationList" THEN DO:
861 pos = LENGTH( ENTRY(1,token) ).
862 IF pos = ? THEN pos = 0.
863 list-name = TRIM( SUBSTRING( token, pos + 2 )).
864 END.
865 WHEN "NoRelations" THEN show-relations = No.
866 WHEN "MonthTotals" THEN show-month-totals = Yes.
867 WHEN "SortBy" THEN sort-entity-type = ENTRY( 2, token).
868 WHEN "NonZeroOnly" THEN no-show-zero = Yes.
869 WHEN "BalancesOnly" THEN balances-only = Yes.
870 WHEN "NoOpeningBalances" THEN show-opening-balances = No.
871 WHEN "ExcludeYearEnd" THEN exclude-year-end = Yes.
872 WHEN "AccountsLike" THEN ASSIGN
873 base-pattern = STRING( ENTRY(2,token), "XXXX.XX")
874 account-pattern = REPLACE( base-pattern, "*", ".").
875 END CASE.
876 END.
878 END PROCEDURE.
880 /* _UIB-CODE-BLOCK-END */
881 &ANALYZE-RESUME
883 &ENDIF
885 &IF DEFINED(EXCLUDE-show-opening-balance) = 0 &THEN
887 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE show-opening-balance Procedure
888 PROCEDURE show-opening-balance :
889 /*------------------------------------------------------------------------------
890 Purpose: Calculate and display the opening balance
891 ------------------------------------------------------------------------------*/
892 DEF VAR opening-balance LIKE AcctTran.Amount NO-UNDO.
893 opening-balance = 0.
895 FOR EACH AccountBalance NO-LOCK
896 WHERE AccountBalance.EntityType = base-entity-type
897 AND AccountBalance.EntityCode = Company.CompanyCode
898 AND AccountBalance.AccountCode = ChartOfAccount.AccountCode
899 AND AccountBalance.MonthCode < month-1:
900 opening-balance = opening-balance + AccountBalance.Balance.
901 END.
903 IF earliest-date > DATE(1,1,1) THEN DO:
904 FOR EACH AcctTran NO-LOCK
905 WHERE AcctTran.EntityType = base-entity-type
906 AND AcctTran.EntityCode = Company.CompanyCode
907 AND AcctTran.AccountCode = ChartOfAccount.AccountCode
908 AND AcctTran.MonthCode = month-1
909 AND AcctTran.Date < earliest-date:
910 opening-balance = opening-balance + AcctTran.Amount.
911 END.
912 END.
914 IF opening-balance <> 0 THEN DO:
915 RUN display-headings-if-needed.
916 FIND LAST Month WHERE Month.MonthCode < month-1 NO-LOCK.
917 ASSIGN
918 dispReference = "O/Bal "
919 dispDescription = "Opening Balance"
920 tr-this-month = yes
923 IF export-fname = "" THEN DO:
924 MESSAGE " " STRING(Month.EndDate + 1, "99/99/9999") dispReference format-big-money(opening-balance) dispDescription.
925 IF show-month-totals THEN PUT SKIP(1).
926 END.
927 ELSE
928 PUT UNFORMATTED ',,,"'
929 base-entity-type '",' Company.CompanyCode ',' ChartOfAccount.AccountCode ',"'
930 TRIM(dispReference) '","'
931 Month.EndDate '",'
932 opening-balance ',"'
933 dispDescription '"'
934 SKIP .
937 ASSIGN
938 account-total = account-total + opening-balance
939 company-total = company-total + opening-balance
941 END.
943 END PROCEDURE.
945 /* _UIB-CODE-BLOCK-END */
946 &ANALYZE-RESUME
948 &ENDIF
950 /* ************************ Function Implementations ***************** */
952 &IF DEFINED(EXCLUDE-balance-is-zero) = 0 &THEN
954 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION balance-is-zero Procedure
955 FUNCTION balance-is-zero RETURNS LOGICAL
956 ( /* no parameter-definitions */ ) :
957 /*------------------------------------------------------------------------------
958 Purpose: Check the balance of the account over the period. If it is 0, then
959 return the string "ZERO".
960 ------------------------------------------------------------------------------*/
961 DEF VAR bal-total AS DEC INITIAL 0 NO-UNDO.
963 FIND AccountSummary WHERE AccountSummary.EntityType = base-entity-type
964 AND AccountSummary.EntityCode = Company.CompanyCode
965 AND AccountSummary.AccountCode = ChartOfAccount.AccountCode
966 NO-LOCK NO-ERROR.
967 IF AVAILABLE(AccountSummary) THEN bal-total = AccountSummary.Balance.
969 /* Subtract back to get balance at end of period */
970 FOR EACH AccountBalance NO-LOCK
971 WHERE AccountBalance.EntityType = base-entity-type
972 AND AccountBalance.EntityCode = Company.CompanyCode
973 AND AccountBalance.AccountCode = ChartOfAccount.AccountCode
974 AND AccountBalance.MonthCode > month-2:
975 bal-total = bal-total - AccountBalance.Balance.
976 END.
978 RETURN (bal-total = 0).
980 END FUNCTION.
982 /* _UIB-CODE-BLOCK-END */
983 &ANALYZE-RESUME
985 &ENDIF
987 &IF DEFINED(EXCLUDE-check-pattern-match) = 0 &THEN
989 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION check-pattern-match Procedure
990 FUNCTION check-pattern-match RETURNS LOGICAL
991 ( INPUT ac AS DEC ) :
992 /*------------------------------------------------------------------------------
993 Purpose: Check that this account matches an OK pattern
994 Notes:
995 ------------------------------------------------------------------------------*/
996 DEF VAR ac-text AS CHAR NO-UNDO.
998 ac-text = STRING( ac, "9999.99").
999 RETURN ac-text MATCHES account-pattern.
1001 END FUNCTION.
1003 /* _UIB-CODE-BLOCK-END */
1004 &ANALYZE-RESUME
1006 &ENDIF
1008 &IF DEFINED(EXCLUDE-format-big-money) = 0 &THEN
1010 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION format-big-money Procedure
1011 FUNCTION format-big-money RETURNS CHARACTER
1012 ( INPUT amt AS DEC ) :
1013 /*------------------------------------------------------------------------------
1014 Purpose: Work around problems experienced formatting billions
1015 ------------------------------------------------------------------------------*/
1016 DEF VAR formatted AS CHAR NO-UNDO.
1017 formatted = STRING( amt, ">>,>>>,>>>,>>9.99CR").
1018 /* MESSAGE "Fmt1" formatted.
1019 formatted = STRING( amt, ">>>>>>>>>>>9.99CR").
1020 /* MESSAGE "Fmt1" formatted. */
1021 formatted = SUBSTRING( formatted, 1, 3) + ","
1022 + SUBSTRING( formatted, 4, 3) + ","
1023 + SUBSTRING( formatted, 7, 3) + ","
1024 + SUBSTRING( formatted, 10).
1025 /* MESSAGE "Fmt2" formatted. */
1026 formatted = LEFT-TRIM(formatted, ", ").
1027 formatted = FILL(" ", money-length - LENGTH(formatted)) + formatted.
1028 /* MESSAGE "Fmt3" formatted. */
1030 RETURN formatted.
1032 END FUNCTION.
1034 /* _UIB-CODE-BLOCK-END */
1035 &ANALYZE-RESUME
1037 &ENDIF
1039 &IF DEFINED(EXCLUDE-interco-outside-group) = 0 &THEN
1041 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION interco-outside-group Procedure
1042 FUNCTION interco-outside-group RETURNS LOGICAL
1043 ( INPUT ac AS DEC ) :
1044 /*------------------------------------------------------------------------------
1045 Purpose:
1046 Notes:
1047 ------------------------------------------------------------------------------*/
1048 /* we disable the whole thing at the moment */
1049 RETURN No.
1051 IF consol-accounts = "" THEN RETURN No.
1052 IF (TRUNC( ac / 1000, 0) * 1000) <> ic-base THEN RETURN No.
1053 IF LOOKUP( STRING(ac, "9999.99"), consol-accounts) > 0 THEN RETURN No.
1055 RETURN Yes.
1057 END FUNCTION.
1059 /* _UIB-CODE-BLOCK-END */
1060 &ANALYZE-RESUME
1062 &ENDIF