1 &ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12
3 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS Procedure
4 /*--------------------------------------------------------------------------
5 File
: process
/report
/tbgrpt.p
6 Purpose
: Produce Trial Balance by Group reports
8 Author
(s
) : Andrew McMillan
10 ------------------------------------------------------------------------*/
12 DEF INPUT PARAMETER report-options
AS CHAR NO-UNDO.
14 DEF VAR regenerate
AS LOGI
NO-UNDO.
15 DEF VAR entity-type
AS CHAR NO-UNDO.
16 DEF VAR entity-1
AS INT NO-UNDO.
17 DEF VAR entity-2
AS INT NO-UNDO.
18 DEF VAR month-1
AS INT NO-UNDO.
19 DEF VAR month-2
AS INT NO-UNDO.
20 DEF VAR csv-file-name
AS CHAR NO-UNDO.
21 DEF VAR list-name
AS CHAR NO-UNDO.
22 DEF VAR column-style
AS CHAR NO-UNDO.
23 DEF VAR r-type
AS CHAR NO-UNDO.
24 DEF VAR range
AS CHAR NO-UNDO.
25 DEF VAR out-to
AS CHAR NO-UNDO.
26 DEF VAR pedantic-listing
AS LOGICAL NO-UNDO INITIAL No.
27 DEF VAR consolidate-together
AS LOGI
NO-UNDO INITIAL No.
28 DEF VAR month-range
AS LOGICAL NO-UNDO INITIAL No.
29 DEF VAR include-bs
AS LOGICAL NO-UNDO INITIAL YES.
30 DEF VAR include-pl
AS LOGICAL NO-UNDO INITIAL YES.
31 DEF VAR exclude-year-end
AS LOGICAL NO-UNDO INITIAL No.
32 DEF VAR debug-mode
AS LOGICAL NO-UNDO INITIAL No.
35 /* global variables used by create-tb-record
*/
36 DEF VAR last-account-code
AS DECIMAL INITIAL -1 NO-UNDO.
37 DEF VAR account-name
AS CHAR NO-UNDO.
38 DEF VAR last-account-group
AS CHAR INITIAL "none-as-yet" NO-UNDO.
39 DEF VAR account-seq
AS INT NO-UNDO.
40 DEF VAR acgroup-name
AS CHAR NO-UNDO.
41 DEF VAR account-comments
AS CHAR NO-UNDO.
42 DEF VAR consol-accounts
AS CHAR NO-UNDO.
44 /* accountgroup totals
, entity totals and grand totals
*/
45 DEF VAR total-name
AS CHAR FORMAT "X(50)" NO-UNDO.
46 DEF VAR ag-balance
AS DECIMAL NO-UNDO.
47 DEF VAR ag-budget
AS DECIMAL NO-UNDO.
48 DEF VAR ag-mtdbal
AS DECIMAL NO-UNDO.
49 DEF VAR ag-mtdbud
AS DECIMAL NO-UNDO.
51 DEF VAR et-balance
AS DECIMAL NO-UNDO.
52 DEF VAR et-budget
AS DECIMAL NO-UNDO.
53 DEF VAR et-mtdbal
AS DECIMAL NO-UNDO.
54 DEF VAR et-mtdbud
AS DECIMAL NO-UNDO.
56 DEF VAR pl-balance
AS DECIMAL NO-UNDO.
57 DEF VAR pl-budget
AS DECIMAL NO-UNDO.
58 DEF VAR pl-mtdbal
AS DECIMAL NO-UNDO.
59 DEF VAR pl-mtdbud
AS DECIMAL NO-UNDO.
61 DEF VAR remaining-comments
AS CHAR NO-UNDO.
64 DEFINE TEMP-TABLE tb
NO-UNDO /* LIKE TrialBalance
*/
65 FIELD EntityType
AS CHAR
66 FIELD EntityCode
AS INTEGER
67 FIELD SequenceCode
AS INTEGER
68 FIELD AccountCode
AS DECIMAL
69 FIELD SequenceName
AS CHAR
70 FIELD AccountName
AS CHAR
71 FIELD Balance
AS DECIMAL
72 FIELD Budget
AS DECIMAL
73 FIELD mtd-Balance
AS DECIMAL
74 FIELD mtd-Budget
AS DECIMAL
76 FIELD GroupType
AS CHAR
78 INDEX e-code
IS UNIQUE PRIMARY EntityType EntityCode SequenceCode AccountCode
79 INDEX xak1 EntityType EntityCode AccountCode
80 INDEX xak2 AccountCode .
82 /* Printer setup string and page size
*/
83 DEF VAR prt-ctrl
AS CHAR NO-UNDO.
84 DEF VAR rows
AS INT NO-UNDO.
85 DEF VAR cols
AS INT NO-UNDO.
86 RUN make-control-string
( "PCL", "reset,landscape,tm,2,a4,lm,6,courier,cpi,18,lpi,9",
87 OUTPUT prt-ctrl
, OUTPUT rows
, OUTPUT cols
).
88 /* MESSAGE "rows =" rows
" cols =" cols.
*/
90 /* Frame
& form definitions */
92 &SCOP WITH-DEFAULT NO-BOX USE-TEXT WIDTH {&page-width}
94 FIND Month
WHERE Month.MonthCode
= month-2
NO-LOCK.
95 DEFINE FRAME heading-frame
WITH 1 DOWN {&WITH-DEFAULT} NO-LABELS PAGE-TOP.
96 DEF VAR user-name
AS CHAR NO-UNDO.
97 DEF VAR timeStamp
AS CHAR FORMAT "X(54)" NO-UNDO.
98 DEF VAR rtypeString
AS CHAR FORMAT "X(12)" INITIAL "Detailed" NO-UNDO.
99 rtypeString
= IF r-type
= "S" THEN "Summary" ELSE (IF r-type
= "C" THEN "Consolidated" ELSE "Detailed" ) .
100 DEF VAR hline2
AS CHAR NO-UNDO.
101 DEF VAR hline3
AS CHAR NO-UNDO.
102 DEF VAR col-heads
AS CHAR NO-UNDO.
103 col-heads
= FILL(" ", 8) + STRING("Account", "X(51)").
104 IF column-style
= "Std" THEN
105 col-heads
= col-heads
+ " YTD Actual YTD Budget YTD Variance Month Actual Month Budget Month Variance Comments".
107 col-heads
= col-heads
+ " Current YTD Last Mth YTD Month Actual Month Budget Month Variance Comments".
109 DEF VAR include-qualifier
AS CHAR NO-UNDO INITIAL "".
110 IF NOT(include-bs
) THEN
111 include-qualifier
= " (P&L)".
112 ELSE IF NOT(include-pl
) THEN
113 include-qualifier
= " (Balance Sheet)".
116 timeStamp
"Page " + STRING( PAGE-NUMBER ) TO {&page-width} SKIP (1)
117 hline2
FORMAT "X({&page-width})"
118 hline3
FORMAT "X({&page-width})"
120 col-heads
FORMAT "X({&page-width})"
121 WITH FRAME heading-frame.
123 DEF VAR money-format
AS CHAR INITIAL ">,>>>,>>>,>>9.99CR" NO-UNDO.
124 DEF VAR minus-line
AS CHAR FORMAT "X(120)" NO-UNDO.
125 minus-line
= " " + FILL("-", 18).
126 minus-line
= FILL(" ", 58) + minus-line
+ minus-line
+ minus-line
127 + minus-line
+ minus-line
128 + (IF column-style
= "Std" THEN minus-line
ELSE "").
130 DEF VAR col-width
AS INT NO-UNDO.
131 IF column-style
= "Std" THEN
132 col-width
= 64 + LENGTH(STRING(0,money-format
)) * 6.
134 col-width
= 63 + LENGTH(STRING(0,money-format
)) * 5.
136 DEFINE STREAM debug-stream.
139 {inc
/ofc-acct.i
"IC-BASE" "ic-base"}
140 {inc
/ofc-set.i
"TB-type" "tb-type"}
142 /* _UIB-CODE-BLOCK-END
*/
146 &ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
148 /* ******************** Preprocessor Definitions
******************** */
150 &Scoped-define PROCEDURE-TYPE Procedure
151 &Scoped-define DB-AWARE no
155 /* _UIB-PREPROCESSOR-BLOCK-END
*/
159 /* ************************ Function Prototypes
********************** */
161 &IF DEFINED(EXCLUDE-balance-from-balances) = 0 &THEN
163 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD balance-from-balances Procedure
164 FUNCTION balance-from-balances
RETURNS DECIMAL
165 ( INPUT et
AS CHAR, INPUT ec
AS INT, INPUT ac
AS DEC, INPUT m-1
AS INT, INPUT m-n
AS INT ) FORWARD.
167 /* _UIB-CODE-BLOCK-END
*/
172 &IF DEFINED(EXCLUDE-balance-from-summary) = 0 &THEN
174 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD balance-from-summary Procedure
175 FUNCTION balance-from-summary
RETURNS DECIMAL
176 ( INPUT et
AS CHAR, INPUT ec
AS INT, INPUT ac
AS DEC, INPUT mnth
AS INT ) FORWARD.
178 /* _UIB-CODE-BLOCK-END
*/
183 &IF DEFINED(EXCLUDE-debug-event) = 0 &THEN
185 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD debug-event Procedure
186 FUNCTION debug-event
RETURNS CHARACTER
187 ( INPUT event-text
AS CHAR ) FORWARD.
189 /* _UIB-CODE-BLOCK-END
*/
194 &IF DEFINED(EXCLUDE-get-balance) = 0 &THEN
196 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD get-balance Procedure
197 FUNCTION get-balance
RETURNS DECIMAL
198 ( INPUT et
AS CHAR, INPUT ec
AS INT, INPUT ac
AS DEC, INPUT month-n
AS INT ) FORWARD.
200 /* _UIB-CODE-BLOCK-END
*/
205 &IF DEFINED(EXCLUDE-get-company-desc) = 0 &THEN
207 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD get-company-desc Procedure
208 FUNCTION get-company-desc
RETURNS CHARACTER
209 ( INPUT ec
AS INT ) FORWARD.
211 /* _UIB-CODE-BLOCK-END
*/
216 &IF DEFINED(EXCLUDE-interco-outside-group) = 0 &THEN
218 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD interco-outside-group Procedure
219 FUNCTION interco-outside-group
RETURNS LOGICAL
220 ( INPUT ac
AS DEC ) FORWARD.
222 /* _UIB-CODE-BLOCK-END
*/
228 /* *********************** Procedure Settings
************************ */
230 &ANALYZE-SUSPEND _PROCEDURE-SETTINGS
231 /* Settings for
THIS-PROCEDURE
235 Add Fields to
: Neither
236 Other Settings
: CODE-ONLY
COMPILE
238 &ANALYZE-RESUME _END-PROCEDURE-SETTINGS
240 /* ************************* Create Window
************************** */
242 &ANALYZE-SUSPEND _CREATE-WINDOW
243 /* DESIGN Window definition
(used by the UIB
)
244 CREATE WINDOW Procedure
ASSIGN
247 /* END WINDOW DEFINITION
*/
251 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _INCLUDED-LIB Procedure
252 /* ************************* Included-Libraries
*********************** */
254 {inc
/method
/m-txtrep.i
}
256 /* _UIB-CODE-BLOCK-END
*/
263 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Procedure
266 /* *************************** Main Block
*************************** */
267 {inc
/username.i
"user-name"}
268 timeStamp
= "Printed " + STRING( TIME, "HH:MM:SS") + ", " + STRING( TODAY, "99/99/9999") + " for " + user-name.
271 OUTPUT STREAM debug-stream
TO debug.log
PAGE-SIZE 0.
273 debug-event
("Start building temp table").
274 IF range
= "E" THEN DO: /* list of entities
*/
275 FIND EntityList
WHERE EntityList.ListCode
= list-name
NO-LOCK.
276 consol-accounts
= STRING( ic-base
, "9999.99").
277 ic-base
= TRUNC( ic-base
/ 1000, 0 ) * 1000.
278 FOR EACH EntityListMember
OF EntityList
NO-LOCK:
279 consol-accounts
= consol-accounts
+ "," + STRING( ic-base
+ DEC( EntityListMember.EntityCode
), "9999.99").
281 FOR EACH EntityListMember
OF EntityList
NO-LOCK:
282 RUN build-temp-file-range
( EntityList.ListType
, EntityListMember.EntityCode
, EntityListMember.EntityCode
, month-1
, month-2
).
284 entity-type
= EntityList.ListType.
286 ELSE IF range
= "L" THEN DO: /* list of companies
*/
287 DEF VAR i
AS INT NO-UNDO.
288 DEF VAR entity
AS INT NO-UNDO.
289 FIND ConsolidationList
WHERE ConsolidationList.Name
= list-name
NO-LOCK.
290 consol-accounts
= STRING( ic-base
, "9999.99").
291 ic-base
= TRUNC( ic-base
/ 1000, 0 ) * 1000.
292 DO i
= 1 TO NUM-ENTRIES( ConsolidationList.CompanyList
):
293 consol-accounts
= consol-accounts
+ "," + STRING( ic-base
+ DEC( ENTRY( i
, ConsolidationList.CompanyList
)), "9999.99").
295 DO i
= 1 TO NUM-ENTRIES( ConsolidationList.CompanyList
):
296 entity
= INTEGER( ENTRY(i
, ConsolidationList.CompanyList
)).
297 RUN build-temp-file-range
( "L", entity
, entity
, month-1
, month-2
).
302 RUN build-temp-file-range
( "L", entity-1
, entity-2
, month-1
, month-2
).
306 debug-event
("Finished building temp table").
307 RUN debug-temp-table.
309 IF r-type
= "DS" THEN DO:
310 IF out-to
= "S" THEN DO:
311 RUN normal-to-csv-file
( Yes
).
312 RUN normal-to-csv-file
( No
).
314 ELSE IF out-to
= "0" THEN
317 RUN normal-to-printer
( Yes
, (out-to
= "V") ).
318 RUN normal-to-printer
( No
, (out-to
= "V") ).
321 ELSE IF r-type
= "D" OR r-type
= "S" THEN DO:
323 RUN normal-to-csv-file
( (r-type
= "D") ).
324 ELSE IF out-to
= "0" THEN
327 RUN normal-to-printer
( (r-type
= "D"), (out-to
= "V") ).
329 ELSE IF r-type
= "E" THEN DO:
331 RUN exhaustive-to-csv.
333 MESSAGE "Consolidated Report only available to Spreadsheet".
334 /* to be continued ...
*/
338 RUN consolidated-to-csv.
340 MESSAGE "Consolidated Report only available to Spreadsheet".
341 /* to be continued ...
*/
344 debug-event
("Finished").
347 OUTPUT STREAM debug-stream
CLOSE.
349 /* _UIB-CODE-BLOCK-END
*/
353 /* ********************** Internal Procedures
*********************** */
355 &IF DEFINED(EXCLUDE-build-temp-file-range) = 0 &THEN
357 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE build-temp-file-range Procedure
358 PROCEDURE build-temp-file-range
:
359 /*------------------------------------------------------------------------------
361 ------------------------------------------------------------------------------*/
362 DEF INPUT PARAMETER et
AS CHAR NO-UNDO.
363 DEF INPUT PARAMETER e1
AS INT NO-UNDO.
364 DEF INPUT PARAMETER e2
AS INT NO-UNDO.
365 DEF INPUT PARAMETER m1
AS INT NO-UNDO.
366 DEF INPUT PARAMETER m2
AS INT NO-UNDO.
368 DEF VAR prev-co
AS INT INITIAL -1 NO-UNDO.
369 DEF VAR prev-acc
AS DECIMAL INITIAL -1 NO-UNDO.
371 DEF VAR bal
AS DEC NO-UNDO.
372 DEF VAR bud
AS DEC NO-UNDO.
373 DEF VAR m-bal
AS DEC NO-UNDO.
374 DEF VAR m-bud
AS DEC NO-UNDO.
378 /* create lots of blank records
*/
379 FOR EACH Company
WHERE CompanyCode
>= e1
AND CompanyCode
<= e2
NO-LOCK:
380 FOR EACH ChartOfAccount
WHERE ChartOfAccount.UpdateTo
<> "" NO-LOCK:
381 RUN create-tb-record
( et
, Company.CompanyCode
, ChartOfAccount.AccountCode
, 0, 0, 0, 0, "", "" ).
387 FOR EACH AccountBalance
WHERE EntityType
= et
388 AND EntityCode
>= e1
AND EntityCode
<= e2
389 AND AccountBalance.MonthCode
>= m1
390 AND AccountBalance.MonthCode
<= m2
NO-LOCK:
391 IF interco-outside-group
( AccountBalance.AccountCode
) THEN NEXT.
392 IF AccountBalance.EntityCode
<> prev-co
OR AccountBalance.AccountCode
<> prev-acc
THEN DO:
393 IF prev-co
<> -1 THEN DO:
394 IF NOT(month-range
) THEN
395 bal
= get-balance
( et
, prev-co
, prev-acc
, m2
).
396 RUN create-tb-record
( et
, prev-co
, prev-acc
, bal
, bud
, m-bal
, m-bud
, "", "" ).
398 ASSIGN bal
= 0 bud
= 0 m-bal
= 0 m-bud
= 0
399 prev-co
= AccountBalance.EntityCode prev-acc
= AccountBalance.AccountCode.
401 IF AccountBalance.Balance
<> ?
THEN bal
= bal
+ AccountBalance.Balance.
402 IF AccountBalance.Budget
<> ?
THEN bud
= bud
+ AccountBalance.Budget.
403 IF AccountBalance.MonthCode
= m2
THEN DO:
404 IF AccountBalance.Balance
<> ?
THEN m-bal
= AccountBalance.Balance.
405 IF AccountBalance.Budget
<> ?
THEN m-bud
= AccountBalance.Budget.
409 IF prev-co
<> -1 THEN DO:
410 IF NOT(month-range
) THEN
411 bal
= get-balance
( et
, prev-co
, prev-acc
, m2
).
412 RUN create-tb-record
( et
, prev-co
, prev-acc
, bal
, bud
, m-bal
, m-bud
, "", "" ).
415 IF month-range
THEN RETURN.
417 /* for those accounts with no balance in the period
, but which do have a balance
*/
418 FOR EACH AccountSummary
NO-LOCK WHERE AccountSummary.EntityType
= et
419 AND AccountSummary.EntityCode
>= e1
AND AccountSummary.EntityCode
<= e2
420 AND NOT CAN-FIND( FIRST AccountBalance
OF AccountSummary
421 WHERE AccountBalance.MonthCode
>= m1
422 AND AccountBalance.MonthCode
<= m2
):
423 IF interco-outside-group
( AccountSummary.AccountCode
) THEN NEXT.
424 bal
= get-balance
( et
, AccountSummary.EntityCode
, AccountSummary.AccountCode
, m2
).
426 RUN create-tb-record
( et
, AccountSummary.EntityCode
, AccountSummary.AccountCode
, bal
, 0.0, 0.0, 0.0, "", "" ).
429 /* for those accounts with no balance now
, but which did have a balance at the end of the period
*/
432 DEF BUFFER OtherBalance
FOR AccountBalance.
433 FOR EACH AccountBalance
NO-LOCK WHERE AccountBalance.EntityType
= et
434 AND AccountBalance.EntityCode
>= e1
AND AccountBalance.EntityCode
<= e2
435 AND NOT CAN-FIND( FIRST OtherBalance
WHERE OtherBalance.EntityType
= et
436 AND OtherBalance.EntityCode
= AccountBalance.EntityCode
437 AND OtherBalance.AccountCode
= AccountBalance.AccountCode
438 AND OtherBalance.MonthCode
>= m1
439 AND OtherBalance.MonthCode
<= m2
)
440 AND NOT CAN-FIND( AccountSummary
OF AccountBalance
):
441 IF interco-outside-group
( AccountBalance.AccountCode
) THEN NEXT.
442 IF AccountBalance.EntityCode
<> prev-co
OR AccountBalance.AccountCode
<> prev-acc
THEN DO:
443 IF prev-co
<> -1 THEN DO:
444 bal
= get-balance
( et
, prev-co
, prev-acc
, m2
).
446 RUN create-tb-record
( et
, prev-co
, prev-acc
, bal
, 0, 0, 0, "", "" ).
448 ASSIGN prev-co
= AccountBalance.EntityCode
449 prev-acc
= AccountBalance.AccountCode.
453 IF prev-co
<> -1 THEN DO:
454 bal
= get-balance
( et
, prev-co
, prev-acc
, m2
).
456 RUN create-tb-record
( et
, prev-co
, prev-acc
, bal
, bud
, m-bal
, m-bud
, "", "" ).
461 /* _UIB-CODE-BLOCK-END
*/
466 &IF DEFINED(EXCLUDE-consolidated-to-csv) = 0 &THEN
468 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE consolidated-to-csv Procedure
469 PROCEDURE consolidated-to-csv
:
470 /*------------------------------------------------------------------------------
471 Purpose
: Consolidated report to a CSV file.
472 ------------------------------------------------------------------------------*/
473 DEF VAR last-sequence
AS INT INITIAL -1 NO-UNDO.
474 DEF VAR total
LIKE tb.Balance
NO-UNDO.
476 OUTPUT TO VALUE(csv-file-name
) KEEP-MESSAGES PAGE-SIZE 0.
478 FOR EACH Company
NO-LOCK WHERE CAN-FIND( FIRST tb
WHERE tb.EntityType
= entity-type
479 AND tb.EntityCode
= Company.CompanyCode
)
480 BY Company.CompanyCode
:
481 PUT UNFORMATTED '
,'
+ STRING(Company.CompanyCode
).
484 PUT UNFORMATTED '
,"Description"'.
485 FOR EACH Company
NO-LOCK WHERE CAN-FIND( FIRST tb
486 WHERE tb.EntityType
= entity-type
487 AND tb.EntityCode
= Company.CompanyCode
)
488 BY Company.CompanyCode
:
489 PUT UNFORMATTED '
,"' + Company.ShortName + '"'.
493 FOR EACH AccountGroup
NO-LOCK WHERE CAN-FIND( FIRST tb
494 WHERE tb.SequenceCode
= AccountGroup.SequenceCode
)
495 BY AccountGroup.SequenceCode
:
496 PUT UNFORMATTED '
"' + AccountGroup.AccountGroupCode
497 + '","' + AccountGroup.Name + '"'.
498 FOR EACH Company
NO-LOCK WHERE CAN-FIND( FIRST tb
499 WHERE tb.EntityType
= entity-type
500 AND tb.EntityCode
= Company.CompanyCode
)
501 BY Company.CompanyCode
:
504 FOR EACH tb
WHERE tb.EntityType
= entity-type
505 AND tb.EntityCode
= Company.CompanyCode
506 AND tb.SequenceCode
= AccountGroup.SequenceCode
508 total
= total
+ tb.Balance.
512 PUT UNFORMATTED total.
519 /* _UIB-CODE-BLOCK-END
*/
524 &IF DEFINED(EXCLUDE-create-tb-record) = 0 &THEN
526 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE create-tb-record Procedure
527 PROCEDURE create-tb-record
:
528 /*------------------------------------------------------------------------------
529 Purpose
: Create a trial balance record
530 ------------------------------------------------------------------------------*/
531 DEF INPUT PARAMETER entity-type
AS CHAR NO-UNDO.
532 DEF INPUT PARAMETER entity-code
AS INTEGER NO-UNDO.
533 DEF INPUT PARAMETER account-code
AS DECIMAL NO-UNDO.
534 DEF INPUT PARAMETER bal
AS DECIMAL NO-UNDO.
535 DEF INPUT PARAMETER bud
AS DECIMAL NO-UNDO.
536 DEF INPUT PARAMETER mtd-bal
AS DECIMAL NO-UNDO.
537 DEF INPUT PARAMETER mtd-bud
AS DECIMAL NO-UNDO.
538 DEF INPUT PARAMETER c1
AS CHAR NO-UNDO.
539 DEF INPUT PARAMETER c2
AS CHAR NO-UNDO.
541 /* all variables are defined globally so their values are held
*/
544 &SCOP BAD-NAME "Unknown"
546 IF account-code
<> last-account-code
THEN DO:
547 FIND ChartOfAccount
WHERE ChartOfAccount.AccountCode
= account-code
NO-LOCK NO-ERROR.
548 IF AVAILABLE(ChartOfAccount
) THEN DO:
549 ASSIGN account-name
= ChartOfAccount.Name
550 last-account-group
= ChartOfAccount.AccountGroupCode .
551 FIND AccountGroup
OF ChartOfAccount
NO-LOCK NO-ERROR.
552 IF AVAILABLE(AccountGroup
) THEN DO:
553 IF AccountGroup.GroupType
= "P" AND NOT(include-pl
) THEN RETURN.
554 IF AccountGroup.GroupType
= "B" AND NOT(include-bs
) THEN RETURN.
555 account-seq
= AccountGroup.SequenceCode.
556 acgroup-name
= AccountGroup.Name.
559 ASSIGN account-seq
= {&BAD-SEQ} acgroup-name = {&BAD-NAME}.
562 ASSIGN account-name
= {&BAD-NAME} + " - " + STRING(account-code, "9999.99")
563 account-seq
= {&BAD-SEQ}
564 acgroup-name
= {&BAD-NAME}.
565 last-account-code
= account-code.
568 IF exclude-year-end
THEN DO:
569 FIND LAST AcctTran
WHERE AcctTran.EntityType
= entity-type
570 AND AcctTran.EntityCode
= entity-code
571 AND AcctTran.AccountCode
= account-code
572 AND AcctTran.MonthCode
= month-2
573 AND (AcctTran.Description
BEGINS "Y/E Transfer to Ret"
574 OR AcctTran.Description
BEGINS "Y/E Accumulated P&L"
575 OR CAN-FIND( FIRST Document
OF AcctTran
WHERE Document.Description
BEGINS "Y/E Transfer to Ret")
576 OR CAN-FIND( FIRST Document
OF AcctTran
WHERE Document.Description
BEGINS "Y/E Accumulated P&L"))
578 IF AVAILABLE(AcctTran
) THEN DO:
579 ASSIGN bal
= bal
- AcctTran.Amount
580 mtd-bal
= mtd-bal
- AcctTran.Amount .
584 IF c1
= ?
THEN c1
= "".
585 IF c2
= ?
THEN c2
= "".
586 IF consolidate-together
THEN DO:
588 FIND tb
WHERE tb.EntityType
= entity-type
589 AND tb.EntityCode
= entity-code
590 AND tb.SequenceCode
= account-seq
591 AND tb.AccountCode
= account-code
NO-ERROR.
592 IF AVAILABLE(tb
) THEN DO:
593 IF tb.Balance
<> ?
THEN bal
= tb.Balance
+ bal.
594 IF tb.Budget
<> ?
THEN bud
= tb.Budget
+ bud.
595 IF tb.mtd-Balance
<> ?
THEN mtd-bal
= tb.mtd-Balance
+ mtd-bal.
596 IF tb.mtd-Budget
<> ?
THEN mtd-bud
= tb.mtd-Budget
+ mtd-bud.
604 ASSIGN tb.EntityType
= entity-type
605 tb.EntityCode
= entity-code
606 tb.AccountCode
= account-code
607 tb.AccountName
= account-name
608 tb.SequenceCode
= account-seq
609 tb.SequenceName
= acgroup-name
612 tb.mtd-Balance
= mtd-bal
613 tb.mtd-Budget
= mtd-bud
614 tb.Comment
= TRIM(c1
)
615 + (IF TRIM(c1
) <> "" AND TRIM(c2
) <> "" THEN "~n" ELSE "")
617 tb.GroupType
= AccountGroup.GroupType
622 /* _UIB-CODE-BLOCK-END
*/
627 &IF DEFINED(EXCLUDE-debug-temp-table) = 0 &THEN
629 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE debug-temp-table Procedure
630 PROCEDURE debug-temp-table
:
631 /*------------------------------------------------------------------------------
632 Purpose
: Dump the first
20 records in the temp table.
633 ------------------------------------------------------------------------------*/
634 DEF VAR i
AS INT NO-UNDO INITIAL 0.
635 DEF VAR line
AS CHAR NO-UNDO.
638 line
= EntityType
+ " "
639 + STRING(EntityCode
) + " "
640 + STRING(SequenceCode
) + " "
641 + STRING(AccountCode
) + " "
642 + STRING(SequenceName
) + " "
643 + STRING(AccountName
) + " "
644 + STRING(Balance
) + " "
645 + STRING(Budget
) + " "
646 + STRING(mtd-Balance
) + " "
647 + STRING(mtd-Budget
) + " "
651 IF i
> 50 THEN LEAVE.
656 /* _UIB-CODE-BLOCK-END
*/
661 &IF DEFINED(EXCLUDE-exhaustive-to-csv) = 0 &THEN
663 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE exhaustive-to-csv Procedure
664 PROCEDURE exhaustive-to-csv
:
665 /*------------------------------------------------------------------------------
666 Purpose
: Exhaustive report to a CSV file.
667 ------------------------------------------------------------------------------*/
668 DEF VAR last-sequence
AS INT INITIAL -1 NO-UNDO.
669 DEF VAR total
LIKE tb.Balance
NO-UNDO.
671 OUTPUT TO VALUE(csv-file-name
) KEEP-MESSAGES PAGE-SIZE 0.
672 PUT UNFORMATTED '
"Account","Description"' .
673 FOR EACH Company
NO-LOCK WHERE CAN-FIND( FIRST tb
674 WHERE tb.EntityType
= entity-type
675 AND tb.EntityCode
= Company.CompanyCode
)
676 BY Company.CompanyCode
:
677 PUT UNFORMATTED '
,"' + Company.ShortName + '"'.
681 FOR EACH AccountGroup
NO-LOCK, EACH ChartOfAccount
OF AccountGroup
NO-LOCK
682 WHERE (pedantic-listing
AND ChartOfAccount.UpdateTo
<> "")
683 OR CAN-FIND( FIRST tb
WHERE tb.AccountCode
= ChartOfAccount.AccountCode
)
684 BY AccountGroup.SequenceCode
BY ChartOfAccount.AccountCode
:
685 PUT UNFORMATTED STRING( ChartOfAccount.AccountCode
, "9999.99") + '
,"' + ChartOfAccount.Name + '"'.
686 FOR EACH Company
NO-LOCK WHERE CAN-FIND( FIRST tb
687 WHERE tb.EntityType
= entity-type
688 AND tb.EntityCode
= Company.CompanyCode
)
689 BY Company.CompanyCode
:
692 FIND FIRST tb
WHERE tb.EntityType
= entity-type
693 AND tb.EntityCode
= Company.CompanyCode
694 AND tb.AccountCode
= ChartOfAccount.AccountCode
696 IF AVAILABLE(tb
) THEN total
= tb.Balance.
699 PUT UNFORMATTED total.
706 /* _UIB-CODE-BLOCK-END
*/
711 &IF DEFINED(EXCLUDE-normal-pedantic-each-co) = 0 &THEN
713 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE normal-pedantic-each-co Procedure
714 PROCEDURE normal-pedantic-each-co
:
715 /*------------------------------------------------------------------------------
717 ------------------------------------------------------------------------------*/
718 DEF INPUT PARAMETER detail
AS LOGI
NO-UNDO.
719 DEF INPUT PARAMETER company-code
AS INT NO-UNDO.
721 DEF VAR last-sequence
AS INT INITIAL -1 NO-UNDO.
722 DEF VAR sequence-name
AS CHAR NO-UNDO.
723 DEF VAR new-company
AS LOGI
NO-UNDO INITIAL Yes.
724 DEF VAR company-desc
AS CHAR NO-UNDO.
726 FOR EACH AccountGroup
NO-LOCK, EACH ChartOfAccount
OF AccountGroup
NO-LOCK
727 WHERE (pedantic-listing
AND ChartOfAccount.UpdateTo
<> "")
728 OR CAN-FIND( tb
WHERE tb.EntityType
= entity-type
729 AND tb.EntityCode
= company-code
730 AND tb.AccountCode
= ChartOfAccount.AccountCode
)
731 BY AccountGroup.SequenceCode
BY ChartOfAccount.AccountCode
:
733 IF new-company
OR AccountGroup.SequenceCode
<> last-sequence
THEN DO:
734 IF NOT detail
AND last-sequence
>= 0 THEN DO:
735 PUT UNFORMATTED '
"","","'
745 PUT UNFORMATTED SKIP.
747 ASSIGN last-sequence
= AccountGroup.SequenceCode
748 sequence-name
= AccountGroup.Name
749 ag-balance
= 0 ag-budget
= 0
750 ag-mtdbal
= 0 ag-mtdbud
= 0.
752 IF new-company
THEN DO:
753 company-desc
= get-company-desc
(company-code
).
754 PUT UNFORMATTED '
"' company-code '","' company-desc '"'
SKIP.
759 FIND tb
WHERE tb.EntityType
= entity-type
760 AND tb.EntityCode
= company-code
761 AND tb.AccountCode
= ChartOfAccount.AccountCode
NO-LOCK NO-ERROR.
764 IF new-company
THEN DO:
765 PUT UNFORMATTED '
"' company-code '"'.
766 company-desc
= get-company-desc
(company-code
).
767 PUT UNFORMATTED '
,"' company-desc '"'
SKIP.
770 PUT UNFORMATTED '
"","","' ChartOfAccount.AccountCode '","' ChartOfAccount.Name '","'.
771 IF AVAILABLE(tb) THEN DO:
781 PUT UNFORMATTED '
0","0","0","0",""' SKIP.
783 ELSE IF AVAILABLE(tb) THEN DO:
784 ag-balance = ag-balance + tb.Balance.
785 ag-budget = ag-budget + tb.Budget.
786 ag-mtdbal = ag-mtdbal + tb.mtd-Balance.
787 ag-mtdbud = ag-mtdbud + tb.mtd-Budget .
793 IF NOT detail AND last-sequence >= 0 THEN DO:
794 PUT UNFORMATTED '"","","'
806 /* _UIB-CODE-BLOCK-END */
811 &IF DEFINED(EXCLUDE-normal-pedantic-to-csv) = 0 &THEN
813 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE normal-pedantic-to-csv Procedure
814 PROCEDURE normal-pedantic-to-csv :
815 /*------------------------------------------------------------------------------
816 Purpose: Generate TB output to a CSV file
817 ------------------------------------------------------------------------------*/
818 DEF INPUT PARAMETER detail AS LOGI NO-UNDO.
821 OUTPUT TO VALUE(csv-file-name) KEEP-MESSAGES PAGE-SIZE 0.
822 PUT UNFORMATTED '"Company Code
","Company Name
","AccountCode
","AccountName
",'
823 '"Balance
","Budget
","mtd-Balance
","mtd-Budget
","Comment
"' SKIP.
825 IF consolidate-together THEN DO:
826 RUN normal-pedantic-each-co( detail, 0 ).
829 FOR EACH Company NO-LOCK WHERE CAN-FIND( FIRST tb WHERE tb.EntityType = entity-type
830 AND tb.EntityCode = Company.CompanyCode ) BY Company.CompanyCode:
831 RUN normal-pedantic-each-co( detail, Company.CompanyCode ).
839 MESSAGE 'File "'
+ csv-file-name
+ '
" generated successfully.'
840 VIEW-AS ALERT-BOX INFORMATION TITLE "Trial Balance by Group
".
843 /* _UIB-CODE-BLOCK-END */
848 &IF DEFINED(EXCLUDE-normal-to-csv-file) = 0 &THEN
850 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE normal-to-csv-file Procedure
851 PROCEDURE normal-to-csv-file :
852 /*------------------------------------------------------------------------------
853 Purpose: Generate TB output to a CSV file
854 ------------------------------------------------------------------------------*/
855 DEF INPUT PARAMETER detail AS LOGI NO-UNDO.
857 IF pedantic-listing THEN DO:
858 RUN normal-pedantic-to-csv( detail ).
862 DEF VAR last-sequence AS INT INITIAL -1 NO-UNDO.
863 DEF VAR sequence-name AS CHAR NO-UNDO.
864 DEF VAR last-company AS INT INITIAL -1 NO-UNDO.
865 DEF VAR company-desc AS CHAR NO-UNDO.
867 OUTPUT TO VALUE(csv-file-name) KEEP-MESSAGES PAGE-SIZE 0.
868 PUT UNFORMATTED '"Company Code
","Company Name
","AccountCode
","AccountName
",'
869 '"Balance
","Budget
","mtd-Balance
","mtd-Budget
","Comment
"' SKIP.
872 BY EntityType BY EntityCode BY SequenceCode BY AccountCode:
873 IF EntityCode <> last-company OR SequenceCode <> last-sequence THEN DO:
874 IF NOT detail AND last-sequence >= 0 THEN DO:
875 PUT UNFORMATTED '"","","'
885 PUT UNFORMATTED SKIP.
887 ASSIGN last-sequence = tb.SequenceCode
888 sequence-name = tb.SequenceName
889 ag-balance = 0 ag-budget = 0
890 ag-mtdbal = 0 ag-mtdbud = 0.
892 IF EntityCode <> last-company THEN DO:
893 company-desc = get-company-desc(EntityCode).
894 PUT UNFORMATTED '"' EntityCode '
","' company-desc '
"' SKIP.
895 last-company = EntityCode.
899 IF EntityCode <> last-company THEN DO:
900 company-desc = get-company-desc(EntityCode).
901 PUT UNFORMATTED '"' EntityCode '
","' company-desc '
"' SKIP.
902 last-company = EntityCode.
904 PUT UNFORMATTED '"","","'
915 ag-balance = ag-balance + tb.Balance
916 ag-budget = ag-budget + tb.Budget
917 ag-mtdbal = ag-mtdbal + tb.mtd-Balance
918 ag-mtdbud = ag-mtdbud + tb.mtd-Budget .
921 IF NOT detail AND last-sequence >= 0 THEN DO:
922 PUT UNFORMATTED '"","","'
934 MESSAGE 'File "'
+ csv-file-name
+ '
" generated successfully.'
935 VIEW-AS ALERT-BOX INFORMATION TITLE "Trial Balance by Group
".
938 /* _UIB-CODE-BLOCK-END */
943 &IF DEFINED(EXCLUDE-normal-to-printer) = 0 &THEN
945 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE normal-to-printer Procedure
946 PROCEDURE normal-to-printer :
947 /*------------------------------------------------------------------------------
948 Purpose: Generate TB output to a print file
949 ------------------------------------------------------------------------------*/
950 DEF INPUT PARAMETER detail-report AS LOGICAL NO-UNDO.
951 DEF INPUT PARAMETER preview AS LOGICAL NO-UNDO.
953 DEF VAR last-sequence AS INT INITIAL -1 NO-UNDO.
954 DEF VAR sequence-name AS CHAR NO-UNDO.
955 DEF VAR last-company AS INT INITIAL -1 NO-UNDO.
956 DEF VAR last-grouptype AS CHAR NO-UNDO.
958 DEF VAR bs-start-sequence LIKE AccountGroup.SequenceCode NO-UNDO.
959 FIND AccountGroup WHERE AccountGroup.AccountGroupCode = "SHCAP
" NO-LOCK NO-ERROR.
960 IF NOT AVAILABLE(AccountGroup) THEN
961 FIND FIRST AccountGroup WHERE AccountGroup.GroupType = "B
" NO-LOCK NO-ERROR.
962 IF NOT AVAILABLE(AccountGroup) THEN DO:
963 MESSAGE "Cannot locate first accountgroup with type
" SKIP
964 "'B' as start of balance sheet accounts.
"
965 VIEW-AS ALERT-BOX ERROR TITLE "Account Groups not set up
!".
968 bs-start-sequence = AccountGroup.SequenceCode.
970 RUN output-control-file ( prt-ctrl ).
971 OUTPUT TO VALUE(txtrep-print-file) KEEP-MESSAGES PAGE-SIZE VALUE(rows).
973 FOR EACH tb BY EntityType
977 IF EntityCode <> last-company OR tb.SequenceCode <> last-sequence THEN DO:
978 IF last-sequence >= 0 THEN DO:
979 RUN print-a-line( detail-report, "", sequence-name, ag-balance, ag-budget, ag-mtdbal, ag-mtdbud, "" ).
982 /* If using Account Group Type then accumulate for Profit and Loss by 'P' types else use sequence */
983 IF (tb-type <> 'AcctGpType' AND last-sequence < bs-start-sequence) OR
984 (tb-type = 'AcctGpType' AND last-grouptype = 'P')
987 pl-balance = pl-balance + ag-balance
988 pl-budget = pl-budget + ag-budget
989 pl-mtdbal = pl-mtdbal + ag-mtdbal
990 pl-mtdbud = pl-mtdbud + ag-mtdbud
993 ASSIGN last-sequence = tb.SequenceCode
994 last-grouptype = tb.GroupType
995 sequence-name = tb.SequenceName
996 et-balance = et-balance + ag-balance
997 et-budget = et-budget + ag-budget
998 et-mtdbal = et-mtdbal + ag-mtdbal
999 et-mtdbud = et-mtdbud + ag-mtdbud
1000 ag-balance = 0 ag-budget = 0
1001 ag-mtdbal = 0 ag-mtdbud = 0.
1002 END. /* IF new sequence */
1004 IF EntityCode <> last-company THEN DO:
1005 IF last-company > 0 THEN DO:
1006 RUN print-a-line( Yes, "", get-company-desc(last-company), et-balance, et-budget, et-mtdbal, et-mtdbud, "" ).
1007 IF detail-report THEN PUT SKIP (1).
1008 RUN print-a-line( detail-report, "", " Profit or Loss
", - pl-balance, - pl-budget, - pl-mtdbal, - pl-mtdbud, "" ).
1010 hline2 = rtypeString + " Trial Balance by Group
" + include-qualifier
1012 + get-company-desc(EntityCode) + " - "
1013 + Month.MonthName + ", " + STRING( YEAR(Month.StartDate), "9999").
1014 hline2 = FILL(" ", INTEGER(({&page-width} - LENGTH(hline2)) / 2)) + hline2.
1015 IF last-company > 0 THEN
1018 VIEW FRAME heading-frame.
1020 IF NOT detail-report THEN VIEW FRAME account-line.
1021 ASSIGN last-company = EntityCode
1022 et-balance = 0 et-budget = 0
1023 et-mtdbal = 0 et-mtdbud = 0
1024 pl-balance = 0 pl-budget = 0
1025 pl-mtdbal = 0 pl-mtdbud = 0.
1026 END. /* if new company */
1029 ag-balance = ag-balance + tb.Balance
1030 ag-budget = ag-budget + tb.Budget
1031 ag-mtdbal = ag-mtdbal + tb.mtd-Balance
1032 ag-mtdbud = ag-mtdbud + tb.mtd-Budget
1034 IF detail-report AND
1035 ( tb.Balance <> 0 OR tb.Budget <> 0
1036 OR tb.mtd-Balance <> 0 OR tb.mtd-Budget <> 0 )
1038 RUN print-a-line( No, STRING( tb.AccountCode, "9999.99"), tb.AccountName,
1039 tb.Balance, tb.Budget, tb.mtd-Balance, tb.mtd-Budget, tb.Comment).
1040 END. /* detail-report */
1041 END. /* each trial balance */
1043 IF last-company > 0 OR consolidate-together THEN DO:
1044 RUN print-a-line ( detail-report, "", sequence-name, ag-balance, ag-budget, ag-mtdbal, ag-mtdbud, "" ).
1045 ASSIGN et-balance = et-balance + ag-balance
1046 et-budget = et-budget + ag-budget
1047 et-mtdbal = et-mtdbal + ag-mtdbal
1048 et-mtdbud = et-mtdbud + ag-mtdbud.
1050 /* If using Account Group Type then accumulate for Profit and Loss by 'P' types else use sequence */
1051 /* IF last-sequence < bs-start-sequence THEN DO: */
1052 IF (tb-type <> 'AcctGpType' AND last-sequence < bs-start-sequence) OR
1053 (tb-type = 'AcctGpType' AND last-grouptype = 'P')
1056 pl-balance = pl-balance + ag-balance
1057 pl-budget = pl-budget + ag-budget
1058 pl-mtdbal = pl-mtdbal + ag-mtdbal
1059 pl-mtdbud = pl-mtdbud + ag-mtdbud
1063 RUN print-a-line ( Yes, "", get-company-desc(last-company), et-balance, et-budget, et-mtdbal, et-mtdbud, "" ).
1064 IF detail-report THEN PUT SKIP (1).
1065 IF include-bs AND include-pl THEN DO:
1066 RUN print-a-line ( detail-report, "", " Profit or Loss
", pl-balance, pl-budget, pl-mtdbal, pl-mtdbud, "" ).
1071 debug-event("Finished
").
1072 RUN view-output-file( preview ).
1076 /* _UIB-CODE-BLOCK-END */
1081 &IF DEFINED(EXCLUDE-parse-parameters) = 0 &THEN
1083 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE parse-parameters Procedure
1084 PROCEDURE parse-parameters :
1085 /*------------------------------------------------------------------------------
1086 Purpose: Decode the command-line parameters
1087 ------------------------------------------------------------------------------*/
1088 DEF VAR i AS INT NO-UNDO.
1089 DEF VAR token AS CHAR NO-UNDO.
1090 DEF VAR j AS INT NO-UNDO.
1092 {inc/showopts.i "report-options
"}
1094 DO i = 1 TO NUM-ENTRIES( report-options, "~n
" ):
1095 token = ENTRY( i, report-options, "~n
" ).
1096 CASE( ENTRY( 1, token ) ):
1097 WHEN "Debug
" THEN debug-mode = Yes.
1098 WHEN "ExcludeYearEnd
" THEN exclude-year-end = Yes.
1099 WHEN "Consolidated
" THEN consolidate-together = Yes.
1100 WHEN "Pedantic
" THEN pedantic-listing = Yes.
1101 WHEN "ColumnStyle
" THEN column-style = ENTRY(2,token).
1102 WHEN "ReportType
" THEN r-type = ENTRY(2,token).
1103 WHEN "SelectionType
" THEN range = ENTRY(2,token).
1104 WHEN "OutputType
" THEN out-to = ENTRY(2,token).
1105 WHEN "CompanyList
" THEN list-name = ENTRY(2,token).
1106 WHEN "EndMonth
" THEN month-2 = INT( ENTRY(2,token) ).
1107 WHEN "IncludeParts
" THEN DO:
1108 CASE( ENTRY(2,token) ):
1109 WHEN "P
" THEN include-bs = NO.
1110 WHEN "B
" THEN include-pl = NO.
1113 WHEN "FileName
" THEN DO:
1114 j = LENGTH( ENTRY(1,token) ).
1115 csv-file-name = TRIM( SUBSTRING(token, j + 2) ).
1117 WHEN "StartMonth
" THEN ASSIGN
1119 month-1 = INT( ENTRY(2,token) ).
1120 WHEN "EntityRange
" THEN ASSIGN
1121 entity-1 = INT(ENTRY(2,token))
1122 entity-2 = INT(ENTRY(3,token)) .
1126 IF NOT( month-range ) THEN DO:
1127 FIND Month WHERE Month.MonthCode = month-2 NO-LOCK.
1128 month-1 = Month.FinancialYearCode.
1129 FIND FIRST Month WHERE month-1 = Month.FinancialYearCode NO-LOCK.
1130 month-1 = Month.MonthCode.
1135 /* _UIB-CODE-BLOCK-END */
1140 &IF DEFINED(EXCLUDE-print-a-line) = 0 &THEN
1142 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE print-a-line Procedure
1143 PROCEDURE print-a-line :
1144 /*------------------------------------------------------------------------------
1145 Purpose: Display a line with preceding dashes if required.
1146 ------------------------------------------------------------------------------*/
1147 DEF INPUT PARAMETER display-minuses AS LOGICAL NO-UNDO.
1148 DEF INPUT PARAMETER account AS CHAR NO-UNDO.
1149 DEF INPUT PARAMETER name AS CHAR NO-UNDO.
1150 DEF INPUT PARAMETER bal AS DECIMAL NO-UNDO.
1151 DEF INPUT PARAMETER bud AS DECIMAL NO-UNDO.
1152 DEF INPUT PARAMETER mbl AS DECIMAL NO-UNDO.
1153 DEF INPUT PARAMETER mbd AS DECIMAL NO-UNDO.
1154 DEF INPUT PARAMETER comment AS CHAR NO-UNDO.
1156 DEF VAR line AS CHAR NO-UNDO.
1157 DEF VAR pre-comment AS CHAR NO-UNDO INITIAL " ".
1159 IF display-minuses THEN DO:
1160 PUT UNFORMATTED minus-line + pre-comment + ENTRY( 1, remaining-comments, "~n
") SKIP.
1161 IF INDEX( remaining-comments, "~n
") > 0 THEN
1162 remaining-comments = SUBSTRING( remaining-comments, INDEX( remaining-comments, "~n
") + 1).
1164 remaining-comments = "".
1167 IF TRIM(comment) <> "" AND comment <> ? THEN DO:
1168 DO WHILE TRIM(remaining-comments) <> "":
1169 line = FILL( " ", col-width) + pre-comment + ENTRY( 1, remaining-comments, "~n
").
1170 PUT UNFORMATTED line SKIP.
1171 IF INDEX( remaining-comments, "~n
") > 0 THEN
1172 remaining-comments = SUBSTRING( remaining-comments, INDEX( remaining-comments, "~n
") + 1).
1174 remaining-comments = "".
1176 remaining-comments = WRAP( comment, 205 - col-width).
1180 IF column-style = "Std
" THEN
1181 line = STRING( account, "X(8)") + STRING( name, "X(51)")
1182 + STRING( bal, money-format ) + " " + STRING( bud, money-format ) + " "
1183 + STRING( bal - bud, money-format ) + " "
1184 + STRING( mbl, money-format ) + " " + STRING( mbd, money-format ) + " "
1185 + STRING( mbl - mbd, money-format )
1186 + pre-comment + ENTRY( 1, remaining-comments, "~n
").
1188 line = STRING( account, "X(8)") + STRING( name, "X(51)")
1189 + STRING( bal, money-format ) + " "
1190 + STRING( bal - mbl, money-format ) + " "
1191 + STRING( mbl, money-format ) + " " + STRING( mbd, money-format ) + " "
1192 + STRING( mbl - mbd, money-format )
1193 + pre-comment + ENTRY( 1, remaining-comments, "~n
").
1194 PUT UNFORMATTED line SKIP.
1195 IF line = ? THEN DO:
1196 PUT STRING( account, "X(8)") STRING( name, "X(51)") FORMAT "X(51)"
1197 STRING( bal, money-format ) " " STRING( bud, money-format ) " "
1198 STRING( bal - bud, money-format ) " "
1199 STRING( mbl, money-format ) " " STRING( mbd, money-format ) " "
1200 STRING( mbl - mbd, money-format )
1201 pre-comment ENTRY( 1, remaining-comments, "~n
")
1202 "actual figures
: " bal bud mbl mbd.
1205 IF INDEX( remaining-comments, "~n
") > 0 THEN
1206 remaining-comments = SUBSTRING( remaining-comments, INDEX( remaining-comments, "~n
") + 1).
1208 remaining-comments = "".
1210 IF display-minuses THEN DO:
1212 PUT UNFORMATTED FILL( " ", col-width) + pre-comment + ENTRY( 1, remaining-comments, "~n
") SKIP.
1213 IF INDEX( remaining-comments, "~n
") > 0 THEN
1214 remaining-comments = SUBSTRING( remaining-comments, INDEX( remaining-comments, "~n
") + 1).
1216 remaining-comments = "".
1221 /* _UIB-CODE-BLOCK-END */
1226 /* ************************ Function Implementations ***************** */
1228 &IF DEFINED(EXCLUDE-balance-from-balances) = 0 &THEN
1230 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION balance-from-balances Procedure
1231 FUNCTION balance-from-balances RETURNS DECIMAL
1232 ( INPUT et AS CHAR, INPUT ec AS INT, INPUT ac AS DEC, INPUT m-1 AS INT, INPUT m-n AS INT ) :
1233 /*------------------------------------------------------------------------------
1234 Purpose: Calculate balance at a particular date by adding a range of months
1235 Notes: Applies to I&E (P&L) accounts
1236 ------------------------------------------------------------------------------*/
1237 DEF VAR bal AS DEC NO-UNDO INITIAL 0.00 .
1239 DEF BUFFER MyBalance FOR AccountBalance.
1240 FOR EACH MyBalance WHERE MyBalance.EntityType = et
1241 AND MyBalance.EntityCode = ec
1242 AND MyBalance.AccountCode = ac
1243 AND MyBalance.MonthCode >= m-1
1244 AND MyBalance.MonthCode <= m-n NO-LOCK:
1245 bal = bal + MyBalance.Balance.
1252 /* _UIB-CODE-BLOCK-END */
1257 &IF DEFINED(EXCLUDE-balance-from-summary) = 0 &THEN
1259 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION balance-from-summary Procedure
1260 FUNCTION balance-from-summary RETURNS DECIMAL
1261 ( INPUT et AS CHAR, INPUT ec AS INT, INPUT ac AS DEC, INPUT mnth AS INT ) :
1262 /*------------------------------------------------------------------------------
1263 Purpose: Calculate balance at a particular date by subtracting backwards
1264 Notes: Applies to balance sheet accounts
1265 ------------------------------------------------------------------------------*/
1266 DEF VAR bal AS DEC NO-UNDO INITIAL 0.00 .
1268 DEF BUFFER MySummary FOR AccountSummary.
1269 FIND MySummary WHERE MySummary.EntityType = et
1270 AND MySummary.EntityCode = ec
1271 AND MySummary.AccountCode = ac NO-LOCK NO-ERROR.
1272 IF AVAILABLE(MySummary) THEN bal = MySummary.Balance.
1274 DEF BUFFER MyBalance FOR AccountBalance.
1275 FOR EACH MyBalance WHERE MyBalance.EntityType = et
1276 AND MyBalance.EntityCode = ec
1277 AND MyBalance.AccountCode = ac
1278 AND MyBalance.MonthCode > mnth NO-LOCK:
1279 bal = bal - MyBalance.Balance.
1286 /* _UIB-CODE-BLOCK-END */
1291 &IF DEFINED(EXCLUDE-debug-event) = 0 &THEN
1293 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION debug-event Procedure
1294 FUNCTION debug-event RETURNS CHARACTER
1295 ( INPUT event-text AS CHAR ) :
1296 /*------------------------------------------------------------------------------
1299 ------------------------------------------------------------------------------*/
1300 IF NOT debug-mode THEN RETURN event-text.
1302 DEF VAR time-text AS CHAR NO-UNDO.
1304 time-text = STRING( TODAY, "99/99/9999") + " " + STRING( TIME, "HH
:MM
:SS
") + ": ".
1305 PUT STREAM debug-stream UNFORMATTED time-text event-text SKIP.
1306 RETURN time-text + event-text.
1310 /* _UIB-CODE-BLOCK-END */
1315 &IF DEFINED(EXCLUDE-get-balance) = 0 &THEN
1317 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION get-balance Procedure
1318 FUNCTION get-balance RETURNS DECIMAL
1319 ( INPUT et AS CHAR, INPUT ec AS INT, INPUT ac AS DEC, INPUT month-n AS INT ) :
1320 /*------------------------------------------------------------------------------
1323 ------------------------------------------------------------------------------*/
1324 DEF BUFFER MyChart FOR ChartOfAccount.
1326 DEF VAR type AS CHAR INITIAL "B
" NO-UNDO.
1328 FIND MyChart WHERE MyChart.AccountCode = ac NO-LOCK NO-ERROR.
1329 IF AVAILABLE(MyChart) THEN FIND AccountGroup OF MyChart NO-LOCK NO-ERROR.
1330 IF AVAILABLE(AccountGroup) THEN type = AccountGroup.GroupType.
1333 RETURN balance-from-summary( et, ec, ac, month-n ).
1335 RETURN balance-from-balances( et, ec, ac, month-1, month-n ).
1339 /* _UIB-CODE-BLOCK-END */
1344 &IF DEFINED(EXCLUDE-get-company-desc) = 0 &THEN
1346 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION get-company-desc Procedure
1347 FUNCTION get-company-desc RETURNS CHARACTER
1348 ( INPUT ec AS INT ) :
1349 /*------------------------------------------------------------------------------
1352 ------------------------------------------------------------------------------*/
1353 DEF BUFFER AltCo FOR Company.
1355 IF consolidate-together THEN DO:
1356 RETURN "Consolidation of
" + (IF range = "L
" THEN list-name ELSE STRING(entity-1) + " to
" + STRING(entity-2)).
1358 FIND FIRST AltCo WHERE AltCo.CompanyCode = ec NO-LOCK.
1359 RETURN AltCo.LegalName + " ("+ STRING(AltCo.CompanyCode) + ")".
1363 /* _UIB-CODE-BLOCK-END */
1368 &IF DEFINED(EXCLUDE-interco-outside-group) = 0 &THEN
1370 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION interco-outside-group Procedure
1371 FUNCTION interco-outside-group RETURNS LOGICAL
1372 ( INPUT ac AS DEC ) :
1373 /*------------------------------------------------------------------------------
1376 ------------------------------------------------------------------------------*/
1377 RETURN No. /* disable this whole business */
1379 DEF VAR coy-no AS INT NO-UNDO.
1380 DEF BUFFER AltCo FOR Company.
1382 IF consol-accounts = "" THEN RETURN No.
1383 IF (TRUNC( ac / 1000, 0) * 1000) <> ic-base THEN RETURN No.
1385 coy-no = (TRUNC( ac / 1000, 0) * 1000) MOD 1000.
1386 IF NOT CAN-FIND(AltCo WHERE AltCo.CompanyCode = coy-no ) THEN RETURN No.
1388 IF LOOKUP( STRING(ac, "9999.99"), consol-accounts) > 0 THEN RETURN No.
1394 /* _UIB-CODE-BLOCK-END */