1 &ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12
3 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS Method-Library
4 /*--------------------------------------------------------------------------
6 Purpose
: Common functions for handling rent charge structures
9 ====== ========= ============================================
10 Tyrone McAuley
5/12/1997 Written
11 Andrew McMillan
15/5/1998 Severely hacked until it actually works
!
12 Andrew McMillan
16/7/1998 Added RentCharge-Outgoings functionality for AmTrust
13 Andrew McMillan
9/9/1998 Added 'rent-charge-one-period' option which is used
14 by some callers to tell the program to charge a single
15 month ignoring whether it's already charged.
16 Andrew McMillan
12/4/2000 Added 'show-override-descriptions' option which is
17 used by the rental advice program to get all descriptions.
18 Andrew McMillan
12/4/2000 Added 'use-past-charges' option which lets you calculate
19 charges as they were As At some time past.
20 ------------------------------------------------------------------------*/
22 DEF VAR annual-outgoings-charges
AS DEC NO-UNDO.
23 DEF VAR rent-charge-one-period
AS LOGI
NO-UNDO INITIAL No.
24 DEF VAR allow-past-leases
AS LOGI
NO-UNDO INITIAL No.
25 DEF VAR show-override-descriptions
AS LOGI
NO-UNDO INITIAL No.
26 DEF VAR check-lease-inclusion
AS LOGI
NO-UNDO INITIAL No.
27 DEF VAR use-past-charges
AS LOGI
NO-UNDO INITIAL No.
29 DEF TEMP-TABLE ChargeDetail
NO-UNDO
31 FIELD TenantCode
LIKE Tenant.TenantCode
32 FIELD ChargeType
LIKE RentChargeType.RentChargeType
33 FIELD Description
LIKE RentCharge.Description
34 FIELD ChargeSeq
LIKE RentCharge.Sequence
35 FIELD ChargeStart
LIKE RentChargeLine.StartDate
36 FIELD ChargeAmount
LIKE RentChargeLine.Amount
37 FIELD AnnualAmount
LIKE RentChargeLine.Amount
38 FIELD PeriodFraction
AS DECIMAL
39 FIELD TaxableAmount
LIKE RentChargeLine.Amount
40 FIELD EntityType
LIKE AcctTran.EntityType
41 FIELD EntityCode
LIKE AcctTran.EntityCode
42 FIELD AccountCode
LIKE AcctTran.AccountCode
43 FIELD AreaDescription
LIKE TenancyLease.AreaDescription
44 FIELD TenancyLeaseCode
LIKE TenancyLease.TenancyLeaseCode
45 FIELD ChargedFrom
AS DATE
46 FIELD ChargedUpTo
AS DATE
47 FIELD ChargeEnd
LIKE RentChargeLine.EndDate
49 INDEX ChargeDetail
IS PRIMARY
57 INDEX XAKRentCharge
IS UNIQUE
61 DEF VAR charge-detail-seq
AS INT NO-UNDO.
64 {inc
/ofc-set.i
"RentCharge-Outgoings" "og-method"}
65 IF NOT AVAILABLE(OfficeSetting
) THEN og-method
= "".
66 {inc
/ofc-set.i
"RentCharge-OG-By-Lease" "charge-og-lease"}
67 IF NOT AVAILABLE(OfficeSetting
) THEN charge-og-lease
= "Yes".
68 IF NOT AVAILABLE(OfficeSetting
) THEN og-method
= "".
69 {inc
/ofc-set-l.i
"RentCharge-PartMonth-Annual" "part-month-annual"}
70 IF NOT AVAILABLE(OfficeSetting
) THEN part-month-annual
= Yes.
72 {inc
/ofc-set.i
"GST-Types-Never" "gst-types-never"}
73 {inc
/ofc-set.i
"GST-Types-Always" "gst-types-always"}
75 /* _UIB-CODE-BLOCK-END
*/
79 &ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
81 /* ******************** Preprocessor Definitions
******************** */
83 &Scoped-define PROCEDURE-TYPE Method-Library
84 &Scoped-define DB-AWARE no
88 /* _UIB-PREPROCESSOR-BLOCK-END
*/
92 /* ************************ Function Prototypes
********************** */
94 &IF DEFINED(EXCLUDE-can-commit-charge) = 0 &THEN
96 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD can-commit-charge Method-Library
97 FUNCTION can-commit-charge
RETURNS LOGICAL
98 ( INPUT lease-code
AS INT, INPUT sequence-code
AS INT, INPUT start-date
AS DATE ) FORWARD.
100 /* _UIB-CODE-BLOCK-END
*/
105 &IF DEFINED(EXCLUDE-get-annual-outgoings) = 0 &THEN
107 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD get-annual-outgoings Method-Library
108 FUNCTION get-annual-outgoings
RETURNS DECIMAL
109 ( INPUT lease-code
AS INT ) FORWARD.
111 /* _UIB-CODE-BLOCK-END
*/
116 &IF DEFINED(EXCLUDE-not-can-action-rent-review) = 0 &THEN
118 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD not-can-action-rent-review Method-Library
119 FUNCTION not-can-action-rent-review
RETURNS LOGICAL
120 ( INPUT lease-code
AS INT, INPUT sequence-code
AS INT, INPUT start-date
AS DATE ) FORWARD.
122 /* _UIB-CODE-BLOCK-END
*/
128 /* *********************** Procedure Settings
************************ */
130 &ANALYZE-SUSPEND _PROCEDURE-SETTINGS
131 /* Settings for
THIS-PROCEDURE
135 Add Fields to
: Neither
136 Other Settings
: CODE-ONLY
138 &ANALYZE-RESUME _END-PROCEDURE-SETTINGS
140 /* ************************* Create Window
************************** */
142 &ANALYZE-SUSPEND _CREATE-WINDOW
143 /* DESIGN Window definition
(used by the UIB
)
144 CREATE WINDOW Method-Library
ASSIGN
147 /* END WINDOW DEFINITION
*/
151 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _INCLUDED-LIB Method-Library
152 /* ************************* Included-Libraries
*********************** */
156 /* _UIB-CODE-BLOCK-END
*/
163 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Method-Library
166 /* *************************** Main Block
*************************** */
168 /* _UIB-CODE-BLOCK-END
*/
172 /* ********************** Internal Procedures
*********************** */
174 &IF DEFINED(EXCLUDE-add-charge-detail) = 0 &THEN
176 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE add-charge-detail Method-Library
177 PROCEDURE add-charge-detail
:
178 /*------------------------------------------------------------------------------
180 ------------------------------------------------------------------------------*/
181 DEF INPUT PARAMETER tenant-code
LIKE Tenant.TenantCode
NO-UNDO.
182 DEF INPUT PARAMETER charge-type
LIKE RentChargeType.RentChargeType
NO-UNDO.
183 DEF INPUT PARAMETER entity-type
LIKE AcctTran.EntityType
NO-UNDO.
184 DEF INPUT PARAMETER entity-code
LIKE AcctTran.EntityCode
NO-UNDO.
185 DEF INPUT PARAMETER account-code
LIKE AcctTran.AccountCode
NO-UNDO.
186 DEF INPUT PARAMETER description
LIKE RentCharge.Description
NO-UNDO.
187 DEF INPUT PARAMETER lease-code
LIKE TenancyLease.TenancyLeaseCode
NO-UNDO.
188 DEF INPUT PARAMETER area-description
LIKE RentCharge.Description
NO-UNDO.
189 DEF INPUT PARAMETER charge-fraction
AS DECIMAL NO-UNDO.
190 DEF INPUT PARAMETER taxable
AS LOGICAL NO-UNDO.
191 DEF INPUT PARAMETER charged-from
AS DATE NO-UNDO.
192 DEF INPUT PARAMETER charged-to
AS DATE NO-UNDO.
193 DEF INPUT PARAMETER freq-units
AS DEC NO-UNDO.
194 DEF INPUT PARAMETER freq-type
AS CHAR NO-UNDO.
196 DEF VAR annual-amount
AS DEC NO-UNDO.
197 DEF VAR period-amount
AS DEC NO-UNDO.
199 IF show-override-descriptions
AND AVAILABLE(RentCharge
) THEN DO:
200 IF RentCharge.Description
<> "" AND RentCharge.Description
<> ?
THEN
201 description
= /* RentChargeType.Description
+ " - " + */ RentCharge.Description.
203 IF CAN-DO( gst-types-always
, charge-type
) THEN taxable
= YES.
204 ELSE IF CAN-DO( gst-types-never
, charge-type
) THEN taxable
= NO.
206 IF og-method
<> "" AND og-method
= RentCharge.RentChargeType
207 AND charge-og-lease
<> "Charge"
209 annual-amount
= annual-outgoings-charges
210 period-amount
= ((annual-amount
* freq-units
) / (IF freq-type
= "D" THEN 365 ELSE 12)).
212 period-amount
= RentChargeLine.Amount
213 annual-amount
= ((period-amount
/ freq-units
) * (IF freq-type
= "D" THEN 365 ELSE 12)).
216 ASSIGN ChargeDetail.Sequence
= charge-detail-seq
217 ChargeDetail.TenantCode
= tenant-code
218 ChargeDetail.ChargeType
= charge-type
219 ChargeDetail.ChargeSeq
= RentCharge.Sequence
220 ChargeDetail.ChargeStart
= RentChargeLine.StartDate
221 ChargeDetail.Description
= description
222 ChargeDetail.AreaDescription
= area-description
223 ChargeDetail.EntityType
= entity-type
224 ChargeDetail.EntityCode
= entity-code
225 ChargeDetail.AccountCode
= account-code
226 ChargeDetail.TenancyLeaseCode
= lease-code
227 ChargeDetail.ChargeAmount
= ROUND( charge-fraction
* period-amount
, 2)
228 ChargeDetail.TaxableAmount
= (IF taxable
THEN ChargeDetail.ChargeAmount
ELSE 0)
229 ChargeDetail.PeriodFraction
= charge-fraction
230 ChargeDetail.AnnualAmount
= annual-amount
231 ChargeDetail.ChargedFrom
= charged-from
232 ChargeDetail.ChargedUpTo
= charged-to
233 ChargeDetail.ChargeEnd
= RentChargeLine.EndDate.
235 charge-detail-seq
= charge-detail-seq
+ 1.
238 /* _UIB-CODE-BLOCK-END
*/
243 &IF DEFINED(EXCLUDE-build-daily-charges) = 0 &THEN
245 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE build-daily-charges Method-Library
246 PROCEDURE build-daily-charges
:
247 /*------------------------------------------------------------------------------
251 ------------------------------------------------------------------------------*/
252 DEF INPUT PARAMETER tenant-code
AS INT NO-UNDO.
253 DEF INPUT PARAMETER tenant-et
AS CHAR NO-UNDO.
254 DEF INPUT PARAMETER tenant-ec
AS INT NO-UNDO.
255 DEF INPUT PARAMETER lease-code
AS INT NO-UNDO.
256 DEF INPUT PARAMETER lease-desc
AS CHAR NO-UNDO.
257 DEF INPUT PARAMETER lease-tax
AS LOGI
NO-UNDO.
258 DEF INPUT PARAMETER start-day
AS DATE NO-UNDO.
259 DEF INPUT PARAMETER stop-day
AS DATE NO-UNDO.
261 DEF VAR period-fraction
AS DEC NO-UNDO.
262 DEF VAR taxable-amount
AS DEC NO-UNDO.
263 DEF VAR rent-end-day
AS DATE NO-UNDO.
264 DEF VAR freq-units
AS INT NO-UNDO.
265 DEF VAR paid-up-to
AS DATE NO-UNDO.
266 DEF VAR this-pay-date
AS DATE NO-UNDO.
267 DEF VAR next-pay-date
AS DATE NO-UNDO.
268 DEF VAR amount-multiplier
AS INT NO-UNDO INITIAL 1.
270 freq-units
= get-freq-days
( RentChargeLine.FrequencyCode
).
271 IF start-day
> stop-day
THEN DO:
272 /* rent-end-day is used as temp variable
, but later it's value is correct
! */
273 rent-end-day
= start-day.
274 start-day
= stop-day.
275 stop-day
= rent-end-day.
276 amount-multiplier
= -1.
279 rent-end-day
= (IF RentChargeLine.EndDate
= ?
THEN TODAY + 1000000 ELSE RentChargeLine.EndDate
).
281 this-pay-date
= start-day.
282 DO WHILE this-pay-date
<= stop-day
:
283 next-pay-date
= next-date-after
( RentChargeLine.StartDate
, this-pay-date
+ 1, "D", freq-units
).
284 paid-up-to
= MINIMUM( next-pay-date
- 1, rent-end-day
).
286 /* This should work right for part-period charges
*/
287 period-fraction
= (((paid-up-to
- this-pay-date
) + 1) / freq-units
).
289 RUN add-charge-detail
( tenant-code
, RentCharge.RentChargeType
,
290 (IF RentCharge.EntityType
<> "" THEN RentCharge.EntityType
ELSE tenant-et
),
291 (IF RentCharge.EntityType
<> "" THEN RentCharge.EntityCode
ELSE tenant-ec
),
292 (IF CAN-FIND( FIRST ChartOfAccount
OF RentCharge
) THEN RentCharge.AccountCode
ELSE RentChargeType.AccountCode
),
293 (IF RentCharge.RentChargeType
<> "S" THEN RentChargeType.Description
ELSE RentCharge.Description
),
294 lease-code
, lease-desc
, amount-multiplier
* period-fraction
,
295 lease-tax
, this-pay-date
, paid-up-to
, freq-units
, "D" ).
297 this-pay-date
= next-pay-date.
299 IF rent-charge-one-period
THEN this-pay-date
= stop-day
+ 1.
304 /* _UIB-CODE-BLOCK-END
*/
309 &IF DEFINED(EXCLUDE-build-monthly-charges) = 0 &THEN
311 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE build-monthly-charges Method-Library
312 PROCEDURE build-monthly-charges
:
313 /*------------------------------------------------------------------------------
314 Purpose
: Build monthly charges
315 ------------------------------------------------------------------------------*/
316 DEF INPUT PARAMETER tenant-code
AS INT NO-UNDO.
317 DEF INPUT PARAMETER tenant-et
AS CHAR NO-UNDO.
318 DEF INPUT PARAMETER tenant-ec
AS INT NO-UNDO.
319 DEF INPUT PARAMETER lease-code
AS INT NO-UNDO.
320 DEF INPUT PARAMETER lease-desc
AS CHAR NO-UNDO.
321 DEF INPUT PARAMETER lease-tax
AS LOGI
NO-UNDO.
322 DEF INPUT PARAMETER start-day
AS DATE NO-UNDO.
323 DEF INPUT PARAMETER stop-day
AS DATE NO-UNDO.
325 DEF VAR period-fraction
AS DEC NO-UNDO.
326 DEF VAR taxable-amount
AS DEC NO-UNDO.
327 DEF VAR rent-end-day
AS DATE NO-UNDO.
328 DEF VAR freq-units
AS INT NO-UNDO.
329 DEF VAR description
AS CHAR NO-UNDO.
330 DEF VAR paid-up-to
AS DATE NO-UNDO.
331 DEF VAR this-pay-date
AS DATE NO-UNDO.
332 DEF VAR next-pay-date
AS DATE NO-UNDO.
333 DEF VAR amount-multiplier
AS INT NO-UNDO INITIAL 1.
335 freq-units
= get-freq-months
( RentChargeLine.FrequencyCode
).
336 IF start-day
> stop-day
THEN DO:
337 /* rent-end-day is used as temp variable
, but later it's value is correct
! */
338 rent-end-day
= start-day.
339 start-day
= stop-day.
340 stop-day
= rent-end-day.
341 amount-multiplier
= -1.
344 rent-end-day
= (IF RentChargeLine.EndDate
= ?
THEN TODAY + 1000000 ELSE RentChargeLine.EndDate
).
346 this-pay-date
= start-day.
347 DO WHILE this-pay-date
<= stop-day
:
348 IF freq-units
= 1 THEN
349 next-pay-date
= next-date-after
( DATE(MONTH(this-pay-date
), 1, YEAR(this-pay-date
)), this-pay-date
+ 1, "M", freq-units
).
351 next-pay-date
= next-date-after
( this-pay-date
, this-pay-date
+ 1, "M", freq-units
).
353 paid-up-to
= MINIMUM( next-pay-date
- 1, rent-end-day
).
355 IF part-month-annual
THEN
356 period-fraction
= ((paid-up-to
- this-pay-date
+ 1) / 365 ) * 12.
358 period-fraction
= ((paid-up-to
- this-pay-date
+ 1) / month-days
(paid-up-to
) ).
360 IF period-fraction
< 0 THEN period-fraction
= 0.
361 ELSE IF period-fraction
> 1 THEN period-fraction
= 1.
362 IF DAY(this-pay-date
) = 1 AND paid-up-to
= last-of-month
(paid-up-to
) THEN period-fraction
= 1.
364 IF freq-units
> 1 THEN DO:
367 ELSE IF period-fraction
<> 1 AND freq-units
> 1 AND freq-units
< 12 THEN DO:
368 /* NOTE
: We are trying to handle a part-period correctly where the
*/
369 /* frequency is non-monthly. It should work out the number of whole
*/
370 /* months and charge a monthly amount for each
, then work out the
*/
371 /* part month charge as a fraction of that month.
*/
372 DEF VAR date-m1
AS DATE NO-UNDO.
373 DEF VAR date-m2
AS DATE NO-UNDO.
376 date-m1
= this-pay-date.
377 DO WHILE date-m1
< paid-up-to
:
378 date-m2
= next-date-after
( this-pay-date
, date-m1
+ 1, "M", 1).
379 IF date-m2
> paid-up-to
THEN DO:
380 period-fraction
= period-fraction
+ ((paid-up-to
- date-m1
+ 1) / (date-m2
- date-m1
)).
383 period-fraction
= period-fraction
+ 1 .
386 period-fraction
= period-fraction
/ freq-units.
389 MESSAGE start-day stop-day rent-end-day
SKIP
390 period-fraction RentChargeLine.Amount
393 description
= (IF RentCharge.RentChargeType
<> "S" THEN RentChargeType.Description
ELSE RentCharge.Description
).
395 RUN add-charge-detail
( tenant-code
, RentCharge.RentChargeType
,
396 (IF RentCharge.EntityType
<> "" THEN RentCharge.EntityType
ELSE tenant-et
),
397 (IF RentCharge.EntityType
<> "" THEN RentCharge.EntityCode
ELSE tenant-ec
),
398 (IF CAN-FIND( FIRST ChartOfAccount
OF RentCharge
) THEN RentCharge.AccountCode
ELSE RentChargeType.AccountCode
),
400 lease-code
, lease-desc
, amount-multiplier
* period-fraction
,
401 lease-tax
, this-pay-date
, paid-up-to
, freq-units
, "M" ).
402 this-pay-date
= next-pay-date.
404 IF rent-charge-one-period
THEN this-pay-date
= stop-day
+ 1.
409 /* _UIB-CODE-BLOCK-END
*/
414 &IF DEFINED(EXCLUDE-build-tenant-charges) = 0 &THEN
416 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE build-tenant-charges Method-Library
417 PROCEDURE build-tenant-charges
:
418 /*------------------------------------------------------------------------------
419 Purpose
: Build a list of the current tenant rental charges.
420 The list
( a temp table
) can be processed in a second pass
421 for charging to several accounts or a single account and
/or
422 for reporting purposes.
425 ------------------------------------------------------------------------------*/
426 DEF INPUT PARAMETER tenant-code
LIKE Tenant.TenantCode
NO-UNDO.
427 DEF INPUT PARAMETER period-start-date
AS DATE NO-UNDO.
428 DEF INPUT PARAMETER period-end-date
AS DATE NO-UNDO.
430 DEF BUFFER Lease
FOR TenancyLease.
431 DEF BUFFER L-Tenant
FOR Tenant.
432 DEF BUFFER OtherLine
FOR RentChargeLine.
434 RUN clear-charge-details.
436 /* First pass
- accumulate payable charegs into buckets
*/
437 DEF VAR start-day
AS DATE NO-UNDO.
438 DEF VAR stop-day
AS DATE NO-UNDO.
439 DEF VAR rent-end-day
AS DATE NO-UNDO.
441 FIND L-Tenant
WHERE L-Tenant.TenantCode
= tenant-code
NO-LOCK NO-ERROR.
442 IF NOT AVAILABLE(L-Tenant
) THEN DO:
443 MESSAGE "Could not find tenant " + STRING(tenant-code
).
446 IF L-Tenant.EntityType
<> "P" THEN RETURN.
447 FOR EACH Lease
NO-LOCK WHERE Lease.PropertyCode
= L-Tenant.EntityCode
448 AND Lease.TenantCode
= tenant-code
449 AND (Lease.LeaseStatus
<> "PAST" OR allow-past-leases
):
451 IF check-lease-inclusion
THEN
452 IF NOT include-lease
(Lease.TenancyLeaseCode
) THEN NEXT.
454 IF og-method
= "" OR charge-og-lease
= "Charge" THEN
455 annual-outgoings-charges
= 0.
457 annual-outgoings-charges
= get-annual-outgoings
(Lease.TenancyLeaseCode
).
460 FOR EACH RentCharge
OF Lease
NO-LOCK:
462 FIND RentChargeType
OF RentCharge
NO-LOCK NO-ERROR.
463 IF NOT AVAILABLE(RentChargeType
) THEN DO:
464 MESSAGE "Tenant" Lease.TenantCode
"has a rent charge of type ~"" RentCharge.RentChargeType "~
" which is not set up properly - ignored".
465 NEXT rent-charge-loop.
468 /* Calculate the current charges payable for the period
*/
469 rent-charge-line-loop
:
470 FOR EACH RentChargeLine
OF RentCharge
NO-LOCK
471 WHERE RentChargeLine.StartDate
<= period-end-date
:
473 IF use-past-charges
THEN DO:
474 IF RentChargeLine.EndDate
< period-start-date
THEN NEXT rent-charge-line-loop.
475 /* IF RentChargeLine.StartDate
> period-end-date
THEN NEXT rent-charge-line-loop.
*/
476 IF RentChargeLine.RentChargeLineStatus
<> "C"
477 AND RentChargeLine.RentChargeLineStatus
<> "P" THEN
478 NEXT rent-charge-line-loop.
480 ELSE IF RentChargeLine.RentChargeLineStatus
<> "C" THEN
481 NEXT rent-charge-line-loop.
483 IF NOT(rent-charge-one-period
) THEN DO:
484 IF RentChargeLine.LastChargedDate
<> ?
485 AND RentChargeLine.LastChargedDate
= RentChargeLine.EndDate
THEN DO:
486 IF NOT( CAN-FIND( FIRST OtherLine
OF RentCharge
WHERE OtherLine.RentChargeLineStatus
= "C"
487 AND OtherLine.StartDate
<= period-end-date
488 AND RECID(OtherLine
) <> RECID(RentChargeLine
) ))
489 THEN NEXT rent-charge-line-loop.
492 IF RentChargeLine.EndDate
= ?
AND RentChargeLine.LastChargedDate
<> ?
493 AND RentChargeLine.LastChargedDate
>= period-end-date
THEN DO:
494 NEXT rent-charge-line-loop.
497 IF RentChargeLine.EndDate
<> ?
THEN DO:
498 IF RentChargeLine.EndDate
< period-start-date
499 AND RentChargeLine.LastChargedDate
< period-start-date
THEN
500 NEXT rent-charge-line-loop.
501 IF RentChargeLine.EndDate
>= period-end-date
502 AND RentChargeLine.LastChargedDate
>= period-end-date
THEN
503 NEXT rent-charge-line-loop.
507 start-day
= period-start-date.
508 stop-day
= period-end-date.
509 IF RentChargeLine.StartDate
<> ?
THEN start-day
= MAXIMUM( start-day
, RentChargeLine.StartDate
).
511 IF RentChargeLine.LastChargedDate
<> ?
THEN start-day
= MAXIMUM( start-day
, (RentChargeLine.LastChargedDate
+ 1) ).
512 ELSE IF RentChargeLine.StartDate
<> ?
THEN start-day
= MINIMUM( start-day
, RentChargeLine.StartDate
).
514 IF RentChargeLine.EndDate
<> ?
THEN ASSIGN
515 stop-day
= MINIMUM( stop-day
, RentChargeLine.EndDate
).
517 IF RentChargeLine.EndDate
< RentChargeLine.LastChargedDate
THEN DO:
518 /* This means that something that was charged should be part credited
*/
519 stop-day
= RentChargeLine.EndDate
+ 1.
520 start-day
= RentChargeLine.LastChargedDate.
521 /* MESSAGE "Start:" start-day
" to " stop-day RentChargeLine.Amount RentChargeLine.StartDate RentChargeLine.LastChargedDate RentChargeLine.EndDate.
*/
524 IF start-day
= stop-day
THEN NEXT rent-charge-line-loop.
527 IF rent-charge-one-period
THEN DO:
528 IF RentChargeLine.EndDate
<> ?
AND RentChargeLine.EndDate
< period-end-date
529 AND CAN-FIND( LAST OtherLine
OF RentCharge
WHERE OtherLine.RentChargeLineStatus
= "C"
530 AND OtherLine.StartDate
<= period-end-date
531 AND OtherLine.EndDate
>= period-end-date
)
532 THEN NEXT rent-charge-line-loop.
533 start-day
= period-start-date.
534 stop-day
= period-end-date.
537 IF get-freq-months
( RentChargeLine.FrequencyCode
) <> ?
THEN
538 RUN build-monthly-charges
( tenant-code
, L-Tenant.EntityType
, L-Tenant.EntityCode
,
539 Lease.TenancyLeaseCode
, Lease.AreaDescription
, Lease.TaxApplies
,
540 start-day
, stop-day
).
541 ELSE IF get-freq-days
( RentChargeLine.FrequencyCode
) <> ?
THEN
542 RUN build-daily-charges
( tenant-code
, L-Tenant.EntityType
, L-Tenant.EntityCode
,
543 Lease.TenancyLeaseCode
, Lease.AreaDescription
, Lease.TaxApplies
,
544 start-day
, stop-day
).
546 MESSAGE "Bad frequency" RentChargeLine.FrequencyCode.
548 END.
/* Each Rent Charge Line
*/
549 END.
/* Each Rent Charge
*/
550 END.
/* Each Lease
*/
554 /* _UIB-CODE-BLOCK-END
*/
559 &IF DEFINED(EXCLUDE-clear-charge-details) = 0 &THEN
561 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE clear-charge-details Method-Library
562 PROCEDURE clear-charge-details
:
563 /*------------------------------------------------------------------------------
567 ------------------------------------------------------------------------------*/
569 FOR EACH ChargeDetail
: DELETE ChargeDetail.
END.
570 charge-detail-seq
= 0.
573 /* _UIB-CODE-BLOCK-END
*/
578 &IF DEFINED(EXCLUDE-commit-charge-entry) = 0 &THEN
580 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE commit-charge-entry Method-Library
581 PROCEDURE commit-charge-entry
:
582 /*------------------------------------------------------------------------------
583 Purpose
: Commits a charge entry for charging
:
584 RentChargeLineStatus
= C
- Chargeable
586 ------------------------------------------------------------------------------*/
588 DEF INPUT PARAMETER lease-code
LIKE RentChargeLine.TenancyLeaseCode
NO-UNDO.
589 DEF INPUT PARAMETER sequence-code
LIKE RentChargeLine.SequenceCode
NO-UNDO.
590 DEF INPUT PARAMETER start-date
LIKE RentChargeLine.StartDate
NO-UNDO.
592 DEF BUFFER ThisChargeEntry
FOR RentChargeLine.
593 DEF BUFFER LastChargeEntry
FOR RentChargeLine.
595 IF NOT can-commit-charge
( lease-code
, sequence-code
, start-date
) THEN RETURN "FAIL".
598 WHERE ThisChargeEntry.TenancyLeaseCode
= lease-code
599 AND ThisChargeEntry.SequenceCode
= sequence-code
600 AND ThisChargeEntry.StartDate
= start-date
601 EXCLUSIVE-LOCK NO-ERROR.
602 IF NOT AVAILABLE ThisChargeEntry
THEN RETURN "FAIL".
604 /* Set the end date of the last existing chargeable line
*/
606 FIND FIRST LastChargeEntry
607 WHERE LastChargeEntry.TenancyLeaseCode
= lease-code
608 AND LastChargeEntry.SequenceCode
= sequence-code
609 AND LastChargeEntry.RentChargeLineStatus
= "C"
610 AND LastChargeEntry.EndDate
= ?
611 AND ROWID( LastChargeEntry
) <> ROWID( ThisChargeEntry
)
612 EXCLUSIVE-LOCK NO-ERROR.
614 IF AVAILABLE LastChargeEntry
THEN DO:
616 IF ThisChargeEntry.StartDate
> LastChargeEntry.StartDate
THEN DO:
617 ASSIGN LastChargeEntry.EndDate
=
618 MAXIMUM( LastChargeEntry.StartDate
, ThisChargeEntry.StartDate
- 1 ).
621 IF ThisChargeEntry.EndDate
= ?
THEN DO:
622 IF LastChargeEntry.LastChargedDate
= ?
THEN
623 ASSIGN LastChargeEntry.RentChargeLineStatus
= "A".
/* Aborted
*/
626 LastChargeEntry.EndDate
= LastChargeEntry.LastChargedDate.
635 ThisChargeEntry.DateCommitted
= TODAY
636 ThisChargeEntry.RentChargeLineStatus
= "C".
640 /* _UIB-CODE-BLOCK-END
*/
645 &IF DEFINED(EXCLUDE-create-charge-entry) = 0 &THEN
647 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE create-charge-entry Method-Library
648 PROCEDURE create-charge-entry
:
649 /*------------------------------------------------------------------------------
650 Purpose
: Schedule a charging entry for the given charge
651 ------------------------------------------------------------------------------*/
653 DEF INPUT PARAMETER lease-code
LIKE RentChargeLine.TenancyLeaseCode
NO-UNDO.
654 DEF INPUT PARAMETER sequence-code
LIKE RentChargeLine.SequenceCode
NO-UNDO.
656 DEF INPUT PARAMETER start-date
LIKE RentChargeLine.StartDate
NO-UNDO.
657 DEF INPUT PARAMETER end-date
LIKE RentChargeLine.EndDate
NO-UNDO.
658 DEF INPUT PARAMETER freq-code
LIKE RentChargeLine.FrequencyCode
NO-UNDO.
659 DEF INPUT PARAMETER charge-amount
LIKE RentChargeLine.Amount
NO-UNDO.
661 FIND TenancyLease
WHERE TenancyLease.TenancyLeaseCode
= lease-code
663 IF NOT AVAILABLE TenancyLease
THEN RETURN.
666 WHERE RentCharge.TenancyLeaseCode
= lease-code
667 AND RentCharge.SequenceCode
= sequence-code
670 IF NOT AVAILABLE RentCharge
THEN RETURN "FAIL".
672 CREATE RentChargeLine.
674 RentChargeLine.TenancyLeaseCode
= lease-code
675 RentChargeLine.SequenceCode
= sequence-code
676 RentChargeLine.RentChargeLineStatus
= "I"
677 RentChargeLine.StartDate
= start-date
678 RentChargeLine.EndDate
= end-date
679 RentChargeLine.FrequencyCode
=
680 IF freq-code
<> ?
THEN freq-code
ELSE
681 IF AVAILABLE TenancyLease
THEN TenancyLease.PaymentFrequency
683 RentChargeLine.Amount
= charge-amount.
687 /* _UIB-CODE-BLOCK-END
*/
692 &IF DEFINED(EXCLUDE-make-blurb) = 0 &THEN
694 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE make-blurb Method-Library
695 PROCEDURE make-blurb
:
696 /*------------------------------------------------------------------------------
698 ------------------------------------------------------------------------------*/
699 DEF INPUT PARAMETER descriptive-word
AS CHAR NO-UNDO.
700 DEF INPUT PARAMETER period-d1
AS DATE NO-UNDO.
701 DEF INPUT PARAMETER period-dn
AS DATE NO-UNDO.
702 DEF OUTPUT PARAMETER inv-blurb
AS CHAR NO-UNDO.
703 DEF OUTPUT PARAMETER inv-amount
AS DEC NO-UNDO.
704 DEF OUTPUT PARAMETER inv-tax
AS DEC NO-UNDO.
705 DEF OUTPUT PARAMETER inv-total
AS DEC NO-UNDO.
707 inv-blurb
= "Rental " + descriptive-word
708 + " for the period from " + STRING( period-d1
, "99/99/9999")
709 + " to " + STRING( period-dn
, "99/99/9999") + "~n".
713 FOR EACH ChargeDetail
:
714 inv-total
= inv-total
+ ChargeDetail.ChargeAmount.
715 inv-tax
= inv-tax
+ ChargeDetail.TaxableAmount.
716 inv-blurb
= inv-blurb
+ "~n"
717 + SUBSTR( STRING( ChargeDetail.ChargedFrom
, "99/99/9999"), 1, 5)
719 + SUBSTR( STRING( ChargeDetail.ChargedUpTo
, "99/99/9999"), 1, 5) + " "
720 + STRING( ChargeDetail.AreaDescription
, "X(33)") + " "
721 + STRING( (IF ChargeDetail.PeriodFraction
< 0 THEN "Reverse " ELSE "")
722 + ChargeDetail.Description
724 + TRIM(STRING( ChargeDetail.AnnualAmount
, ">>>,>>>,>>9.99CR" ))
726 + STRING( ChargeDetail.ChargeAmount
, "(>,>>>,>>9.99)" ).
729 inv-tax
= inv-tax
* (Office.GST
/ 100).
730 inv-amount
= inv-total
+ inv-tax.
731 inv-blurb
= inv-blurb
+ "~n~n~n".
735 /* _UIB-CODE-BLOCK-END
*/
740 /* ************************ Function Implementations
***************** */
742 &IF DEFINED(EXCLUDE-can-commit-charge) = 0 &THEN
744 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION can-commit-charge Method-Library
745 FUNCTION can-commit-charge
RETURNS LOGICAL
746 ( INPUT lease-code
AS INT, INPUT sequence-code
AS INT, INPUT start-date
AS DATE ) :
747 /*------------------------------------------------------------------------------
748 Purpose
: Detremines whether or not a charge entry can be committed for
751 ------------------------------------------------------------------------------*/
753 IF start-date
= ?
THEN RETURN No.
755 DEF BUFFER ChargeEntry
FOR RentChargeLine.
757 FIND ChargeEntry
WHERE ChargeEntry.TenancyLeaseCode
= lease-code
758 AND ChargeEntry.SequenceCode
= sequence-code
759 AND ChargeEntry.StartDate
= start-date
761 IF NOT AVAILABLE ChargeEntry
THEN RETURN No.
763 RETURN( ChargeEntry.Amount
<> 0 AND ChargeEntry.FrequencyCode
<> "" ).
767 /* _UIB-CODE-BLOCK-END
*/
772 &IF DEFINED(EXCLUDE-get-annual-outgoings) = 0 &THEN
774 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION get-annual-outgoings Method-Library
775 FUNCTION get-annual-outgoings
RETURNS DECIMAL
776 ( INPUT lease-code
AS INT ) :
777 /*------------------------------------------------------------------------------
778 Purpose
: Calculate the estimated annual outgoings charges
780 ------------------------------------------------------------------------------*/
781 DEF BUFFER Lse
FOR TenancyLease.
782 DEF BUFFER Prp
FOR Property.
783 DEF BUFFER Pog
FOR PropertyOutgoing.
784 DEF BUFFER Tnt
FOR Tenant.
785 DEF BUFFER Tog
FOR TenancyOutgoing.
787 IF og-method
= "" THEN RETURN 0.0.
788 FIND Lse
WHERE Lse.TenancyLeaseCode
= lease-code
NO-LOCK NO-ERROR.
789 IF NOT AVAILABLE(Lse
) THEN DO:
790 MESSAGE "Lease " + STRING(lease-code
) + " not on file." .
794 IF charge-og-lease
BEGINS "Y" THEN RETURN Lse.OutgoingsBudget.
795 ELSE IF Lse.RecoveryType
= "F" THEN RETURN Lse.OutgoingsBudget.
796 ELSE IF Lse.RecoveryType
= "A" THEN RETURN 0.0 .
797 ELSE IF Lse.RecoveryType
<> "B" THEN DO:
798 MESSAGE "Invalid recovery type '" Lse.RecoveryType
"'for lease " + STRING(lease-code
).
802 DEF VAR fixed
AS DEC NO-UNDO.
803 DEF VAR percent
AS DEC NO-UNDO.
804 DEF VAR amount
AS DEC NO-UNDO INITIAL 0.0 .
805 FOR EACH Pog
WHERE Pog.PropertyCode
= Lse.PropertyCode
NO-LOCK:
806 FIND Tog
WHERE Tog.TenancyLeaseCode
= lease-code
807 AND Tog.AccountCode
= Pog.AccountCode
NO-LOCK NO-ERROR.
810 IF AVAILABLE(Tog
) THEN DO:
811 IF Tog.FixedAmount
> 0 THEN
812 fixed
= ROUND(Tog.FixedAmount
/ 12, 2).
814 percent
= Tog.Percentage.
817 percent
= Lse.OutgoingsRate.
819 IF percent
= ?
THEN percent
= 0.
820 IF Pog.BudgetAmount
= ?
THEN DO:
821 MESSAGE Pog.BudgetAmount
"is not a valid budget!".
824 amount
= amount
+ fixed
+ ROUND((percent
* Pog.BudgetAmount
) / 1200, 2).
827 FOR EACH Tog
WHERE Tog.TenancyLeaseCode
= lease-code
828 AND Tog.FixedAmount
> 0
829 AND NOT CAN-FIND( Pog
WHERE Pog.PropertyCode
= Lse.PropertyCode
830 AND Tog.AccountCode
= Pog.AccountCode
)
832 fixed
= ROUND(Tog.FixedAmount
/ 12, 2).
833 amount
= amount
+ fixed.
840 /* _UIB-CODE-BLOCK-END
*/
845 &IF DEFINED(EXCLUDE-not-can-action-rent-review) = 0 &THEN
847 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION not-can-action-rent-review Method-Library
848 FUNCTION not-can-action-rent-review
RETURNS LOGICAL
849 ( INPUT lease-code
AS INT, INPUT sequence-code
AS INT, INPUT start-date
AS DATE ) :
850 /*------------------------------------------------------------------------------
851 Purpose
: Detremines whether or not a rent review can be committed for
854 ------------------------------------------------------------------------------*/
856 IF start-date
= ?
THEN RETURN No.
858 DEF BUFFER Review
FOR RentReview.
861 WHERE Review.TenancyLeaseCode
= lease-code
862 /* AND Review.SequenceCode
= sequence-code
*/
863 /* AND Review.StartDate
= start-date
*/
865 IF NOT AVAILABLE Review
THEN RETURN No.
868 /* Review.Amount
<> 0 AND */
869 /* Review.DateCommitted
= ?
AND */
870 Review.DateComplete
<> ?
AND
871 Review.EstimateBasis
<> "" AND
872 /* Review.FrequencyCode
<> "" AND */
873 /* Review.LastChargedDate
= ?
AND */
874 Review.ReviewStatus
<> "C" AND
875 Review.ReviewStatus
<> "" AND
876 Review.ReviewType
<> ""
878 /* Review.DateDue
<> ?
886 /* _UIB-CODE-BLOCK-END
*/