1 &ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12
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 month-1
AS INT NO-UNDO INIT ?.
13 DEF VAR month-n
AS INT NO-UNDO INIT ?.
14 DEF VAR forecast-start
AS DATE NO-UNDO.
15 DEF VAR forecast-end
AS DATE NO-UNDO.
17 IF ERROR-STATUS:ERROR THEN RETURN.
19 DEF VAR mfmt
AS CHAR NO-UNDO INITIAL "->>>,>>>,>>9.99".
20 DEF VAR pfmt
AS CHAR NO-UNDO INITIAL "->>9.99999".
21 DEF VAR i
AS INT NO-UNDO.
23 DEF VAR user-name
AS CHAR NO-UNDO.
24 {inc
/username.i
"user-name"}
25 DEF VAR timeStamp
AS CHAR FORMAT "X(44)" NO-UNDO.
26 timeStamp
= STRING( TODAY, "99/99/9999") + ", " + STRING( TIME, "HH:MM:SS") + " for " + user-name.
28 DEF VAR base-font
AS CHAR NO-UNDO INITIAL "fixed,courier,cpi,18,lpi,9,normal".
29 DEF VAR header-font
AS CHAR NO-UNDO INITIAL "proportional,helvetica,point,10,lpi,7,bold".
33 /* revised
/ budget closed-to months
*/
34 DEF VAR forecast-first
AS INT NO-UNDO INITIAL 999999.
35 DEF VAR budget-first
AS INT NO-UNDO INITIAL 999999.
36 {inc
/ofc-set.i
"Budget-Closed-To" "budget-closed-date" "ERROR"}
37 {inc
/ofc-set.i
"Forecast-Closed-To" "forecast-closed-date" "ERROR"}
38 FIND FIRST Month
WHERE Month.StartDate
> DATE(budget-closed-date
) NO-LOCK.
39 budget-first
= Month.MonthCode.
40 FIND FIRST Month
WHERE Month.StartDate
> DATE(forecast-closed-date
) NO-LOCK.
41 forecast-first
= Month.MonthCode.
43 month-1
= MAX( month-1
, MIN(forecast-first
, budget-first
) ).
45 DEF BUFFER CascadeP
FOR AccountBalance.
46 DEF BUFFER CascadeL
FOR AccountBalance.
48 /* _UIB-CODE-BLOCK-END
*/
52 &ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
54 /* ******************** Preprocessor Definitions
******************** */
56 &Scoped-define PROCEDURE-TYPE Procedure
60 /* _UIB-PREPROCESSOR-BLOCK-END
*/
64 /* ************************ Function Prototypes
********************** */
66 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD clear-account-balance Procedure
67 FUNCTION clear-account-balance
RETURNS LOGICAL
68 ( /* no parameters
*/ ) FORWARD.
70 /* _UIB-CODE-BLOCK-END
*/
73 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD set-budget Procedure
74 FUNCTION set-budget
RETURNS LOGICAL
75 ( INPUT delta-bud
AS DEC ) FORWARD.
77 /* _UIB-CODE-BLOCK-END
*/
81 /* *********************** Procedure Settings
************************ */
83 &ANALYZE-SUSPEND _PROCEDURE-SETTINGS
84 /* Settings for
THIS-PROCEDURE
88 Add Fields to
: Neither
89 Other Settings
: CODE-ONLY
COMPILE
91 &ANALYZE-RESUME _END-PROCEDURE-SETTINGS
93 /* ************************* Create Window
************************** */
95 &ANALYZE-SUSPEND _CREATE-WINDOW
96 /* DESIGN Window definition
(used by the UIB
)
97 CREATE WINDOW Procedure
ASSIGN
100 /* END WINDOW DEFINITION
*/
106 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _INCLUDED-LIB Procedure
107 /* ************************* Included-Libraries
*********************** */
110 {inc
/method
/m-txtrep.i
}
112 /* _UIB-CODE-BLOCK-END
*/
117 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Procedure
120 /* *************************** Main Block
*************************** */
122 RUN pclrep-start
( Yes
, "reset,portrait,tm,2,a4,lm,6," + base-font
).
123 OUTPUT TO VALUE(txtrep-print-file
) KEEP-MESSAGES PAGE-SIZE 0.
126 RUN apply-to-budgets.
132 /* _UIB-CODE-BLOCK-END
*/
136 /* ********************** Internal Procedures
*********************** */
138 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE apply-to-budgets Procedure
139 PROCEDURE apply-to-budgets
:
140 /*------------------------------------------------------------------------------
142 ------------------------------------------------------------------------------*/
143 DEF VAR et
AS CHAR NO-UNDO.
144 DEF VAR ec
AS INT NO-UNDO.
145 DEF VAR ac
AS DEC NO-UNDO.
146 DEF VAR amount
AS DEC NO-UNDO.
148 FOR EACH PropForecast
WHERE PropForecast.MonthCode
>= month-1
149 AND PropForecast.MonthCode
<= month-n
150 AND PropForecast.Amount
<> 0 NO-LOCK:
151 et
= PropForecast.EntityType.
152 ec
= PropForecast.EntityCode.
153 amount
= PropForecast.Amount.
154 IF LOOKUP( PropForecast.PropForecastType
, "BASE,GBAS,NEW,GNEW,VACT,GVAC,ONE") > 0 THEN
159 ec
= PropForecast.PropertyCode.
162 FIND AccountBalance
WHERE AccountBalance.EntityType
= et
163 AND AccountBalance.EntityCode
= ec
164 AND AccountBalance.AccountCode
= PropForecast.AccountCode
165 AND AccountBalance.MonthCode
= PropForecast.MonthCode
166 EXCLUSIVE-LOCK NO-ERROR.
167 IF NOT AVAILABLE(AccountBalance
) THEN DO:
168 CREATE AccountBalance.
169 AccountBalance.EntityType
= et.
170 AccountBalance.EntityCode
= ec.
171 AccountBalance.AccountCode
= PropForecast.AccountCode.
172 AccountBalance.MonthCode
= PropForecast.MonthCode.
174 set-budget
( amount
).
180 /* _UIB-CODE-BLOCK-END
*/
184 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE clear-budgets Procedure
185 PROCEDURE clear-budgets
:
186 /*------------------------------------------------------------------------------
187 Purpose
: Clear the budget
/ revised budget figures
188 Notes
: trigger
/wractbal.p writes the GL but we can't override it because
190 ------------------------------------------------------------------------------*/
191 RUN pclrep-line
( base-font
, "Clearing months from " + STRING(month-1
) + " to " + STRING(month-n
) ).
193 FOR EACH AccountBalance
WHERE AccountBalance.EntityType
= "T"
194 AND AccountBalance.EntityCode
> 0 AND AccountBalance.AccountCode
> 0
195 AND AccountBalance.MonthCode
>= month-1
AND AccountBalance.MonthCode
<= month-n
EXCLUSIVE-LOCK:
196 clear-account-balance
().
198 FOR EACH AccountBalance
WHERE AccountBalance.EntityType
= "P"
199 AND AccountBalance.EntityCode
> 0 AND AccountBalance.AccountCode
> 0
200 AND AccountBalance.MonthCode
>= month-1
AND AccountBalance.MonthCode
<= month-n
EXCLUSIVE-LOCK:
201 clear-account-balance
().
203 FOR EACH AccountBalance
WHERE AccountBalance.EntityType
= "L"
204 AND AccountBalance.EntityCode
> 0 AND AccountBalance.AccountCode
> 0
205 AND AccountBalance.MonthCode
>= month-1
AND AccountBalance.MonthCode
<= month-n
EXCLUSIVE-LOCK:
206 clear-account-balance
().
210 /* _UIB-CODE-BLOCK-END
*/
214 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE inst-page-footer Procedure
215 PROCEDURE inst-page-footer
:
216 /*------------------------------------------------------------------------------
217 Purpose
: Print any page footer
218 ------------------------------------------------------------------------------*/
222 /* _UIB-CODE-BLOCK-END
*/
226 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE inst-page-header Procedure
227 PROCEDURE inst-page-header
:
228 /*------------------------------------------------------------------------------
229 Purpose
: Print page header for the rent report
230 ------------------------------------------------------------------------------*/
231 DEF VAR tfmt
AS CHAR NO-UNDO.
233 RUN pclrep-line
( "univers,Point,7,bold,Proportional", TimeStamp
).
234 RUN pclrep-line
( "univers,Point,11,bold,Proportional", SPC
(20) + "AmTrust Forecasting Run - Apply to Budgets" ).
235 RUN pclrep-line
( "", "" ).
237 RUN pclrep-line
( base-font
+ ",bold", "").
239 RUN pclrep-line
( "", "" ).
243 /* _UIB-CODE-BLOCK-END
*/
247 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE parse-parameters Procedure
248 PROCEDURE parse-parameters
:
249 /*------------------------------------------------------------------------------
251 ------------------------------------------------------------------------------*/
252 DEF VAR token
AS CHAR NO-UNDO.
253 DEF VAR i
AS INT NO-UNDO.
255 {inc
/showopts.i
"report-options"}
257 DO i
= 1 TO NUM-ENTRIES( report-options
, "~n" ):
258 token
= ENTRY( i
, report-options
, "~n" ).
260 /* Preview and Property options are set for each run
*/
261 CASE ENTRY( 1, token
):
262 WHEN "Preview" THEN preview
= Yes.
264 WHEN "FromMonth" THEN ASSIGN
265 month-1
= INT(ENTRY(2,token
)).
270 DEF VAR forecast-end
AS DATE NO-UNDO.
271 FIND Month
WHERE Month.MonthCode
= month-1
NO-LOCK NO-ERROR.
272 IF NOT AVAILABLE(Month
) THEN DO:
273 MESSAGE "Invalid starting month for forecast"
274 VIEW-AS ALERT-BOX ERROR.
277 forecast-start
= Month.StartDate.
278 forecast-end
= Month.StartDate
+ 367.
280 FIND LAST Month
WHERE Month.EndDate
< forecast-end
NO-LOCK NO-ERROR.
281 IF NOT AVAILABLE(Month
) THEN DO:
282 MESSAGE "Invalid ending month for forecast"
283 VIEW-AS ALERT-BOX ERROR.
286 forecast-end
= Month.EndDate.
287 month-n
= Month.MonthCode.
291 /* _UIB-CODE-BLOCK-END
*/
295 /* ************************ Function Implementations
***************** */
297 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION clear-account-balance Procedure
298 FUNCTION clear-account-balance
RETURNS LOGICAL
299 ( /* no parameters
*/ ) :
300 /*------------------------------------------------------------------------------
301 Purpose
: Clear any budget
/ revised budget figures
302 Notes
: Checks to see if it's a valid month for applying first.
303 Just
DELETE the accountbalance if there are no transactions.
304 ------------------------------------------------------------------------------*/
307 RUN pclrep-line
( base-font
, AccountBalance.EntityType
+ STRING(AccountBalance.EntityCode
,"99999")
308 + STRING(AccountBalance.AccountCode
, " 9999.99 ")
309 + STRING(AccountBalance.MonthCode
, ">>,>>9 ")
312 IF AccountBalance.MonthCode
>= forecast-first
THEN
313 AccountBalance.RevisedBudget
= 0.0 .
315 IF AccountBalance.MonthCode
>= budget-first
THEN
316 AccountBalance.Budget
= 0.0 .
320 /* _UIB-CODE-BLOCK-END
*/
324 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION set-budget Procedure
325 FUNCTION set-budget
RETURNS LOGICAL
326 ( INPUT delta-bud
AS DEC ) :
327 /*------------------------------------------------------------------------------
328 Purpose
: Apply the figure to the current AccountBalance budget figure
329 Notes
: Checks to see if it's a valid month for applying first.
330 ------------------------------------------------------------------------------*/
331 DEF VAR et
AS CHAR NO-UNDO.
332 DEF VAR ec
AS INT NO-UNDO.
334 IF AccountBalance.MonthCode
>= forecast-first
THEN
335 AccountBalance.RevisedBudget
= AccountBalance.RevisedBudget
+ delta-bud.
336 IF AccountBalance.MonthCode
>= budget-first
THEN
337 AccountBalance.Budget
= AccountBalance.Budget
+ delta-bud.
339 /* We use two separate buffers for the cascading
- it may be a wee bit
*/
341 IF AccountBalance.EntityType
<> "L"
342 AND AccountBalance.MonthCode
>= forecast-first
343 AND AccountBalance.MonthCode
>= budget-first
345 IF AccountBalance.EntityType
= "T" THEN DO:
346 /* Cascade update to relevant entity account of the tenant
*/
347 FIND Tenant
WHERE Tenant.TenantCode
= AccountBalance.EntityCode
NO-LOCK.
348 et
= Tenant.EntityType.
349 ec
= Tenant.EntityCode.
350 FIND CascadeP
WHERE CascadeP.EntityType
= et
351 AND CascadeP.EntityCode
= ec
352 AND CascadeP.AccountCode
= AccountBalance.AccountCode
353 AND CascadeP.MonthCode
= AccountBalance.MonthCode
EXCLUSIVE-LOCK NO-ERROR.
354 IF NOT AVAILABLE(CascadeP
) THEN DO:
356 CascadeP.EntityType
= et.
357 CascadeP.EntityCode
= ec.
358 CascadeP.AccountCode
= AccountBalance.AccountCode.
359 CascadeP.MonthCode
= AccountBalance.MonthCode.
361 IF CascadeP.MonthCode
>= forecast-first
THEN CascadeP.RevisedBudget
= CascadeP.RevisedBudget
+ delta-bud.
362 IF CascadeP.MonthCode
>= budget-first
THEN CascadeP.Budget
= CascadeP.Budget
+ delta-bud.
365 et
= AccountBalance.EntityType
366 ec
= AccountBalance.EntityCode.
368 /* Property-
>ledger update is done by the write trigger
(trigger
/wractbal.p
)
370 /* cascade update to relevant GL account
*/
371 FIND Property
WHERE Property.PropertyCode
= ec
NO-LOCK.
373 ec
= Property.CompanyCode.
374 FIND CascadeL
WHERE CascadeL.EntityType
= et
375 AND CascadeL.EntityCode
= ec
376 AND CascadeL.AccountCode
= AccountBalance.AccountCode
377 AND CascadeL.MonthCode
= AccountBalance.MonthCode
EXCLUSIVE-LOCK NO-ERROR.
378 IF NOT AVAILABLE(CascadeL
) THEN DO:
380 CascadeL.EntityType
= et.
381 CascadeL.EntityCode
= ec.
382 CascadeL.AccountCode
= AccountBalance.AccountCode.
383 CascadeL.MonthCode
= AccountBalance.MonthCode.
385 IF CascadeL.MonthCode
>= forecast-first
THEN CascadeL.RevisedBudget
= CascadeL.RevisedBudget
+ delta-bud.
386 IF CascadeL.MonthCode
>= budget-first
THEN CascadeL.Budget
= CascadeL.Budget
+ delta-bud.
391 RUN pclrep-line
( base-font
, AccountBalance.EntityType
+ STRING(AccountBalance.EntityCode
,"99999")
392 + STRING(AccountBalance.AccountCode
, " 9999.99 ")
393 + STRING(AccountBalance.MonthCode
, ">>,>>9 ")
394 + STRING( delta-bud
, "->>,>>>,>>9.99 ") ).
400 /* _UIB-CODE-BLOCK-END
*/