1 &ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12
3 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS Procedure
4 TRIGGER PROCEDURE FOR WRITE OF AcctTran
NEW BUFFER new-tran
OLD BUFFER old-tran.
6 /* _UIB-CODE-BLOCK-END
*/
10 &ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
12 /* ******************** Preprocessor Definitions
******************** */
14 &Scoped-define PROCEDURE-TYPE Procedure
18 /* _UIB-PREPROCESSOR-BLOCK-END
*/
23 /* *********************** Procedure Settings
************************ */
25 &ANALYZE-SUSPEND _PROCEDURE-SETTINGS
26 /* Settings for
THIS-PROCEDURE
30 Add Fields to
: Neither
31 Other Settings
: CODE-ONLY
COMPILE
33 &ANALYZE-RESUME _END-PROCEDURE-SETTINGS
35 /* ************************* Create Window
************************** */
37 &ANALYZE-SUSPEND _CREATE-WINDOW
38 /* DESIGN Window definition
(used by the UIB
)
39 CREATE WINDOW Procedure
ASSIGN
42 /* END WINDOW DEFINITION
*/
49 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Procedure
52 /* *************************** Main Block
*************************** */
54 RUN check-set-flag
IN THIS-PROCEDURE.
57 OR new-tran.EntityType
<> old-tran.EntityType
58 OR new-tran.EntityCode
<> old-tran.EntityCode
59 OR new-tran.AccountCode
<> old-tran.AccountCode
60 OR new-tran.MonthCode
<> old-tran.MonthCode
61 THEN RUN move-between-accounts.
63 IF old-tran.Amount
<> new-tran.Amount
THEN RUN change-balance.
65 /* _UIB-CODE-BLOCK-END
*/
69 /* ********************** Internal Procedures
*********************** */
71 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE change-balance Procedure
72 PROCEDURE change-balance
:
73 /*------------------------------------------------------------------------------
74 Purpose
: If the amount of the transaction has changed
, change the balance
75 on the Account related to new-tran.
76 ------------------------------------------------------------------------------*/
77 FIND AccountBalance
OF new-tran
EXCLUSIVE-LOCK.
78 AccountBalance.Balance
= AccountBalance.Balance
- old-tran.Amount
+ new-tran.Amount.
82 /* _UIB-CODE-BLOCK-END
*/
86 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE check-set-flag Procedure
87 PROCEDURE check-set-flag
:
88 /*------------------------------------------------------------------------------
89 Purpose
: Check
/set the flagged by field.
90 ------------------------------------------------------------------------------*/
91 IF new-tran.FlagAttention
<> old-tran.FlagAttention
THEN DO:
92 DEF VAR user-name
AS CHAR NO-UNDO.
93 {inc
/username.i
"user-name"}
94 FIND Usr
WHERE Usr.UserName
= user-name
NO-LOCK NO-ERROR.
95 new-tran.FlaggedBy
= IF AVAILABLE(Usr
) THEN Usr.PersonCode
ELSE ?.
100 /* _UIB-CODE-BLOCK-END
*/
104 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE move-between-accounts Procedure
105 PROCEDURE move-between-accounts
:
106 /*------------------------------------------------------------------------------
107 Purpose
: Move balance from one account
/month to another to follow trn.
108 Note that we always use the amount from 'old-tran'
- any change
109 in amount done at the same time will happen after this.
110 ------------------------------------------------------------------------------*/
111 IF NOT NEW new-tran
THEN DO:
112 /* subtract from old account
, deleting if appropriate
*/
113 DEF BUFFER alt-tran
FOR AcctTran.
114 FIND AccountBalance
OF old-tran
EXCLUSIVE-LOCK.
115 AccountBalance.Balance
= AccountBalance.Balance
- old-tran.Amount.
118 /* Add onto new account
, creating as appropriate
*/
119 FIND AccountBalance
OF new-tran
EXCLUSIVE-LOCK NO-ERROR.
120 IF NOT AVAILABLE(AccountBalance
) THEN DO:
121 CREATE AccountBalance.
122 ASSIGN AccountBalance.EntityType
= new-tran.EntityType
123 AccountBalance.EntityCode
= new-tran.EntityCode
124 AccountBalance.AccountCode
= new-tran.AccountCode
125 AccountBalance.MonthCode
= new-tran.MonthCode .
127 AccountBalance.Balance
= AccountBalance.Balance
+ old-tran.Amount.
131 /* _UIB-CODE-BLOCK-END
*/