Add blank column, rename column.
[capital-apms-progress.git] / process / report / rentsum.p
blob4bb90aab53e2bd68535fee1270e03d67720a8c26
1 &ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12
2 &ANALYZE-RESUME
3 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS Procedure
4 /*--------------------------------------------------------------------------
5 File :
6 Purpose :
7 Author(s) :
8 Created :
9 Notes :
10 ------------------------------------------------------------------------*/
11 /* *************************** Definitions ************************** */
12 DEF INPUT PARAMETER report-options AS CHAR NO-UNDO.
13 DEF INPUT PARAMETER preview AS LOGI NO-UNDO.
15 /* Office Settings */
16 {inc/ofc-this.i}
17 {inc/ofc-set-l.i "Use-Rent-Charges" "use-rent-charges"}
18 {inc/ofc-set.i "RentCharge-Outgoings" "og-rentcharge-type"}
19 IF NOT AVAILABLE(OfficeSetting) THEN og-rentcharge-type = "".
21 /* page control */
22 DEF VAR prt-ctrl AS CHAR NO-UNDO.
23 DEF VAR cols AS INT NO-UNDO.
24 DEF VAR rows AS INT NO-UNDO.
25 DEF VAR rent-report AS LOGICAL NO-UNDO.
26 DEF VAR detail-report AS LOGICAL NO-UNDO.
27 DEF VAR include-external AS LOGICAL NO-UNDO.
28 rent-report = (SUBSTRING(report-options, 1, 1) = "R").
29 detail-report = (SUBSTRING(report-options, 2, 1) = "D").
30 include-external = NOT (SUBSTRING(report-options, 3, 1) = "X").
32 /* tenant accumulators */
33 DEF VAR tenant-contract AS DECIMAL NO-UNDO.
34 DEF VAR tenant-charged AS DECIMAL NO-UNDO.
35 DEF VAR last-tenant-code AS INTEGER INITIAL -1 NO-UNDO.
36 DEF VAR user-name AS CHAR NO-UNDO.
37 {inc/username.i "user-name"}
39 /* page header */
40 &SCOPED-DEFINE page-width 126
41 &SCOPED-DEFINE with-clause NO-BOX USE-TEXT NO-LABELS WIDTH {&page-width}
43 DEF VAR timeStamp AS CHAR FORMAT "X(40)" NO-UNDO.
44 timeStamp = STRING( TODAY, "99/99/9999") + ", " + STRING( TIME, "HH:MM:SS") + " for " + user-name.
45 DEF VAR hline2 AS CHAR FORMAT "X({&page-width})" NO-UNDO.
46 DEF VAR hline3 AS CHAR FORMAT "X({&page-width})" NO-UNDO.
47 hline2 = "Trans Tasman Properties Limited".
48 hline2 = SUBSTRING( STRING("","X({&page-width})"), 1, INTEGER(({&page-width} - LENGTH(hline2) ) / 2)) + hline2.
49 hline3 = (IF rent-report THEN "Rental" ELSE "Outgoings") + " Summary Report".
50 hline3 = SUBSTRING( STRING("","X({&page-width})"), 1, INTEGER(({&page-width} - LENGTH(hline3) ) / 2)) + hline3.
52 DEF VAR column-headings AS CHAR FORMAT "X({&page-width})" NO-UNDO.
53 IF rent-report THEN
54 column-headings = FILL(' ',51) + " Contract Charged Variance".
55 ELSE
56 column-headings = FILL(' ',51) + " Outgoings".
58 DEFINE FRAME heading-frame WITH 1 DOWN {&with-clause} PAGE-TOP.
59 FORM HEADER
60 timeStamp "Page " + STRING( PAGE-NUMBER ) TO {&page-width} SKIP (1)
61 hline2 FORMAT "X({&page-width})"
62 hline3 FORMAT "X({&page-width})"
63 SKIP (2) column-headings
64 WITH FRAME heading-frame.
66 DEF VAR contract-amount AS DECIMAL FORMAT "->>>,>>>,>>9.99" COLUMN-LABEL "Contract" NO-UNDO.
67 DEF VAR charged-rent AS DECIMAL FORMAT "->>>,>>>,>>9.99" COLUMN-LABEL "Charged" NO-UNDO.
68 DEF VAR variance AS DECIMAL FORMAT "->>,>>>,>>9.99" COLUMN-LABEL "Variance" NO-UNDO.
69 DEFINE FRAME report-line WITH DOWN {&with-clause}.
70 FORM Property.Name contract-amount charged-rent variance WITH FRAME report-line.
72 /* _UIB-CODE-BLOCK-END */
73 &ANALYZE-RESUME
76 &ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
78 /* ******************** Preprocessor Definitions ******************** */
80 &Scoped-define PROCEDURE-TYPE Procedure
84 /* _UIB-PREPROCESSOR-BLOCK-END */
85 &ANALYZE-RESUME
89 /* *********************** Procedure Settings ************************ */
91 &ANALYZE-SUSPEND _PROCEDURE-SETTINGS
92 /* Settings for THIS-PROCEDURE
93 Type: Procedure
94 Allow:
95 Frames: 0
96 Add Fields to: Neither
97 Other Settings: CODE-ONLY COMPILE
99 &ANALYZE-RESUME _END-PROCEDURE-SETTINGS
101 /* ************************* Create Window ************************** */
103 &ANALYZE-SUSPEND _CREATE-WINDOW
104 /* DESIGN Window definition (used by the UIB)
105 CREATE WINDOW Procedure ASSIGN
106 HEIGHT = .1
107 WIDTH = 31.72.
108 /* END WINDOW DEFINITION */
110 &ANALYZE-RESUME
114 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _INCLUDED-LIB Procedure
115 /* ************************* Included-Libraries *********************** */
117 {inc/method/m-txtrep.i}
119 /* _UIB-CODE-BLOCK-END */
120 &ANALYZE-RESUME
124 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Procedure
127 /* *************************** Main Block *************************** */
129 RUN make-control-string ( "PCL", "reset,portrait,tm,2,a4,lm,6,courier,cpi,18,lpi,9",
130 OUTPUT prt-ctrl, OUTPUT rows, OUTPUT cols ).
132 RUN output-control-file ( prt-ctrl ).
133 OUTPUT TO VALUE(txtrep-print-file) KEEP-MESSAGES PAGE-SIZE VALUE(rows).
135 VIEW FRAME heading-frame.
137 DEF VAR region-contract LIKE contract-amount NO-UNDO.
138 DEF VAR region-charged LIKE charged-rent NO-UNDO.
139 DEF VAR portfolio-contract LIKE contract-amount INITIAL 0 NO-UNDO.
140 DEF VAR portfolio-charged LIKE charged-rent INITIAL 0 NO-UNDO.
142 &GLOB NONE "none as yet"
143 DEF VAR last-region AS CHAR INITIAL {&NONE} NO-UNDO.
145 FOR EACH Property NO-LOCK WHERE Property.Active
146 AND ((NOT Property.ExternallyManaged) OR include-external)
147 BY Property.Region BY Property.ShortName:
148 IF last-region <> Property.Region THEN DO:
149 IF last-region <> {&NONE} THEN DO:
150 RUN put-underlines('-').
151 RUN print-report-line( " ", region-contract, region-charged).
152 IF detail-report THEN PAGE. ELSE PUT SKIP (1).
153 END.
154 RUN region-heading.
155 portfolio-contract = portfolio-contract + region-contract.
156 portfolio-charged = portfolio-charged + region-charged.
157 region-contract = 0.
158 region-charged = 0.
159 last-region = Property.Region.
160 END.
162 RUN each-property.
164 region-contract = region-contract + contract-amount.
165 region-charged = region-charged + charged-rent.
167 END.
169 IF last-region <> {&NONE} THEN DO:
170 RUN put-underlines('-').
171 RUN print-report-line( " ", region-contract, region-charged).
172 END.
173 portfolio-contract = portfolio-contract + region-contract.
174 portfolio-charged = portfolio-charged + region-charged.
176 PUT SKIP (1).
177 RUN put-underlines('=').
178 RUN print-report-line( " ", portfolio-contract, portfolio-charged).
179 RUN put-underlines('=').
182 OUTPUT CLOSE.
183 RUN view-output-file ( preview ).
185 /* _UIB-CODE-BLOCK-END */
186 &ANALYZE-RESUME
189 /* ********************** Internal Procedures *********************** */
191 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE each-property Procedure
192 PROCEDURE each-property :
193 /*------------------------------------------------------------------------------
194 Purpose: Detail for each tenant of a property
195 ------------------------------------------------------------------------------*/
197 /* initialise totals for property */
198 contract-amount = 0.
199 charged-rent = 0.
200 last-tenant-code = -1.
202 FOR EACH TenancyLease NO-LOCK WHERE TenancyLease.PropertyCode = Property.PropertyCode
203 AND TenancyLease.LeaseStatus <> "PAST"
204 AND CAN-FIND( FIRST RentalSpace OF TenancyLease WHERE RentalSpace.AreaStatus <> "V")
205 BY TenancyLease.PropertyCode BY TenancyLease.TenantCode:
206 IF TenancyLease.TenantCode <> last-tenant-code THEN DO:
207 RUN each-tenant( last-tenant-code, TenancyLease.TenantCode ).
208 END.
209 IF rent-report THEN DO:
210 FOR EACH RentalSpace OF TenancyLease WHERE RentalSpace.AreaStatus <> "V" NO-LOCK:
211 tenant-contract = tenant-contract + RentalSpace.ContractedRental.
212 IF NOT use-rent-charges THEN
213 tenant-charged = tenant-charged + RentalSpace.ChargedRental.
214 END.
215 IF use-rent-charges THEN DO:
216 FOR EACH RentCharge NO-LOCK OF TenancyLease
217 WHERE RentCharge.RentChargeType <> og-rentcharge-type:
218 tenant-charged = tenant-charged + RentCharge.CurrentAnnualRental .
219 END.
220 END.
221 END.
222 ELSE
223 tenant-contract = tenant-contract + TenancyLease.OutgoingsBudget.
224 END.
225 RUN each-tenant( last-tenant-code, -1 ).
227 IF detail-report THEN RUN put-underlines( '-' ).
228 RUN print-report-line( Property.Name, contract-amount, charged-rent).
230 IF detail-report THEN PUT SKIP (2).
231 END PROCEDURE.
233 /* _UIB-CODE-BLOCK-END */
234 &ANALYZE-RESUME
237 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE each-tenant Procedure
238 PROCEDURE each-tenant :
239 /*------------------------------------------------------------------------------
240 Purpose:
241 ------------------------------------------------------------------------------*/
242 DEF INPUT PARAMETER last-code AS INT NO-UNDO.
243 DEF INPUT PARAMETER next-code AS INT NO-UNDO.
245 IF last-code > 0 THEN DO:
246 FIND Tenant WHERE Tenant.TenantCode = last-code NO-LOCK NO-ERROR.
247 IF AVAILABLE( Tenant ) THEN DO:
248 IF NOT Tenant.Active THEN tenant-charged = 0.
249 IF detail-report AND (tenant-contract <> 0 OR tenant-charged <> 0) THEN
250 RUN print-report-line( Tenant.Name, tenant-contract, tenant-charged ).
252 contract-amount = contract-amount + tenant-contract.
253 charged-rent = charged-rent + tenant-charged.
254 END.
255 END.
257 ASSIGN
258 tenant-charged = 0
259 tenant-contract = 0
260 last-tenant-code = next-code
263 END PROCEDURE.
265 /* _UIB-CODE-BLOCK-END */
266 &ANALYZE-RESUME
269 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE print-report-line Procedure
270 PROCEDURE print-report-line :
271 /*------------------------------------------------------------------------------
272 Purpose:
273 ------------------------------------------------------------------------------*/
274 DEF INPUT PARAMETER name AS CHAR NO-UNDO.
275 DEF INPUT PARAMETER column1 AS DECIMAL NO-UNDO.
276 DEF INPUT PARAMETER column2 AS DECIMAL NO-UNDO.
278 IF rent-report THEN DO:
279 DEF VAR col-variance AS DECIMAL NO-UNDO.
280 col-variance = column2 - column1.
281 DISPLAY name @ Property.Name
282 column1 @ contract-amount
283 column2 @ charged-rent
284 col-variance @ variance
285 WITH FRAME report-line.
286 END.
287 ELSE
288 DISPLAY name @ Property.Name
289 column1 @ contract-amount
290 WITH FRAME report-line.
292 DOWN WITH FRAME report-line.
294 END PROCEDURE.
296 /* _UIB-CODE-BLOCK-END */
297 &ANALYZE-RESUME
300 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE put-underlines Procedure
301 PROCEDURE put-underlines :
302 /*------------------------------------------------------------------------------
303 Purpose:
304 ------------------------------------------------------------------------------*/
305 DEF INPUT PARAMETER ul-char AS CHAR NO-UNDO.
307 IF rent-report THEN
308 PUT UNFORMATTED FILL(" ",51) + FILL(ul-char,14) + " " + FILL(ul-char,14) + " " + FILL(ul-char,14).
309 ELSE
310 PUT UNFORMATTED FILL(" ",51) + FILL(ul-char,14).
312 END PROCEDURE.
314 /* _UIB-CODE-BLOCK-END */
315 &ANALYZE-RESUME
318 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE region-heading Procedure
319 PROCEDURE region-heading :
320 /*------------------------------------------------------------------------------
321 Purpose:
322 ------------------------------------------------------------------------------*/
323 DEF VAR region-name AS CHAR NO-UNDO.
325 CASE Property.Region:
326 WHEN "akld" THEN region-name = "Auckland".
327 WHEN "wgtn" THEN region-name = "Wellington".
328 WHEN "rot" THEN region-name = "Rotorua".
329 WHEN "chch" THEN region-name = "Christchurch".
330 WHEN "ham" THEN region-name = "Hamilton".
331 WHEN "ZZZZ" THEN region-name = "Sundry".
332 OTHERWISE DO:
333 region-name = CAPS( Property.Region ) + " buildings".
334 END.
335 END.
336 PUT UNFORMATTED SKIP region-name SKIP FILL("-",LENGTH(region-name)) SKIP.
337 END PROCEDURE.
339 /* _UIB-CODE-BLOCK-END */
340 &ANALYZE-RESUME