Add blank column, rename column.
[capital-apms-progress.git] / process / report / tr-c.p
blob41da8f3b40100459815f0048a7311fe840f71d5d
1 &ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12
2 &ANALYZE-RESUME
3 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS Procedure
4 /*--------------------------------------------------------------------------
5 File : tr-c.p
6 Purpose : Transactions by Creditor report
7 Author(s) : Andrew McMillan
8 ------------------------------------------------------------------------*/
9 DEF INPUT PARAMETER report-options AS CHAR NO-UNDO.
11 DEF VAR creditor-1 LIKE AcctTran.EntityCode NO-UNDO.
12 DEF VAR creditor-2 LIKE AcctTran.EntityCode NO-UNDO.
13 DEF VAR month-1 AS INTEGER FORMAT "9999" NO-UNDO.
14 DEF VAR month-2 AS INTEGER FORMAT "9999" NO-UNDO.
15 DEF VAR show-all AS LOGICAL NO-UNDO.
16 DEF VAR sort-entity-type LIKE AcctTran.EntityType NO-UNDO.
17 DEF VAR account-selection-type AS CHAR NO-UNDO INITIAL "1".
18 DEF VAR entity-1 LIKE AcctTran.EntityCode NO-UNDO.
19 DEF VAR entity-2 LIKE AcctTran.EntityCode NO-UNDO.
20 DEF VAR preview AS LOGICAL NO-UNDO.
21 DEF VAR export-fname AS CHAR NO-UNDO.
22 DEF VAR show-month-totals AS LOGICAL INITIAL no NO-UNDO.
23 DEF VAR file-name AS CHAR NO-UNDO.
24 DEF VAR base-entity-type AS CHAR INITIAL "C" NO-UNDO. /* The basic entity we deal with */
25 RUN parse-parameters.
27 DEF VAR prt-ctrl AS CHAR NO-UNDO.
28 DEF VAR rows AS INT NO-UNDO.
29 DEF VAR cols AS INT NO-UNDO.
30 DEF VAR need-creditor-header AS LOGI NO-UNDO.
31 DEF VAR need-account-header AS LOGI NO-UNDO.
32 DEF VAR line AS CHAR NO-UNDO.
34 DEF VAR fixed-font AS CHAR NO-UNDO INITIAL "courier,fixed,cpi,18,lpi,9".
35 DEF VAR header-font AS CHAR NO-UNDO INITIAL "univers,proportional,point,13,bold".
36 DEF VAR entity-header-font AS CHAR NO-UNDO INITIAL "univers,proportional,point,14,bold,lpi,5".
37 DEF VAR creditor-header-font AS CHAR NO-UNDO INITIAL "univers,proportional,point,12,bold,lpi,6".
38 DEF VAR account-header-font AS CHAR NO-UNDO INITIAL "univers,proportional,point,11,normal,lpi,7".
40 DEF VAR user-name AS CHAR NO-UNDO.
41 {inc/username.i "user-name"}
42 DEF VAR timeStamp AS CHAR FORMAT "X(54)" NO-UNDO.
43 DEF VAR dispReference AS CHARACTER COLUMN-LABEL "Reference" FORMAT "x(13)" NO-UNDO.
44 DEF VAR dispDescription AS CHARACTER NO-UNDO.
45 DEF VAR dispAmount AS CHARACTER FORMAT "X(16)" NO-UNDO.
46 DEF VAR dispName AS CHARACTER FORMAT "X(50)" NO-UNDO.
47 DEF VAR tr-this-month AS LOGICAL NO-UNDO.
49 DEF VAR money-format AS CHAR NO-UNDO INITIAL ">>>,>>>,>>9.99CR".
50 DEF VAR creditor-total LIKE AcctTran.Amount NO-UNDO.
51 DEF VAR grand-total LIKE AcctTran.Amount INITIAL 0 NO-UNDO.
53 DEF VAR report-time AS INTEGER NO-UNDO.
54 ASSIGN report-time = TIME.
56 {inc/ofc-this.i}
57 {inc/ofc-acct.i "CREDITORS" "sundry-creditors"}
58 {inc/ofc-set-l.i "CredTrxRep-Incld-Vouchers" "include-vouchers"}
59 {inc/ofc-set-l.i "CredTrxRep-Xcld-OBal" "exclude-OBal"}
60 {inc/ofc-set-l.i "Multi-Ledger-Creditors" "multi-ledger-creditors"}
62 /*** Get the report parameters from the user. ***/
63 DEF VAR m1-start AS DATE NO-UNDO.
64 DEF VAR m2-end AS DATE NO-UNDO.
66 FIND Month WHERE Month.MonthCode = month-1 NO-LOCK.
67 m1-start = Month.StartDate.
69 FIND Month WHERE Month.MonthCode = month-2 NO-LOCK.
70 m2-end = Month.EndDate.
72 &SCOPED-DEFINE page-width 126
73 timeStamp = "Printed " + STRING( TODAY, "99/99/9999") + ", " + STRING( TIME, "HH:MM:SS") + " for " + user-name.
74 DEF VAR hline2 AS CHAR FORMAT "X({&page-width})" NO-UNDO.
75 DEF VAR hline3 AS CHAR FORMAT "X({&page-width})" NO-UNDO.
76 hline2 = "Transactions for Creditor " + STRING(creditor-1,"99999") +
77 " to " + STRING(creditor-2,"99999") +
78 ", from " + STRING( m1-start, "99/99/9999") +
79 " to " + STRING( m2-end, "99/99/9999").
80 hline2 = SUBSTRING( STRING("","X({&page-width})"), 1, INTEGER(({&page-width} - LENGTH(hline2) ) / 2)) + hline2.
82 IF entity-1 > 0 OR entity-2 < 99999 THEN DO:
83 hline3 = ( IF sort-entity-type = "P" THEN "Properties" ELSE "Companies" ) +
84 STRING(entity-1, ">>999") +
85 " to" + STRING(entity-2, ">>999").
86 hline3 = SUBSTRING( STRING("","X({&page-width})"), 1, INTEGER(({&page-width} - LENGTH(hline3) ) / 2)) + hline3.
87 END.
88 ELSE
89 hline3 = "".
91 /* define all the frames for the report */
92 &SCOPED-DEFINE with-clause NO-BOX USE-TEXT NO-LABELS WIDTH {&page-width}
94 DEFINE FRAME default-frame WITH DOWN {&with-clause}.
96 DEFINE FRAME heading-frame WITH 1 DOWN {&with-clause} PAGE-TOP.
97 FORM HEADER
98 timeStamp "Page " + STRING( PAGE-NUMBER ) TO {&page-width} SKIP (1)
99 hline2 FORMAT "X({&page-width})"
100 hline3 FORMAT "X({&page-width})"
101 SKIP (2) " Date Reference Amount Description Entity Account Batch Doc"
102 WITH FRAME heading-frame.
104 DEFINE FRAME total-frame-1 WITH DOWN {&with-clause}.
105 FORM
106 SPACE(14)
107 dispReference
108 dispAmount
109 dispName
110 WITH FRAME total-frame-1.
112 DEFINE FRAME report-frame-1 WITH DOWN {&with-clause}.
113 FORM
114 SKIP(1)
115 Creditor.CreditorCode
116 Creditor.Name COLUMN-LABEL "Name" FORMAT "X(50)"
117 WITH FRAME report-frame-1.
120 DEFINE FRAME report-frame-2 WITH DOWN {&with-clause}.
121 FORM
123 AcctTran.Date COLUMN-LABEL "Date" FORMAT "99/99/9999"
124 dispReference
125 AcctTran.Amount COLUMN-LABEL "Amount" FORMAT ">>>,>>>,>>9.99CR"
126 dispDescription COLUMN-LABEL "Description" FORMAT "X(50)"
127 AcctTran.EntityType
128 AcctTran.EntityCode COLUMN-LABEL "Entity Code"
129 AcctTran.AccountCode COLUMN-LABEL "Account"
130 AcctTran.BatchCode COLUMN-LABEL "Batch"
131 AcctTran.DocumentCode COLUMN-LABEL "Doc"
132 WITH FRAME report-frame-2.
134 /* _UIB-CODE-BLOCK-END */
135 &ANALYZE-RESUME
138 &ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
140 /* ******************** Preprocessor Definitions ******************** */
142 &Scoped-define PROCEDURE-TYPE Procedure
143 &Scoped-define DB-AWARE no
147 /* _UIB-PREPROCESSOR-BLOCK-END */
148 &ANALYZE-RESUME
151 /* ************************ Function Prototypes ********************** */
153 &IF DEFINED(EXCLUDE-time-stamp) = 0 &THEN
155 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD time-stamp Procedure
156 FUNCTION time-stamp RETURNS CHARACTER
157 ( cc AS INT, txt AS CHAR ) FORWARD.
159 /* _UIB-CODE-BLOCK-END */
160 &ANALYZE-RESUME
162 &ENDIF
165 /* *********************** Procedure Settings ************************ */
167 &ANALYZE-SUSPEND _PROCEDURE-SETTINGS
168 /* Settings for THIS-PROCEDURE
169 Type: Procedure
170 Allow:
171 Frames: 0
172 Add Fields to: Neither
173 Other Settings: CODE-ONLY COMPILE
175 &ANALYZE-RESUME _END-PROCEDURE-SETTINGS
177 /* ************************* Create Window ************************** */
179 &ANALYZE-SUSPEND _CREATE-WINDOW
180 /* DESIGN Window definition (used by the UIB)
181 CREATE WINDOW Procedure ASSIGN
182 HEIGHT = 1.3
183 WIDTH = 36.14.
184 /* END WINDOW DEFINITION */
186 &ANALYZE-RESUME
188 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _INCLUDED-LIB Procedure
189 /* ************************* Included-Libraries *********************** */
191 {inc/method/m-txtrep.i}
193 /* _UIB-CODE-BLOCK-END */
194 &ANALYZE-RESUME
200 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Procedure
203 /* *************************** Main Block *************************** */
204 IF export-fname = "" THEN DO:
205 RUN make-control-string ( "PCL", "reset,portrait,tm,2,a4,lm,6,courier,cpi,18,lpi,9",
206 OUTPUT prt-ctrl, OUTPUT rows, OUTPUT cols ).
208 RUN output-control-file ( prt-ctrl ).
209 OUTPUT TO VALUE(txtrep-print-file) KEEP-MESSAGES PAGE-SIZE VALUE(rows).
211 VIEW FRAME heading-frame.
212 END.
213 ELSE DO:
214 OUTPUT TO VALUE(export-fname) KEEP-MESSAGES .
215 PUT UNFORMATTED '"Batch","Doc","Trn","Type","Entity","Account","Reference","Date","Amount","Narrative","Flag","Flagged By","Month code","Closing Group","Closed State"' SKIP .
216 END.
217 IF multi-ledger-creditors THEN DO:
218 FOR EACH Company NO-LOCK
219 WHERE Company.CompanyCode >= entity-1 AND Company.CompanyCode <= entity-2
220 BY Company.CompanyCode:
221 FOR EACH Creditor NO-LOCK
222 WHERE Creditor.CreditorCode >= creditor-1 AND Creditor.CreditorCode <= creditor-2
223 AND CAN-FIND( FIRST AcctTran WHERE EntityType = "C" AND EntityCode = Creditor.CreditorCode AND AccountCode = Company.CompanyCode
224 AND MonthCode >= month-1 AND MonthCode <= month-2)
225 BY Creditor.CreditorCode:
226 RUN each-company-creditor.
227 END.
228 END.
229 END.
230 ELSE IF sort-entity-type <> base-entity-type THEN DO:
231 FOR EACH Creditor NO-LOCK
232 WHERE Creditor.CompanyCode >= entity-1 AND Creditor.CompanyCode <= entity-2
233 AND Creditor.CreditorCode >= creditor-1 AND Creditor.CreditorCode <= creditor-2
234 BY Creditor.CompanyCode BY Creditor.CreditorCode:
235 RUN each-creditor.
236 END.
237 END.
238 ELSE DO:
239 FOR EACH Creditor NO-LOCK
240 WHERE Creditor.CreditorCode >= creditor-1 AND Creditor.CreditorCode <= creditor-2
241 BY Creditor.CreditorCode:
242 RUN each-creditor.
243 END.
244 END.
246 IF export-fname = "" THEN DO:
247 PUT SKIP (2).
248 dispName = "Entire report".
249 RUN disp-totals(grand-total).
250 OUTPUT CLOSE.
251 RUN view-output-file( preview ).
252 END.
253 ELSE DO:
254 OUTPUT CLOSE.
255 MESSAGE "Export Completed" VIEW-AS ALERT-BOX INFORMATION TITLE "Finished!".
256 END.
258 /* _UIB-CODE-BLOCK-END */
259 &ANALYZE-RESUME
262 /* ********************** Internal Procedures *********************** */
264 &IF DEFINED(EXCLUDE-account-header) = 0 &THEN
266 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE account-header Procedure
267 PROCEDURE account-header :
268 /*------------------------------------------------------------------------------
269 Purpose:
270 ------------------------------------------------------------------------------*/
271 need-account-header = No.
272 IF need-creditor-header THEN
273 RUN creditor-header.
274 ELSE IF export-fname = "" THEN
275 RUN pclrep-down-by( 0.2 ).
277 IF account-selection-type = "1" THEN RETURN.
279 line = STRING( ChartOfAccount.AccountCode, "9999.99") + " "
280 + ChartOfAccount.Name.
281 IF export-fname = "" THEN DO:
282 RUN pclrep-line( account-header-font, line ).
283 RUN pclrep-down-by( 0.1).
284 END.
285 ELSE DO:
286 PUT UNFORMATTED line SKIP.
287 END.
289 END PROCEDURE.
291 /* _UIB-CODE-BLOCK-END */
292 &ANALYZE-RESUME
294 &ENDIF
296 &IF DEFINED(EXCLUDE-creditor-header) = 0 &THEN
298 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE creditor-header Procedure
299 PROCEDURE creditor-header :
300 /*------------------------------------------------------------------------------
301 Purpose:
302 ------------------------------------------------------------------------------*/
304 DISPLAY Creditor.Name Creditor.CreditorCode WITH FRAME report-frame-1.
305 need-creditor-header = No.
307 END PROCEDURE.
309 /* _UIB-CODE-BLOCK-END */
310 &ANALYZE-RESUME
312 &ENDIF
314 &IF DEFINED(EXCLUDE-disp-totals) = 0 &THEN
316 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE disp-totals Procedure
317 PROCEDURE disp-totals :
318 /*------------------------------------------------------------------------------
319 Purpose:
320 Parameters: <none>
321 Notes:
322 ------------------------------------------------------------------------------*/
323 DEF INPUT PARAMETER disp-total AS DECIMAL NO-UNDO.
325 IF export-fname <> "" THEN RETURN.
327 DISPLAY " " @ dispReference
328 " ----------" @ dispAmount
329 " " @ dispName
330 WITH FRAME total-frame-1.
331 DOWN WITH FRAME total-frame-1.
332 DISPLAY dispName
333 "Total" @ dispReference
334 STRING( disp-total, money-format) @ dispAmount
335 WITH FRAME total-frame-1.
336 DOWN WITH FRAME total-frame-1.
338 END PROCEDURE.
340 /* _UIB-CODE-BLOCK-END */
341 &ANALYZE-RESUME
343 &ENDIF
345 &IF DEFINED(EXCLUDE-each-account) = 0 &THEN
347 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE each-account Procedure
348 PROCEDURE each-account :
349 /*------------------------------------------------------------------------------
350 Purpose:
351 ------------------------------------------------------------------------------*/
352 DEF BUFFER AltTran FOR AcctTran.
354 need-creditor-header = Yes.
356 IF NOT( exclude-OBal = YES ) THEN RUN show-opening-balance.
357 time-stamp( Creditor.CreditorCode, "G").
359 IF show-all THEN
360 RUN each-account-all-transactions.
361 ELSE
362 RUN each-account-open-transactions.
364 /* Move up to each creditor to include Voucher totals
365 ***********************************************************
366 IF creditor-total <> 0 OR NOT need-creditor-header THEN DO:
367 dispName = Creditor.Name.
368 RUN disp-totals( creditor-total ).
369 grand-total = grand-total + creditor-total.
370 END.
371 ************************************************************/
373 END PROCEDURE.
375 /* _UIB-CODE-BLOCK-END */
376 &ANALYZE-RESUME
378 &ENDIF
380 &IF DEFINED(EXCLUDE-each-account-all-transactions) = 0 &THEN
382 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE each-account-all-transactions Procedure
383 PROCEDURE each-account-all-transactions :
384 /*------------------------------------------------------------------------------
385 Purpose:
386 ------------------------------------------------------------------------------*/
387 DEF VAR account-code AS DEC NO-UNDO.
388 IF multi-ledger-creditors THEN
389 account-code = Company.CompanyCode.
390 ELSE
391 account-code = sundry-creditors.
393 FOR EACH AcctTran WHERE AcctTran.EntityType = base-entity-type
394 AND AcctTran.EntityCode = Creditor.CreditorCode
395 AND AcctTran.AccountCode = account-code
396 AND AcctTran.MonthCode >= month-1
397 AND AcctTran.MonthCode <= month-2 NO-LOCK,
398 FIRST Month OF AcctTran NO-LOCK,
399 FIRST Document OF AcctTran NO-LOCK
400 BY AcctTran.EntityType BY AcctTran.EntityCode BY AcctTran.AccountCode
401 BY AcctTran.MonthCode BY AcctTran.Date
402 BY AcctTran.BatchCode BY AcctTran.DocumentCode BY AcctTran.TransactionCode :
403 RUN for-each-transaction .
404 END.
406 END PROCEDURE.
408 /* _UIB-CODE-BLOCK-END */
409 &ANALYZE-RESUME
411 &ENDIF
413 &IF DEFINED(EXCLUDE-each-account-open-transactions) = 0 &THEN
415 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE each-account-open-transactions Procedure
416 PROCEDURE each-account-open-transactions :
417 /*------------------------------------------------------------------------------
418 Purpose:
419 ------------------------------------------------------------------------------*/
420 DEF BUFFER AltTran FOR AcctTran.
421 DEF VAR account-code AS DEC NO-UNDO.
422 IF multi-ledger-creditors THEN
423 account-code = Company.CompanyCode.
424 ELSE
425 account-code = sundry-creditors.
427 time-stamp( Creditor.CreditorCode, "I").
428 IF CAN-FIND( FIRST AltTran WHERE AltTran.EntityType = base-entity-type
429 AND AltTran.EntityCode = Creditor.CreditorCode
430 AND AltTran.AccountCode = account-code
431 AND AltTran.MonthCode > month-2
432 AND AltTran.ClosedState = "F")
433 THEN DO:
434 time-stamp( Creditor.CreditorCode, "J").
435 FOR EACH AcctTran WHERE AcctTran.EntityType = base-entity-type
436 AND AcctTran.EntityCode = Creditor.CreditorCode
437 AND AcctTran.AccountCode = account-code
438 AND AcctTran.MonthCode >= month-1
439 AND AcctTran.MonthCode <= month-2
440 AND (AcctTran.CLosingGroup = ?
441 OR AcctTran.ClosedState = "P"
442 OR CAN-FIND(FIRST AltTran WHERE AltTran.EntityType = base-entity-type
443 AND AltTran.EntityCode = Creditor.CreditorCode
444 AND AltTran.AccountCode = account-code
445 AND AltTran.MonthCode > month-2
446 AND AltTran.ClosingGroup = AcctTran.ClosingGroup
447 AND AltTran.ClosedState = "F")
448 ) NO-LOCK,
449 FIRST Month OF AcctTran NO-LOCK,
450 FIRST Document OF AcctTran NO-LOCK
451 BY AcctTran.EntityType BY AcctTran.EntityCode BY AcctTran.AccountCode
452 BY AcctTran.MonthCode BY AcctTran.Date
453 BY AcctTran.BatchCode BY AcctTran.DocumentCode BY AcctTran.TransactionCode :
454 RUN for-each-transaction.
455 END.
456 END.
457 ELSE DO:
458 time-stamp( Creditor.CreditorCode, "K").
459 FOR EACH AcctTran WHERE AcctTran.EntityType = base-entity-type
460 AND AcctTran.EntityCode = Creditor.CreditorCode
461 AND AcctTran.AccountCode = account-code
462 AND AcctTran.MonthCode >= month-1
463 AND AcctTran.MonthCode <= month-2
464 AND (AcctTran.CLosingGroup = ? OR AcctTran.ClosedState = "P")
465 NO-LOCK,
466 FIRST Month OF AcctTran NO-LOCK,
467 FIRST Document OF AcctTran NO-LOCK
468 BY AcctTran.EntityType BY AcctTran.EntityCode BY AcctTran.AccountCode
469 BY AcctTran.MonthCode BY AcctTran.Date
470 BY AcctTran.BatchCode BY AcctTran.DocumentCode BY AcctTran.TransactionCode :
471 RUN for-each-transaction.
472 END.
473 END.
474 time-stamp( Creditor.CreditorCode, "L").
476 END PROCEDURE.
478 /* _UIB-CODE-BLOCK-END */
479 &ANALYZE-RESUME
481 &ENDIF
483 &IF DEFINED(EXCLUDE-each-company-creditor) = 0 &THEN
485 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE each-company-creditor Procedure
486 PROCEDURE each-company-creditor :
487 /*------------------------------------------------------------------------------
488 Purpose: Decide whether the company creditor has suitable transactions
490 This will only be called for multi-ledger-creditors setups where there
491 are per-company creditor account balances.
492 ------------------------------------------------------------------------------*/
493 DEF BUFFER AltTran FOR AcctTran.
494 DEF VAR has-transactions AS LOGI NO-UNDO INITIAL No.
495 DEF VAR printed_trx AS LOGI NO-UNDO INITIAL NO.
497 IF show-all THEN DO:
498 has-transactions = TRUE.
499 END.
500 ELSE DO:
501 FIND FIRST AcctTran WHERE AcctTran.EntityType = "C"
502 AND AcctTran.EntityCode = Creditor.CreditorCode
503 AND AcctTran.AccountCode = Company.CompanyCode
504 AND AcctTran.MonthCode <= month-2
505 AND (AcctTran.CLosingGroup = ? OR AcctTran.ClosedState = "P")
506 NO-LOCK NO-ERROR.
507 IF AVAILABLE(AcctTran) THEN
508 has-transactions = Yes.
509 ELSE DO:
510 FIND FIRST AcctTran WHERE AcctTran.EntityType = "C"
511 AND AcctTran.EntityCode = Creditor.CreditorCode
512 AND AcctTran.AccountCode = Company.CompanyCode
513 AND AcctTran.MonthCode > month-2
514 AND AcctTran.ClosedState = "F"
515 AND CAN-FIND(FIRST AltTran WHERE AltTran.EntityType = AcctTran.EntityType
516 AND AltTran.EntityCode = AcctTran.EntityCode
517 AND AltTran.AccountCode = AcctTran.AccountCode
518 AND AltTran.MonthCode <= month-2
519 AND AltTran.ClosingGroup = AcctTran.ClosingGroup
520 AND AltTran.ClosedState = "F")
521 NO-LOCK NO-ERROR.
522 IF AVAILABLE(AcctTran) THEN has-transactions = Yes.
523 END.
524 END.
526 IF has-transactions THEN DO:
527 sundry-creditors = Company.CompanyCode. /* A dirty hack! */
528 RUN each-account.
529 ASSIGN printed_trx = YES.
530 END.
532 IF include-vouchers THEN DO:
533 IF CAN-FIND( FIRST Voucher OF Creditor
534 WHERE Voucher.Date >= m1-start AND Voucher.Date <= m2-end)
535 THEN DO:
536 RUN each-voucher.
537 ASSIGN printed_trx = YES.
538 END.
539 END.
541 /* Print Creditor Totals */
542 IF printed_trx = YES THEN DO:
543 IF creditor-total <> 0 OR NOT need-creditor-header THEN DO:
544 dispName = Creditor.Name.
545 RUN disp-totals( creditor-total ).
546 ASSIGN grand-total = grand-total + creditor-total
547 creditor-total = 0.
548 END.
549 END.
551 END PROCEDURE.
553 /* _UIB-CODE-BLOCK-END */
554 &ANALYZE-RESUME
556 &ENDIF
558 &IF DEFINED(EXCLUDE-each-creditor) = 0 &THEN
560 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE each-creditor Procedure
561 PROCEDURE each-creditor :
562 /*------------------------------------------------------------------------------
563 Purpose: Decide whether the creditor has suitable transactions
564 ------------------------------------------------------------------------------*/
565 DEF BUFFER AltTran FOR AcctTran.
566 DEF VAR has-transactions AS LOGI NO-UNDO INITIAL No.
567 DEF VAR printed_trx AS LOGI NO-UNDO INITIAL NO.
569 time-stamp( Creditor.CreditorCode, ?).
571 IF show-all THEN DO:
572 FIND FIRST AcctTran WHERE AcctTran.EntityType = base-entity-type
573 AND AcctTran.EntityCode = Creditor.CreditorCode
574 AND AcctTran.AccountCode = sundry-creditors
575 AND AcctTran.MonthCode <= month-2 NO-LOCK NO-ERROR.
576 has-transactions = AVAILABLE(AcctTran).
577 time-stamp( Creditor.CreditorCode, "B").
578 END.
579 ELSE DO:
580 FIND FIRST AcctTran WHERE AcctTran.EntityType = base-entity-type
581 AND AcctTran.EntityCode = Creditor.CreditorCode
582 AND AcctTran.AccountCode = sundry-creditors
583 AND AcctTran.MonthCode <= month-2
584 AND (AcctTran.CLosingGroup = ? OR AcctTran.ClosedState = "P")
585 NO-LOCK NO-ERROR.
586 time-stamp( Creditor.CreditorCode, "C").
587 IF AVAILABLE(AcctTran) THEN has-transactions = Yes.
588 ELSE DO:
589 FIND FIRST AcctTran WHERE AcctTran.EntityType = base-entity-type
590 AND AcctTran.EntityCode = Creditor.CreditorCode
591 AND AcctTran.AccountCode = sundry-creditors
592 AND AcctTran.MonthCode > month-2
593 AND AcctTran.ClosedState = "F"
594 AND CAN-FIND(FIRST AltTran WHERE AltTran.EntityType = AcctTran.EntityType
595 AND AltTran.EntityCode = AcctTran.EntityCode
596 AND AltTran.AccountCode = AcctTran.AccountCode
597 AND AltTran.MonthCode <= month-2
598 AND AltTran.ClosingGroup = AcctTran.ClosingGroup
599 AND AltTran.ClosedState = "F")
600 NO-LOCK NO-ERROR.
601 IF AVAILABLE(AcctTran) THEN has-transactions = Yes.
602 time-stamp( Creditor.CreditorCode, "D").
603 END.
604 END.
606 IF has-transactions THEN DO:
607 RUN each-account.
608 ASSIGN printed_trx = YES.
609 END.
611 IF include-vouchers THEN DO:
612 IF CAN-FIND( FIRST Voucher OF Creditor
613 WHERE Voucher.Date >= m1-start AND Voucher.Date <= m2-end)
614 THEN DO:
615 RUN each-voucher.
616 ASSIGN printed_trx = YES.
617 END.
618 END.
620 /* Print Creditor Totals */
621 IF printed_trx = YES THEN DO:
622 IF creditor-total <> 0 OR NOT need-creditor-header THEN DO:
623 dispName = Creditor.Name.
624 RUN disp-totals( creditor-total ).
625 ASSIGN grand-total = grand-total + creditor-total
626 creditor-total = 0.
627 END.
628 END.
630 END PROCEDURE.
632 /* _UIB-CODE-BLOCK-END */
633 &ANALYZE-RESUME
635 &ENDIF
637 &IF DEFINED(EXCLUDE-each-voucher) = 0 &THEN
639 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE each-voucher Procedure
640 PROCEDURE each-voucher :
641 /*------------------------------------------------------------------------------
642 Purpose: Print Voucher details for each Creditor
643 Parameters: <none>
644 Notes:
645 ------------------------------------------------------------------------------*/
647 FOR EACH Voucher OF Creditor NO-LOCK
648 WHERE Voucher.Date >= m1-start AND Voucher.Date <= m2-end
649 BY Voucher.VoucherSeq:
651 IF export-fname <> "" THEN RUN export-voucher .
652 ELSE DO:
653 DISPLAY
654 voucher.DATE @ AcctTran.Date
655 voucher.invoicereference @ dispReference
656 ( voucher.goodsvalue + voucher.taxvalue) @ AcctTran.Amount
657 voucher.DESCRIPTION @ dispDescription
658 voucher.EntityType @ AcctTran.EntityType
659 voucher.EntityCode @ AcctTran.EntityCode
660 voucher.AccountCode @ AcctTran.AccountCode
661 voucher.BatchCode @ AcctTran.BatchCode
662 voucher.DocumentCode @ AcctTran.DocumentCode
663 WITH FRAME report-frame-2.
665 DOWN WITH FRAME report-frame-2.
666 END.
668 creditor-total = creditor-total + Voucher.GoodsValue .
670 END.
675 END PROCEDURE.
677 /* _UIB-CODE-BLOCK-END */
678 &ANALYZE-RESUME
680 &ENDIF
682 &IF DEFINED(EXCLUDE-export-transaction) = 0 &THEN
684 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE export-transaction Procedure
685 PROCEDURE export-transaction :
686 /*------------------------------------------------------------------------------
687 Purpose:
688 Parameters: <none>
689 Notes:
690 ------------------------------------------------------------------------------*/
691 DEF VAR FlagBy AS CHAR INITIAL "" NO-UNDO.
692 DEF VAR v-date AS CHAR NO-UNDO.
694 FIND Person WHERE Person.PersonCode = AcctTran.FlaggedBy NO-LOCK NO-ERROR.
695 IF AVAILABLE(Person) THEN
696 FlagBy = Person.FirstName + " " + Person.LastName.
698 IF AcctTran.DATE = ?
699 THEN v-date = ''.
700 ELSE v-date = STRING(AcctTran.DATE, "99/99/9999").
702 PUT UNFORMATTED
703 AcctTran.BatchCode ','
704 AcctTran.DocumentCode ','
705 AcctTran.TransactionCode ',"'
706 AcctTran.EntityType '",'
707 AcctTran.EntityCode ','
708 AcctTran.AccountCode ',"'
709 dispReference '","'
710 v-date '",'
711 AcctTran.Amount ',"'
712 dispDescription '","'
713 AcctTran.FlagAttention '","'
714 FlagBy '","'
715 AcctTran.MonthCode '","'
716 AcctTran.ClosingGroup '","'
717 AcctTran.ClosedState '"'
718 SKIP .
720 END PROCEDURE.
722 /* _UIB-CODE-BLOCK-END */
723 &ANALYZE-RESUME
725 &ENDIF
727 &IF DEFINED(EXCLUDE-export-voucher) = 0 &THEN
729 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE export-voucher Procedure
730 PROCEDURE export-voucher :
731 /*------------------------------------------------------------------------------
732 Purpose:
733 Parameters: <none>
734 Notes:
735 ------------------------------------------------------------------------------*/
736 DEF VAR FlagBy AS CHAR INITIAL "" NO-UNDO.
737 DEF VAR v-date AS CHAR NO-UNDO.
739 IF Voucher.DATE = ?
740 THEN v-date = ''.
741 ELSE v-date = STRING(Voucher.DATE, "99/99/9999").
743 PUT UNFORMATTED
744 Voucher.BatchCode ','
745 Voucher.DocumentCode ','
746 ' ' ',"'
747 Voucher.EntityType '",'
748 Voucher.EntityCode ','
749 Voucher.AccountCode ',"'
750 Voucher.InvoiceReference '","'
751 v-Date '",'
752 (Voucher.GoodsValue + Voucher.TaxValue) ',"'
753 Voucher.Description '","'
754 ' ' '","'
755 ' ' '","'
756 ' ' '","'
757 ' ' '","'
758 ' ' '"'
759 SKIP .
762 END PROCEDURE.
764 /* _UIB-CODE-BLOCK-END */
765 &ANALYZE-RESUME
767 &ENDIF
769 &IF DEFINED(EXCLUDE-for-each-transaction) = 0 &THEN
771 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE for-each-transaction Procedure
772 PROCEDURE for-each-transaction :
773 /*------------------------------------------------------------------------------
774 Purpose:
775 ------------------------------------------------------------------------------*/
777 IF need-creditor-header THEN RUN creditor-header.
779 ASSIGN dispReference = STRING( (IF (AcctTran.Reference = "") THEN (Document.Reference) ELSE (AcctTran.Reference) ), "X(12)" )
780 + ( IF AcctTran.ClosingGroup > 0 THEN (IF AcctTran.ClosedState = "P" THEN "P" ELSE "*") ELSE " " )
781 dispDescription = IF (AcctTran.Description = "") THEN (Document.Description) ELSE (AcctTran.Description)
782 tr-this-month = yes .
784 IF export-fname <> "" THEN RUN export-transaction .
785 ELSE DO:
786 DISPLAY
787 AcctTran.Date
788 dispReference
789 AcctTran.Amount
790 dispDescription
791 AcctTran.EntityType
792 AcctTran.EntityCode
793 AcctTran.AccountCode
794 AcctTran.BatchCode
795 AcctTran.DocumentCode
796 WITH FRAME report-frame-2.
798 DOWN WITH FRAME report-frame-2.
799 END.
801 creditor-total = creditor-total + AcctTran.Amount .
803 END PROCEDURE.
805 /* _UIB-CODE-BLOCK-END */
806 &ANALYZE-RESUME
808 &ENDIF
810 &IF DEFINED(EXCLUDE-parse-parameters) = 0 &THEN
812 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE parse-parameters Procedure
813 PROCEDURE parse-parameters :
814 /*------------------------------------------------------------------------------
815 Purpose:
816 ------------------------------------------------------------------------------*/
817 /* Now detail to the complex options string */
818 DEF VAR i AS INT NO-UNDO.
819 DEF VAR token AS CHAR NO-UNDO.
821 {inc/showopts.i "report-options"}
823 DO i = 1 TO NUM-ENTRIES( report-options, "~n" ):
824 token = ENTRY( i, report-options, "~n" ).
825 CASE( ENTRY( 1, token ) ):
826 WHEN "EntityType" THEN sort-entity-type = ENTRY( 2, token ).
827 WHEN "EntityRange" THEN ASSIGN
828 entity-1 = INT( ENTRY( 2, token ))
829 entity-2 = INT( ENTRY( 3, token )).
830 WHEN "CreditorRange" THEN ASSIGN
831 creditor-1 = INT( ENTRY( 2, token ))
832 creditor-2 = INT( ENTRY( 3, token )).
833 WHEN "MonthRange" THEN ASSIGN
834 month-1 = INT( ENTRY( 2, token ))
835 month-2 = INT( ENTRY( 3, token )).
837 WHEN "Export" THEN export-fname = SUBSTRING( token, INDEX( token, ",") + 1 ).
839 WHEN "Preview" THEN preview = Yes.
840 WHEN "Show-All" THEN show-all = Yes.
841 END CASE.
842 END.
843 END PROCEDURE.
845 /* _UIB-CODE-BLOCK-END */
846 &ANALYZE-RESUME
848 &ENDIF
850 &IF DEFINED(EXCLUDE-show-opening-balance) = 0 &THEN
852 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE show-opening-balance Procedure
853 PROCEDURE show-opening-balance :
854 /*------------------------------------------------------------------------------
855 Purpose: Calculate and display the opening balance
856 ------------------------------------------------------------------------------*/
857 DEF BUFFER AltTran FOR AcctTran.
859 creditor-total = 0.
861 IF show-all THEN DO:
862 FOR EACH AccountBalance NO-LOCK
863 WHERE AccountBalance.EntityType = base-entity-type
864 AND AccountBalance.EntityCode = Creditor.CreditorCode
865 AND AccountBalance.AccountCode = sundry-creditors
866 AND AccountBalance.MonthCode < month-1:
867 creditor-total = creditor-total + AccountBalance.Balance.
868 END.
869 END.
870 ELSE DO:
871 FOR EACH AcctTran WHERE AcctTran.EntityType = base-entity-type
872 AND AcctTran.EntityCode = Creditor.CreditorCode
873 AND AcctTran.AccountCode = sundry-creditors
874 AND AcctTran.MonthCode < month-1
875 AND (AcctTran.CLosingGroup = ?
876 OR AcctTran.ClosedState = "P"
877 OR CAN-FIND(FIRST AltTran WHERE AltTran.EntityType = base-entity-type
878 AND AltTran.EntityCode = Creditor.CreditorCode
879 AND AltTran.AccountCode = sundry-creditors
880 AND AltTran.MonthCode > month-2
881 AND AltTran.ClosedState = "F")
882 ) NO-LOCK:
883 creditor-total = creditor-total + AcctTran.Amount.
884 END.
885 END.
887 IF creditor-total <> 0 THEN DO:
888 IF need-creditor-header THEN RUN creditor-header.
889 FIND Month WHERE Month.MonthCode = month-1 NO-LOCK.
890 ASSIGN
891 dispReference = "O/Bal"
892 dispDescription = "Opening Balance"
893 tr-this-month = yes
896 IF export-fname = "" THEN DO:
897 DISPLAY Month.StartDate @ AcctTran.Date
898 dispReference
899 creditor-total @ AcctTran.Amount
900 dispDescription
901 WITH FRAME report-frame-2.
902 DOWN WITH FRAME report-frame-2.
903 IF show-month-totals THEN DOWN WITH FRAME report-frame-2.
904 END.
905 ELSE
906 PUT UNFORMATTED ',,,"'
907 base-entity-type '",' Creditor.CreditorCode ',' sundry-creditors ',"'
908 dispReference '","'
909 Month.StartDate '",'
910 creditor-total ',"'
911 dispDescription '"'
912 SKIP .
914 END.
916 END PROCEDURE.
918 /* _UIB-CODE-BLOCK-END */
919 &ANALYZE-RESUME
921 &ENDIF
923 /* ************************ Function Implementations ***************** */
925 &IF DEFINED(EXCLUDE-time-stamp) = 0 &THEN
927 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION time-stamp Procedure
928 FUNCTION time-stamp RETURNS CHARACTER
929 ( cc AS INT, txt AS CHAR ) :
930 /*------------------------------------------------------------------------------
931 Purpose: Produce a timestamp
932 ------------------------------------------------------------------------------*/
933 DEF VAR now AS INT NO-UNDO.
934 DEF VAR elapsed AS DEC NO-UNDO.
935 DEF VAR msg AS CHAR NO-UNDO.
937 RETURN "".
938 now = TIME.
939 elapsed = ETIME(Yes).
940 msg = "Creditor " + STRING(Creditor.CreditorCode,"99999")
941 + " " + STRING(now,"HH:MM:SS").
942 IF txt <> ? THEN
943 msg = msg + " " + STRING(elapsed / 1000, ">>>>9.999")
944 + " " + txt.
945 MESSAGE msg.
946 RETURN msg.
948 END FUNCTION.
950 /* _UIB-CODE-BLOCK-END */
951 &ANALYZE-RESUME
953 &ENDIF