Added capital works blank section. Synced calling screen.
[capital-apms-progress.git] / process / report / tbgrpt.p
blobc48780c60136035db126043a5e5f8cdd92d32617
1 &ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12
2 &ANALYZE-RESUME
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
9 Created : 14/11/96
10 ------------------------------------------------------------------------*/
11 /* Parameter list */
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.
33 RUN parse-parameters.
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
75 FIELD Comment AS CHAR
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 */
91 &SCOP page-width 180
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".
106 ELSE
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)".
115 FORM HEADER
116 timeStamp "Page " + STRING( PAGE-NUMBER ) TO {&page-width} SKIP (1)
117 hline2 FORMAT "X({&page-width})"
118 hline3 FORMAT "X({&page-width})"
119 SKIP (1)
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.
133 ELSE
134 col-width = 63 + LENGTH(STRING(0,money-format)) * 5.
136 DEFINE STREAM debug-stream.
138 {inc/ofc-this.i}
139 {inc/ofc-acct.i "IC-BASE" "ic-base"}
140 {inc/ofc-set.i "TB-type" "tb-type"}
142 /* _UIB-CODE-BLOCK-END */
143 &ANALYZE-RESUME
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 */
156 &ANALYZE-RESUME
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 */
168 &ANALYZE-RESUME
170 &ENDIF
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 */
179 &ANALYZE-RESUME
181 &ENDIF
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 */
190 &ANALYZE-RESUME
192 &ENDIF
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 */
201 &ANALYZE-RESUME
203 &ENDIF
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 */
212 &ANALYZE-RESUME
214 &ENDIF
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 */
223 &ANALYZE-RESUME
225 &ENDIF
228 /* *********************** Procedure Settings ************************ */
230 &ANALYZE-SUSPEND _PROCEDURE-SETTINGS
231 /* Settings for THIS-PROCEDURE
232 Type: Procedure
233 Allow:
234 Frames: 0
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
245 HEIGHT = 1.05
246 WIDTH = 40.57.
247 /* END WINDOW DEFINITION */
249 &ANALYZE-RESUME
251 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _INCLUDED-LIB Procedure
252 /* ************************* Included-Libraries *********************** */
254 {inc/method/m-txtrep.i}
256 /* _UIB-CODE-BLOCK-END */
257 &ANALYZE-RESUME
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.
270 IF debug-mode THEN
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").
280 END.
281 FOR EACH EntityListMember OF EntityList NO-LOCK:
282 RUN build-temp-file-range( EntityList.ListType, EntityListMember.EntityCode, EntityListMember.EntityCode, month-1, month-2 ).
283 END.
284 entity-type = EntityList.ListType.
285 END.
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").
294 END.
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 ).
298 END.
299 entity-type = "L".
300 END.
301 ELSE DO:
302 RUN build-temp-file-range( "L", entity-1, entity-2, month-1, month-2 ).
303 entity-type = "L".
304 END.
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 ).
313 END.
314 ELSE IF out-to = "0" THEN
315 . /* Don't report */
316 ELSE DO:
317 RUN normal-to-printer( Yes, (out-to = "V") ).
318 RUN normal-to-printer( No, (out-to = "V") ).
319 END.
320 END.
321 ELSE IF r-type = "D" OR r-type = "S" THEN DO:
322 IF out-to = "S" THEN
323 RUN normal-to-csv-file( (r-type = "D") ).
324 ELSE IF out-to = "0" THEN
325 . /* Don't report */
326 ELSE
327 RUN normal-to-printer( (r-type = "D"), (out-to = "V") ).
328 END.
329 ELSE IF r-type = "E" THEN DO:
330 IF out-to = "S" THEN
331 RUN exhaustive-to-csv.
332 ELSE
333 MESSAGE "Consolidated Report only available to Spreadsheet".
334 /* to be continued ... */
335 END.
336 ELSE DO:
337 IF out-to = "S" THEN
338 RUN consolidated-to-csv.
339 ELSE
340 MESSAGE "Consolidated Report only available to Spreadsheet".
341 /* to be continued ... */
342 END.
344 debug-event("Finished").
346 IF debug-mode THEN
347 OUTPUT STREAM debug-stream CLOSE.
349 /* _UIB-CODE-BLOCK-END */
350 &ANALYZE-RESUME
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 /*------------------------------------------------------------------------------
360 Purpose:
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.
377 IF No THEN DO:
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, "", "" ).
382 END.
383 END.
384 END.
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, "", "" ).
397 END.
398 ASSIGN bal = 0 bud = 0 m-bal = 0 m-bud = 0
399 prev-co = AccountBalance.EntityCode prev-acc = AccountBalance.AccountCode.
400 END.
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.
406 END.
407 END.
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, "", "" ).
413 END.
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 ).
425 IF bal <> 0 THEN
426 RUN create-tb-record ( et, AccountSummary.EntityCode, AccountSummary.AccountCode, bal, 0.0, 0.0, 0.0, "", "" ).
427 END.
429 /* for those accounts with no balance now, but which did have a balance at the end of the period */
430 prev-co = -1.
431 prev-acc = -1.
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 ).
445 IF bal <> 0 THEN
446 RUN create-tb-record ( et, prev-co, prev-acc, bal, 0, 0, 0, "", "" ).
447 END.
448 ASSIGN prev-co = AccountBalance.EntityCode
449 prev-acc = AccountBalance.AccountCode.
450 END.
451 END.
453 IF prev-co <> -1 THEN DO:
454 bal = get-balance( et, prev-co, prev-acc, m2 ).
455 IF bal <> 0 THEN
456 RUN create-tb-record ( et, prev-co, prev-acc, bal, bud, m-bal, m-bud, "", "" ).
457 END.
459 END PROCEDURE.
461 /* _UIB-CODE-BLOCK-END */
462 &ANALYZE-RESUME
464 &ENDIF
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.
477 PUT UNFORMATTED ','.
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).
482 END.
483 PUT SKIP.
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 + '"'.
490 END.
491 PUT SKIP.
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:
503 total = 0.
504 FOR EACH tb WHERE tb.EntityType = entity-type
505 AND tb.EntityCode = Company.CompanyCode
506 AND tb.SequenceCode = AccountGroup.SequenceCode
507 NO-LOCK:
508 total = total + tb.Balance.
509 END.
511 PUT UNFORMATTED ",".
512 PUT UNFORMATTED total.
513 END.
514 PUT SKIP.
515 END.
516 OUTPUT CLOSE.
517 END PROCEDURE.
519 /* _UIB-CODE-BLOCK-END */
520 &ANALYZE-RESUME
522 &ENDIF
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 */
543 &SCOP BAD-SEQ 9999
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.
557 END.
558 ELSE
559 ASSIGN account-seq = {&BAD-SEQ} acgroup-name = {&BAD-NAME}.
560 END.
561 ELSE
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.
566 END.
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"))
577 NO-LOCK NO-ERROR.
578 IF AVAILABLE(AcctTran) THEN DO:
579 ASSIGN bal = bal - AcctTran.Amount
580 mtd-bal = mtd-bal - AcctTran.Amount .
581 END.
582 END.
584 IF c1 = ? THEN c1 = "".
585 IF c2 = ? THEN c2 = "".
586 IF consolidate-together THEN DO:
587 entity-code = 0.
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.
597 END.
598 ELSE
599 CREATE tb.
600 END.
601 ELSE
602 CREATE tb.
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
610 tb.Balance = bal
611 tb.Budget = bud
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 "")
616 + TRIM(c2)
617 tb.GroupType = AccountGroup.GroupType
620 END PROCEDURE.
622 /* _UIB-CODE-BLOCK-END */
623 &ANALYZE-RESUME
625 &ENDIF
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.
637 FOR EACH tb:
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) + " "
648 + STRING(Comment).
649 debug-event(line).
650 i = i + 1.
651 IF i > 50 THEN LEAVE.
652 END.
654 END PROCEDURE.
656 /* _UIB-CODE-BLOCK-END */
657 &ANALYZE-RESUME
659 &ENDIF
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 + '"'.
678 END.
679 PUT SKIP.
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:
691 total = 0.
692 FIND FIRST tb WHERE tb.EntityType = entity-type
693 AND tb.EntityCode = Company.CompanyCode
694 AND tb.AccountCode = ChartOfAccount.AccountCode
695 NO-LOCK NO-ERROR.
696 IF AVAILABLE(tb) THEN total = tb.Balance.
698 PUT UNFORMATTED ",".
699 PUT UNFORMATTED total.
700 END.
701 PUT SKIP.
702 END.
703 OUTPUT CLOSE.
704 END PROCEDURE.
706 /* _UIB-CODE-BLOCK-END */
707 &ANALYZE-RESUME
709 &ENDIF
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 /*------------------------------------------------------------------------------
716 Purpose:
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 '"","","'
736 last-sequence '","'
737 sequence-name '","'
738 ag-balance '","'
739 ag-budget '","'
740 ag-mtdbal '","'
741 ag-mtdbud '"'
742 SKIP.
743 END.
744 ELSE
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.
755 new-company = No.
756 END.
757 END.
759 FIND tb WHERE tb.EntityType = entity-type
760 AND tb.EntityCode = company-code
761 AND tb.AccountCode = ChartOfAccount.AccountCode NO-LOCK NO-ERROR.
763 IF detail THEN DO:
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.
768 new-company = No.
769 END.
770 PUT UNFORMATTED '"","","' ChartOfAccount.AccountCode '","' ChartOfAccount.Name '","'.
771 IF AVAILABLE(tb) THEN DO:
772 PUT UNFORMATTED
773 tb.Balance '","'
774 tb.Budget '","'
775 tb.mtd-Balance '","'
776 tb.mtd-Budget '","'
777 tb.Comment '"'
778 SKIP.
779 END.
780 ELSE
781 PUT UNFORMATTED '0","0","0","0",""' SKIP.
782 END.
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 .
788 END.
790 PUT SKIP.
791 END.
793 IF NOT detail AND last-sequence >= 0 THEN DO:
794 PUT UNFORMATTED '"","","'
795 last-sequence '","'
796 sequence-name '","'
797 ag-balance '","'
798 ag-budget '","'
799 ag-mtdbal '","'
800 ag-mtdbud '"'
801 SKIP.
802 END.
804 END PROCEDURE.
806 /* _UIB-CODE-BLOCK-END */
807 &ANALYZE-RESUME
809 &ENDIF
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 ).
827 END.
828 ELSE DO:
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 ).
832 END.
833 END.
837 OUTPUT CLOSE.
839 MESSAGE 'File "' + csv-file-name + '" generated successfully.'
840 VIEW-AS ALERT-BOX INFORMATION TITLE "Trial Balance by Group".
841 END PROCEDURE.
843 /* _UIB-CODE-BLOCK-END */
844 &ANALYZE-RESUME
846 &ENDIF
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 ).
859 RETURN.
860 END.
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.
871 FOR EACH tb
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 '"","","'
876 last-sequence '","'
877 sequence-name '","'
878 ag-balance '","'
879 ag-budget '","'
880 ag-mtdbal '","'
881 ag-mtdbud '"'
882 SKIP.
883 END.
884 ELSE
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.
896 END.
897 END.
898 IF detail THEN DO:
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.
903 END.
904 PUT UNFORMATTED '"","","'
905 tb.AccountCode '","'
906 tb.AccountName '","'
907 tb.Balance '","'
908 tb.Budget '","'
909 tb.mtd-Balance '","'
910 tb.mtd-Budget '","'
911 tb.Comment '"'
912 SKIP.
913 END.
914 ELSE ASSIGN
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 .
919 END.
921 IF NOT detail AND last-sequence >= 0 THEN DO:
922 PUT UNFORMATTED '"","","'
923 last-sequence '","'
924 sequence-name '","'
925 ag-balance '","'
926 ag-budget '","'
927 ag-mtdbal '","'
928 ag-mtdbud '"'
929 SKIP.
930 END.
932 OUTPUT CLOSE.
934 MESSAGE 'File "' + csv-file-name + '" generated successfully.'
935 VIEW-AS ALERT-BOX INFORMATION TITLE "Trial Balance by Group".
936 END PROCEDURE.
938 /* _UIB-CODE-BLOCK-END */
939 &ANALYZE-RESUME
941 &ENDIF
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!".
966 RETURN.
967 END.
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
974 BY EntityCode
975 BY tb.SequenceCode
976 BY AccountCode:
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, "" ).
980 END.
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')
985 THEN DO:
986 ASSIGN
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
992 END.
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, "" ).
1009 END.
1010 hline2 = rtypeString + " Trial Balance by Group" + include-qualifier
1011 + " - "
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
1016 PAGE.
1017 ELSE
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 */
1028 ASSIGN
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 )
1037 THEN DO:
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')
1054 THEN DO:
1055 ASSIGN
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
1061 END.
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, "" ).
1067 END.
1068 END.
1070 OUTPUT CLOSE.
1071 debug-event("Finished").
1072 RUN view-output-file( preview ).
1074 END PROCEDURE.
1076 /* _UIB-CODE-BLOCK-END */
1077 &ANALYZE-RESUME
1079 &ENDIF
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.
1111 END CASE.
1112 END.
1113 WHEN "FileName" THEN DO:
1114 j = LENGTH( ENTRY(1,token) ).
1115 csv-file-name = TRIM( SUBSTRING(token, j + 2) ).
1116 END.
1117 WHEN "StartMonth" THEN ASSIGN
1118 month-range = Yes
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)) .
1123 END CASE.
1124 END.
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.
1131 END.
1133 END PROCEDURE.
1135 /* _UIB-CODE-BLOCK-END */
1136 &ANALYZE-RESUME
1138 &ENDIF
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).
1163 ELSE
1164 remaining-comments = "".
1165 END.
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).
1173 ELSE
1174 remaining-comments = "".
1175 END.
1176 remaining-comments = WRAP( comment, 205 - col-width).
1177 pre-comment = " ".
1178 END.
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").
1187 ELSE
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.
1203 END.
1205 IF INDEX( remaining-comments, "~n") > 0 THEN
1206 remaining-comments = SUBSTRING( remaining-comments, INDEX( remaining-comments, "~n") + 1).
1207 ELSE
1208 remaining-comments = "".
1210 IF display-minuses THEN DO:
1211 pre-comment = " ".
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).
1215 ELSE
1216 remaining-comments = "".
1217 END.
1219 END PROCEDURE.
1221 /* _UIB-CODE-BLOCK-END */
1222 &ANALYZE-RESUME
1224 &ENDIF
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.
1246 END.
1248 RETURN bal.
1250 END FUNCTION.
1252 /* _UIB-CODE-BLOCK-END */
1253 &ANALYZE-RESUME
1255 &ENDIF
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.
1280 END.
1282 RETURN bal.
1284 END FUNCTION.
1286 /* _UIB-CODE-BLOCK-END */
1287 &ANALYZE-RESUME
1289 &ENDIF
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 /*------------------------------------------------------------------------------
1297 Purpose:
1298 Notes:
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.
1308 END FUNCTION.
1310 /* _UIB-CODE-BLOCK-END */
1311 &ANALYZE-RESUME
1313 &ENDIF
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 /*------------------------------------------------------------------------------
1321 Purpose:
1322 Notes:
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.
1332 IF type = "B" THEN
1333 RETURN balance-from-summary( et, ec, ac, month-n ).
1334 ELSE
1335 RETURN balance-from-balances( et, ec, ac, month-1, month-n ).
1337 END FUNCTION.
1339 /* _UIB-CODE-BLOCK-END */
1340 &ANALYZE-RESUME
1342 &ENDIF
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 /*------------------------------------------------------------------------------
1350 Purpose:
1351 Notes:
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)).
1357 END.
1358 FIND FIRST AltCo WHERE AltCo.CompanyCode = ec NO-LOCK.
1359 RETURN AltCo.LegalName + " ("+ STRING(AltCo.CompanyCode) + ")".
1361 END FUNCTION.
1363 /* _UIB-CODE-BLOCK-END */
1364 &ANALYZE-RESUME
1366 &ENDIF
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 /*------------------------------------------------------------------------------
1374 Purpose:
1375 Notes:
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.
1390 RETURN Yes.
1392 END FUNCTION.
1394 /* _UIB-CODE-BLOCK-END */
1395 &ANALYZE-RESUME
1397 &ENDIF