Add missing brackets.
[capital-apms-progress.git] / process / rentchg.p
blob5e7569e1b20f6a1c3eaaa2dc5bc386f73621cc74
1 &ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12
2 &ANALYZE-RESUME
3 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS Procedure
4 /*--------------------------------------------------------------------------
5 File : rentchg.p
6 Purpose : Create monthly charges for Rent and Outgoings
7 Author(s) : Andrew McMillan
8 Created : 27/11/96
9 ------------------------------------------------------------------------*/
10 DEF INPUT PARAMETER process-options AS CHAR NO-UNDO.
12 DEF VAR charge-type AS CHAR NO-UNDO.
13 DEF VAR charge-period LIKE Month.MonthCode NO-UNDO.
14 DEF VAR preview AS LOGICAL NO-UNDO.
15 DEF VAR frequency-list AS CHAR NO-UNDO.
16 RUN parse-options.
18 DEF VAR this-document LIKE NewDocument.DocumentCode NO-UNDO.
19 DEF VAR this-transaction LIKE NewAcctTrans.TransactionCode NO-UNDO.
20 DEF VAR debit-total LIKE AcctTran.Amount NO-UNDO.
21 DEF VAR og-total LIKE AcctTran.Amount NO-UNDO.
22 DEF VAR rent-total LIKE AcctTran.Amount NO-UNDO.
23 DEF VAR tax-total LIKE AcctTran.Amount NO-UNDO.
24 DEF VAR untaxed-total LIKE AcctTran.Amount NO-UNDO.
25 DEF VAR tax-amount LIKE AcctTran.Amount NO-UNDO.
26 DEF VAR property-total LIKE AcctTran.Amount NO-UNDO.
27 DEF VAR tenant-total LIKE AcctTran.Amount NO-UNDO.
28 DEF VAR rent-description AS CHAR NO-UNDO.
29 DEF VAR og-description AS CHAR NO-UNDO.
30 DEF VAR line AS CHAR NO-UNDO.
31 DEF VAR i AS INT NO-UNDO.
32 DEF VAR rows AS INT NO-UNDO.
33 DEF VAR cols AS INT NO-UNDO.
34 DEF VAR last-property AS INT INITIAL -1 NO-UNDO.
35 DEF VAR partial-period AS LOGICAL INITIAL No NO-UNDO.
38 {inc/ofc-this.i}
39 {inc/ofc-acct.i "DEBTORS" "sundry-debtors"}
40 {inc/ofc-acct.i "RENT" "rent-account"}
41 {inc/ofc-acct.i "OUTGOINGS" "og-account"}
42 DEF VAR gst-entity LIKE AcctTran.EntityCode NO-UNDO.
43 IF Office.GST <> ? THEN DO:
44 {inc/ofc-acct.i "GST-OUT" "gst-account"}
45 gst-entity = OfficeControlAccount.EntityCode.
46 END.
47 {inc/ofc-set.i "RentCharge-Type" "set-type"}
48 IF set-type <> "Accounts" THEN set-type = "Single".
49 {inc/ofc-set.i "RentCharge-Sequence" "set-sequence"}
50 IF set-sequence <> "PropertyCode" AND set-sequence <> "TenantCode" THEN
51 set-sequence = "Region".
52 {inc/ofc-set.i "RentCharge-Partial" "set-partial"}
53 {inc/ofc-set-l.i "GST-Multi-Company" "GST-Multi-Company" }
56 DEF VAR rent-charge-routine AS CHAR NO-UNDO.
57 rent-charge-routine = "charge-rental-" + set-type.
58 IF THIS-PROCEDURE:GET-SIGNATURE( rent-charge-routine ) = "" THEN DO:
59 MESSAGE "The rent charge type '" + set-type "' is not valid." SKIP(1)
60 "Set it to 'Single' or 'Accounts'"
61 VIEW-AS ALERT-BOX TITLE "Invalid RentCharge-Type setting for office.".
62 RETURN.
63 END.
65 DEF VAR batch-string AS CHAR NO-UNDO.
66 DEF VAR date-string AS CHAR NO-UNDO.
67 FIND Month WHERE Month.MonthCode = charge-period NO-LOCK.
68 batch-string = (IF INDEX( charge-type, "R") > 0 THEN "Rent" ELSE "").
69 IF INDEX( charge-type, "O") > 0 THEN
70 batch-string = batch-string + (IF INDEX( charge-type, "R") > 0 THEN " & " ELSE "") + "Outgoings".
71 batch-string = batch-string + " to " + STRING( Month.EndDate, "99/99/9999").
73 date-string = " " + STRING( Month.StartDate, "99/99/9999") + " to " + STRING( Month.EndDate, "99/99/9999").
74 DEF VAR tenant-date-string AS CHAR NO-UNDO.
76 DEF VAR user-name AS CHAR NO-UNDO.
77 {inc/username.i "user-name"}
78 FIND Usr WHERE Usr.UserName = user-name NO-LOCK NO-ERROR.
80 /* Doing this here ensures that Batch is scoped to the whole program */
81 DEF VAR batch-code LIKE NewBatch.BatchCode NO-UNDO.
82 FIND LAST Batch NO-LOCK NO-ERROR.
83 batch-code = 1 + (IF AVAILABLE(Batch) THEN Batch.BatchCode ELSE 0).
84 FIND LAST NewBatch NO-LOCK NO-ERROR.
85 IF AVAILABLE(NewBatch) AND NewBatch.BatchCode >= batch-code THEN batch-code = NewBatch.BatchCode + 1.
86 IF NOT preview THEN DO:
87 CREATE NewBatch.
88 ASSIGN
89 NewBatch.BatchCode = batch-code
90 NewBatch.BatchType = "AUTO"
91 NewBatch.Description = batch-string
92 NewBatch.PersonCode = (IF AVAILABLE(Usr) THEN Usr.PersonCode ELSE 0)
93 NewBatch.DocumentCount = 0
94 NewBatch.Total = 0
96 END.
98 /* Doing this here ensures that NewAcctTrans is scoped to the whole program */
99 FIND FIRST NewAcctTrans NO-LOCK NO-ERROR.
101 &SCOPED-DEFINE page-width 180
102 &SCOPED-DEFINE with-clause NO-BOX USE-TEXT NO-LABELS WIDTH {&page-width}
104 DEF VAR timeStamp AS CHAR FORMAT "X(44)" NO-UNDO.
105 timeStamp = STRING( TODAY, "99/99/9999") + ", " + STRING( TIME, "HH:MM:SS") + " for " + user-name.
106 DEF VAR hline2 AS CHAR FORMAT "X({&page-width})" NO-UNDO.
107 hline2 = "Rent Charge Preview: " + batch-string.
108 hline2 = SUBSTRING( STRING("","X({&page-width})"), 1, INTEGER(({&page-width} - LENGTH(hline2) ) / 2)) + hline2.
110 DEFINE FRAME heading-frame WITH 1 DOWN {&with-clause} PAGE-TOP.
111 FORM HEADER
112 timeStamp "Page " + STRING( PAGE-NUMBER ) TO {&page-width} SKIP (1)
113 hline2 FORMAT "X({&page-width})"
114 SKIP (1)
115 WITH FRAME heading-frame.
117 /* _UIB-CODE-BLOCK-END */
118 &ANALYZE-RESUME
121 &ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
123 /* ******************** Preprocessor Definitions ******************** */
125 &Scoped-define PROCEDURE-TYPE Procedure
126 &Scoped-define DB-AWARE no
130 /* _UIB-PREPROCESSOR-BLOCK-END */
131 &ANALYZE-RESUME
135 /* *********************** Procedure Settings ************************ */
137 &ANALYZE-SUSPEND _PROCEDURE-SETTINGS
138 /* Settings for THIS-PROCEDURE
139 Type: Procedure
140 Allow:
141 Frames: 0
142 Add Fields to: Neither
143 Other Settings: CODE-ONLY COMPILE
145 &ANALYZE-RESUME _END-PROCEDURE-SETTINGS
147 /* ************************* Create Window ************************** */
149 &ANALYZE-SUSPEND _CREATE-WINDOW
150 /* DESIGN Window definition (used by the UIB)
151 CREATE WINDOW Procedure ASSIGN
152 HEIGHT = 25.15
153 WIDTH = 39.72.
154 /* END WINDOW DEFINITION */
156 &ANALYZE-RESUME
158 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _INCLUDED-LIB Procedure
159 /* ************************* Included-Libraries *********************** */
161 {inc/method/m-txtrep.i}
163 /* _UIB-CODE-BLOCK-END */
164 &ANALYZE-RESUME
170 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Procedure
173 /* *************************** Main Block *************************** */
174 ON WRITE OF NewAcctTrans OVERRIDE DO: END.
175 ON WRITE OF NewDocument OVERRIDE DO: END.
177 RUN make-control-string ( "PCL", "reset,landscape,tm,1,a4,lm,4,courier,cpi,18,lpi,9",
178 OUTPUT line, OUTPUT rows, OUTPUT cols ).
180 RUN output-control-file ( line ).
181 OUTPUT TO VALUE(txtrep-print-file) KEEP-MESSAGES PAGE-SIZE VALUE(rows).
182 IF preview THEN VIEW FRAME heading-frame.
184 this-document = 0.
185 debit-total = 0.
187 &SCOPED-DEFINE F-E-DEFINITION ~
188 FOR EACH Property NO-LOCK ~
189 WHERE Property.Active AND (NOT Property.ExternallyManaged),~
190 EACH Tenant NO-LOCK~
191 WHERE Tenant.Active AND Tenant.EntityType = "P"~
192 AND Tenant.EntityCode = Property.PropertyCode~
193 AND CAN-FIND( FIRST TenancyLease~
194 WHERE TenancyLease.TenantCode = Tenant.TenantCode~
195 AND TenancyLease.LeaseStatus <> "PAST"~
196 AND CAN-FIND( FIRST RentalSpace OF TenancyLease WHERE RentalSpace.AreaStatus <> "V") )~
197 /* SCOPED-DEFINE ends */
199 IF set-sequence = "PropertyCode":U THEN DO:
200 {&F-E-DEFINITION} BY Property.PropertyCode BY Tenant.TenantCode:
201 RUN each-tenant.
202 END.
203 END.
204 ELSE IF set-sequence = "TenantCode":U THEN DO:
205 {&F-E-DEFINITION} BY Tenant.TenantCode:
206 RUN each-tenant.
207 END.
208 END.
209 ELSE DO:
210 {&F-E-DEFINITION} BY Property.Region BY Property.ShortName:
211 RUN each-tenant.
212 END.
213 END.
215 IF preview THEN DO:
217 RUN after-each-property( last-property, property-total ).
219 line = "".
220 RUN output-line.
221 line = "Total outgoings = " + STRING( og-total, "->>>,>>>,>>9.99").
222 RUN output-line.
223 line = "Total rentals = " + STRING( rent-total, "->>>,>>>,>>9.99").
224 RUN output-line.
225 line = "Total un-taxed = " + STRING( untaxed-total, "->>>,>>>,>>9.99").
226 RUN output-line.
227 line = "Total GST = " + STRING( tax-total, "->>>,>>>,>>9.99").
228 RUN output-line.
229 line = "".
230 RUN output-line.
231 line = "Total for batch = " + STRING( debit-total, "->>>,>>>,>>9.99").
232 RUN output-line.
233 OUTPUT CLOSE.
234 RUN view-output-file ( preview ).
235 END.
236 ELSE DO:
238 OUTPUT CLOSE.
240 OS-DELETE VALUE( txtrep-control-file ).
241 OS-DELETE VALUE( txtrep-print-file ).
243 ASSIGN
244 NewBatch.DocumentCount = this-document
245 NewBatch.Total = debit-total
247 END.
249 /* _UIB-CODE-BLOCK-END */
250 &ANALYZE-RESUME
253 /* ********************** Internal Procedures *********************** */
255 &IF DEFINED(EXCLUDE-after-each-property) = 0 &THEN
257 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE after-each-property Procedure
258 PROCEDURE after-each-property :
259 /*------------------------------------------------------------------------------
260 Purpose:
261 ------------------------------------------------------------------------------*/
262 DEF INPUT PARAMETER last-code AS INT NO-UNDO.
263 DEF INPUT PARAMETER total-amt AS DEC NO-UNDO.
265 IF last-code > -1 THEN DO:
266 line = "Total rental for P" + STRING(last-code,"99999") + " = " + STRING( total-amt, "->>>,>>>,>>9.99") + " " + STRING( (total-amt * 12), "->>>,>>>,>>9.99") + " p.a.".
267 RUN output-line.
268 line = "".
269 RUN output-line.
270 RUN output-line.
271 END.
273 IF AVAILABLE(Property) THEN DO:
274 line = STRING( Property.PropertyCode, "99999") + " "
275 + Property.Name .
276 RUN output-line.
277 line = FILL( "=", LENGTH(line)).
278 RUN output-line.
279 END.
281 END PROCEDURE.
283 /* _UIB-CODE-BLOCK-END */
284 &ANALYZE-RESUME
286 &ENDIF
288 &IF DEFINED(EXCLUDE-calculate-outgoings) = 0 &THEN
290 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE calculate-outgoings Procedure
291 PROCEDURE calculate-outgoings :
292 /*------------------------------------------------------------------------------
293 Purpose:
294 Parameters: <none>
295 Notes:
296 ------------------------------------------------------------------------------*/
297 DEF INPUT PARAMETER tenant-code LIKE Tenant.TenantCode NO-UNDO.
298 DEF OUTPUT PARAMETER TotalOutGoings AS DEC NO-UNDO INITIAL 0.
300 DEF VAR part-of-month AS DEC NO-UNDO.
301 DEF VAR og-amount AS DEC NO-UNDO.
303 FOR EACH TenancyLease WHERE TenancyLease.TenantCode = tenant-code
304 AND TenancyLease.PropertyCode = Property.PropertyCode
305 AND TenancyLease.LeaseStatus <> "PAST"
306 AND (TenancyLease.LeaseStartDate < Month.EndDate OR
307 TenancyLease.LeaseStartDate = ?) NO-LOCK:
308 RUN calculate-part-of-month( OUTPUT part-of-month).
309 og-amount = ROUND(((TenancyLease.OutgoingsBudget * part-of-month) / 12), 2).
310 TotalOutgoings = TotalOutgoings + og-amount.
311 END.
313 END PROCEDURE.
315 /* _UIB-CODE-BLOCK-END */
316 &ANALYZE-RESUME
318 &ENDIF
320 &IF DEFINED(EXCLUDE-calculate-part-of-month) = 0 &THEN
322 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE calculate-part-of-month Procedure
323 PROCEDURE calculate-part-of-month :
324 /*------------------------------------------------------------------------------
325 Purpose: Calculate the portion of the month for which rent is due.
326 ------------------------------------------------------------------------------*/
327 DEF OUTPUT PARAMETER part-of-month AS DECIMAL NO-UNDO.
329 /* 27 days = 2219.18 (where full month = $2500) */
331 DEF VAR start-day AS DATE NO-UNDO.
332 DEF VAR stop-day AS DATE NO-UNDO.
333 DEF VAR month-days AS INT NO-UNDO.
334 month-days = (Month.EndDate - Month.StartDate) + 1.
336 ASSIGN part-of-month = 1
337 stop-day = Month.EndDate
338 start-day = Month.StartDate.
340 IF TenancyLease.RentEndDate <> ? THEN stop-day = MINIMUM( stop-day, TenancyLease.RentEndDate ).
342 IF TenancyLease.FirstLeaseStart <> ? THEN start-day = MAXIMUM( start-day, TenancyLease.FirstLeaseStart ).
343 ELSE IF TenancyLease.LeaseStartDate <> ? THEN start-day = MAXIMUM( start-day, TenancyLease.LeaseStartDate ).
344 IF TenancyLease.RentStartDate <> ? THEN start-day = MAXIMUM( start-day, TenancyLease.RentStartDate ).
346 IF start-day = Month.StartDate AND stop-day = Month.EndDate THEN RETURN.
348 part-of-month = ((1 + stop-day - start-day) / 365 ) * 12.
349 IF part-of-month >= 1 THEN
350 part-of-month = 1.
351 ELSE IF part-of-month <= 0 THEN
352 part-of-month = 0.
354 /* IF we're set to not do it then just return with part = 1 */
355 IF set-partial = "No" AND part-of-month <> 0 THEN ASSIGN
356 start-day = Month.StartDate
357 stop-day = Month.EndDate
358 part-of-month = 1.
360 IF part-of-month > 0 AND part-of-month < 1 THEN DO:
361 partial-period = Yes.
362 tenant-date-string = " " + STRING( start-day, "99/99/9999") + " to " + STRING( stop-day, "99/99/9999").
363 END.
365 END PROCEDURE.
367 /* _UIB-CODE-BLOCK-END */
368 &ANALYZE-RESUME
370 &ENDIF
372 &IF DEFINED(EXCLUDE-calculate-rental) = 0 &THEN
374 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE calculate-rental Procedure
375 PROCEDURE calculate-rental :
376 /*------------------------------------------------------------------------------
377 Purpose:
378 ------------------------------------------------------------------------------*/
379 DEF INPUT PARAMETER tenant-code LIKE Tenant.TenantCode NO-UNDO.
380 DEF OUTPUT PARAMETER rent-amount LIKE AcctTran.Amount NO-UNDO.
381 DEF OUTPUT PARAMETER contract-rent LIKE AcctTran.Amount NO-UNDO.
382 DEF OUTPUT PARAMETER taxable-amount AS DECIMAL NO-UNDO INITIAL 0.
384 DEF VAR part-of-month AS DEC NO-UNDO.
385 DEF VAR month-charge AS DEC NO-UNDO.
386 DEF VAR month-contract AS DEC NO-UNDO.
388 rent-amount = 0.
389 contract-rent = 0.
390 FOR EACH TenancyLease WHERE TenancyLease.TenantCode = tenant-code
391 AND TenancyLease.PropertyCode = Property.PropertyCode
392 AND TenancyLease.LeaseStatus <> "PAST"
393 AND (TenancyLease.LeaseStartDate < Month.EndDate OR
394 TenancyLease.LeaseStartDate = ?) NO-LOCK,
395 EACH RentalSpace WHERE RentalSpace.TenancyLeaseCode = TenancyLease.TenancyLeaseCode
396 AND RentalSpace.AreaStatus <> "V" NO-LOCK:
398 RUN calculate-part-of-month( OUTPUT part-of-month).
400 ASSIGN
401 rent-amount = rent-amount + (RentalSpace.ChargedRental * part-of-month)
402 contract-rent = contract-rent + (RentalSpace.ContractedRental * part-of-month)
403 taxable-amount = taxable-amount + (IF TenancyLease.TaxApplies THEN (RentalSpace.ChargedRental * part-of-month) ELSE 0)
405 END.
406 rent-amount = INTEGER((rent-amount / 12) * 100) / 100.
407 contract-rent = INTEGER((contract-rent / 12) * 100) / 100.
408 taxable-amount = INTEGER((taxable-amount / 12) * 100) / 100.
410 END PROCEDURE.
412 /* _UIB-CODE-BLOCK-END */
413 &ANALYZE-RESUME
415 &ENDIF
417 &IF DEFINED(EXCLUDE-calculate-typed-rental) = 0 &THEN
419 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE calculate-typed-rental Procedure
420 PROCEDURE calculate-typed-rental :
421 /*------------------------------------------------------------------------------
422 Purpose: Calculate rentals broken down by area type
423 ------------------------------------------------------------------------------*/
424 DEF INPUT PARAMETER tenant-code LIKE Tenant.TenantCode NO-UNDO.
425 DEF OUTPUT PARAMETER rental-types AS CHAR NO-UNDO.
426 DEF OUTPUT PARAMETER rental-amounts AS CHAR NO-UNDO.
427 DEF OUTPUT PARAMETER rental-descriptions AS CHAR NO-UNDO.
428 DEF OUTPUT PARAMETER taxable-amount AS DECIMAL NO-UNDO INITIAL 0.
430 DEF VAR area-type AS CHAR NO-UNDO.
431 DEF VAR type-pos AS INT NO-UNDO.
432 DEF VAR rent-amount AS DECIMAL NO-UNDO.
433 DEF VAR part-of-month AS DEC NO-UNDO.
435 FOR EACH TenancyLease WHERE TenancyLease.TenantCode = tenant-code
436 AND TenancyLease.LeaseStatus <> "PAST"
437 AND TenancyLease.PropertyCode = Property.PropertyCode
438 AND (TenancyLease.LeaseStartDate < Month.EndDate OR
439 TenancyLease.LeaseStartDate = ?) NO-LOCK,
440 EACH RentalSpace WHERE RentalSpace.TenancyLeaseCode = TenancyLease.TenancyLeaseCode
441 AND RentalSpace.AreaStatus <> "V" NO-LOCK:
442 area-type = (IF RentalSpace.ChargedRental < 0 THEN "-" ELSE "+")
443 + RentalSpace.Areatype.
444 type-pos = INDEX( rental-types, area-type) / 2.
445 IF type-pos = 0 OR RentalSpace.AreaType = "S" THEN DO:
446 rental-types = rental-types + area-type.
447 type-pos = LENGTH( rental-types ) / 2.
448 rental-amounts = rental-amounts + (IF rental-amounts = "" THEN "" ELSE ",") + "0".
449 rental-descriptions = rental-descriptions + (IF rental-descriptions = "" THEN "" ELSE ",") + RentalSpace.Description.
450 END.
451 RUN calculate-part-of-month( OUTPUT part-of-month).
452 rent-amount = DECIMAL( ENTRY( type-pos, rental-amounts)).
453 IF TenancyLease.TaxApplies THEN
454 taxable-amount = taxable-amount + ROUND( (RentalSpace.ChargedRental * part-of-month) / 12, 2).
455 rent-amount = rent-amount + ROUND( (RentalSpace.ChargedRental * part-of-month) / 12, 2).
456 ENTRY( type-pos, rental-amounts) = STRING( rent-amount, "-999999999.99").
457 IF preview THEN DO:
458 line = FILL(" ", 6) + RentalSpace.AreaType + " "
459 + STRING( RentalSpace.Description, "X(40)") + " "
460 + STRING( ROUND( ((RentalSpace.ChargedRental * part-of-month) / 12), 2), "->>,>>>,>>9.99").
461 RUN output-line.
462 END.
463 END.
464 END PROCEDURE.
466 /* _UIB-CODE-BLOCK-END */
467 &ANALYZE-RESUME
469 &ENDIF
471 &IF DEFINED(EXCLUDE-charge-outgoings) = 0 &THEN
473 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE charge-outgoings Procedure
474 PROCEDURE charge-outgoings :
475 /*------------------------------------------------------------------------------
476 Purpose: Create a transaction charging outgoings
477 ------------------------------------------------------------------------------*/
478 DEF VAR og-amount AS DECIMAL NO-UNDO.
479 DEF VAR part-of-month AS DEC NO-UNDO.
481 RUN calculate-outgoings( Tenant.TenantCode, OUTPUT og-amount ).
483 IF og-amount <> 0 THEN DO:
484 property-total = property-total + og-amount.
485 og-total = og-total + og-amount.
487 og-description = "Outgoings from" + tenant-date-string.
488 RUN create-transaction( "T", Tenant.TenantCode, sundry-debtors,
489 Month.StartDate,
490 "T" + STRING( Tenant.TenantCode, "99999"),
491 og-amount,
492 og-description,
493 og-amount
495 RUN create-transaction( Tenant.EntityType, Tenant.EntityCode, og-account,
496 Month.StartDate,
497 "T" + STRING( Tenant.TenantCode, "99999"),
498 - og-amount,
499 og-description,
500 - og-amount
503 RUN charge-tax( "T", Tenant.TenantCode, sundry-debtors,
504 Month.StartDate,
505 "T" + STRING( Tenant.TenantCode, "99999"),
506 og-amount,
507 og-description
509 END.
511 END PROCEDURE.
513 /* _UIB-CODE-BLOCK-END */
514 &ANALYZE-RESUME
516 &ENDIF
518 &IF DEFINED(EXCLUDE-charge-rental-accounts) = 0 &THEN
520 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE charge-rental-accounts Procedure
521 PROCEDURE charge-rental-accounts :
522 /*------------------------------------------------------------------------------
523 Purpose:
524 Parameters: <none>
525 Notes:
526 ------------------------------------------------------------------------------*/
527 DEF VAR rental-types AS CHAR NO-UNDO.
528 DEF VAR rental-amounts AS CHAR NO-UNDO.
529 DEF VAR area-descriptions AS CHAR NO-UNDO.
531 DEF VAR no-types AS INT NO-UNDO.
532 DEF VAR i AS INT NO-UNDO.
533 DEF VAR this-type AS CHAR NO-UNDO.
534 DEF VAR this-rent AS DEC NO-UNDO.
535 DEF VAR tenant-rent-total AS DEC INITIAL 0.00 NO-UNDO.
536 DEF VAR taxable AS DECIMAL NO-UNDO.
537 DEF VAR descr AS CHAR NO-UNDO.
539 RUN calculate-typed-rental( Tenant.TenantCode, OUTPUT rental-types, OUTPUT rental-amounts, OUTPUT area-descriptions, OUTPUT taxable).
541 line = "".
542 RUN output-line.
544 rent-description = "Rental from" + tenant-date-string.
545 no-types = LENGTH( rental-types ) / 2.
546 DO i = 1 TO no-types:
547 this-type = SUBSTRING( rental-types, (2 * i), 1).
548 this-rent = DECIMAL( ENTRY( i, rental-amounts) ).
549 FIND AreaType WHERE AreaType.AreaType = this-type NO-LOCK.
550 IF this-type = "S" THEN
551 descr = ENTRY( i, area-descriptions) + tenant-date-string .
552 ELSE
553 descr = AreaType.Description + (IF this-rent < 0 THEN " credit" ELSE "") + tenant-date-string .
555 RUN create-transaction( "T", Tenant.TenantCode, sundry-debtors,
556 Month.StartDate,
557 "T" + STRING( Tenant.TenantCode, "99999"),
558 this-rent,
559 descr,
560 this-rent
563 RUN create-transaction( Tenant.EntityType, Tenant.EntityCode, AreaType.AccountCode,
564 Month.StartDate,
565 "T" + STRING( Tenant.TenantCode, "99999"),
566 - this-rent,
567 descr,
568 - this-rent
570 tenant-rent-total = tenant-rent-total + this-rent.
571 END.
572 property-total = property-total + tenant-rent-total.
573 rent-total = rent-total + tenant-rent-total.
575 IF taxable <> 0 THEN
576 RUN charge-tax( "T", Tenant.TenantCode, sundry-debtors, Month.StartDate,
577 "T" + STRING( Tenant.TenantCode, "99999"), taxable, rent-description ).
579 IF Office.GST <> ? THEN
580 untaxed-total = untaxed-total + this-rent - taxable.
582 END PROCEDURE.
584 /* _UIB-CODE-BLOCK-END */
585 &ANALYZE-RESUME
587 &ENDIF
589 &IF DEFINED(EXCLUDE-charge-rental-single) = 0 &THEN
591 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE charge-rental-single Procedure
592 PROCEDURE charge-rental-single :
593 /*------------------------------------------------------------------------------
594 Purpose: Create a transaction charging rental.
595 ------------------------------------------------------------------------------*/
596 DEF VAR rent-amount AS DECIMAL NO-UNDO.
597 DEF VAR contract-rent AS DECIMAL NO-UNDO.
598 DEF VAR taxable AS DECIMAL NO-UNDO.
600 RUN calculate-rental( Tenant.TenantCode, OUTPUT rent-amount, OUTPUT contract-rent, OUTPUT taxable ).
601 IF rent-amount <> 0 THEN DO:
602 property-total = property-total + rent-amount.
603 rent-total = rent-total + rent-amount.
605 rent-description = "Rental from" + tenant-date-string.
606 RUN create-transaction( "T", Tenant.TenantCode, sundry-debtors,
607 Month.StartDate,
608 "T" + STRING( Tenant.TenantCode, "99999"),
609 rent-amount,
610 rent-description,
611 taxable
614 RUN create-transaction( Tenant.EntityType, Tenant.EntityCode, rent-account,
615 Month.StartDate,
616 "T" + STRING( Tenant.TenantCode, "99999"),
617 - rent-amount,
618 rent-description,
619 - taxable
622 IF taxable > 0 THEN
623 RUN charge-tax( "T", Tenant.TenantCode, sundry-debtors, Month.StartDate,
624 "T" + STRING( Tenant.TenantCode, "99999"), taxable, rent-description ).
626 IF Office.GST <> ? THEN
627 untaxed-total = untaxed-total + rent-amount - taxable.
628 END.
630 END PROCEDURE.
632 /* _UIB-CODE-BLOCK-END */
633 &ANALYZE-RESUME
635 &ENDIF
637 &IF DEFINED(EXCLUDE-charge-tax) = 0 &THEN
639 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE charge-tax Procedure
640 PROCEDURE charge-tax :
641 /*------------------------------------------------------------------------------
642 Purpose: Create a transaction charging tax
643 ------------------------------------------------------------------------------*/
644 DEF INPUT PARAMETER et LIKE NewAcctTrans.EntityType NO-UNDO.
645 DEF INPUT PARAMETER ec LIKE NewAcctTrans.EntityCode NO-UNDO.
646 DEF INPUT PARAMETER ac LIKE NewAcctTrans.AccountCode NO-UNDO.
647 DEF INPUT PARAMETER dat LIKE NewAcctTrans.Date NO-UNDO.
648 DEF INPUT PARAMETER ref LIKE NewAcctTrans.Reference NO-UNDO.
649 DEF INPUT PARAMETER amt LIKE NewAcctTrans.Amount NO-UNDO.
650 DEF INPUT PARAMETER dsc LIKE NewAcctTrans.Description NO-UNDO.
652 DEF VAR v-gst-entity LIKE NewAcctTrans.EntityCode NO-UNDO.
654 IF Office.GST = 0 OR amt = 0 THEN RETURN.
655 amt = amt * Office.GST / 100.
656 tax-total = tax-total + amt.
657 RUN create-transaction ( et, ec, ac,
658 dat, ref, amt, "GST, " + dsc, amt ).
660 /* Find the ledger to allocate GST */
661 IF GST-Multi-company = YES THEN DO:
662 /*FIND Property WHERE Property.PropertyCode = ec NO-LOCK.*/
663 ASSIGN v-gst-entity = Property.CompanyCode.
664 END.
665 ELSE v-gst-entity = gst-entity.
667 RUN create-transaction ( "L", v-gst-entity, gst-account,
668 dat, ref, - amt, "GST, " + dsc, - amt ).
671 END PROCEDURE.
673 /* _UIB-CODE-BLOCK-END */
674 &ANALYZE-RESUME
676 &ENDIF
678 &IF DEFINED(EXCLUDE-create-transaction) = 0 &THEN
680 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE create-transaction Procedure
681 PROCEDURE create-transaction :
682 /*------------------------------------------------------------------------------
683 Purpose: Create a NewTransaction record
684 ------------------------------------------------------------------------------*/
685 DEF INPUT PARAMETER et LIKE NewAcctTrans.EntityType NO-UNDO.
686 DEF INPUT PARAMETER ec LIKE NewAcctTrans.EntityCode NO-UNDO.
687 DEF INPUT PARAMETER ac LIKE NewAcctTrans.AccountCode NO-UNDO.
688 DEF INPUT PARAMETER dat LIKE NewAcctTrans.Date NO-UNDO.
689 DEF INPUT PARAMETER ref LIKE NewAcctTrans.Reference NO-UNDO.
690 DEF INPUT PARAMETER amt LIKE NewAcctTrans.Amount NO-UNDO.
691 DEF INPUT PARAMETER dsc LIKE NewAcctTrans.Description NO-UNDO.
692 DEF INPUT PARAMETER tax-amount LIKE NewAcctTrans.Amount NO-UNDO.
694 IF amt > 0 THEN debit-total = debit-total + amt.
695 IF preview THEN DO:
696 IF et = "P" OR
697 (et = "L" AND ec = gst-entity AND ac = gst-account AND set-type = "ACCOUNTS":U)
698 THEN DO:
699 line = " T"
700 + STRING( Tenant.TenantCode, "99999") + " "
701 + STRING( ac, "9999.99") + " "
702 + STRING( dsc, "X(50)" ) + " "
703 + STRING( - amt, "->>>,>>>,>>9.99" ) + " "
704 + STRING( Tenant.Name, "X(50)")
705 + (IF partial-period THEN " part period" ELSE FILL(" ", 12) ) + " "
706 + (IF Office.GST <> ? AND tax-amount <> amt THEN STRING( - (tax-amount * Office.GST / 100), "->>>,>>>,>>9.99" ) ELSE "").
707 RUN output-line.
708 tenant-total = tenant-total - amt.
709 END.
710 RETURN.
711 END.
712 IF this-transaction = 0 THEN DO:
713 this-document = this-document + 1.
714 CREATE NewDocument.
715 ASSIGN
716 NewDocument.BatchCode = batch-code
717 NewDocument.DocumentCode = this-document
718 NewDocument.DocumentType = "RENT"
719 NewDocument.Reference = ( et + STRING( ec, "99999") )
720 NewDocument.Description = NewBatch.Description
722 RELEASE NewDocument.
723 END.
725 this-transaction = this-transaction + 1.
726 CREATE NewAcctTrans.
727 ASSIGN
728 NewAcctTrans.BatchCode = batch-code
729 NewAcctTrans.DocumentCode = this-document
730 NewAcctTrans.TransactionCode = this-transaction
731 NewAcctTrans.EntityType = et
732 NewAcctTrans.EntityCode = ec
733 NewAcctTrans.AccountCode = ac
734 NewAcctTrans.Date = dat
735 NewAcctTrans.Reference = ref
736 NewAcctTrans.Amount = amt
737 NewAcctTrans.Description = dsc
740 RELEASE NewAcctTrans.
741 END PROCEDURE.
743 /* _UIB-CODE-BLOCK-END */
744 &ANALYZE-RESUME
746 &ENDIF
748 &IF DEFINED(EXCLUDE-each-tenant) = 0 &THEN
750 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE each-tenant Procedure
751 PROCEDURE each-tenant :
752 /*------------------------------------------------------------------------------
753 Purpose:
754 Parameters: <none>
755 Notes:
756 ------------------------------------------------------------------------------*/
757 this-transaction = 0.
758 partial-period = No.
760 IF preview THEN DO:
761 IF Property.PropertyCode <> last-property THEN DO:
762 RUN after-each-property( last-property, property-total ).
763 last-property = Property.PropertyCode.
764 property-total = 0.
765 END.
766 IF set-type = "ACCOUNTS":U THEN DO:
767 line = Tenant.Name + " (T" + STRING( Tenant.TenantCode, "99999") + ")".
768 RUN output-line.
769 END.
770 tenant-total = 0.
771 END.
773 tenant-date-string = date-string.
774 IF INDEX( charge-type, "R") > 0 THEN RUN VALUE(rent-charge-routine) IN THIS-PROCEDURE.
775 IF INDEX( charge-type, "O") > 0 THEN RUN charge-outgoings.
777 IF preview AND set-type = "ACCOUNTS":U THEN DO:
778 line = FILL( " ", 74) + "===============".
779 RUN output-line.
780 line = "Total charge for tenant " + STRING( Tenant.TenantCode, "99999")
781 + FILL( " ", 45) + STRING( tenant-total, "->>>,>>>,>>9.99").
782 RUN output-line.
783 line = "".
784 RUN output-line.
785 RUN output-line.
786 END.
788 END PROCEDURE.
790 /* _UIB-CODE-BLOCK-END */
791 &ANALYZE-RESUME
793 &ENDIF
795 &IF DEFINED(EXCLUDE-output-line) = 0 &THEN
797 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE output-line Procedure
798 PROCEDURE output-line :
799 /*------------------------------------------------------------------------------
800 Purpose:
801 ------------------------------------------------------------------------------*/
802 IF line = "" THEN
803 PUT SKIP(1).
804 ELSE
805 PUT UNFORMATTED line SKIP.
807 END PROCEDURE.
809 /* _UIB-CODE-BLOCK-END */
810 &ANALYZE-RESUME
812 &ENDIF
814 &IF DEFINED(EXCLUDE-parse-options) = 0 &THEN
816 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE parse-options Procedure
817 PROCEDURE parse-options :
818 /*------------------------------------------------------------------------------
819 Purpose:
820 ------------------------------------------------------------------------------*/
822 DEF VAR charge-type AS CHAR NO-UNDO.
823 DEF VAR charge-period LIKE Month.MonthCode NO-UNDO.
824 DEF VAR preview AS LOGICAL NO-UNDO.
825 DEF VAR frequency-list AS CHAR NO-UNDO.
828 {inc/showopts.i "process-options"}
830 charge-type = ENTRY( 1, process-options, "~n").
831 charge-period = INT( ENTRY( 2, process-options, "~n")).
832 preview = (ENTRY( 3, process-options, "~n") = "Yes").
833 frequency-list = ENTRY( 4, process-options, "~n").
835 END PROCEDURE.
837 /* _UIB-CODE-BLOCK-END */
838 &ANALYZE-RESUME
840 &ENDIF