Add blank column, rename column.
[capital-apms-progress.git] / process / report / expense-variance.p
blobd1ce12163103371bc5afe1f50cf866e29e99246c
1 &ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12
2 &ANALYZE-RESUME
3 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS Procedure
4 /*--------------------------------------------------------------------------
5 Expense Variance Report
6 ------------------------------------------------------------------------*/
7 DEF INPUT PARAMETER report-options AS CHAR NO-UNDO.
9 &GLOB MIN-KEY -99999
10 &GLOB MAX-KEY 9999999
12 DEF VAR preview AS LOGI NO-UNDO INIT No.
13 DEF VAR exporting AS LOGI NO-UNDO INIT No.
14 DEF VAR file-name AS CHAR NO-UNDO INIT "".
15 DEF VAR by-account AS LOGI NO-UNDO INIT No.
16 DEF VAR consolidate-subs AS LOGI NO-UNDO INIT No.
17 DEF VAR show-vacant-space AS LOGI NO-UNDO INIT Yes.
18 DEF VAR detailed AS LOGI NO-UNDO INIT No.
19 DEF VAR client-code AS CHAR NO-UNDO INIT ?.
20 DEF VAR company-list AS CHAR NO-UNDO INIT ?.
21 DEF VAR group-list AS CHAR NO-UNDO INIT ?.
22 DEF VAR revised AS LOGI NO-UNDO INIT No.
23 DEF VAR manager-code AS INT NO-UNDO INIT ?.
24 DEF VAR region-code AS CHAR NO-UNDO INIT ?.
25 DEF VAR entity-type AS CHAR NO-UNDO INIT ?.
26 DEF VAR property-1 AS INT NO-UNDO INIT 0.
27 DEF VAR property-n AS INT NO-UNDO INIT {&MAX-KEY}.
28 DEF VAR account-1 AS DEC NO-UNDO INIT 0.
29 DEF VAR account-n AS DEC NO-UNDO INIT {&MAX-KEY}.
30 DEF VAR company-1 AS INT NO-UNDO INIT 0.
31 DEF VAR company-n AS INT NO-UNDO INIT {&MAX-KEY}.
32 DEF VAR month-1 AS INT NO-UNDO INIT ?.
33 DEF VAR month-n AS INT NO-UNDO INIT ?.
34 DEF VAR multiplier AS INT NO-UNDO INIT 1.
35 DEF VAR page-title-1 AS CHAR NO-UNDO.
36 DEF VAR page-title-2 AS CHAR NO-UNDO.
37 RUN parse-parameters.
39 DEF VAR user-name AS CHAR NO-UNDO.
40 {inc/username.i "user-name"}
41 DEF VAR timeStamp AS CHAR FORMAT "X(44)" NO-UNDO.
42 timeStamp = STRING( TODAY, "99/99/9999") + ", " + STRING( TIME, "HH:MM:SS") + " for " + user-name.
44 DEF VAR major-key AS DEC NO-UNDO INITIAL ?.
45 DEF VAR report-key AS DEC NO-UNDO.
46 DEF VAR pr-line AS CHAR INIT "" NO-UNDO. /* used everywhere to hold print line */
48 DEF VAR title-font AS CHAR NO-UNDO INITIAL "proportional,helv,point,12,bold".
49 DEF VAR time-font AS CHAR NO-UNDO INITIAL "proportional,helv,point,6,normal".
50 DEF VAR break1-font AS CHAR NO-UNDO INITIAL "proportional,helv,point,12,bold".
51 DEF VAR break2-font AS CHAR NO-UNDO INITIAL "proportional,helv,point,8,bold".
52 DEF VAR line1-font AS CHAR NO-UNDO INITIAL "fixed,courier,cpi,18,lpi,9,bold".
53 DEF VAR line2-font AS CHAR NO-UNDO INITIAL "fixed,courier,cpi,18,lpi,9,normal".
54 DEF VAR amt-fmt AS CHAR INIT "(>>,>>>,>>9.99)" NO-UNDO.
55 IF exporting THEN amt-fmt = "->>>>>>>>>>9.99".
56 DEF VAR i AS INT NO-UNDO.
58 {inc/ofc-this.i}
60 DEF TEMP-TABLE RepLine NO-UNDO
61 FIELD Key AS DEC
62 FIELD Key2 AS DEC
63 FIELD Description AS CHAR
64 FIELD Balance LIKE AccountBalance.Balance
65 FIELD Budget LIKE AccountBalance.Budget
66 FIELD Variance LIKE AccountBalance.Budget
67 FIELD Month LIKE AccountBalance.Balance
68 INDEX XPKPseudo IS UNIQUE PRIMARY Key Key2.
70 DEF BUFFER MajorLine FOR RepLine.
72 /* _UIB-CODE-BLOCK-END */
73 &ANALYZE-RESUME
76 &ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
78 /* ******************** Preprocessor Definitions ******************** */
80 &Scoped-define PROCEDURE-TYPE Procedure
81 &Scoped-define DB-AWARE no
85 /* _UIB-PREPROCESSOR-BLOCK-END */
86 &ANALYZE-RESUME
89 /* ************************ Function Prototypes ********************** */
91 &IF DEFINED(EXCLUDE-include-company) = 0 &THEN
93 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD include-company Procedure
94 FUNCTION include-company RETURNS LOGICAL
95 ( /* parameter-definitions */ ) FORWARD.
97 /* _UIB-CODE-BLOCK-END */
98 &ANALYZE-RESUME
100 &ENDIF
102 &IF DEFINED(EXCLUDE-include-property) = 0 &THEN
104 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD include-property Procedure
105 FUNCTION include-property RETURNS LOGICAL
106 ( /* parameter-definitions */ ) FORWARD.
108 /* _UIB-CODE-BLOCK-END */
109 &ANALYZE-RESUME
111 &ENDIF
113 &IF DEFINED(EXCLUDE-include-tenant) = 0 &THEN
115 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD include-tenant Procedure
116 FUNCTION include-tenant RETURNS LOGICAL
117 ( /* parameter-definitions */ ) FORWARD.
119 /* _UIB-CODE-BLOCK-END */
120 &ANALYZE-RESUME
122 &ENDIF
125 /* *********************** Procedure Settings ************************ */
127 &ANALYZE-SUSPEND _PROCEDURE-SETTINGS
128 /* Settings for THIS-PROCEDURE
129 Type: Procedure
130 Allow:
131 Frames: 0
132 Add Fields to: Neither
133 Other Settings: CODE-ONLY COMPILE
135 &ANALYZE-RESUME _END-PROCEDURE-SETTINGS
137 /* ************************* Create Window ************************** */
139 &ANALYZE-SUSPEND _CREATE-WINDOW
140 /* DESIGN Window definition (used by the UIB)
141 CREATE WINDOW Procedure ASSIGN
142 HEIGHT = 20.15
143 WIDTH = 40.
144 /* END WINDOW DEFINITION */
146 &ANALYZE-RESUME
148 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _INCLUDED-LIB Procedure
149 /* ************************* Included-Libraries *********************** */
151 {inc/method/m-txtrep.i}
153 /* _UIB-CODE-BLOCK-END */
154 &ANALYZE-RESUME
160 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Procedure
163 /* *************************** Main Block *************************** */
165 OUTPUT TO VALUE( IF exporting THEN file-name ELSE txtrep-print-file ) KEEP-MESSAGES PAGE-SIZE 0.
166 RUN pclrep-start( preview OR exporting,
167 "reset,portrait,tm,2,a4,lm,6," + line1-font).
169 RUN build-variance-info.
170 RUN output-report.
172 OUTPUT CLOSE.
174 IF exporting THEN
175 MESSAGE "Export Complete" VIEW-AS ALERT-BOX INFORMATION TITLE "Finished".
176 ELSE
177 RUN pclrep-finish.
179 /* _UIB-CODE-BLOCK-END */
180 &ANALYZE-RESUME
183 /* ********************** Internal Procedures *********************** */
185 &IF DEFINED(EXCLUDE-add-one-account) = 0 &THEN
187 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE add-one-account Procedure
188 PROCEDURE add-one-account :
189 /*------------------------------------------------------------------------------
190 Purpose:
191 ------------------------------------------------------------------------------*/
192 DEF INPUT PARAMETER et AS CHAR NO-UNDO.
193 DEF INPUT PARAMETER ec AS INT NO-UNDO.
194 DEF INPUT PARAMETER ac AS DEC NO-UNDO.
196 DEF VAR delta-bal AS DEC NO-UNDO INITIAL 0.0 .
197 DEF VAR delta-bud AS DEC NO-UNDO INITIAL 0.0 .
198 DEF VAR delta-mth AS DEC NO-UNDO INITIAL 0.0 .
200 FOR EACH AccountBalance WHERE AccountBalance.EntityType = et
201 AND AccountBalance.EntityCode = ec
202 AND AccountBalance.AccountCode = ac
203 AND AccountBalance.MonthCode >= month-1
204 AND AccountBalance.MonthCode <= month-n NO-LOCK:
205 delta-bal = delta-bal + (AccountBalance.Balance * multiplier).
206 delta-bud = delta-bud + ((IF revised THEN AccountBalance.RevisedBudget ELSE AccountBalance.Budget) * multiplier).
207 IF AccountBalance.MonthCode = month-n THEN
208 delta-mth = ((IF revised THEN AccountBalance.RevisedBudget ELSE AccountBalance.Budget) * multiplier)
209 - (AccountBalance.Balance * multiplier) .
211 END.
213 RepLine.Balance = RepLine.Balance + delta-bal.
214 RepLine.Budget = RepLine.Budget + delta-bud.
215 RepLine.Variance = (RepLine.Budget - RepLine.Balance) * multiplier.
216 RepLine.Month = RepLine.Month + delta-mth.
218 IF AVAILABLE(MajorLine) THEN DO:
219 MajorLine.Balance = MajorLine.Balance + delta-bal.
220 MajorLine.Budget = MajorLine.Budget + delta-bud.
221 MajorLine.Variance = (MajorLine.Budget - MajorLine.Balance) * multiplier.
222 MajorLine.Month = MajorLine.Month + delta-mth.
223 END.
225 END PROCEDURE.
227 /* _UIB-CODE-BLOCK-END */
228 &ANALYZE-RESUME
230 &ENDIF
232 &IF DEFINED(EXCLUDE-build-each-account) = 0 &THEN
234 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE build-each-account Procedure
235 PROCEDURE build-each-account :
236 /*------------------------------------------------------------------------------
237 Purpose:
238 ------------------------------------------------------------------------------*/
239 DEF VAR ac AS DEC NO-UNDO.
241 FOR EACH ChartOfAccount WHERE ChartOfAccount.AccountCode >= account-1
242 AND ChartOfAccount.AccountCode <= account-n
243 AND LOOKUP( ChartOfAccount.AccountGroupCode, group-list ) > 0 NO-LOCK:
244 ac = ChartOfAccount.AccountCode.
245 IF consolidate-subs THEN ac = TRUNC( ac, 0 ).
246 report-key = ac.
247 FIND RepLine WHERE RepLine.Key = major-key AND RepLine.Key2 = report-key NO-ERROR.
248 IF NOT AVAILABLE(RepLine) THEN DO:
249 CREATE RepLine.
250 RepLine.Key = major-key.
251 RepLine.Key2 = report-key.
252 RepLine.Description = STRING( ChartOfAccount.AccountCode, (IF consolidate-subs THEN (IF exporting THEN "9999" ELSE " 9999 ") ELSE "9999.99"))
253 + (IF exporting THEN '","' ELSE " ") + ChartOfAccount.Name .
254 END.
255 RUN build-one-account(ChartOfAccount.AccountCode).
256 END.
258 END PROCEDURE.
260 /* _UIB-CODE-BLOCK-END */
261 &ANALYZE-RESUME
263 &ENDIF
265 &IF DEFINED(EXCLUDE-build-each-entity) = 0 &THEN
267 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE build-each-entity Procedure
268 PROCEDURE build-each-entity :
269 /*------------------------------------------------------------------------------
270 Purpose:
271 ------------------------------------------------------------------------------*/
272 DEF VAR sep AS CHAR INITIAL " " NO-UNDO.
274 IF exporting THEN sep = '","'.
275 CASE entity-type:
276 WHEN "P" THEN DO:
277 FOR EACH Property NO-LOCK:
278 IF NOT include-property() THEN NEXT.
279 report-key = Property.PropertyCode.
280 CREATE RepLine.
281 RepLine.Key = major-key.
282 RepLine.Key2 = report-key.
283 RepLine.Description = STRING( Property.PropertyCode, "99999") + sep + Property.Name .
284 RUN build-one-entity( entity-type, Property.PropertyCode ).
285 END.
286 END.
287 WHEN "L" THEN DO:
288 FOR EACH Company NO-LOCK:
289 IF NOT include-company() THEN NEXT.
290 report-key = Company.CompanyCode.
291 CREATE RepLine.
292 RepLine.Key = major-key.
293 RepLine.Key2 = report-key.
294 RepLine.Description = STRING( Company.CompanyCode, "99999") + sep + Company.LegalName .
295 RUN build-one-entity( entity-type, Company.CompanyCode ).
296 END.
297 END.
298 WHEN "T" THEN DO:
299 FOR EACH Property NO-LOCK:
300 IF NOT include-property() THEN NEXT.
301 FOR EACH Tenant WHERE Tenant.EntityType = "P" AND Tenant.EntityCode = Property.PropertyCode NO-LOCK:
302 IF NOT include-tenant() THEN NEXT.
303 report-key = Property.PropertyCode.
304 FIND RepLine WHERE RepLine.Key = major-key AND RepLine.Key2 = report-key NO-ERROR.
305 IF NOT AVAILABLE(RepLine) THEN DO:
306 CREATE RepLine.
307 RepLine.Key = major-key.
308 RepLine.Key2 = report-key.
309 RepLine.Description = STRING( Property.PropertyCode, "99999") + sep + Property.Name .
310 END.
311 RUN build-one-entity( entity-type, Tenant.TenantCode ).
312 END.
313 IF detailed THEN DO:
314 report-key = Property.PropertyCode.
315 FIND RepLine WHERE RepLine.Key = major-key AND RepLine.Key2 = report-key NO-ERROR.
316 IF NOT AVAILABLE(RepLine) THEN DO:
317 CREATE RepLine.
318 RepLine.Key = major-key.
319 RepLine.Key2 = report-key.
320 RepLine.Description = STRING( Property.PropertyCode, "99999") + sep + Property.Name .
321 END.
322 RUN build-vacant-entity( Property.PropertyCode ).
323 END.
324 END.
325 END.
326 END CASE.
328 END PROCEDURE.
330 /* _UIB-CODE-BLOCK-END */
331 &ANALYZE-RESUME
333 &ENDIF
335 &IF DEFINED(EXCLUDE-build-one-account) = 0 &THEN
337 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE build-one-account Procedure
338 PROCEDURE build-one-account :
339 /*------------------------------------------------------------------------------
340 Purpose:
341 ------------------------------------------------------------------------------*/
342 DEF INPUT PARAMETER ac AS DEC NO-UNDO.
344 CASE entity-type:
345 WHEN "P" THEN DO:
346 FOR EACH Property NO-LOCK:
347 IF NOT include-property() THEN NEXT.
348 RUN add-one-account( entity-type, Property.PropertyCode, ac ).
349 END.
350 END.
351 WHEN "L" THEN DO:
352 FOR EACH Company NO-LOCK:
353 IF NOT include-company() THEN NEXT.
354 RUN add-one-account( entity-type, Company.CompanyCode, ac ).
355 END.
356 END.
357 WHEN "T" THEN DO:
358 FOR EACH Property NO-LOCK:
359 IF NOT include-property() THEN NEXT.
360 FOR EACH Tenant WHERE Tenant.EntityType = "P" AND Tenant.EntityCode = Property.PropertyCode NO-LOCK:
361 IF NOT include-tenant() THEN NEXT.
362 RUN add-one-account( entity-type, Tenant.TenantCode, ac ).
363 END.
364 END.
365 END.
366 END CASE.
368 IF AVAILABLE(RepLine) AND RepLine.Balance = 0 AND RepLine.Budget = 0 THEN DELETE RepLine.
370 END PROCEDURE.
372 /* _UIB-CODE-BLOCK-END */
373 &ANALYZE-RESUME
375 &ENDIF
377 &IF DEFINED(EXCLUDE-build-one-entity) = 0 &THEN
379 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE build-one-entity Procedure
380 PROCEDURE build-one-entity :
381 /*------------------------------------------------------------------------------
382 Purpose:
383 ------------------------------------------------------------------------------*/
384 DEF INPUT PARAMETER et AS CHAR NO-UNDO.
385 DEF INPUT PARAMETER ec AS INT NO-UNDO.
387 DEF VAR ac AS DEC NO-UNDO.
389 FOR EACH ChartOfAccount WHERE ChartOfAccount.AccountCode >= account-1
390 AND ChartOfAccount.AccountCode <= account-n
391 AND LOOKUP( ChartOfAccount.AccountGroupCode, group-list ) > 0 NO-LOCK:
392 IF detailed THEN DO:
393 ac = ChartOfAccount.AccountCode.
394 IF consolidate-subs THEN ac = TRUNC( ac, 0 ).
395 report-key = ac.
396 FIND RepLine WHERE RepLine.Key = major-key AND RepLine.Key2 = report-key NO-ERROR.
397 IF NOT AVAILABLE(RepLine) THEN DO:
398 CREATE RepLine.
399 RepLine.Key = major-key.
400 RepLine.Key2 = report-key.
401 RepLine.Description = STRING( ChartOfAccount.AccountCode, (IF consolidate-subs THEN (IF exporting THEN "9999" ELSE " 9999 ") ELSE "9999.99"))
402 + (IF exporting THEN '","' ELSE " ") + ChartOfAccount.Name .
403 END.
404 END.
405 RUN add-one-account( et, ec, ChartOfAccount.AccountCode ).
406 IF detailed AND RepLine.Balance = 0 AND RepLine.Budget = 0 THEN DELETE RepLine.
407 END.
408 IF detailed THEN DO:
409 IF AVAILABLE(MajorLine) AND MajorLine.Balance = 0 AND MajorLine.Budget = 0 THEN DELETE MajorLine.
410 END.
411 ELSE IF RepLine.Balance = 0 AND RepLine.Budget = 0 THEN DELETE RepLine.
413 END PROCEDURE.
415 /* _UIB-CODE-BLOCK-END */
416 &ANALYZE-RESUME
418 &ENDIF
420 &IF DEFINED(EXCLUDE-build-vacant-entity) = 0 &THEN
422 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE build-vacant-entity Procedure
423 PROCEDURE build-vacant-entity :
424 /*------------------------------------------------------------------------------
425 Purpose:
426 ------------------------------------------------------------------------------*/
427 DEF INPUT PARAMETER property-code AS INT NO-UNDO.
429 DEF VAR bal AS DEC NO-UNDO.
430 DEF VAR bud AS DEC NO-UNDO.
432 FOR EACH ChartOfAccount WHERE ChartOfAccount.AccountCode >= account-1
433 AND ChartOfAccount.AccountCode <= account-n
434 AND LOOKUP( ChartOfAccount.AccountGroupCode, group-list ) > 0 NO-LOCK:
435 FOR EACH AccountBalance WHERE AccountBalance.EntityType = "P"
436 AND AccountBalance.EntityCode = property-code
437 AND AccountBalance.AccountCode = ChartOfAccount.AccountCode
438 AND AccountBalance.MonthCode >= month-1
439 AND AccountBalance.MonthCode <= month-n NO-LOCK:
440 bal = bal + (AccountBalance.Balance * multiplier).
441 bud = bud + ((IF revised THEN AccountBalance.RevisedBudget ELSE AccountBalance.Budget) * multiplier).
442 END.
443 END.
445 /* the vacant space is the difference between the property amount and the sum
446 * of the tenants
448 IF AVAILABLE(MajorLine) THEN ASSIGN
449 RepLine.Balance = bal - MajorLine.Balance
450 RepLine.Budget = bud - MajorLine.Budget.
451 ELSE ASSIGN
452 RepLine.Balance = bal
453 RepLine.Budget = bud.
455 IF RepLine.Balance = 0 AND RepLine.Budget = 0 THEN DO:
456 DELETE RepLine.
457 RETURN.
458 END.
460 RepLine.Variance = (RepLine.Budget - RepLine.Balance) * multiplier.
462 IF NOT AVAILABLE(MajorLine) THEN RETURN.
463 MajorLine.Balance = MajorLine.Balance + RepLine.Balance.
464 MajorLine.Budget = MajorLine.Budget + RepLine.Budget.
465 MajorLine.Variance = (MajorLine.Budget - MajorLine.Balance) * multiplier.
467 END PROCEDURE.
469 /* _UIB-CODE-BLOCK-END */
470 &ANALYZE-RESUME
472 &ENDIF
474 &IF DEFINED(EXCLUDE-build-variance-info) = 0 &THEN
476 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE build-variance-info Procedure
477 PROCEDURE build-variance-info :
478 /*------------------------------------------------------------------------------
479 Purpose:
480 ------------------------------------------------------------------------------*/
482 IF detailed THEN RUN detailed-each-entity.
483 ELSE IF by-account THEN RUN build-each-account.
484 ELSE RUN build-each-entity.
486 END PROCEDURE.
488 /* _UIB-CODE-BLOCK-END */
489 &ANALYZE-RESUME
491 &ENDIF
493 &IF DEFINED(EXCLUDE-detailed-each-entity) = 0 &THEN
495 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE detailed-each-entity Procedure
496 PROCEDURE detailed-each-entity :
497 /*------------------------------------------------------------------------------
498 Purpose:
499 ------------------------------------------------------------------------------*/
500 DEF VAR sep AS CHAR INITIAL " " NO-UNDO.
502 IF exporting THEN sep = '","'.
503 CASE entity-type:
504 WHEN "P" THEN DO:
505 FOR EACH Property NO-LOCK:
506 IF NOT include-property() THEN NEXT.
507 major-key = Property.PropertyCode.
508 CREATE MajorLine.
509 MajorLine.Key = major-key.
510 MajorLine.Key2 = {&MIN-KEY}.
511 MajorLine.Description = STRING( Property.PropertyCode, "99999") + sep + Property.Name .
512 CREATE MajorLine.
513 MajorLine.Key = major-key.
514 MajorLine.Key2 = {&MAX-KEY}.
515 MajorLine.Description = STRING( Property.PropertyCode, "99999") + sep + Property.Name .
516 RUN build-one-entity( "P", Property.PropertyCode ).
517 END.
518 END.
519 WHEN "L" THEN DO:
520 FOR EACH Company NO-LOCK:
521 IF NOT include-company() THEN NEXT.
522 major-key = Company.CompanyCode.
523 CREATE MajorLine.
524 MajorLine.Key = major-key.
525 MajorLine.Key2 = {&MIN-KEY}.
526 MajorLine.Description = STRING( Company.CompanyCode, "99999") + sep + Company.LegalName .
527 CREATE MajorLine.
528 MajorLine.Key = major-key.
529 MajorLine.Key2 = {&MAX-KEY}.
530 MajorLine.Description = STRING( Company.CompanyCode, "99999") + sep + Company.LegalName .
531 RUN build-one-entity( "L", Company.CompanyCode ).
532 END.
533 END.
534 WHEN "T" THEN DO:
535 detailed = No.
536 FOR EACH Property NO-LOCK:
537 IF NOT include-property() THEN NEXT.
538 major-key = Property.PropertyCode.
539 CREATE MajorLine.
540 MajorLine.Key = major-key.
541 MajorLine.Key2 = {&MIN-KEY}.
542 MajorLine.Description = STRING( Property.PropertyCode, "99999") + sep + Property.Name .
543 CREATE MajorLine.
544 MajorLine.Key = major-key.
545 MajorLine.Key2 = {&MAX-KEY}.
546 MajorLine.Description = STRING( Property.PropertyCode, "99999") + sep + Property.Name .
547 FOR EACH Tenant WHERE Tenant.EntityType = "P" AND Tenant.EntityCode = Property.PropertyCode NO-LOCK:
548 IF NOT include-tenant() THEN NEXT.
549 report-key = Tenant.TenantCode.
550 CREATE RepLine.
551 RepLine.Key = major-key.
552 RepLine.Key2 = report-key.
553 RepLine.Description = STRING( Tenant.TenantCode, "99999") + sep + Tenant.Name .
554 RUN build-one-entity( entity-type, Tenant.TenantCode ).
555 END.
556 IF show-vacant-space THEN DO:
557 report-key = 999999.
558 CREATE RepLine.
559 RepLine.Key = major-key.
560 RepLine.Key2 = report-key.
561 RepLine.Description = " Vacant Areas" .
562 RUN build-vacant-entity( Property.PropertyCode ).
563 END.
564 IF MajorLine.Balance = 0 AND MajorLine.Budget = 0 THEN DELETE MajorLine.
565 END.
566 END.
567 WHEN "TA" THEN DO:
568 FOR EACH Property NO-LOCK:
569 IF NOT include-property() THEN NEXT.
570 FOR EACH Tenant WHERE Tenant.EntityType = "P"
571 AND Tenant.EntityCode = Property.PropertyCode NO-LOCK:
572 IF NOT include-tenant() THEN NEXT.
573 major-key = Tenant.TenantCode.
574 CREATE MajorLine.
575 MajorLine.Key = major-key.
576 MajorLine.Key2 = {&MIN-KEY}.
577 MajorLine.Description = STRING( Tenant.TenantCode, "99999") + sep + Tenant.Name .
578 CREATE MajorLine.
579 MajorLine.Key = major-key.
580 MajorLine.Key2 = {&MAX-KEY}.
581 MajorLine.Description = STRING( Tenant.TenantCode, "99999") + sep + Tenant.Name .
582 RUN build-one-entity( "T", Tenant.TenantCode ).
583 END.
584 END.
585 END.
586 END CASE.
588 END PROCEDURE.
590 /* _UIB-CODE-BLOCK-END */
591 &ANALYZE-RESUME
593 &ENDIF
595 &IF DEFINED(EXCLUDE-inst-page-footer) = 0 &THEN
597 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE inst-page-footer Procedure
598 PROCEDURE inst-page-footer :
599 /*------------------------------------------------------------------------------
600 Purpose:
601 ------------------------------------------------------------------------------*/
603 END PROCEDURE.
605 /* _UIB-CODE-BLOCK-END */
606 &ANALYZE-RESUME
608 &ENDIF
610 &IF DEFINED(EXCLUDE-inst-page-header) = 0 &THEN
612 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE inst-page-header Procedure
613 PROCEDURE inst-page-header :
614 /*------------------------------------------------------------------------------
615 Purpose:
616 ------------------------------------------------------------------------------*/
618 pr-line = timeStamp.
619 IF NOT exporting THEN DO:
620 pr-line = pr-line + (IF preview THEN SPC(65) ELSE CHR(13) + SPC(275)) + "Page: " + STRING( pclrep-page-number ).
621 END.
622 RUN pclrep-line( time-font, '"' + pr-line + '"').
624 RUN pclrep-line( ?, "").
625 IF exporting THEN DO:
626 RUN pclrep-line( ?, '"' + page-title-1 + ", " + page-title-2 + '"' ).
627 RUN pclrep-line( ?, "Account,Name,Actual,Budget,Variance,Month").
628 END.
629 ELSE DO:
630 RUN pclrep-line( ?, "").
631 RUN pclrep-line( title-font, SPC(45 - INT( LENGTH(page-title-1) / 2)) + page-title-1 ).
632 RUN pclrep-line( time-font, "").
633 RUN pclrep-line( title-font, SPC(45 - INT( LENGTH(page-title-2) / 2)) + page-title-2 ).
634 RUN pclrep-line( time-font, "").
635 RUN pclrep-line( line1-font, SPC(70) + "Actual Budget Variance Month").
636 RUN pclrep-line( time-font, "").
637 END.
639 END PROCEDURE.
641 /* _UIB-CODE-BLOCK-END */
642 &ANALYZE-RESUME
644 &ENDIF
646 &IF DEFINED(EXCLUDE-output-report) = 0 &THEN
648 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE output-report Procedure
649 PROCEDURE output-report :
650 /*------------------------------------------------------------------------------
651 Purpose:
652 ------------------------------------------------------------------------------*/
653 DEF VAR line AS CHAR NO-UNDO.
654 DEF VAR balance-total AS DEC NO-UNDO.
655 DEF VAR budget-total AS DEC NO-UNDO.
656 DEF VAR variance-total AS DEC NO-UNDO.
657 DEF VAR month-total AS DEC NO-UNDO.
659 DEF BUFFER RepLine2 FOR RepLine.
661 FOR EACH RepLine:
662 IF exporting THEN
663 line = '"' + RepLine.Description + '",'
664 + TRIM(STRING( RepLine.Balance, amt-fmt )) + ","
665 + TRIM(STRING( RepLine.Budget, amt-fmt )) + ","
666 + TRIM(STRING( RepLine.Variance, amt-fmt )) + ","
667 + TRIM(STRING( RepLine.Month, amt-fmt )).
668 ELSE
669 line = STRING( RepLine.Description, "X(65)")
670 + STRING( RepLine.Balance, amt-fmt ) + " "
671 + STRING( RepLine.Budget, amt-fmt ) + " "
672 + STRING( RepLine.Variance, amt-fmt ) + " "
673 + STRING( RepLine.Month, amt-fmt ).
674 IF RepLine.Key2 = {&MIN-KEY} THEN DO:
675 IF CAN-FIND( FIRST RepLine2 WHERE RepLine2.Key = RepLine.Key AND RepLine2.Key2 = {&MAX-KEY} ) THEN DO:
676 IF exporting THEN
677 RUN pclrep-line( ?, '"' + RepLine.Description + '"' ).
678 ELSE
679 RUN pclrep-line( line1-font, RepLine.Description ).
680 RUN pclrep-line( ?, ? ).
681 END.
682 END.
683 ELSE IF RepLine.Key2 = {&MAX-KEY} THEN DO:
684 IF exporting THEN
685 RUN pclrep-line( ?, "," + FILL( ",--------------", 4) ).
686 ELSE
687 RUN pclrep-line( line1-font, SPC(63) + FILL( " --------------", 4) ).
688 RUN pclrep-line( ?, line ).
689 RUN pclrep-line( ?, ? ).
690 RUN pclrep-line( ?, ? ).
691 END.
692 ELSE DO:
693 RUN pclrep-line( (IF exporting THEN ? ELSE line2-font), line ).
694 balance-total = balance-total + RepLine.Balance .
695 budget-total = budget-total + RepLine.Budget .
696 variance-total = variance-total + RepLine.Variance .
697 month-total = month-total + RepLine.Month .
698 END.
699 END.
701 IF exporting THEN
702 line = "," + FILL( ",==============", 4).
703 ELSE
704 line = SPC(63) + FILL( " ==============", 4).
706 RUN pclrep-line( line1-font, line ).
707 IF exporting THEN
708 line = ',"Totals",'
709 + TRIM(STRING( balance-total, amt-fmt )) + ","
710 + TRIM(STRING( budget-total, amt-fmt )) + ","
711 + TRIM(STRING( variance-total, amt-fmt )) + ","
712 + TRIM(STRING( month-total, amt-fmt )).
713 ELSE
714 line = STRING( "Totals", "X(65)")
715 + STRING( balance-total, amt-fmt ) + " "
716 + STRING( budget-total, amt-fmt ) + " "
717 + STRING( variance-total, amt-fmt ) + " "
718 + STRING( month-total, amt-fmt ).
720 RUN pclrep-line( line1-font, line ).
722 END PROCEDURE.
724 /* _UIB-CODE-BLOCK-END */
725 &ANALYZE-RESUME
727 &ENDIF
729 &IF DEFINED(EXCLUDE-parse-parameters) = 0 &THEN
731 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE parse-parameters Procedure
732 PROCEDURE parse-parameters :
733 /*------------------------------------------------------------------------------
734 Purpose:
735 ------------------------------------------------------------------------------*/
736 DEF VAR token AS CHAR NO-UNDO.
737 DEF VAR i AS INT NO-UNDO.
739 {inc/showopts.i "report-options"}
741 DO i = 1 TO NUM-ENTRIES( report-options, "~n" ):
742 token = ENTRY( i, report-options, "~n" ).
744 CASE ENTRY( 1, token ):
745 WHEN "Preview" THEN preview = Yes.
746 WHEN "ConsolidateSubs" THEN consolidate-subs = Yes.
747 WHEN "NoVacantSpace" THEN show-vacant-space = No.
748 WHEN "AccountGroups" THEN group-list = SUBSTRING( token, INDEX( token, ",") + 1).
749 WHEN "File" THEN ASSIGN
750 exporting = Yes
751 file-name = SUBSTRING( token, INDEX( token, ",") + 1).
753 WHEN "Month" THEN ASSIGN
754 month-1 = INT(ENTRY(2,token))
755 month-n = INT(ENTRY(3,token)).
757 WHEN "Style" THEN DO:
758 CASE ENTRY( 2, token ):
759 WHEN "Detailed" THEN detailed = Yes.
760 WHEN "Account" THEN by-account = Yes.
761 END CASE.
762 END.
764 WHEN "AccountRange" THEN ASSIGN
765 account-1 = DEC(ENTRY(2,token))
766 account-n = DEC(ENTRY(3,token)).
768 WHEN "Company" THEN DO:
769 CASE ENTRY(2,token):
770 WHEN "Company" THEN ASSIGN
771 company-1 = INT(ENTRY(3,token))
772 company-n = INT(ENTRY(4,token))
773 entity-type = "L"
774 page-title-1 = "Company " + ENTRY(3,token) + " to " + ENTRY(4,token).
775 WHEN "List" THEN DO:
776 company-list = ENTRY(3,token).
777 FIND ConsolidationList WHERE ConsolidationList.Name = company-list NO-LOCK.
778 company-list = ConsolidationList.CompanyList.
779 entity-type = "L".
780 page-title-1 = ConsolidationList.Description.
781 END.
782 WHEN "Client" THEN ASSIGN
783 client-code = ENTRY(3,token)
784 page-title-1 = "Client/Owner: " + client-code.
785 END CASE.
786 END.
788 WHEN "Tenant" THEN DO:
789 CASE ENTRY(2,token):
790 WHEN "Tenant" THEN ASSIGN
791 property-1 = INT(ENTRY(3,token))
792 property-n = INT(ENTRY(4,token))
793 entity-type = "T"
794 page-title-1 = "Tenants of Properties " + ENTRY(3,token) + " to " + ENTRY(4,token).
795 END CASE.
796 END.
798 WHEN "Property" THEN DO:
799 CASE ENTRY(2,token):
800 WHEN "Property" THEN ASSIGN
801 property-1 = INT(ENTRY(3,token))
802 property-n = INT(ENTRY(4,token))
803 entity-type = "P"
804 page-title-1 = "Property " + ENTRY(3,token) + " to " + ENTRY(4,token).
805 WHEN "Region" THEN ASSIGN
806 region-code = ENTRY(3,token)
807 entity-type = "P"
808 page-title-1 = "Region " + ENTRY(3,token).
809 WHEN "Manager" THEN DO:
810 manager-code = INT(ENTRY(3,token)).
811 entity-type = "P".
812 FIND Person WHERE Person.PersonCode = manager-code NO-LOCK NO-ERROR.
813 page-title-1 = "Managed by " + (IF AVAILABLE(Person) THEN Person.FirstName + " " + Person.LastName ELSE "Unknown Manager").
814 END.
815 END CASE.
816 END.
818 END CASE.
819 END.
821 DO ON ERROR UNDO, RETURN ERROR:
822 FIND Month WHERE Month.MonthCode = month-n NO-LOCK.
823 page-title-1 = " to " + STRING( Month.EndDate, "99/99/9999" ) + " - " + page-title-1.
824 FIND Month WHERE Month.MonthCode = month-1 NO-LOCK.
825 page-title-1 = "Variances from "
826 + STRING( Month.StartDate, "99/99/9999" )
827 + page-title-1.
829 IF NUM-ENTRIES( group-list ) = 1 THEN DO:
830 FIND AccountGroup WHERE AccountGroup.AccountGroupCode = group-list NO-LOCK.
831 page-title-2 = AccountGroup.Name + " (" + AccountGroup.AccountGroupCode + ")".
832 IF AccountGroup.CreditGroup THEN multiplier = -1.
833 END.
834 ELSE
835 page-title-2 = "Account groups " + group-list.
837 END.
839 END PROCEDURE.
841 /* _UIB-CODE-BLOCK-END */
842 &ANALYZE-RESUME
844 &ENDIF
846 /* ************************ Function Implementations ***************** */
848 &IF DEFINED(EXCLUDE-include-company) = 0 &THEN
850 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION include-company Procedure
851 FUNCTION include-company RETURNS LOGICAL
852 ( /* parameter-definitions */ ) :
853 /*------------------------------------------------------------------------------
854 Purpose: Decide whether the current company should be in the report
855 Notes:
856 ------------------------------------------------------------------------------*/
857 IF Company.CompanyCode < company-1 THEN RETURN No.
858 IF Company.CompanyCode > company-n THEN RETURN No.
860 IF client-code <> ? THEN DO:
861 IF Company.ClientCode <> client-code THEN RETURN No.
862 END.
864 IF company-list <> ? THEN DO:
865 IF LOOKUP( STRING(Company.CompanyCode), company-list) = 0 THEN RETURN No.
866 END.
868 FIND FIRST AccountBalance WHERE AccountBalance.EntityType = "L"
869 AND AccountBalance.EntityCode = Company.CompanyCode
870 AND (AccountBalance.Balance <> 0
871 OR AccountBalance.Budget <> 0 ) NO-LOCK NO-ERROR.
872 IF NOT AVAILABLE(AccountBalance) THEN RETURN No.
874 RETURN Yes.
876 END FUNCTION.
878 /* _UIB-CODE-BLOCK-END */
879 &ANALYZE-RESUME
881 &ENDIF
883 &IF DEFINED(EXCLUDE-include-property) = 0 &THEN
885 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION include-property Procedure
886 FUNCTION include-property RETURNS LOGICAL
887 ( /* parameter-definitions */ ) :
888 /*------------------------------------------------------------------------------
889 Purpose: Decide whether the current property should be in the report
890 Notes:
891 ------------------------------------------------------------------------------*/
892 IF Property.PropertyCode < property-1 THEN RETURN No.
893 IF Property.PropertyCode > property-n THEN RETURN No.
895 IF manager-code <> ? THEN DO:
896 IF Property.Manager <> manager-code THEN RETURN No.
897 END.
899 IF region-code <> ? THEN DO:
900 IF NOT(Property.Region BEGINS region-code) THEN RETURN No.
901 END.
903 FIND FIRST AccountBalance WHERE AccountBalance.EntityType = "P"
904 AND AccountBalance.EntityCode = Property.PropertyCode
905 AND (AccountBalance.Balance <> 0
906 OR AccountBalance.Budget <> 0 ) NO-LOCK NO-ERROR.
907 RETURN AVAILABLE(AccountBalance).
909 END FUNCTION.
911 /* _UIB-CODE-BLOCK-END */
912 &ANALYZE-RESUME
914 &ENDIF
916 &IF DEFINED(EXCLUDE-include-tenant) = 0 &THEN
918 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION include-tenant Procedure
919 FUNCTION include-tenant RETURNS LOGICAL
920 ( /* parameter-definitions */ ) :
921 /*------------------------------------------------------------------------------
922 Purpose: Decide whether the current tenant should be in the report
923 Notes:
924 ------------------------------------------------------------------------------*/
925 FIND FIRST AccountBalance WHERE AccountBalance.EntityType = "T"
926 AND AccountBalance.EntityCode = Tenant.TenantCode
927 AND (AccountBalance.Balance <> 0
928 OR AccountBalance.Budget <> 0 ) NO-LOCK NO-ERROR.
929 RETURN AVAILABLE(AccountBalance).
931 END FUNCTION.
933 /* _UIB-CODE-BLOCK-END */
934 &ANALYZE-RESUME
936 &ENDIF