Added capital works blank section. Synced calling screen.
[capital-apms-progress.git] / inc / entity.i
blob0a48962101dc498ffe9638a7b99ffd96990d786d
1 &ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12
2 &ANALYZE-RESUME
3 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS Method-Library
4 /*--------------------------------------------------------------------------
5 Library : inc/entity.i
6 Purpose : Deal with getting things associated with accounting entities
8 Syntax :
10 Description :
12 Author(s) :
13 Created :
14 Notes :
15 ------------------------------------------------------------------------*/
17 /* _UIB-CODE-BLOCK-END */
18 &ANALYZE-RESUME
21 &ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
23 /* ******************** Preprocessor Definitions ******************** */
27 /* _UIB-PREPROCESSOR-BLOCK-END */
28 &ANALYZE-RESUME
31 /* ************************ Function Prototypes ********************** */
33 &IF DEFINED(EXCLUDE-get-entity-account) = 0 &THEN
35 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD get-entity-account Method-Library
36 FUNCTION get-entity-account RETURNS CHARACTER
37 ( INPUT et AS CHAR, INPUT ec AS INT, INPUT ac AS DEC ) FORWARD.
39 /* _UIB-CODE-BLOCK-END */
40 &ANALYZE-RESUME
42 &ENDIF
44 &IF DEFINED(EXCLUDE-get-entity-client) = 0 &THEN
46 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD get-entity-client Method-Library
47 FUNCTION get-entity-client RETURNS CHARACTER
48 ( INPUT et AS CHAR, INPUT ec AS INT ) FORWARD.
50 /* _UIB-CODE-BLOCK-END */
51 &ANALYZE-RESUME
53 &ENDIF
55 &IF DEFINED(EXCLUDE-get-entity-ledger) = 0 &THEN
57 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD get-entity-ledger Method-Library
58 FUNCTION get-entity-ledger RETURNS INTEGER
59 ( INPUT et AS CHAR, INPUT ec AS INT ) FORWARD.
61 /* _UIB-CODE-BLOCK-END */
62 &ANALYZE-RESUME
64 &ENDIF
66 &IF DEFINED(EXCLUDE-get-entity-name) = 0 &THEN
68 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD get-entity-name Method-Library
69 FUNCTION get-entity-name RETURNS CHARACTER
70 ( INPUT et AS CHAR, INPUT ec AS INT ) FORWARD.
72 /* _UIB-CODE-BLOCK-END */
73 &ANALYZE-RESUME
75 &ENDIF
77 &IF DEFINED(EXCLUDE-get-entity-type-name) = 0 &THEN
79 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD get-entity-type-name Method-Library
80 FUNCTION get-entity-type-name RETURNS CHARACTER
81 ( INPUT et AS CHAR ) FORWARD.
83 /* _UIB-CODE-BLOCK-END */
84 &ANALYZE-RESUME
86 &ENDIF
88 &IF DEFINED(EXCLUDE-get-parent-entity) = 0 &THEN
90 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION-FORWARD get-parent-entity Method-Library
91 FUNCTION get-parent-entity RETURNS CHARACTER
92 ( INPUT et AS CHAR, INPUT ec AS INT ) FORWARD.
94 /* _UIB-CODE-BLOCK-END */
95 &ANALYZE-RESUME
97 &ENDIF
100 /* *********************** Procedure Settings ************************ */
102 &ANALYZE-SUSPEND _PROCEDURE-SETTINGS
103 /* Settings for THIS-PROCEDURE
104 Type: Method-Library
105 Allow:
106 Frames: 0
107 Add Fields to: Neither
108 Other Settings: INCLUDE-ONLY
110 &ANALYZE-RESUME _END-PROCEDURE-SETTINGS
112 /* ************************* Create Window ************************** */
114 &ANALYZE-SUSPEND _CREATE-WINDOW
115 /* DESIGN Window definition (used by the UIB)
116 CREATE WINDOW Method-Library ASSIGN
117 HEIGHT = .4
118 WIDTH = 40.
119 /* END WINDOW DEFINITION */
121 &ANALYZE-RESUME
123 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _INCLUDED-LIB Method-Library
124 /* ************************* Included-Libraries *********************** */
126 /* _UIB-CODE-BLOCK-END */
127 &ANALYZE-RESUME
133 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Method-Library
136 /* *************************** Main Block *************************** */
138 /* _UIB-CODE-BLOCK-END */
139 &ANALYZE-RESUME
142 /* ************************ Function Implementations ***************** */
144 &IF DEFINED(EXCLUDE-get-entity-account) = 0 &THEN
146 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION get-entity-account Method-Library
147 FUNCTION get-entity-account RETURNS CHARACTER
148 ( INPUT et AS CHAR, INPUT ec AS INT, INPUT ac AS DEC ) :
149 /*------------------------------------------------------------------------------
150 Purpose:
151 Notes:
152 ------------------------------------------------------------------------------*/
153 DEF VAR name AS CHAR NO-UNDO INITIAL "* * * Unknown * * *".
155 DEF BUFFER tmp_COA FOR ChartOfAccount.
156 DEF BUFFER tmp_ProjectBudget FOR ProjectBudget.
158 IF et = "J" THEN DO:
159 FIND tmp_ProjectBudget WHERE tmp_ProjectBudget.ProjectCode = ec AND tmp_ProjectBudget.AccountCode = ac NO-LOCK NO-ERROR.
160 IF AVAILABLE(tmp_ProjectBudget) THEN RETURN tmp_ProjectBudget.Description.
161 END.
163 FIND tmp_COA WHERE tmp_COA.AccountCode = ac NO-LOCK NO-ERROR.
164 IF AVAILABLE(tmp_COA) THEN name = tmp_COA.Name.
166 RETURN name.
168 END FUNCTION.
170 /* _UIB-CODE-BLOCK-END */
171 &ANALYZE-RESUME
173 &ENDIF
175 &IF DEFINED(EXCLUDE-get-entity-client) = 0 &THEN
177 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION get-entity-client Method-Library
178 FUNCTION get-entity-client RETURNS CHARACTER
179 ( INPUT et AS CHAR, INPUT ec AS INT ) :
180 /*------------------------------------------------------------------------------
181 Purpose: Find the client for this entity type / entity code.
182 ------------------------------------------------------------------------------*/
183 DEF VAR entity-code AS CHAR NO-UNDO.
185 DEF BUFFER tmp_Company FOR Company.
186 DO WHILE et <> "L":
187 entity-code = get-parent-entity( et, ec ).
188 et = SUBSTRING( entity-code, 1, 1).
189 ec = INT( SUBSTRING( entity-code, 2) ).
190 END.
192 FIND tmp_Company WHERE tmp_Company.CompanyCode = ec NO-LOCK NO-ERROR.
193 RETURN tmp_Company.ClientCode.
195 END FUNCTION.
197 /* _UIB-CODE-BLOCK-END */
198 &ANALYZE-RESUME
200 &ENDIF
202 &IF DEFINED(EXCLUDE-get-entity-ledger) = 0 &THEN
204 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION get-entity-ledger Method-Library
205 FUNCTION get-entity-ledger RETURNS INTEGER
206 ( INPUT et AS CHAR, INPUT ec AS INT ) :
207 /*------------------------------------------------------------------------------
208 Purpose: Find the ultimate ledger parent for this entity type / entity code.
209 ------------------------------------------------------------------------------*/
210 DEF VAR entity-code AS CHAR NO-UNDO.
212 DO WHILE et <> "L":
213 entity-code = get-parent-entity( et, ec ).
214 et = SUBSTRING( entity-code, 1, 1).
215 ec = INT( SUBSTRING( entity-code, 2) ).
216 END.
218 RETURN ec.
220 END FUNCTION.
222 /* _UIB-CODE-BLOCK-END */
223 &ANALYZE-RESUME
225 &ENDIF
227 &IF DEFINED(EXCLUDE-get-entity-name) = 0 &THEN
229 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION get-entity-name Method-Library
230 FUNCTION get-entity-name RETURNS CHARACTER
231 ( INPUT et AS CHAR, INPUT ec AS INT ) :
232 /*------------------------------------------------------------------------------
233 Purpose:
234 Notes:
235 ------------------------------------------------------------------------------*/
236 DEF VAR name AS CHAR NO-UNDO.
238 CASE et:
239 WHEN "T" THEN DO:
240 DEF BUFFER tmp_Tenant FOR Tenant.
241 FIND tmp_Tenant WHERE tmp_Tenant.TenantCode = ec NO-LOCK NO-ERROR.
242 name = IF AVAILABLE(tmp_Tenant) THEN tmp_Tenant.Name ELSE "* * * Unknown * * *".
243 END.
244 WHEN "C" THEN DO:
245 DEF BUFFER tmp_Creditor FOR Creditor.
246 FIND tmp_Creditor WHERE tmp_Creditor.CreditorCode = ec NO-LOCK NO-ERROR.
247 name = IF AVAILABLE(tmp_Creditor) THEN tmp_Creditor.Name ELSE "* * * Unknown * * *".
248 END.
249 WHEN "P" THEN DO:
250 DEF BUFFER tmp_Property FOR Property.
251 FIND tmp_Property WHERE tmp_Property.PropertyCode = ec NO-LOCK NO-ERROR.
252 name = IF AVAILABLE(tmp_Property) THEN tmp_Property.Name ELSE "* * * Unknown * * *".
253 END.
254 WHEN "L" THEN DO:
255 DEF BUFFER tmp_Company FOR Company.
256 FIND tmp_Company WHERE tmp_Company.CompanyCode = ec NO-LOCK NO-ERROR.
257 name = IF AVAILABLE(tmp_Company) THEN tmp_Company.LegalName ELSE "* * * Unknown * * *".
258 END.
259 WHEN "J" THEN DO:
260 DEF BUFFER tmp_Project FOR Project.
261 FIND tmp_Project WHERE tmp_Project.ProjectCode = ec NO-LOCK NO-ERROR.
262 name = IF AVAILABLE(tmp_Project) THEN tmp_Project.Name ELSE "* * * Unknown * * *".
263 END.
264 WHEN "F" THEN DO:
265 DEF BUFFER tmp_FixedAsset FOR FixedAsset.
266 FIND tmp_FixedAsset WHERE tmp_FixedAsset.AssetCode = ec NO-LOCK NO-ERROR.
267 name = IF AVAILABLE(tmp_FixedAsset) THEN tmp_FixedAsset.Description ELSE "* * * Unknown * * *".
268 END.
269 END CASE.
271 RETURN name.
273 END FUNCTION.
275 /* _UIB-CODE-BLOCK-END */
276 &ANALYZE-RESUME
278 &ENDIF
280 &IF DEFINED(EXCLUDE-get-entity-type-name) = 0 &THEN
282 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION get-entity-type-name Method-Library
283 FUNCTION get-entity-type-name RETURNS CHARACTER
284 ( INPUT et AS CHAR ) :
285 /*------------------------------------------------------------------------------
286 Purpose:
287 Notes:
288 ------------------------------------------------------------------------------*/
289 CASE et:
290 WHEN 'P' THEN RETURN "Property".
291 WHEN "J" THEN RETURN "Project".
292 WHEN "C" THEN RETURN "Creditor".
293 WHEN "L" THEN RETURN "Company".
294 WHEN "T" THEN RETURN "Tenant".
295 WHEN "F" THEN RETURN "Fixed Asset".
296 END CASE.
298 RETURN ?. /* Function return value. */
300 END FUNCTION.
302 /* _UIB-CODE-BLOCK-END */
303 &ANALYZE-RESUME
305 &ENDIF
307 &IF DEFINED(EXCLUDE-get-parent-entity) = 0 &THEN
309 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _FUNCTION get-parent-entity Method-Library
310 FUNCTION get-parent-entity RETURNS CHARACTER
311 ( INPUT et AS CHAR, INPUT ec AS INT ) :
312 /*------------------------------------------------------------------------------
313 Purpose:
314 Notes:
315 ------------------------------------------------------------------------------*/
316 DEF VAR parent-entity AS CHAR NO-UNDO.
318 CASE et:
319 WHEN "J" THEN DO:
320 DEF BUFFER tmp_Project FOR Project.
321 FIND tmp_Project WHERE tmp_Project.ProjectCode = ec NO-LOCK NO-ERROR.
322 parent-entity = tmp_Project.EntityType + STRING( tmp_Project.EntityCode, "99999").
323 END.
324 WHEN "P" THEN DO:
325 DEF BUFFER tmp_Property FOR Property.
326 FIND tmp_Property WHERE tmp_Property.PropertyCode = ec NO-LOCK NO-ERROR.
327 parent-entity = "L" + STRING( tmp_Property.CompanyCode, "99999").
328 END.
329 WHEN "T" THEN DO:
330 DEF BUFFER tmp_Tenant FOR Tenant.
331 FIND tmp_Tenant WHERE tmp_Tenant.TenantCode = ec NO-LOCK NO-ERROR.
332 parent-entity = tmp_Tenant.EntityType + STRING( tmp_Tenant.EntityCode, "99999").
333 END.
334 WHEN "C" THEN DO:
335 DEF BUFFER tmp_Creditor FOR Creditor.
336 FIND tmp_Creditor WHERE tmp_Creditor.CreditorCode = ec NO-LOCK NO-ERROR.
337 parent-entity = "L" + STRING( tmp_Creditor.CompanyCode, "99999").
338 END.
339 OTHERWISE DO:
340 parent-entity = "L00001".
341 END.
342 END CASE.
344 RETURN parent-entity.
346 END FUNCTION.
348 /* _UIB-CODE-BLOCK-END */
349 &ANALYZE-RESUME
351 &ENDIF