Make date field wider to accommodate 10 digits properly.
[capital-apms-progress.git] / process / fid-chg.p
blob95d1b198ca8170f7272eb7b54c358517bd546da1
1 &ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12
2 &ANALYZE-RESUME
3 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS Procedure
4 /*--------------------------------------------------------------------------
5 ------------------------------------------------------------------------*/
6 &IF DEFINED( UIB_IS_RUNNING ) &THEN
7 DEF VAR run-options AS CHAR NO-UNDO INITIAL "111,502,502".
8 DEF VAR preview AS LOGICAL NO-UNDO INITIAL Yes.
9 &ELSE
10 DEF INPUT PARAMETER run-options AS CHAR NO-UNDO.
11 DEF INPUT PARAMETER preview AS LOGICAL NO-UNDO.
12 &ENDIF
14 DEF VAR m-code LIKE Month.MonthCode NO-UNDO.
15 DEF VAR p1 LIKE Property.PropertyCode NO-UNDO.
16 DEF VAR p2 LIKE Property.PropertyCode NO-UNDO.
18 m-code = INTEGER( ENTRY( 1, run-options )).
19 p1 = INTEGER( ENTRY( 2, run-options )).
20 p2 = INTEGER( ENTRY( 3, run-options )).
21 IF p1 = ? THEN DO:
22 p1 = 0.
23 IF p2 = ? THEN p2 = 99999.
24 END.
25 IF p2 = ? OR p2 < p1 THEN p2 = p1.
27 {inc/ofc-this.i}
28 {inc/ofc-acct.i "DEBTORS" "sundry-debtors"}
29 DEF BUFFER FID-DB FOR OfficeControlAccount.
30 DEF BUFFER FID-CR FOR OfficeControlAccount.
31 FIND FID-DB OF Office WHERE FID-DB.Name = "FID-DB" NO-LOCK.
32 FIND FID-CR OF Office WHERE FID-CR.Name = "FID-CR" NO-LOCK.
33 {inc/ofc-set.i "FID-RATE" "c-fid-rate"}
34 DEF VAR fid-rate AS DECIMAL NO-UNDO.
35 fid-rate = DECIMAL( c-fid-rate ).
37 DEF VAR tr-description AS CHAR NO-UNDO.
38 FIND Month WHERE Month.MonthCode = m-code NO-LOCK.
39 tr-description = "FID for the period from " + STRING( Month.StartDate, "99/99/9999") + " to " + STRING( Month.EndDate, "99/99/9999").
41 DEF VAR out-line AS CHAR NO-UNDO.
42 DEF VAR user-name AS CHAR NO-UNDO.
43 {inc/username.i "user-name"}
44 FIND Usr WHERE Usr.UserName = user-name NO-LOCK NO-ERROR.
46 /* Doing this here ensures that Batch is scoped to the whole program */
47 DEF VAR batch-code LIKE NewBatch.BatchCode NO-UNDO.
48 FIND LAST Batch NO-LOCK NO-ERROR.
49 batch-code = Batch.BatchCode + 1.
50 FIND LAST NewBatch NO-LOCK NO-ERROR.
51 IF NewBatch.BatchCode >= batch-code THEN batch-code = NewBatch.BatchCode + 1.
52 IF NOT(preview) THEN DO:
53 CREATE NewBatch.
54 ASSIGN
55 NewBatch.BatchCode = batch-code
56 NewBatch.BatchType = "AUTO"
57 NewBatch.Description = tr-description
58 NewBatch.PersonCode = (IF AVAILABLE(Usr) THEN Usr.PersonCode ELSE 0)
59 NewBatch.DocumentCount = 0
60 NewBatch.Total = 0
62 END.
64 /* Doing this here ensures that NewAcctTrans is scoped to the whole program */
65 FIND FIRST NewAcctTrans NO-LOCK NO-ERROR.
67 DEF VAR this-document LIKE Document.DocumentCode NO-UNDO INITIAL 0.
68 DEF VAR this-transaction LIKE AcctTran.TransactionCode NO-UNDO INITIAL 0.
69 DEF VAR debit-total AS DECIMAL NO-UNDO INITIAL 0.
72 /* page control */
73 DEF VAR prt-ctrl AS CHAR NO-UNDO.
74 DEF VAR cols AS INT NO-UNDO.
75 DEF VAR rows AS INT NO-UNDO.
77 /* page header */
78 &SCOPED-DEFINE page-width 100
79 &SCOPED-DEFINE with-clause NO-BOX USE-TEXT NO-LABELS WIDTH {&page-width}
81 DEF VAR timeStamp AS CHAR FORMAT "X(44)" NO-UNDO.
82 timeStamp = STRING( TODAY, "99/99/9999") + ", " + STRING( TIME, "HH:MM:SS") + " for " + user-name.
83 DEF VAR hline2 AS CHAR FORMAT "X({&page-width})" NO-UNDO.
84 DEF VAR hline3 AS CHAR FORMAT "X({&page-width})" NO-UNDO.
85 hline2 = "FID Charges".
86 hline2 = SUBSTRING( STRING("","X({&page-width})"), 1, INTEGER(({&page-width} - LENGTH(hline2) ) / 2)) + hline2.
87 hline3 = STRING( Month.StartDate, "99/99/9999") + " to " + STRING( Month.EndDate, "99/99/9999").
88 hline3 = SUBSTRING( STRING("","X({&page-width})"), 1, INTEGER(({&page-width} - LENGTH(hline3) ) / 2)) + hline3.
90 DEFINE FRAME heading-frame WITH 1 DOWN {&with-clause} PAGE-TOP.
91 FORM HEADER
92 timeStamp "Page " + STRING( PAGE-NUMBER ) TO {&page-width} SKIP (1)
93 hline2 FORMAT "X({&page-width})"
94 hline3 FORMAT "X({&page-width})"
95 SKIP (2) "column headings"
96 WITH FRAME heading-frame.
98 /* _UIB-CODE-BLOCK-END */
99 &ANALYZE-RESUME
102 &ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
104 /* ******************** Preprocessor Definitions ******************** */
106 &Scoped-define PROCEDURE-TYPE Procedure
110 /* _UIB-PREPROCESSOR-BLOCK-END */
111 &ANALYZE-RESUME
115 /* *********************** Procedure Settings ************************ */
117 &ANALYZE-SUSPEND _PROCEDURE-SETTINGS
118 /* Settings for THIS-PROCEDURE
119 Type: Procedure
120 Allow:
121 Frames: 0
122 Add Fields to: Neither
123 Other Settings: CODE-ONLY COMPILE
125 &ANALYZE-RESUME _END-PROCEDURE-SETTINGS
127 /* ************************* Create Window ************************** */
129 &ANALYZE-SUSPEND _CREATE-WINDOW
130 /* DESIGN Window definition (used by the UIB)
131 CREATE WINDOW Procedure ASSIGN
132 HEIGHT = .33
133 WIDTH = 31.72.
134 /* END WINDOW DEFINITION */
136 &ANALYZE-RESUME
140 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _INCLUDED-LIB Procedure
141 /* ************************* Included-Libraries *********************** */
143 {inc/method/m-txtrep.i}
145 /* _UIB-CODE-BLOCK-END */
146 &ANALYZE-RESUME
150 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Procedure
153 /* *************************** Main Block *************************** */
154 ON WRITE OF NewAcctTrans OVERRIDE DO: END.
155 ON WRITE OF NewDocument OVERRIDE DO: END.
158 RUN make-control-string ( "PCL", "reset,portrait,tm,2,a4,lm,6,courier,cpi,18,lpi,9",
159 OUTPUT prt-ctrl, OUTPUT rows, OUTPUT cols ).
161 RUN output-control-file ( prt-ctrl ).
162 OUTPUT TO VALUE(txtrep-print-file) KEEP-MESSAGES PAGE-SIZE VALUE(rows).
164 VIEW FRAME heading-frame.
166 FOR EACH Property NO-LOCK WHERE Property.Active AND NOT Property.ExternallyManaged
167 AND Property.PropertyCode >= p1
168 AND Property.PropertyCode <= p2:
169 RUN each-property.
170 END.
172 IF NOT(preview) THEN ASSIGN
173 NewBatch.DocumentCount = this-document
174 NewBatch.Total = debit-total .
177 OUTPUT CLOSE.
178 RUN view-output-file ( preview ).
180 /* _UIB-CODE-BLOCK-END */
181 &ANALYZE-RESUME
184 /* ********************** Internal Procedures *********************** */
186 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE create-transaction Procedure
187 PROCEDURE create-transaction :
188 /*------------------------------------------------------------------------------
189 Purpose: Create a NewTransaction record
190 ------------------------------------------------------------------------------*/
191 DEF INPUT PARAMETER et LIKE NewAcctTrans.EntityType NO-UNDO.
192 DEF INPUT PARAMETER ec LIKE NewAcctTrans.EntityCode NO-UNDO.
193 DEF INPUT PARAMETER ac LIKE NewAcctTrans.AccountCode NO-UNDO.
194 DEF INPUT PARAMETER amt LIKE NewAcctTrans.Amount NO-UNDO.
196 IF amt > 0 THEN debit-total = debit-total + amt.
197 IF this-transaction = 0 THEN DO:
198 this-document = this-document + 1.
199 CREATE NewDocument.
200 ASSIGN
201 NewDocument.BatchCode = batch-code
202 NewDocument.DocumentCode = this-document
203 NewDocument.DocumentType = "FID"
204 NewDocument.Reference = ( et + STRING( ec, "99999") )
205 NewDocument.Description = NewBatch.Description
207 RELEASE NewDocument.
208 END.
210 this-transaction = this-transaction + 1.
211 CREATE NewAcctTrans.
212 ASSIGN
213 NewAcctTrans.BatchCode = batch-code
214 NewAcctTrans.DocumentCode = this-document
215 NewAcctTrans.TransactionCode = this-transaction
216 NewAcctTrans.EntityType = et
217 NewAcctTrans.EntityCode = ec
218 NewAcctTrans.AccountCode = ac
219 NewAcctTrans.Date = Month.StartDate
220 NewAcctTrans.Reference = ("FID "
221 + STRING( MONTH( Month.StartDate ), "99")
222 + STRING( (YEAR( Month.StartDate ) MODULO 100) , "99"))
223 NewAcctTrans.Amount = amt
224 NewAcctTrans.Description = tr-description
227 RELEASE NewAcctTrans.
228 END PROCEDURE.
230 /* _UIB-CODE-BLOCK-END */
231 &ANALYZE-RESUME
234 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE each-property Procedure
235 PROCEDURE each-property :
236 /*------------------------------------------------------------------------------
237 Purpose: Calculate the FID for each property
238 ------------------------------------------------------------------------------*/
239 DEF VAR property-total AS DECIMAL NO-UNDO INITIAL 0.
241 this-transaction = 0.
242 FOR EACH Tenant NO-LOCK WHERE Tenant.EntityType = "P"
243 AND Tenant.EntityCode = Property.PropertyCode:
244 RUN each-tenant( INPUT-OUTPUT property-total ).
245 END.
247 IF property-total <> 0 THEN DO:
248 out-line = " ---------------".
249 RUN print-line( out-line ).
250 out-line = " "
251 + STRING( property-total, "->>>,>>>,>>9.99") + " ".
252 /* Allocate Federal Tax against property */
253 property-total = property-total * fid-rate.
254 out-line = out-line
255 + STRING( property-total, "->,>>>,>>9.99") + " "
256 + "FID for " + Property.Name.
257 RUN print-line( out-line ).
258 RUN print-line("").
259 IF NOT(preview) THEN DO:
260 RUN create-transaction( FID-DB.EntityType, Property.PropertyCode, FID-DB.AccountCode, property-total).
261 RUN create-transaction( "P", Property.PropertyCode, FID-CR.AccountCode, - property-total).
262 END.
263 END.
264 END PROCEDURE.
266 /* _UIB-CODE-BLOCK-END */
267 &ANALYZE-RESUME
270 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE each-tenant Procedure
271 PROCEDURE each-tenant :
272 /*------------------------------------------------------------------------------
273 Purpose:
274 ------------------------------------------------------------------------------*/
275 DEF INPUT-OUTPUT PARAMETER p-total AS DECIMAL NO-UNDO.
277 FOR EACH AcctTran NO-LOCK WHERE AcctTran.EntityType = "T"
278 AND AcctTran.EntityCode = Tenant.TenantCode
279 AND AcctTran.AccountCode = sundry-debtors
280 AND AcctTran.MonthCode = m-code
281 AND AcctTran.Amount < 0:
282 IF SUBSTRING( AcctTran.Reference, 1, 3) = "INV" THEN NEXT.
283 IF SUBSTRING( AcctTran.Reference, 1, 1) = "T"
284 AND INTEGER(SUBSTRING( AcctTran.Reference, 2, 5)) = Tenant.TenantCode THEN NEXT.
286 p-total = p-total - AcctTran.Amount.
287 out-line = "T" + STRING( Tenant.TenantCode, "99999") + " "
288 + STRING( - AcctTran.Amount, "->>>,>>>,>>9.99") + " "
289 + STRING( AcctTran.Reference, "X(12)") + " "
290 + STRING( Accttran.Description, "X(50)" ).
291 RUN print-line( out-line ).
292 END.
293 END PROCEDURE.
295 /* _UIB-CODE-BLOCK-END */
296 &ANALYZE-RESUME
299 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE print-line Procedure
300 PROCEDURE print-line :
301 /*------------------------------------------------------------------------------
302 Purpose:
303 ------------------------------------------------------------------------------*/
304 DEF INPUT PARAMETER out-line AS CHAR NO-UNDO.
306 PUT UNFORMATTED out-line.
307 IF out-line = "" THEN PUT SKIP(1). ELSE PUT SKIP.
308 END PROCEDURE.
310 /* _UIB-CODE-BLOCK-END */
311 &ANALYZE-RESUME