Add blank column, rename column.
[capital-apms-progress.git] / process / period / rr-renew.p
blob70076e4baea152e6520faac92060018794e26530
1 &ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12
2 &ANALYZE-RESUME
3 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS Procedure
4 /*--------------------------------------------------------------------------
5 ------------------------------------------------------------------------*/
7 DEF INPUT PARAMETER options AS CHAR NO-UNDO.
9 DEF VAR gen-report AS LOGICAL NO-UNDO INITIAL No.
10 DEF VAR report-id AS CHAR NO-UNDO INITIAL "RVRN".
12 DEF VAR report-start AS DATE NO-UNDO.
13 DEF VAR report-end AS DATE NO-UNDO.
15 DEF VAR report-from AS DATE NO-UNDO.
16 DEF VAR report-to AS DATE NO-UNDO.
18 DEF VAR report-reviews AS LOGICAL NO-UNDO.
19 DEF VAR report-renewals AS LOGICAL NO-UNDO.
21 DEF VAR option-desc AS CHAR NO-UNDO.
23 DEF VAR current-process AS CHAR NO-UNDO.
25 DEF VAR merge-parks AS LOGICAL NO-UNDO INITIAL No.
26 DEF VAR report-exclude-entity AS LOGICAL NO-UNDO INITIAL No.
27 DEF VAR entity-list AS CHAR NO-UNDO.
29 /* _UIB-CODE-BLOCK-END */
30 &ANALYZE-RESUME
33 &ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
35 /* ******************** Preprocessor Definitions ******************** */
37 &Scoped-define PROCEDURE-TYPE Procedure
41 /* _UIB-PREPROCESSOR-BLOCK-END */
42 &ANALYZE-RESUME
46 /* *********************** Procedure Settings ************************ */
48 &ANALYZE-SUSPEND _PROCEDURE-SETTINGS
49 /* Settings for THIS-PROCEDURE
50 Type: Procedure
51 Allow:
52 Frames: 0
53 Add Fields to: Neither
54 Other Settings: CODE-ONLY COMPILE
56 &ANALYZE-RESUME _END-PROCEDURE-SETTINGS
58 /* ************************* Create Window ************************** */
60 &ANALYZE-SUSPEND _CREATE-WINDOW
61 /* DESIGN Window definition (used by the UIB)
62 CREATE WINDOW Procedure ASSIGN
63 HEIGHT = .33
64 WIDTH = 40.
65 /* END WINDOW DEFINITION */
67 &ANALYZE-RESUME
71 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _INCLUDED-LIB Procedure
72 /* ************************* Included-Libraries *********************** */
74 {inc/method/m-period.i}
76 /* _UIB-CODE-BLOCK-END */
77 &ANALYZE-RESUME
81 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Procedure
84 /* *************************** Main Block *************************** */
86 RUN decode-parameters.
88 IF file-name = "Printer" THEN
89 OUTPUT TO VALUE(txtrep-print-file) KEEP-MESSAGES PAGE-SIZE 0.
90 ELSE
91 OUTPUT TO VALUE( file-name ).
93 IF gen-report THEN DO:
94 RUN delete-todays-report.
95 RUN generate-reviews-and-renewals.
96 END.
98 IF report-reviews THEN RUN output-reviews.
99 IF report-renewals THEN RUN output-renewals.
101 OUTPUT CLOSE.
103 IF file-name = "Printer" THEN RUN view-output-file( report-preview ).
105 /* _UIB-CODE-BLOCK-END */
106 &ANALYZE-RESUME
109 /* ********************** Internal Procedures *********************** */
111 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE decode-parameters Procedure
112 PROCEDURE decode-parameters :
113 /*------------------------------------------------------------------------------
114 Decode parameters string:
115 1 - "Yes" if we should regenerate statistics
116 2 - "Printer" or a file name to output to.
117 3 - "As At" date for report
118 4 - break date 1.
119 5 - break date 2.
120 6 - end date.
121 7 - Y/N/? Only / Exclude / Both : Carpark only leases
122 8 - Decimal value of minimum lease value to be displayed.
123 ------------------------------------------------------------------------------*/
125 gen-report = (ENTRY( 1, options) = "Yes").
126 file-name = ENTRY( 2, options).
127 IF file-name = "Preview" THEN ASSIGN
128 file-name = "Printer"
129 report-preview = Yes.
131 report-asat-date = DATE( ENTRY( 3, options) ).
133 report-start = DATE( ENTRY( 4, options) ).
134 report-end = DATE( ENTRY( 5, options) ).
136 report-reviews = (ENTRY( 6, options) = "Yes").
137 report-renewals = (ENTRY( 7, options) = "Yes").
139 option-desc = "".
140 IF report-reviews = Yes THEN
141 option-desc = option-desc + "Rent Reviews".
142 IF report-reviews = Yes AND report-renewals = Yes THEN
143 option-desc = option-desc + " and ".
144 IF report-renewals = Yes THEN
145 option-desc = option-desc + "Lease Renewals".
147 END PROCEDURE.
149 /* _UIB-CODE-BLOCK-END */
150 &ANALYZE-RESUME
153 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE generate-reviews-and-renewals Procedure
154 PROCEDURE generate-reviews-and-renewals :
155 /*------------------------------------------------------------------------------
156 Purpose:
157 ------------------------------------------------------------------------------*/
158 DEF VAR start-of-period AS DATE NO-UNDO.
159 DEF VAR end-of-period AS DATE NO-UNDO.
161 start-of-period = DATE( MONTH(TODAY), 1, YEAR(TODAY) - 1 ).
162 end-of-period = TODAY + 300.
164 FOR EACH Property NO-LOCK WHERE Property.Active,
165 EACH TenancyLease NO-LOCK OF Property WHERE TenancyLease.LeaseStatus <> "PAST"
166 AND TenancyLease.LeaseEndDate >= start-of-period,
167 FIRST Tenant NO-LOCK OF TenancyLease
168 BREAK BY Property.PropertyCode:
171 IF FIRST-OF( Property.PropertyCode ) THEN RUN get-property-info.
173 IF CAN-FIND( FIRST LeaseHistory WHERE LeaseHistory.TenancyLeaseCode = TenancyLease.TenancyLeaseCode
174 AND LeaseHistory.DateChanged >= start-of-period
175 AND LeaseHistory.LeaseEndDate < TenancyLease.LeaseEndDate )
176 OR CAN-FIND( FIRST RentReview OF TenancyLease WHERE RentReview.DateDue > start-of-period
177 AND RentReview.ReviewStatus = "DONE" )
178 THEN
179 RUN get-lease-info.
180 ELSE
181 NEXT.
183 FIND LAST LeaseHistory WHERE LeaseHistory.TenancyLeaseCode = TenancyLease.TenancyLeaseCode
184 AND LeaseHistory.DateChanged >= start-of-period
185 AND LeaseHistory.LeaseEndDate < TenancyLease.LeaseEndDate
186 AND LeaseHistory.LeaseEndDate < end-of-period
187 NO-LOCK NO-ERROR.
188 IF AVAILABLE(LeaseHistory) THEN DO:
189 brk-val[1] = "Lease Renewals" + delim
190 + STRING( YEAR(LeaseHistory.LeaseEndDate), "9999") + "." + STRING( MONTH(LeaseHistory.LeaseEndDate), "99") + "." + STRING( DAY(LeaseHistory.LeaseEndDate), "99").
191 id = "RENEW," + STRING( TenancyLease.PropertyCode ) + "," + STRING( TenancyLease.TenancyLeaseCode ) + "," +
192 STRING( LeaseHistory.DateChanged, "99/99/9999" ).
194 LeaseInfo.c-change = STRING( LeaseHistory.DateChanged, "99/99/9999").
195 LeaseInfo.c-start = STRING( LeaseHistory.LeaseEndDate, "99/99/9999").
196 LeaseInfo.change-type = "Renewal".
198 /* calculate previous rental here */
199 /* LeaseInfo fields are new-rent[i], new-psm[i], c-new-rent[i], c-new-psm[i] */
201 RUN create-lease-detail.
202 END.
204 FOR EACH RentReview OF TenancyLease WHERE RentReview.DateDue > start-of-period
205 AND RentReview.ReviewStatus = "DONE"
206 NO-LOCK BY RentReview.DateDue:
208 RUN get-term-remaining( RentReview.DateDue, TenancyLease.LeaseEndDate, OUTPUT c-term ).
210 brk-val[1] = "Rent Reviews" + delim
211 + STRING( YEAR(RentReview.DateDue), "9999") + "." + STRING( MONTH(RentReview.DateDue), "99") + "." + STRING( DAY(RentReview.DateDue), "99") .
212 id = "REVIEW ," + STRING( TenancyLease.PropertyCode ) + "," + STRING( TenancyLease.TenancyLeaseCode ) + "," +
213 STRING( RentReview.DateDue, "99/99/9999" ).
215 LeaseInfo.c-change = STRING( RentReview.DateComplete, "99/99/9999").
216 LeaseInfo.c-start = STRING( RentReview.DateDue, "99/99/9999").
217 IF LeaseInfo.c-change = ? THEN LeaseInfo.c-change = STRING( RentReview.DateDue, "99/99/9999").
218 LeaseInfo.change-type = "Review".
220 /* calculate previous rental here */
221 /* LeaseInfo fields are new-rent[i], new-psm[i], c-new-rent[i], c-new-psm[i] */
223 RUN create-lease-detail.
224 END.
225 DELETE LeaseInfo.
226 END.
229 END PROCEDURE.
231 /* _UIB-CODE-BLOCK-END */
232 &ANALYZE-RESUME
235 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE get-month Procedure
236 PROCEDURE get-month :
237 /*------------------------------------------------------------------------------
238 Purpose:
239 ------------------------------------------------------------------------------*/
240 DEF INPUT PARAMETER the-date AS DATE NO-UNDO.
241 DEF OUTPUT PARAMETER the-month AS CHAR NO-UNDO.
243 DEF VAR month-list AS CHAR NO-UNDO.
244 month-list = "January,February,March,April,May,June,July,August,September,October,November,December".
246 the-month = STRING( YEAR( the-date ), "9999" ) + "." + STRING( MONTH( the-date ), "99" ).
247 the-month = the-month + " - " + ENTRY( MONTH( the-date ), month-list ) + " " +
248 STRING( YEAR( the-date ) ).
250 END PROCEDURE.
252 /* _UIB-CODE-BLOCK-END */
253 &ANALYZE-RESUME
256 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE output-renewals Procedure
257 PROCEDURE output-renewals :
258 /*------------------------------------------------------------------------------
259 Purpose:
260 ------------------------------------------------------------------------------*/
261 DEF VAR no-fields AS INT NO-UNDO.
263 current-process = "RENEWALS".
264 FIND LAST PeriodicDetail WHERE PeriodicDetail.ReportID = report-id
265 AND PeriodicDetail.Date <= report-asat-date
266 AND PeriodicDetail.DetailType = "D" NO-LOCK.
267 report-title = "Lease Renewals settled for the period " + STRING( report-start, "99/99/9999")
268 + " to " + STRING( report-end, "99/99/9999").
269 report-title = report-title + "~nAs at " + STRING( PeriodicDetail.Date, "99/99/9999").
271 now = STRING( TODAY, "99/99/9999" ) + ", " + STRING( TIME, "HH:MM:SS" ).
273 xlate-list = "14,23,1,3,2,17,4,15,5,6,10,7,12,C".
274 RUN set-lease-fields.
275 no-fields = NUM-ENTRIES( xlate-list ).
276 ENTRY( no-fields, field-list, delim) = "Incentives / Leasing Notes".
277 ENTRY( 1, field-list, delim) = "Renewal~nDate".
279 n-breaks = 2.
280 break-type = 1.
282 RUN basic-report( report-asat-date ).
284 END PROCEDURE.
286 /* _UIB-CODE-BLOCK-END */
287 &ANALYZE-RESUME
290 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE output-reviews Procedure
291 PROCEDURE output-reviews :
292 /*------------------------------------------------------------------------------
293 Purpose:
294 ------------------------------------------------------------------------------*/
295 DEF VAR no-fields AS INT NO-UNDO.
297 current-process = "REVIEWS".
298 FIND LAST PeriodicDetail WHERE PeriodicDetail.ReportID = report-id
299 AND PeriodicDetail.Date <= report-asat-date
300 AND PeriodicDetail.DetailType = "D" NO-LOCK.
301 report-title = "Rent Reviews settled for the period " + STRING( report-start, "99/99/9999")
302 + " to " + STRING( report-end, "99/99/9999").
303 report-title = report-title + "~nAs at " + STRING( PeriodicDetail.Date, "99/99/9999").
305 now = STRING( TODAY, "99/99/9999" ) + ", " + STRING( TIME, "HH:MM:SS" ).
307 xlate-list = "14,23,1,3,2,17,4,15,5,6,10,7,12,C".
308 RUN set-lease-fields.
309 no-fields = NUM-ENTRIES( xlate-list ).
310 ENTRY( no-fields, field-list, delim) = "Incentives / Leasing Notes".
311 ENTRY( 1, field-list, delim) = "Rent Review~nDate".
313 n-breaks = 2.
314 break-type = 1.
316 RUN basic-report( report-asat-date ).
318 END PROCEDURE.
320 /* _UIB-CODE-BLOCK-END */
321 &ANALYZE-RESUME
324 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE pre-break-begin Procedure
325 PROCEDURE pre-break-begin :
326 /*------------------------------------------------------------------------------
327 Purpose: override the break begin procedure
328 ------------------------------------------------------------------------------*/
329 DEF INPUT PARAMETER break-level AS INT NO-UNDO.
331 /* ensure we only have one level but always get a total */
332 IF break-level > 1 THEN RETURN "No".
334 END PROCEDURE.
336 /* _UIB-CODE-BLOCK-END */
337 &ANALYZE-RESUME
340 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE pre-break-end Procedure
341 PROCEDURE pre-break-end :
342 /*------------------------------------------------------------------------------
343 Purpose: Override the default break-end process
344 ------------------------------------------------------------------------------*/
345 DEF INPUT PARAMETER break-level AS INT NO-UNDO.
347 /* ensure we only have one level but always get a total */
348 IF break-level > 1 THEN RETURN "No".
350 END PROCEDURE.
352 /* _UIB-CODE-BLOCK-END */
353 &ANALYZE-RESUME
356 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE pre-detail-line Procedure
357 PROCEDURE pre-detail-line :
358 /*------------------------------------------------------------------------------
359 Purpose: Override the default detail-line processing
360 ------------------------------------------------------------------------------*/
361 DEF INPUT-OUTPUT PARAMETER break-value AS CHAR NO-UNDO.
363 DEF VAR type AS CHAR NO-UNDO.
364 type = ENTRY( 24, PeriodicDetail.Data, delim ).
365 IF current-process = "REVIEWS" AND type <> "Review" THEN RETURN "No".
366 IF current-process = "RENEWALS" AND type <> "Renewal" THEN RETURN "No".
368 DEF VAR d-change AS DATE NO-UNDO.
369 d-change = DATE( ENTRY( 23, PeriodicDetail.Data, delim) ).
370 IF d-change < report-start OR d-change > report-end THEN RETURN "No".
372 END PROCEDURE.
374 /* _UIB-CODE-BLOCK-END */
375 &ANALYZE-RESUME
378 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE pre-output-line Procedure
379 PROCEDURE pre-output-line :
380 /*------------------------------------------------------------------------------
381 Purpose: Selectively override the printing of the detail line
382 ------------------------------------------------------------------------------*/
383 DEF INPUT PARAMETER break-value AS CHAR NO-UNDO.
385 END PROCEDURE.
387 /* _UIB-CODE-BLOCK-END */
388 &ANALYZE-RESUME