Really, this should be it, for the passing income.
[capital-apms-progress.git] / forecast / amtrust-market-rents.p
bloba8ecc5d9c6e835f864f31e18d2025db9cfad0510
1 &ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12
2 &ANALYZE-RESUME
3 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS Procedure
4 /*--------------------------------------------------------------------------
5 AmTrust Rental Forecasting Run
6 ------------------------------------------------------------------------*/
7 &SCOPED-DEFINE REPORT-ID "Amtrust Rental Run"
9 DEF INPUT PARAMETER report-options AS CHAR NO-UNDO.
11 DEF VAR preview AS LOGI NO-UNDO INIT No.
12 DEF VAR property-1 AS INT NO-UNDO INIT ?.
13 DEF VAR property-n AS INT NO-UNDO INIT ?.
14 DEF VAR forecast-start AS DATE NO-UNDO.
15 DEF VAR forecast-end AS DATE NO-UNDO.
16 RUN parse-parameters.
17 IF ERROR-STATUS:ERROR THEN RETURN.
19 DEF VAR mfmt AS CHAR NO-UNDO INITIAL "->>>,>>>,>>9.99".
20 DEF VAR i AS INT NO-UNDO.
22 DEF VAR user-name AS CHAR NO-UNDO.
23 {inc/username.i "user-name"}
24 DEF VAR timeStamp AS CHAR FORMAT "X(44)" NO-UNDO.
25 timeStamp = STRING( TODAY, "99/99/9999") + ", " + STRING( TIME, "HH:MM:SS") + " for " + user-name.
27 DEF VAR base-font AS CHAR NO-UNDO INITIAL "fixed,courier,cpi,18,lpi,9,normal".
28 DEF VAR header-font AS CHAR NO-UNDO INITIAL "proportional,helvetica,point,10,lpi,7,bold".
30 {inc/ofc-this.i}
32 /* _UIB-CODE-BLOCK-END */
33 &ANALYZE-RESUME
36 &ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
38 /* ******************** Preprocessor Definitions ******************** */
40 &Scoped-define PROCEDURE-TYPE Procedure
44 /* _UIB-PREPROCESSOR-BLOCK-END */
45 &ANALYZE-RESUME
48 /* ************************ Function Prototypes ********************** */
50 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD to-annual Procedure
51 FUNCTION to-annual RETURNS DECIMAL
52 ( INPUT freq-code AS CHAR, INPUT period-amount AS DEC ) FORWARD.
54 /* _UIB-CODE-BLOCK-END */
55 &ANALYZE-RESUME
58 /* *********************** Procedure Settings ************************ */
60 &ANALYZE-SUSPEND _PROCEDURE-SETTINGS
61 /* Settings for THIS-PROCEDURE
62 Type: Procedure
63 Allow:
64 Frames: 0
65 Add Fields to: Neither
66 Other Settings: CODE-ONLY COMPILE
68 &ANALYZE-RESUME _END-PROCEDURE-SETTINGS
70 /* ************************* Create Window ************************** */
72 &ANALYZE-SUSPEND _CREATE-WINDOW
73 /* DESIGN Window definition (used by the UIB)
74 CREATE WINDOW Procedure ASSIGN
75 HEIGHT = .5
76 WIDTH = 49.86.
77 /* END WINDOW DEFINITION */
79 &ANALYZE-RESUME
83 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _INCLUDED-LIB Procedure
84 /* ************************* Included-Libraries *********************** */
86 {inc/date.i}
87 {inc/method/m-txtrep.i}
89 /* _UIB-CODE-BLOCK-END */
90 &ANALYZE-RESUME
94 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Procedure
97 /* *************************** Main Block *************************** */
99 RUN pclrep-start( preview, "reset,landscape,tm,2,a4,lm,6," + base-font).
100 OUTPUT TO VALUE(txtrep-print-file) KEEP-MESSAGES PAGE-SIZE 0.
102 RUN market-rentals.
104 OUTPUT CLOSE.
106 RUN pclrep-finish.
108 /* _UIB-CODE-BLOCK-END */
109 &ANALYZE-RESUME
112 /* ********************** Internal Procedures *********************** */
114 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE each-tenant Procedure
115 PROCEDURE each-tenant :
116 /*------------------------------------------------------------------------------
117 Purpose:
118 ------------------------------------------------------------------------------*/
119 DEF INPUT-OUTPUT PARAMETER pmkt AS DEC NO-UNDO .
120 DEF INPUT-OUTPUT PARAMETER pact AS DEC NO-UNDO .
122 DEF VAR market AS DEC NO-UNDO INITIAL 0.0 .
123 DEF VAR actual AS DEC NO-UNDO INITIAL 0.0 .
125 FOR EACH TenancyLease OF Tenant NO-LOCK:
126 RUN get-lease-rates( INPUT-OUTPUT market, INPUT-OUTPUT actual ).
127 END.
129 IF market = 0 AND actual = 0 THEN RETURN.
131 RUN pclrep-line( base-font, " "
132 + STRING(Tenant.TenantCode, "99999") + " " + STRING(Tenant.Name,"X(50)")
133 + STRING(market,mfmt) + STRING(actual,mfmt) + STRING(actual - market,mfmt) ).
135 pmkt = pmkt + market.
136 pact = pact + actual.
138 END PROCEDURE.
140 /* _UIB-CODE-BLOCK-END */
141 &ANALYZE-RESUME
144 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE get-lease-rates Procedure
145 PROCEDURE get-lease-rates :
146 /*------------------------------------------------------------------------------
147 Purpose: Set up the 'rates' record for the current lease
148 ------------------------------------------------------------------------------*/
149 DEF INPUT-OUTPUT PARAMETER market AS DEC NO-UNDO.
150 DEF INPUT-OUTPUT PARAMETER actual AS DEC NO-UNDO.
152 DEF VAR other-rent AS DEC NO-UNDO INITIAL 0.0 .
153 DEF VAR mkt-pc AS DEC NO-UNDO.
154 DEF VAR other-size AS DEC NO-UNDO INITIAL 0.0.
155 DEF VAR other-mult AS DEC NO-UNDO INITIAL 0.0.
157 /* do rentals */
158 FOR EACH RentalSpace WHERE RentalSpace.TenancyLeaseCode = TenancyLease.TenancyLeaseCode NO-LOCK,
159 FIRST AreaType OF RentalSpace:
160 mkt-pc = (IF RentalSpace.MarketRental > 0 THEN RentalSpace.MarketRental / 100.0 ELSE 1.0).
161 IF AreaType.IsFloorArea THEN
162 market = market + (mkt-pc * RentalSpace.AreaSize * Property.MarketRental).
163 ELSE IF AreaType.IsCarPark THEN ASSIGN
164 market = market + (mkt-pc * RentalSpace.AreaSize * Property.MarketCarpark * 52).
165 ELSE ASSIGN
166 /* for market we use actual, which is set below, but we need to be able to handle a %age */
167 other-size = other-size + RentalSpace.AreaSize
168 other-mult = other-mult + (RentalSpace.AreaSize * mkt-pc).
170 /* MESSAGE "Market " + STRING(mkt-pc * 100, ">>9.99% ") market other-size other-mult . */
171 END.
173 /* do actual rentals */
174 FOR EACH RentCharge OF TenancyLease NO-LOCK,
175 FIRST AreaType WHERE AreaType.AreaType = RentCharge.RentChargeType:
176 FOR EACH RentChargeLine OF RentCharge WHERE RentChargeLine.RentChargeLineStatus = "C"
177 AND RentChargeLine.StartDate <= forecast-start
178 AND (RentChargeLine.EndDate >= forecast-start
179 OR RentChargeLine.EndDate = ?) NO-LOCK:
180 IF AreaType.IsFloorArea THEN
181 actual = actual + to-annual( RentChargeLine.FrequencyCode, RentChargeLine.Amount ).
182 ELSE IF AreaType.IsCarPark THEN ASSIGN
183 actual = actual + to-annual( RentChargeLine.FrequencyCode, RentChargeLine.Amount ).
184 ELSE ASSIGN
185 other-rent = other-rent + to-annual( RentChargeLine.FrequencyCode, RentChargeLine.Amount ).
186 END.
187 END.
189 market = market + (other-rent * (IF other-size > 0 THEN other-mult / other-size ELSE 1.0)).
190 /* MESSAGE "Market " market other-rent. */
191 actual = actual + other-rent.
193 END PROCEDURE.
195 /* _UIB-CODE-BLOCK-END */
196 &ANALYZE-RESUME
199 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE inst-page-footer Procedure
200 PROCEDURE inst-page-footer :
201 /*------------------------------------------------------------------------------
202 Purpose: Print any page footer
203 ------------------------------------------------------------------------------*/
205 END PROCEDURE.
207 /* _UIB-CODE-BLOCK-END */
208 &ANALYZE-RESUME
211 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE inst-page-header Procedure
212 PROCEDURE inst-page-header :
213 /*------------------------------------------------------------------------------
214 Purpose: Print any page header
215 ------------------------------------------------------------------------------*/
216 RUN pclrep-line( "univers,Point,7,bold,Proportional", TimeStamp).
217 RUN pclrep-line( "univers,Point,11,bold,Proportional", SPC(30) + "AmTrust Market Rentals" ).
218 RUN pclrep-line( "", "" ).
220 RUN pclrep-line( base-font + ",bold", " Tenancy" + FILL(" ",50) + " Market Actual Variance").
222 RUN pclrep-line( "", "" ).
224 END PROCEDURE.
226 /* _UIB-CODE-BLOCK-END */
227 &ANALYZE-RESUME
230 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE market-rentals Procedure
231 PROCEDURE market-rentals :
232 /*------------------------------------------------------------------------------
233 Purpose:
234 ------------------------------------------------------------------------------*/
235 DEF VAR gmkt AS DEC NO-UNDO INITIAL 0.0 .
236 DEF VAR gact AS DEC NO-UNDO INITIAL 0.0 .
237 DEF VAR pmkt AS DEC NO-UNDO INITIAL 0.0 .
238 DEF VAR pact AS DEC NO-UNDO INITIAL 0.0 .
240 FOR EACH Property WHERE Active AND Property.PropertyCode >= property-1
241 AND Property.PropertyCode <= property-n NO-LOCK:
242 RUN pclrep-line( header-font, "P" + STRING(Property.PropertyCode,"99999")
243 + " " + Property.Name ).
244 pmkt = 0. pact = 0.
245 FOR EACH Tenant WHERE Tenant.EntityType = "P" AND Tenant.EntityCode = Property.PropertyCode
246 AND Tenant.Active NO-LOCK:
247 RUN each-tenant( INPUT-OUTPUT pmkt, INPUT-OUTPUT pact).
248 END.
249 RUN pclrep-line( base-font, FILL(" ",59) + FILL( " " + FILL( "-", LENGTH(mfmt) - 1), 3)).
250 RUN pclrep-line( base-font, FILL(" ",59)
251 + STRING(pmkt,mfmt) + STRING(pact,mfmt) + STRING(pact - pmkt,mfmt)).
252 RUN pclrep-down-by( 0.7 ).
253 gmkt = gmkt + pmkt.
254 gact = gact + pact.
255 END.
257 RUN pclrep-line( base-font, FILL(" ",59) + FILL( " " + FILL( "=", LENGTH(mfmt) - 1), 3)).
258 RUN pclrep-line( base-font, STRING("Grand totals","X(59)")
259 + STRING(gmkt,mfmt) + STRING(gact,mfmt) + STRING(gact - gmkt,mfmt)).
261 END PROCEDURE.
263 /* _UIB-CODE-BLOCK-END */
264 &ANALYZE-RESUME
267 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE parse-parameters Procedure
268 PROCEDURE parse-parameters :
269 /*------------------------------------------------------------------------------
270 Purpose:
271 ------------------------------------------------------------------------------*/
272 DEF VAR token AS CHAR NO-UNDO.
273 DEF VAR i AS INT NO-UNDO.
275 {inc/showopts.i "report-options"}
277 DO i = 1 TO NUM-ENTRIES( report-options, "~n" ):
278 token = ENTRY( i, report-options, "~n" ).
280 /* Preview and Property options are set for each run */
281 CASE ENTRY( 1, token ):
282 WHEN "Preview" THEN preview = Yes.
284 WHEN "All" THEN ASSIGN
285 property-1 = 0
286 property-n = 999999.
288 WHEN "Properties" THEN ASSIGN
289 property-1 = INT(ENTRY(2,token))
290 property-n = INT(ENTRY(3,token)).
291 END CASE.
292 END.
294 END PROCEDURE.
296 /* _UIB-CODE-BLOCK-END */
297 &ANALYZE-RESUME
300 /* ************************ Function Implementations ***************** */
302 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION to-annual Procedure
303 FUNCTION to-annual RETURNS DECIMAL
304 ( INPUT freq-code AS CHAR, INPUT period-amount AS DEC ) :
305 /*------------------------------------------------------------------------------
306 Purpose: Convert period amount to annual figure
307 Notes:
308 ------------------------------------------------------------------------------*/
309 /* short circuit for most cases */
310 IF freq-code = "MNTH" THEN RETURN (period-amount * 12.0).
312 FIND FrequencyType WHERE FrequencyType.FrequencyCode = freq-code NO-LOCK NO-ERROR.
313 IF NOT AVAILABLE(FrequencyType) THEN RETURN (period-amount * 12.0). /* assume monthly! */
315 IF FrequencyType.RepeatUnits BEGINS "M" THEN
316 RETURN ((period-amount / DEC(FrequencyType.UnitCount)) * 12.0 ).
318 RETURN ((period-amount / DEC(FrequencyType.UnitCount)) * 365.0 ).
320 END FUNCTION.
322 /* _UIB-CODE-BLOCK-END */
323 &ANALYZE-RESUME