Add blank column, rename column.
[capital-apms-progress.git] / process / report / tenant-rentals.p
blobc72432572c16dba10bf50cbd13fb286eb2fff1a9
1 &ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12
2 &ANALYZE-RESUME
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
9 Created : 19/1/1999
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.
19 RUN parse-parameters.
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
34 FIELD Name AS CHAR
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
40 FIELD Name AS CHAR
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 */
49 &ANALYZE-RESUME
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 */
62 &ANALYZE-RESUME
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 */
74 &ANALYZE-RESUME
76 &ENDIF
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 */
85 &ANALYZE-RESUME
87 &ENDIF
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 */
96 &ANALYZE-RESUME
98 &ENDIF
101 /* *********************** Procedure Settings ************************ */
103 &ANALYZE-SUSPEND _PROCEDURE-SETTINGS
104 /* Settings for THIS-PROCEDURE
105 Type: Procedure
106 Allow:
107 Frames: 0
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
118 HEIGHT = .1
119 WIDTH = 36.14.
120 /* END WINDOW DEFINITION */
122 &ANALYZE-RESUME
124 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _INCLUDED-LIB Procedure
125 /* ************************* Included-Libraries *********************** */
127 {inc/rentchrg.i}
128 {inc/entity.i}
129 {inc/null.i}
130 {inc/method/m-txtrep.i}
131 {inc/tenant-atb.i}
133 /* _UIB-CODE-BLOCK-END */
134 &ANALYZE-RESUME
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.
151 OUTPUT CLOSE.
153 RUN pclrep-finish.
155 /* _UIB-CODE-BLOCK-END */
156 &ANALYZE-RESUME
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 /*------------------------------------------------------------------------------
166 Purpose:
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:
173 CREATE tenant-names.
174 tenant-names.Name = Tenant.Name.
175 END.
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() .
182 END.
183 END.
184 END.
186 FOR EACH tenant-names:
187 FOR EACH tenant-rentals OF tenant-names:
188 tenant-names.ChargedRent = tenant-names.ChargedRent + tenant-rentals.ChargedRent .
189 END.
190 END.
192 END PROCEDURE.
194 /* _UIB-CODE-BLOCK-END */
195 &ANALYZE-RESUME
197 &ENDIF
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 /*------------------------------------------------------------------------------
204 Purpose:
205 ------------------------------------------------------------------------------*/
207 END PROCEDURE.
209 /* _UIB-CODE-BLOCK-END */
210 &ANALYZE-RESUME
212 &ENDIF
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 /*------------------------------------------------------------------------------
219 Purpose:
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).
237 END PROCEDURE.
239 /* _UIB-CODE-BLOCK-END */
240 &ANALYZE-RESUME
242 &ENDIF
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 /*------------------------------------------------------------------------------
249 Purpose:
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:
255 i = i + 1.
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) + ",".
264 END.
266 line = RIGHT-TRIM( line, ",").
267 RUN pclrep-line( details-font, line ).
269 END.
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 ).
279 END PROCEDURE.
281 /* _UIB-CODE-BLOCK-END */
282 &ANALYZE-RESUME
284 &ENDIF
286 &IF DEFINED(EXCLUDE-parse-parameters) = 0 &THEN
288 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE parse-parameters Procedure
289 PROCEDURE parse-parameters :
290 /*------------------------------------------------------------------------------
291 Purpose:
292 ------------------------------------------------------------------------------*/
293 DEF VAR i AS INT NO-UNDO.
294 DEF VAR token AS CHAR NO-UNDO.
296 {inc/showopts.i "report-options"}
298 run-date = TODAY.
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
307 exporting = Yes
308 export-file = SUBSTRING(token, INDEX(token,",",1) + 1).
309 END CASE.
310 END.
312 END PROCEDURE.
314 /* _UIB-CODE-BLOCK-END */
315 &ANALYZE-RESUME
317 &ENDIF
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 /*------------------------------------------------------------------------------
327 Purpose:
328 Notes:
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.
338 END FUNCTION.
340 /* _UIB-CODE-BLOCK-END */
341 &ANALYZE-RESUME
343 &ENDIF
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 /*------------------------------------------------------------------------------
351 Purpose:
352 Notes:
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).
371 END.
373 END.
375 RETURN current-charges.
377 END FUNCTION.
379 /* _UIB-CODE-BLOCK-END */
380 &ANALYZE-RESUME
382 &ENDIF
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 /*------------------------------------------------------------------------------
390 Purpose:
391 Notes: Dummy function.
392 ------------------------------------------------------------------------------*/
394 RETURN Yes. /* Function return value. */
396 END FUNCTION.
398 /* _UIB-CODE-BLOCK-END */
399 &ANALYZE-RESUME
401 &ENDIF