1 &ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12
3 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS Procedure
4 /*--------------------------------------------------------------------------
5 File
: process
/report
/tenant-rentals.p
6 Purpose
: Report on tenant rentals
, tenants with the same name are merged
,
7 ranked in descending order of income.
8 Author
(s
) : Andrew McMillan
10 ------------------------------------------------------------------------*/
12 DEF INPUT PARAMETER report-options
AS CHAR NO-UNDO.
14 DEF VAR preview
AS LOGICAL NO-UNDO.
15 DEF VAR exporting
AS LOGICAL NO-UNDO INITIAL No.
16 DEF VAR run-date
AS DATE NO-UNDO.
17 DEF VAR show-top
AS INT NO-UNDO INITIAL 50.
18 DEF VAR export-file
AS CHAR NO-UNDO.
21 DEF VAR details-font
AS CHAR NO-UNDO INITIAL "courier,lpi,9,cpi,18,normal,fixed".
22 DEF VAR header-font
AS CHAR NO-UNDO INITIAL "Helvetica,point,10,proportional,bold,lpi,7".
23 DEF VAR page-reset
AS CHAR NO-UNDO INITIAL "reset,portrait,lm,7,tm,2".
24 DEF VAR page-header-font
AS CHAR NO-UNDO INITIAL "Helvetica,point,12,proportional,bold".
26 DEF VAR line
AS CHAR NO-UNDO.
27 DEF VAR time-font
AS CHAR NO-UNDO INITIAL "proportional,helv,point,6,normal".
28 DEF VAR now
AS CHAR NO-UNDO.
29 now
= STRING( TODAY, "99/99/9999" ) + " " + STRING( TIME, "HH:MM:SS" ).
31 DEF VAR user-name
AS CHAR NO-UNDO.
33 DEF TEMP-TABLE tenant-names
NO-UNDO
35 FIELD ChargedRent
AS DEC
36 INDEX XPKname
IS UNIQUE PRIMARY Name
37 INDEX XPKfinal ChargedRent
DESCENDING Name.
39 DEF TEMP-TABLE tenant-rentals
NO-UNDO
41 FIELD TenantCode
AS INT
42 FIELD ChargedRent
AS DEC
43 INDEX XPKrent
IS PRIMARY Name ChargedRent
DESCENDING
44 INDEX XAK1rent
IS UNIQUE TenantCode.
46 {inc
/username.i
"user-name"}
48 /* _UIB-CODE-BLOCK-END
*/
52 &ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
54 /* ******************** Preprocessor Definitions
******************** */
56 &Scoped-define PROCEDURE-TYPE Procedure
57 &Scoped-define DB-AWARE no
61 /* _UIB-PREPROCESSOR-BLOCK-END
*/
65 /* ************************ Function Prototypes
********************** */
67 &IF DEFINED(EXCLUDE-get-annual-amount) = 0 &THEN
69 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD get-annual-amount Procedure
70 FUNCTION get-annual-amount
RETURNS DECIMAL
71 ( INPUT period-amount
AS DEC, INPUT freq-type
AS CHAR ) FORWARD.
73 /* _UIB-CODE-BLOCK-END
*/
78 &IF DEFINED(EXCLUDE-get-rent-charges) = 0 &THEN
80 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD get-rent-charges Procedure
81 FUNCTION get-rent-charges
RETURNS DECIMAL
82 ( /* parameter-definitions
*/ ) FORWARD.
84 /* _UIB-CODE-BLOCK-END
*/
89 &IF DEFINED(EXCLUDE-include-lease) = 0 &THEN
91 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD include-lease Procedure
92 FUNCTION include-lease
RETURNS LOGICAL
93 ( INPUT lease-code
AS INT ) FORWARD.
95 /* _UIB-CODE-BLOCK-END
*/
101 /* *********************** Procedure Settings
************************ */
103 &ANALYZE-SUSPEND _PROCEDURE-SETTINGS
104 /* Settings for
THIS-PROCEDURE
108 Add Fields to
: Neither
109 Other Settings
: CODE-ONLY
COMPILE
111 &ANALYZE-RESUME _END-PROCEDURE-SETTINGS
113 /* ************************* Create Window
************************** */
115 &ANALYZE-SUSPEND _CREATE-WINDOW
116 /* DESIGN Window definition
(used by the UIB
)
117 CREATE WINDOW Procedure
ASSIGN
120 /* END WINDOW DEFINITION
*/
124 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _INCLUDED-LIB Procedure
125 /* ************************* Included-Libraries
*********************** */
130 {inc
/method
/m-txtrep.i
}
133 /* _UIB-CODE-BLOCK-END
*/
140 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Procedure
143 /* *************************** Main Block
*************************** */
145 RUN pclrep-start
( preview
, page-reset
+ "," + details-font
).
146 OUTPUT TO VALUE(txtrep-print-file
) KEEP-MESSAGES APPEND.
148 RUN build-tenant-rentals.
149 RUN list-tenant-rentals.
155 /* _UIB-CODE-BLOCK-END
*/
159 /* ********************** Internal Procedures
*********************** */
161 &IF DEFINED(EXCLUDE-build-tenant-rentals) = 0 &THEN
163 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE build-tenant-rentals Procedure
164 PROCEDURE build-tenant-rentals
:
165 /*------------------------------------------------------------------------------
167 ------------------------------------------------------------------------------*/
168 FOR EACH Property
WHERE Property.Active
NO-LOCK:
169 FOR EACH Tenant
WHERE Tenant.Active
AND Tenant.EntityType
= "P"
170 AND Tenant.EntityCode
= Property.PropertyCode
NO-LOCK:
171 FIND tenant-names
WHERE tenant-names.Name
= Tenant.Name
NO-ERROR.
172 IF NOT AVAILABLE(tenant-names
) THEN DO:
174 tenant-names.Name
= Tenant.Name.
176 CREATE tenant-rentals.
177 tenant-rentals.TenantCode
= Tenant.TenantCode.
178 tenant-rentals.Name
= Tenant.Name.
179 tenant-rentals.ChargedRent
= 0.0 .
180 FOR EACH TenancyLease
OF Tenant
WHERE TenancyLease.LeaseStatus
<> "PAST" NO-LOCK:
181 tenant-rentals.ChargedRent
= tenant-rentals.ChargedRent
+ get-rent-charges
() .
186 FOR EACH tenant-names
:
187 FOR EACH tenant-rentals
OF tenant-names
:
188 tenant-names.ChargedRent
= tenant-names.ChargedRent
+ tenant-rentals.ChargedRent .
194 /* _UIB-CODE-BLOCK-END
*/
199 &IF DEFINED(EXCLUDE-inst-page-footer) = 0 &THEN
201 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE inst-page-footer Procedure
202 PROCEDURE inst-page-footer
:
203 /*------------------------------------------------------------------------------
205 ------------------------------------------------------------------------------*/
209 /* _UIB-CODE-BLOCK-END
*/
214 &IF DEFINED(EXCLUDE-inst-page-header) = 0 &THEN
216 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE inst-page-header Procedure
217 PROCEDURE inst-page-header
:
218 /*------------------------------------------------------------------------------
220 ------------------------------------------------------------------------------*/
221 DEF VAR p-line
AS CHAR NO-UNDO.
223 p-line
= "Printed: " + now
+ " for " + user-name.
224 RUN pclrep-line
( time-font
, p-line
).
226 RUN pclrep-line
( time-font
, "").
228 p-line
= FILL( " ", 30)
229 + "Tenant Rentals Listing as at "
230 + STRING(run-date
,"99/99/9999").
231 RUN pclrep-line
( page-header-font
, p-line
).
233 RUN pclrep-down-by
( 0.7).
234 RUN pclrep-line
( details-font
, FILL(" ",50) + "Annual Rental Tenant Numbers").
235 RUN pclrep-down-by
( 0.6).
239 /* _UIB-CODE-BLOCK-END
*/
244 &IF DEFINED(EXCLUDE-list-tenant-rentals) = 0 &THEN
246 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE list-tenant-rentals Procedure
247 PROCEDURE list-tenant-rentals
:
248 /*------------------------------------------------------------------------------
250 ------------------------------------------------------------------------------*/
251 DEF VAR i
AS INT NO-UNDO INITIAL 0.
252 DEF VAR rent-total
AS DEC NO-UNDO INITIAL 0.0 .
254 FOR EACH tenant-names
BY tenant-names.ChargedRent
DESCENDING WHILE i
< show-top
:
257 rent-total
= rent-total
+ tenant-names.ChargedRent.
258 line
= STRING( i
, ">>>>9") + " "
259 + STRING( tenant-names.Name
, "X(40)") + " "
260 + STRING( tenant-names.ChargedRent
, "->>,>>>,>>9.99") + " ".
262 FOR EACH tenant-rentals
OF tenant-names
BY tenant-rentals.ChargedRent
DESCENDING:
263 line
= line
+ " T" + STRING(tenant-rentals.TenantCode
) + ",".
266 line
= RIGHT-TRIM( line
, ",").
267 RUN pclrep-line
( details-font
, line
).
271 RUN pclrep-down-by
( 0.4 ).
272 line
= FILL( " ", 49) + FILL( "=", 14).
273 RUN pclrep-line
( details-font
, line
).
274 line
= FILL( " ", 49) + STRING( rent-total
, "->>,>>>,>>9.99").
275 RUN pclrep-line
( details-font
, line
).
276 line
= FILL( " ", 49) + FILL( "=", 14).
277 RUN pclrep-line
( details-font
, line
).
281 /* _UIB-CODE-BLOCK-END
*/
286 &IF DEFINED(EXCLUDE-parse-parameters) = 0 &THEN
288 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE parse-parameters Procedure
289 PROCEDURE parse-parameters
:
290 /*------------------------------------------------------------------------------
292 ------------------------------------------------------------------------------*/
293 DEF VAR i
AS INT NO-UNDO.
294 DEF VAR token
AS CHAR NO-UNDO.
296 {inc
/showopts.i
"report-options"}
300 DO i
= 1 TO NUM-ENTRIES( report-options
, "~n" ):
301 token
= ENTRY( i
, report-options
, "~n" ).
302 CASE( ENTRY( 1, token
) ):
303 WHEN "Preview" THEN preview
= Yes.
304 WHEN "RunDate" THEN run-date
= DATE(ENTRY(2,token
)).
305 WHEN "ShowTop" THEN show-top
= INT(ENTRY(2,token
)).
306 WHEN "Export" THEN ASSIGN
308 export-file
= SUBSTRING(token
, INDEX(token
,",",1) + 1).
314 /* _UIB-CODE-BLOCK-END
*/
319 /* ************************ Function Implementations
***************** */
321 &IF DEFINED(EXCLUDE-get-annual-amount) = 0 &THEN
323 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION get-annual-amount Procedure
324 FUNCTION get-annual-amount
RETURNS DECIMAL
325 ( INPUT period-amount
AS DEC, INPUT freq-type
AS CHAR ) :
326 /*------------------------------------------------------------------------------
329 ------------------------------------------------------------------------------*/
330 DEF VAR annual-amount
AS DEC NO-UNDO.
332 FIND FrequencyType
WHERE FrequencyType.FrequencyCode
= freq-type
NO-LOCK.
334 annual-amount
= ((period-amount
/ FrequencyType.UnitCount
) * (IF FrequencyType.RepeatUnits
BEGINS "D" THEN 365 ELSE 12)).
336 RETURN annual-amount.
340 /* _UIB-CODE-BLOCK-END
*/
345 &IF DEFINED(EXCLUDE-get-rent-charges) = 0 &THEN
347 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION get-rent-charges Procedure
348 FUNCTION get-rent-charges
RETURNS DECIMAL
349 ( /* parameter-definitions
*/ ) :
350 /*------------------------------------------------------------------------------
353 ------------------------------------------------------------------------------*/
354 DEF VAR current-charges
AS DEC NO-UNDO INITIAL 0.0 .
356 IF TenancyLease.LeaseStartDate
> run-date
THEN RETURN 0.0 .
357 IF TenancyLease.LeaseEndDate
< run-date
THEN RETURN 0.0 .
359 FOR EACH RentCharge
OF TenancyLease
NO-LOCK:
361 /* skip all outgoings charges
*/
362 IF og-method
<> "" AND og-method
= RentCharge.RentChargeType
THEN NEXT.
364 FOR EACH RentChargeLine
OF RentCharge
WHERE RentChargeLine.RentChargeLineStatus
= "C" NO-LOCK:
365 IF RentChargeLine.StartDate
> run-date
366 OR (RentChargeLine.EndDate
< run-date
AND RentChargeLine.EndDate
<> ?
)
367 THEN NEXT.
/* not a current charge at run date
(usually today
) */
369 current-charges
= current-charges
370 + get-annual-amount
( RentChargeLine.Amount
, RentChargeLine.FrequencyCode
).
375 RETURN current-charges.
379 /* _UIB-CODE-BLOCK-END
*/
384 &IF DEFINED(EXCLUDE-include-lease) = 0 &THEN
386 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION include-lease Procedure
387 FUNCTION include-lease
RETURNS LOGICAL
388 ( INPUT lease-code
AS INT ) :
389 /*------------------------------------------------------------------------------
391 Notes
: Dummy function.
392 ------------------------------------------------------------------------------*/
394 RETURN Yes.
/* Function return value.
*/
398 /* _UIB-CODE-BLOCK-END
*/