Allow deleting of unreferenced account groups.
[capital-apms-progress.git] / inc / method / m-lease-rentals.i
blobb8b19bc45c338e799a1f81bb371b447a993325ef
1 &ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12
2 &ANALYZE-RESUME
3 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS Method-Library
4 /*--------------------------------------------------------------------------
5 Library : inc/method/m-lease-rentals.i
6 Purpose : Used by reports which report on rentals for leases / areas
8 Author(s) : Andrew McMillan
9 Created : 2/2/1999
10 Notes : Cut from Sydney Schedule.
11 ------------------------------------------------------------------------*/
12 DEF VAR show-future-rentals AS LOGI NO-UNDO INITIAL No.
13 DEF VAR all-future-rentals AS LOGI NO-UNDO INITIAL No.
15 DEF TEMP-TABLE LeaseTotal NO-UNDO
16 FIELD LeaseCode AS INT
17 FIELD AnnualRent AS DEC INITIAL 0.0
18 FIELD ContractRent AS DEC INITIAL 0.0
19 FIELD AnnualOutgoings AS DEC INITIAL 0.0
20 FIELD AnnualCleaning AS DEC INITIAL 0.0
21 FIELD AreaSize AS DEC INITIAL 0.0
22 FIELD AreaCount AS INT INITIAL 0
23 INDEX XPKLeaseTotals IS UNIQUE PRIMARY LeaseCode.
25 DEF TEMP-TABLE LeaseRental NO-UNDO
26 FIELD LeaseCode AS INT
27 FIELD AreaType AS CHAR
28 FIELD AnnualRent AS DEC INITIAL 0.0
29 FIELD AnnualOutgoings AS DEC INITIAL 0.0
30 FIELD AnnualCleaning AS DEC INITIAL 0.0
31 FIELD ContractRent AS DEC INITIAL 0.0
32 FIELD AreaSize AS DEC INITIAL 0.0
33 FIELD AreaCount AS INT INITIAL 0
34 FIELD Future AS LOGI INITIAL No
35 INDEX XPKLeaseRentals IS UNIQUE PRIMARY LeaseCode AreaType.
37 DEF TEMP-TABLE AreaRental NO-UNDO
38 FIELD PropertyCode AS INT
39 FIELD RentalSpaceCode AS INT
40 FIELD LeaseCode AS INT
41 FIELD AreaType AS CHAR
42 FIELD AnnualRent AS DEC INITIAL 0.0
43 FIELD AnnualCleaning AS DEC INITIAL 0.0
44 FIELD AnnualOutgoings AS DEC INITIAL 0.0
45 FIELD ContractRent AS DEC INITIAL 0.0
46 FIELD AreaSize AS DEC INITIAL 0.0
47 INDEX XPKLeaseRentals IS UNIQUE PRIMARY PropertyCode RentalSpaceCode .
49 {inc/ofc-this.i}
50 {inc/ofc-set.i "RentCharge-Outgoings" "outgoings-type-list"}
51 {inc/ofc-set.i "RentCharge-Cleaning" "cleaning-type-list"}
53 /* _UIB-CODE-BLOCK-END */
54 &ANALYZE-RESUME
57 &ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
59 /* ******************** Preprocessor Definitions ******************** */
63 /* _UIB-PREPROCESSOR-BLOCK-END */
64 &ANALYZE-RESUME
67 /* ************************ Function Prototypes ********************** */
69 &IF DEFINED(EXCLUDE-get-area-cleaning) = 0 &THEN
71 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD get-area-cleaning Method-Library
72 FUNCTION get-area-cleaning RETURNS DECIMAL
73 ( INPUT property-code AS INT, INPUT area-code AS INT ) FORWARD.
75 /* _UIB-CODE-BLOCK-END */
76 &ANALYZE-RESUME
78 &ENDIF
80 &IF DEFINED(EXCLUDE-get-area-outgoings) = 0 &THEN
82 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD get-area-outgoings Method-Library
83 FUNCTION get-area-outgoings RETURNS DECIMAL
84 ( INPUT property-code AS INT, INPUT area-code AS INT ) FORWARD.
86 /* _UIB-CODE-BLOCK-END */
87 &ANALYZE-RESUME
89 &ENDIF
91 &IF DEFINED(EXCLUDE-get-area-rental) = 0 &THEN
93 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD get-area-rental Method-Library
94 FUNCTION get-area-rental RETURNS DECIMAL
95 ( INPUT property-code AS INT, INPUT area-code AS INT ) FORWARD.
97 /* _UIB-CODE-BLOCK-END */
98 &ANALYZE-RESUME
100 &ENDIF
103 /* *********************** Procedure Settings ************************ */
105 &ANALYZE-SUSPEND _PROCEDURE-SETTINGS
106 /* Settings for THIS-PROCEDURE
107 Type: Method-Library
108 Allow:
109 Frames: 0
110 Add Fields to: Neither
111 Other Settings: INCLUDE-ONLY
113 &ANALYZE-RESUME _END-PROCEDURE-SETTINGS
115 /* ************************* Create Window ************************** */
117 &ANALYZE-SUSPEND _CREATE-WINDOW
118 /* DESIGN Window definition (used by the UIB)
119 CREATE WINDOW Method-Library ASSIGN
120 HEIGHT = 8.4
121 WIDTH = 45.
122 /* END WINDOW DEFINITION */
124 &ANALYZE-RESUME
126 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _INCLUDED-LIB Method-Library
127 /* ************************* Included-Libraries *********************** */
129 /* _UIB-CODE-BLOCK-END */
130 &ANALYZE-RESUME
136 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Method-Library
139 /* *************************** Main Block *************************** */
141 /* _UIB-CODE-BLOCK-END */
142 &ANALYZE-RESUME
145 /* ********************** Internal Procedures *********************** */
147 &IF DEFINED(EXCLUDE-build-lease-rentals) = 0 &THEN
149 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE build-lease-rentals Method-Library
150 PROCEDURE build-lease-rentals :
151 /*------------------------------------------------------------------------------
152 Purpose: Build tables of rental for each type for each lease
153 and then build allocate them by the area type for each LseSpace.
154 ------------------------------------------------------------------------------*/
155 DEF BUFFER Lease FOR TenancyLease.
156 DEF BUFFER LseCharge FOR RentCharge.
157 DEF BUFFER LseSpace FOR RentalSpace.
158 DEF VAR no-current-rentals AS LOGI NO-UNDO INITIAL NO.
159 DEF VAR this-rental AS DEC NO-UNDO.
161 FOR EACH Lease OF Property WHERE Lease.LeaseStatus <> "PAST" NO-LOCK:
162 CREATE LeaseTotal.
163 LeaseTotal.LeaseCode = Lease.TenancyLeaseCode.
164 no-current-rentals = NOT CAN-FIND( FIRST LseCharge OF Lease WHERE CAN-FIND( FIRST RentChargeLine OF LseCharge WHERE RentChargeLine.RentChargeLineStatus = "C" AND RentChargeLine.StartDate <= TODAY)).
165 FOR EACH LseCharge OF Lease WHERE CAN-FIND( FIRST RentChargeLine OF LseCharge WHERE RentChargeLine.RentChargeLineStatus = "C"
166 OR RentChargeLine.RentChargeLineStatus = "I") NO-LOCK:
167 FIND LeaseRental WHERE LeaseRental.LeaseCode = Lease.TenancyLeaseCode
168 AND LeaseRental.AreaType = LseCharge.RentChargeType
169 NO-LOCK NO-ERROR.
170 IF NOT AVAILABLE(LeaseRental) THEN DO:
171 CREATE LeaseRental.
172 LeaseRental.LeaseCode = Lease.TenancyLeaseCode.
173 LeaseRental.AreaType = LseCharge.RentChargeType.
174 END.
176 IF (show-future-rentals AND (Lease.LeaseStartDate > TODAY)) OR no-current-rentals THEN DO:
177 FIND FIRST RentChargeLine OF LseCharge WHERE RentChargeLine.RentChargeLineStatus = "C"
178 AND (no-current-rentals OR RentChargeLine.StartDate > TODAY)
179 NO-LOCK NO-ERROR.
180 IF NOT AVAILABLE(RentChargeLine) OR (RentChargeLine.EndDate = RentChargeLine.LastChargedDate
181 AND RentChargeLine.LastChargedDate <> ?) THEN
182 NEXT.
183 this-rental = to-annual( RentChargeLine.FrequencyCode, RentChargeLine.Amount ) .
184 IF RentChargeLine.StartDate > TODAY THEN LeaseRental.Future = Yes.
185 END.
186 ELSE DO:
187 this-rental = LseCharge.CurrentAnnualRental .
188 END.
189 IF CAN-DO( outgoings-type-list, LseCharge.RentChargeType ) THEN DO:
190 LeaseTotal.AnnualOutgoings = LeaseTotal.AnnualOutgoings + this-rental.
191 END.
192 ELSE IF CAN-DO( cleaning-type-list, LseCharge.RentChargeType ) THEN DO:
193 LeaseTotal.AnnualCleaning = LeaseTotal.AnnualCleaning + this-rental.
194 END.
195 ELSE DO:
196 LeaseTotal.AnnualRent = LeaseTotal.AnnualRent + this-rental.
197 END.
198 LeaseRental.AnnualRent = LeaseRental.AnnualRent + this-rental.
199 END.
201 FOR EACH LseSpace OF Lease WHERE LseSpace.AreaStatus = "L" NO-LOCK:
202 CREATE AreaRental.
203 AreaRental.PropertyCode = LseSpace.PropertyCode.
204 AreaRental.RentalSpaceCode = LseSpace.RentalSpaceCode.
205 AreaRental.LeaseCode = Lease.TenancyLeaseCode.
206 AreaRental.AreaSize = LseSpace.AreaSize.
207 AreaRental.AreaType = LseSpace.AreaType.
208 AreaRental.ContractRent = LseSpace.ContractedRental.
209 FIND LeaseRental WHERE LeaseRental.LeaseCode = Lease.TenancyLeaseCode
210 AND LeaseRental.AreaType = LseSpace.AreaType
211 NO-LOCK NO-ERROR.
212 IF NOT AVAILABLE(LeaseRental) THEN DO:
213 CREATE LeaseRental.
214 LeaseRental.LeaseCode = Lease.TenancyLeaseCode.
215 LeaseRental.AreaType = LseSpace.AreaType.
216 END.
217 LeaseRental.AreaSize = LeaseRental.AreaSize + LseSpace.AreaSize.
218 LeaseRental.AreaCount = LeaseRental.AreaCount + 1.
219 LeaseRental.ContractRent = LeaseRental.ContractRent + LseSpace.ContractedRental.
221 FIND AreaType WHERE AreaType.AreaType = LeaseRental.AreaType NO-LOCK NO-ERROR.
222 IF AVAILABLE(AreaType) AND AreaType.IsFloorArea THEN DO:
223 LeaseTotal.AreaSize = LeaseTotal.AreaSize + LseSpace.AreaSize.
224 LeaseTotal.AreaCount = LeaseTotal.AreaCount + 1.
225 LeaseTotal.ContractRent = LeaseTotal.ContractRent + LseSpace.ContractedRental.
226 END.
227 END.
229 DEF BUFFER NextAreaRent FOR AreaRental.
230 DEF VAR i AS INT NO-UNDO.
231 DEF VAR j AS INT NO-UNDO.
232 DEF VAR rent-ratio AS DEC NO-UNDO.
233 DEF VAR area-ratio AS DEC NO-UNDO.
234 FOR EACH LeaseRental WHERE LeaseRental.LeaseCode = Lease.TenancyLeaseCode
235 AND LeaseRental.AnnualRent <> 0:
236 i = 1.
237 j = 1.
238 FIND AreaType WHERE AreaType.AreaType = LeaseRental.AreaType NO-LOCK NO-ERROR.
240 FOR EACH AreaRental WHERE AreaRental.LeaseCode = LeaseRental.LeaseCode
241 AND AreaRental.AreaType = LeaseRental.AreaType:
242 IF LeaseRental.AreaCount < 2 THEN
243 AreaRental.AnnualRent = LeaseRental.AnnualRent.
244 ELSE IF AreaRental.ContractRent <> 0 AND LeaseRental.ContractRent <> 0 THEN
245 AreaRental.AnnualRent = LeaseRental.AnnualRent * (AreaRental.ContractRent / LeaseRental.ContractRent).
246 ELSE IF LeaseRental.AreaSize <> 0 THEN
247 AreaRental.AnnualRent = LeaseRental.AnnualRent * (AreaRental.AreaSize / LeaseRental.AreaSize) .
248 ELSE IF i = 1 THEN
249 AreaRental.AnnualRent = LeaseRental.AnnualRent.
251 IF AVAILABLE(AreaType) AND AreaType.IsFloorArea THEN DO:
252 area-ratio = AreaRental.AreaSize / LeaseTotal.AreaSize.
253 IF LeaseTotal.AreaCount < 2 THEN DO:
254 AreaRental.AnnualOutgoings = LeaseTotal.AnnualOutgoings.
255 AreaRental.AnnualCleaning = LeaseTotal.AnnualCleaning.
256 END.
257 ELSE IF AreaRental.ContractRent <> 0 AND LeaseTotal.ContractRent <> 0 THEN DO:
258 rent-ratio = (AreaRental.ContractRent / LeaseTotal.ContractRent).
259 AreaRental.AnnualOutgoings = LeaseTotal.AnnualOutgoings * rent-ratio.
260 AreaRental.AnnualCleaning = LeaseTotal.AnnualCleaning * area-ratio.
261 END.
262 ELSE IF LeaseTotal.AreaSize <> 0 THEN DO:
263 AreaRental.AnnualOutgoings = LeaseTotal.AnnualOutgoings * area-ratio.
264 AreaRental.AnnualCleaning = LeaseTotal.AnnualCleaning * area-ratio.
265 END.
266 ELSE IF j = 1 THEN DO:
267 AreaRental.AnnualOutgoings = LeaseTotal.AnnualOutgoings.
268 AreaRental.AnnualCleaning = LeaseTotal.AnnualCleaning.
269 END.
270 j = j + 1.
271 END.
273 i = i + 1.
274 END.
275 END.
276 END.
278 END PROCEDURE.
280 /* _UIB-CODE-BLOCK-END */
281 &ANALYZE-RESUME
283 &ENDIF
285 /* ************************ Function Implementations ***************** */
287 &IF DEFINED(EXCLUDE-get-area-cleaning) = 0 &THEN
289 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION get-area-cleaning Method-Library
290 FUNCTION get-area-cleaning RETURNS DECIMAL
291 ( INPUT property-code AS INT, INPUT area-code AS INT ) :
292 /*------------------------------------------------------------------------------
293 Purpose: Get the rental for this area
294 Notes:
295 ------------------------------------------------------------------------------*/
296 FIND AreaRental WHERE AreaRental.PropertyCode = property-code
297 AND AreaRental.RentalSpaceCode = area-code NO-ERROR.
299 RETURN (IF AVAILABLE(AreaRental) THEN AreaRental.AnnualCleaning ELSE 0.0 ).
301 END FUNCTION.
303 /* _UIB-CODE-BLOCK-END */
304 &ANALYZE-RESUME
306 &ENDIF
308 &IF DEFINED(EXCLUDE-get-area-outgoings) = 0 &THEN
310 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION get-area-outgoings Method-Library
311 FUNCTION get-area-outgoings RETURNS DECIMAL
312 ( INPUT property-code AS INT, INPUT area-code AS INT ) :
313 /*------------------------------------------------------------------------------
314 Purpose: Get the rental for this area
315 Notes:
316 ------------------------------------------------------------------------------*/
317 FIND AreaRental WHERE AreaRental.PropertyCode = property-code
318 AND AreaRental.RentalSpaceCode = area-code NO-ERROR.
320 RETURN (IF AVAILABLE(AreaRental) THEN AreaRental.AnnualOutgoings ELSE 0.0 ).
322 END FUNCTION.
324 /* _UIB-CODE-BLOCK-END */
325 &ANALYZE-RESUME
327 &ENDIF
329 &IF DEFINED(EXCLUDE-get-area-rental) = 0 &THEN
331 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION get-area-rental Method-Library
332 FUNCTION get-area-rental RETURNS DECIMAL
333 ( INPUT property-code AS INT, INPUT area-code AS INT ) :
334 /*------------------------------------------------------------------------------
335 Purpose: Get the rental for this area
336 Notes:
337 ------------------------------------------------------------------------------*/
338 FIND AreaRental WHERE AreaRental.PropertyCode = property-code
339 AND AreaRental.RentalSpaceCode = area-code NO-ERROR.
341 RETURN (IF AVAILABLE(AreaRental) THEN AreaRental.AnnualRent ELSE 0.0 ).
343 END FUNCTION.
345 /* _UIB-CODE-BLOCK-END */
346 &ANALYZE-RESUME
348 &ENDIF