1 &ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12
3 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS Procedure
4 /*--------------------------------------------------------------------------
6 Purpose
: WRITE trigger for RentChargeLine
10 Author
(s
) : Andrew McMillan
13 ------------------------------------------------------------------------*/
15 TRIGGER PROCEDURE FOR WRITE OF RentChargeLine
OLD OldChargeLine.
18 {inc
/ofc-set.i
"Rent-Charged-To" "rent-charged-to-text" "WARNING"}
19 IF NOT AVAILABLE(OfficeSetting
) THEN rent-charged-to-text
= STRING(TODAY + 27).
21 /* _UIB-CODE-BLOCK-END
*/
25 &ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
27 /* ******************** Preprocessor Definitions
******************** */
29 &Scoped-define PROCEDURE-TYPE Procedure
33 /* _UIB-PREPROCESSOR-BLOCK-END
*/
37 /* ************************ Function Prototypes
********************** */
39 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD get-annual-amount Procedure
40 FUNCTION get-annual-amount
RETURNS DECIMAL
41 ( INPUT period-amount
AS DEC, INPUT freq-type
AS CHAR ) FORWARD.
43 /* _UIB-CODE-BLOCK-END
*/
46 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD get-charge Procedure
47 FUNCTION get-charge
RETURNS DECIMAL
48 ( INPUT active-date
AS DATE, INPUT end-date
AS DATE, INPUT d-from
AS DATE, INPUT upto
AS DATE, INPUT freq
AS CHAR, INPUT amount
AS DEC ) FORWARD.
50 /* _UIB-CODE-BLOCK-END
*/
54 /* *********************** Procedure Settings
************************ */
56 &ANALYZE-SUSPEND _PROCEDURE-SETTINGS
57 /* Settings for
THIS-PROCEDURE
61 Add Fields to
: Neither
62 Other Settings
: CODE-ONLY
COMPILE
64 &ANALYZE-RESUME _END-PROCEDURE-SETTINGS
66 /* ************************* Create Window
************************** */
68 &ANALYZE-SUSPEND _CREATE-WINDOW
69 /* DESIGN Window definition
(used by the UIB
)
70 CREATE WINDOW Procedure
ASSIGN
73 /* END WINDOW DEFINITION
*/
79 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _INCLUDED-LIB Procedure
80 /* ************************* Included-Libraries
*********************** */
84 /* _UIB-CODE-BLOCK-END
*/
89 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Procedure
92 /* *************************** Main Block
*************************** */
95 OR RentChargeLine.Amount
<> OldChargeLine.Amount
96 OR RentChargeLine.EndDate
<> OldChargeLine.EndDate
97 OR RentChargeLine.FrequencyCode
<> OldChargeLine.FrequencyCode
98 OR RentChargeLine.StartDate
<> OldChargeLine.StartDate
99 /* OR RentChargeLine.LastChargedDate
<> OldChargeLine.LastChargedDate
*/
100 OR RentChargeLine.RentChargeLineStatus
<> OldChargeLine.RentChargeLineStatus
102 RUN recalculate-annual-rental.
104 /* _UIB-CODE-BLOCK-END
*/
108 /* ********************** Internal Procedures
*********************** */
110 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE recalculate-annual-rental Procedure
111 PROCEDURE recalculate-annual-rental
:
112 /*------------------------------------------------------------------------------
113 Purpose
: Recalculate the annual rental for this rent charge based on the
114 fact that this RentChargeLine has changed
(pass through all of
115 the RentChargeLine records
).
116 ------------------------------------------------------------------------------*/
117 DEF BUFFER ChgLine
FOR RentChargeLine.
118 DEF VAR annual-charge
AS DEC NO-UNDO INITIAL 0.0 .
119 DEF VAR active-date
AS DATE NO-UNDO .
120 DEF VAR end-date
AS DATE NO-UNDO .
121 DEF VAR this-charge
AS DEC NO-UNDO .
122 DEF VAR mo-days
AS DEC NO-UNDO .
124 FIND RentCharge
OF RentChargeLine
NO-LOCK NO-ERROR.
125 IF NOT AVAILABLE(RentCharge
) THEN RETURN.
127 active-date
= DATE(rent-charged-to-text
) + 1.
128 end-date
= last-of-month
(active-date
).
130 FOR EACH ChgLine
OF RentCharge
WHERE ChgLine.RentChargeLineStatus
= "C"
131 AND ROWID(ChgLine
) <> ROWID(RentChargeLine
) NO-LOCK:
132 IF ChgLine.StartDate
<= end-date
133 AND (ChgLine.EndDate
>= active-date
OR ChgLine.EndDate
= ?
)
135 annual-charge
= annual-charge
+ get-charge
( active-date
, end-date
,
136 ChgLine.StartDate
, ChgLine.EndDate
, ChgLine.FrequencyCode
, ChgLine.Amount
).
140 IF RentChargeLine.RentChargeLineStatus
= "C"
141 AND RentChargeLine.StartDate
<= active-date
142 AND (RentChargeLine.EndDate
>= active-date
OR RentChargeLine.EndDate
= ?
)
144 annual-charge
= annual-charge
+ get-charge
( active-date
, end-date
,
145 RentChargeLine.StartDate
, RentChargeLine.EndDate
,
146 RentChargeLine.FrequencyCode
, RentChargeLine.Amount
).
150 IF annual-charge
<> RentCharge.CurrentAnnualRental
THEN DO:
151 ON WRITE OF RentCharge
OVERRIDE DO: END.
152 ON WRITE OF RentChargeLine
OVERRIDE DO: END.
153 FIND CURRENT RentCharge
EXCLUSIVE-LOCK.
154 RentCharge.CurrentAnnualRental
= annual-charge.
155 FIND CURRENT RentCharge
NO-LOCK.
156 ON WRITE OF RentChargeLine
REVERT.
157 ON WRITE OF RentCharge
REVERT.
162 /* _UIB-CODE-BLOCK-END
*/
166 /* ************************ Function Implementations
***************** */
168 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION get-annual-amount Procedure
169 FUNCTION get-annual-amount
RETURNS DECIMAL
170 ( INPUT period-amount
AS DEC, INPUT freq-type
AS CHAR ) :
171 /*------------------------------------------------------------------------------
174 ------------------------------------------------------------------------------*/
175 DEF VAR annual-amount
AS DEC NO-UNDO.
177 FIND FrequencyType
WHERE FrequencyType.FrequencyCode
= freq-type
NO-LOCK.
179 annual-amount
= ((period-amount
/ FrequencyType.UnitCount
) * (IF FrequencyType.RepeatUnits
BEGINS "D" THEN 365 ELSE 12)).
181 RETURN annual-amount.
185 /* _UIB-CODE-BLOCK-END
*/
189 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION get-charge Procedure
190 FUNCTION get-charge
RETURNS DECIMAL
191 ( INPUT active-date
AS DATE, INPUT end-date
AS DATE, INPUT d-from
AS DATE, INPUT upto
AS DATE, INPUT freq
AS CHAR, INPUT amount
AS DEC ) :
192 /*------------------------------------------------------------------------------
193 Purpose
: Get the charge for the period
195 ------------------------------------------------------------------------------*/
196 DEF VAR active-days
AS DEC NO-UNDO.
197 DEF VAR month-days
AS DEC NO-UNDO.
199 month-days
= (end-date
- active-date
) + 1.
200 active-days
= month-days.
201 IF d-from
> active-date
OR (upto
< end-date
) THEN DO:
202 IF d-from
> active-date
THEN active-days
= active-days
- (d-from
- active-date
).
203 IF upto
< end-date
THEN active-days
= active-days
- (end-date
- upto
).
204 amount
= amount
* (active-days
/ month-days
).
207 RETURN get-annual-amount
( amount
, freq
).
211 /* _UIB-CODE-BLOCK-END
*/