Menu

[4640d3]: / Aptran.prg  Maximize  Restore  History

Download this file

512 lines (461 with data), 14.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
/** @package
Aptran.prg
Copyright(c) DEPT OF FOREIGN AFFAIRS TRADE 2000
Author: DEPT OF FOREIGN AFFAIRS TRADE
Created: DOF 6/03/2009 11:27:24 PM
Last change: TG 15 Jan 2011 2:02 pm
*/
#include "bpos.ch"
Procedure ApTran
#define INV 1
#define CRE 2
#define PAY 3
#define DJN 4
#define CJN 5
#define CURRENT 1
#define DAYS30 2
#define DAYS60 3
#define DAYS90 4
local mscr, again := FALSE, gotfiles := ap_file_open( SHARED )
local oksf10, oldscr := Box_Save()
local mttloop, dummy, msupp, getlist:={}, aArray
local mttype
// field amtcur, amt30, amt60, amt90, ttype, tage, amt, amtpaid
while gotfiles
select supplier
dummy := space(10)
while !again
msupp:=space(4)
mscr:=Box_Save( 2, 25, 4, 55 )
@ 3,28 say 'Enter supplier Code' get msupp pict '@!';
valid( Dup_chk( msupp , "supplier" ) )
read
Box_Restore( mscr )
if !updated()
close databases
return
endif
select supplier
seek msupp
if !found()
Error( "Supplier not on File",12 )
else
again := TRUE
endif
enddo
mttloop := TRUE
while mttloop
Box_Restore( oldscr )
mttype := 1
Creddisp( FALSE )
Heading( 'Select transaction type' )
aArray := {}
aadd( aArray, { ' 1. Invoice ', '' } )
aadd( aArray, { '2. Credit ', '' } )
aadd( aArray, { '3. Payment ', '' } )
aadd( aArray, { '4. Debt Jnl', '' } )
aadd( aArray, { '5. Cred Jnl', '' } )
aadd( aArray, { 'Show Trans.', '' } )
aadd( aArray, { 'History', '' } )
oksf10 := setkey( K_SH_F10 , { || Ap_balchange() } )
mttype := MenuGen( aArray, 9, 5 )
setkey( K_SH_F10 , oksf10 )
do case
case mttype > 0 .and. mttype < 6
Aptrango( mttype )
case mttype = 6
A_tran_disp( TRUE )
case mttype = 7
A_tran_disp( FALSE )
otherwise
mttloop := FALSE
endcase
enddo
again := NO
enddo
close databases
return
*
function aptrango ( mttype )
local mamt := 0, mtnum := space(16), mdesc := space(16), mduedate := Bvars( B_DATE )
local mamtpaid := 0, mtran_age := 0, mdate:= Bvars( B_DATE ), getlist:={}
local mscr := Box_Save( 08, 02, 17, 40 ), tscr, mt, mc, m3, m6, m9
// field amtcur, amt30, amt60, amt90, ttype, tage, amt, amtpaid, ytdamt
Highlight( 09, 04, 'Transaction type->', Tname( mttype ) )
@ 10,04 say "Date ............." get mdate
@ 11,04 say "Reference number ." get mtnum pict '@!'
@ 12,04 say 'Transaction Amt..$' get mamt pict '#######.##'
@ 13,04 say 'Description ......' get mdesc
@ 14,04 say 'Due Date .........' get mduedate
read
if lastkey() = K_ESC .or. mamt = 0
return 0
else
mt := mamt
@ 15,23 say '컴컴컴컴컴'
@ 16,4 say 'Transaction Total.$'
@ 16,23 say mt pict '#######.##'
if mttype != INV .and. !supplier->op_it
tscr := Box_Save( 19, 1, 22, 75 )
@ 21,2 say " 1..current 2..30 days 3..60 days 4..90+ days 5... Oldest First"
@ 20,2 say "Transaction age?..............." get mtran_age pict "#" range 1,5
read
Box_Restore( tscr )
if lastkey() = K_ESC
Box_Restore( mscr )
return 0
endif
else
mtran_age := CURRENT
endif
if Isready( 19 )
select supplier
Rec_lock()
if mttype != INV .and. supplier->op_it
mamtpaid := Apopenpay( supplier->code, mamt, mttype )
endif
tscr := Box_Save( 18,25,20,55 )
@ 19,27 say "Updating files..."
select cretrans
if mttype = CRE .or. mttype = PAY .or. mttype = CJN
mamt := -mamt
mt := -mt
mamtpaid := -mamtpaid
endif
Add_rec()
replace code with supplier->code ,;
ttype with mttype ,;
date with mdate ,;
tnum with mtnum ,;
amt with mamt ,;
tage with if( mttype < PAY, mtran_age, 1 ) ,;
amtpaid with mamtpaid ,;
desc with mdesc,;
duedate with mduedate
select supplier
if mttype != PAY
replace supplier->ytdamt with supplier->ytdamt + mt
endif
if !supplier->op_it .or. mttype = INV
do case
case mtran_age = CURRENT
supplier->amtcur += mt
case mtran_age = DAYS30
supplier->amt30 += mt
case mtran_age = DAYS60
supplier->amt60 += mt
case mtran_age = DAYS90
supplier->amt90 += mt
case mtran_age = 5
m9 := supplier->amt90
m6 := supplier->amt60
m3 := supplier->amt30
mc := supplier->amtcur
if m9 >= -mt
supplier->amt90 += mt
mt := 0
else
mt += supplier->amt90
supplier->amt90 := 0
endif
if m6 >= -mt
supplier->amt60 += mt
mt := 0
else
mt += supplier->amt60
supplier->amt60 :=0
endif
if m3 >= -mt
supplier->amt30 += mt
mt := 0
else
mt += supplier->amt30
supplier->amt30 := 0
endif
supplier->amtcur += mt
endcase
endif
if cretrans->ttype = INV
supplier->lastbuy := 1
endif
Box_Restore( tscr )
dbunlockall()
endif
endif
Creddisp( FALSE )
Box_Restore( mscr )
return mamt
*
function apopenpay ( mcode, mamt, mttype )
local paycur := FALSE, pay30 := FALSE, pay60 := FALSE, pay90 := FALSE
local sel,mgo,mscr,sscr:=Box_Save(16,0,24,79),bal,tpaid
local mun_alloc, mamtpaid, mfound, mamt_to_pay, mtran_age, mb, getlist:={}
field amtcur, amt30, amt60, amt90, ttype, tage, amt, amtpaid, date, tnum
if mttype = PAY
do case
case mamt = amt90
@ 20,2 say 'Payment Is Equal To Outstanding 90+ days Amount'
pay90 := YES
case mamt = amt60
@ 20,2 say 'Payment Is Equal To Outstanding 60 day Amount'
pay60 := YES
case mamt = amt30
@ 20,2 say 'Payment Is Equal To Outstanding 30 day Amount'
pay30 := YES
case mamt = amtcur
@ 20,2 say 'Payment Is Equal To Outstanding Current Amount'
paycur := YES
case mamt = amt60+amt90
@ 20,2 say 'Payment Is Equal To Outstanding 60 + 90 day Amounts'
pay60 := YES
pay90 := YES
case mamt = amt30+amt60
@ 20,2 say 'Payment Is Equal To Outstanding 30 + 60 day Amounts'
pay30 := YES
pay60 := YES
case mamt = amt30+amt60+amt90
@ 20,3 say 'Payment Is Equal To Outstanding 30 + 60 + 90 day Amounts'
pay30 := YES
pay60 := YES
pay90 := YES
case mamt = amtcur+amt30+amt60+amt90
@ 20,3 say 'Payment Is Equal To Outstanding Cur + 30 + 60 + 90 day Amounts'
paycur := YES
pay30 := YES
pay60 := YES
pay90 := YES
endcase
if paycur .or. pay30 .or. pay60 .or. pay90
mgo := NO
@ 22,02 say 'Do you wish to mark these invoices paid' get mgo pict 'y'
read
if mgo
if cretrans->( dbseek( mcode ) )
while cretrans->code = mcode .and. !cretrans->( eof() )
if ( cretrans->tage = CURRENT .and. paycur ) .or. ;
( cretrans->tage = DAYS30 .and. pay30 ) .or. ;
( cretrans->tage = DAYS60 .and. pay60 ) .or. ;
( cretrans->tage = DAYS90 .and. pay90 )
Rec_lock( 'cretrans' )
cretrans->amtpaid := cretrans->amt
cretrans->( dbrunlock() )
endif
cretrans->( dbskip() )
enddo
endif
select supplier
if paycur
supplier->amtcur := 0
endif
if pay30
supplier->amt30 := 0
endif
if pay60
supplier->amt60 := 0
endif
if pay90
supplier->amt90 := 0
endif
Box_Restore( sscr )
return mamt // all paid up return full amt
endif
endif
endif
select cretrans
mun_alloc := Vs(mamt,10,2) // Unallocated Balance
mamt_to_pay := 0
Box_Save( 16, 1, 21, 78 )
@ 17,2 say "Trans. Date Trans. Amount Total Balance Age"
@ 18,2 say " Type # $ $ $"
@ 19,2 say "컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴"
while TRUE
Box_Save( 21, 01, 23, 20 )
@ 22,03 say 'First Transaction'
inkey( 1 )
select cretrans
seek mcode
// mfound indicates if any transactions with a balance are found.
mfound := FALSE
while cretrans->code = mcode .and. !eof()
bal := Vs( cretrans->amt - cretrans->amtpaid )
if Vs( bal ) != 0
do case
case ( ttype = INV .or. ttype = DJN ) .and. mttype = DJN
skip
loop
case ( ttype = CRE .or. ttype = PAY .or. ttype = CJN ) .and. mttype != DJN
skip
loop
endcase
@ 20,2 say Tname( ttype )+' '+dtoc( date )+' '+substr( tnum,1,6 )+' '+str( amt,10,2 )+' ';
+space( 10 )+' '+str( cretrans->amtpaid,10,2 )+' '+str( bal,10,2 )+' ';
+Agename( tage )
mfound := TRUE
Box_Save( 21, 50, 23, 78 )
Highlight( 22, 52, 'Unallocated Cash $', Ns( mun_alloc,10,2 ) )
sel := FALSE
mscr := Box_Save( 21, 01, 23, 30 )
@ 22,03 say 'Pay this transaction ?' get sel pict 'y'
read
Box_Restore( mscr )
if lastkey() = K_ESC
select supplier
if mttype != DJN
supplier->amtcur -= mun_alloc
else
supplier->amtcur += mun_alloc
endif
Box_Restore( sscr )
return mamt - mun_alloc
endif
if sel
while TRUE
mscr := Box_Save( 21, 01, 23, 40 )
mamt_to_pay := 0
@ 22,02 say 'Enter amount to pay ..$' get mamt_to_pay pict '@Z 9999999.99'
read
Box_Restore( mscr )
mamt_to_pay := Vs( mamt_to_pay )
mb := bal
if ttype != INV .and. ttype != DJN // will convert a (-) figure to a (+)
mb := -mb // figure for comparison
endif
if mamt_to_pay > Vs( mun_alloc ) .or. mamt_to_pay > Vs( mb )
if mamt_to_pay > Vs( mun_alloc )
Error( 'Amount exceeds unallocated Balance !', 12 )
else
Error( 'Amount exceeds transaction Balance !', 12 )
endif
else
exit
endif
enddo
select cretrans
Rec_lock()
if mttype != DJN
cretrans->amtpaid += mamt_to_pay
else
cretrans->amtpaid -= mamt_to_pay
endif
mtran_age := cretrans->tage
tpaid := if( mttype != DJN, -mamt_to_pay, mamt_to_pay )
select supplier
do case // Update Aged Balances
case mtran_age = CURRENT
supplier->amtcur += tpaid
case mtran_age = DAYS30
supplier->amt30 += tpaid
case mtran_age = DAYS60
supplier->amt60 += tpaid
case mtran_age = DAYS90
supplier->amt90 += tpaid
endcase
select cretrans
mun_alloc := Vs( mun_alloc - mamt_to_pay )
if mun_alloc = 0 // Nothing left to allocate
Box_Restore( sscr )
return mamt // All allocated return full amt
endif
endif
endif
skip
enddo
if !mfound
Error('No outstanding transactions to Pay !',08)
select supplier
if mttype != DJN // credit or debit unallocated amounts
supplier->amtcur -= mun_alloc // to current balance
else
supplier->amtcur += mun_alloc
endif
Box_Restore( sscr )
return mamt - mun_alloc
endif
@ 22,2 say 'Last Transaction'
inkey(2)
enddo
Box_Restore( sscr )
return mamtpaid
*
Function creditor_type_change
local mscr, aArray, x, mchoice, sscr:=Box_Save()
if Secure( X_SUPERVISOR )
mscr := Box_Save( 2, 2, 9, 78 )
Center( 3, 'WARNING!!! - Be very sure you know what you are doing here!!!' )
Center( 4, DEVELOPER + ' WILL NOT ACCEPT ANY responsibility for the incorrect' )
Center( 5, 'use of this procedure!' )
Center( 7, 'PERFORM AN ACCOUNTS BACKUP FIRST' )
if Isready( 12 )
if Isready( 14, , 'Again are you sure you wish to proceed?' )
aArray := {}
aadd( aArray, { 'Change ALL Open item to Balance Brought Forward', '' } )
aadd( aArray, { 'Change ALL Balance Brought Forward to Open Item', '' } )
mchoice := Menugen( aArray, 17, 10 )
if mchoice > 0 .and. Isready( 12, , 'One last time - Are you sure about this?' )
if Netuse( 'aphist', EXCLUSIVE )
if Netuse( 'cretrans', EXCLUSIVE )
if Netuse( 'supplier', EXCLUSIVE )
ordsetfocus( 'code' )
supplier->( dbgotop() )
while !supplier->( eof() )
Center( 8, supplier->name )
do case
case mchoice = 1 .and. supplier->op_it
// Move all 30, 60, 90 day transactions to the history file
cretrans->( dbseek( supplier->code ) )
while cretrans->code = supplier->code .and. !cretrans->( eof() )
if cretrans->tage >= 2 // 30 day line
Add_rec( 'aphist' )
aphist->code := cretrans->code
aphist->ttype := cretrans->ttype
aphist->date := cretrans->date
aphist->tnum := cretrans->tnum
aphist->amt := cretrans->amt
aphist->duedate := cretrans->duedate
aphist->amtpaid := cretrans->amtpaid
aphist->tage := cretrans->tage
aphist->desc := cretrans->desc
Del_rec( 'cretrans' )
endif
cretrans->( dbskip() )
enddo
supplier->laststat := supplier->amt30 + supplier->amt60 + supplier->amt90
supplier->op_it := FALSE
case mchoice = 2 .and. !supplier->op_it
for x := 2 to 4
do case
case x = 2 .and. supplier->amt30 != 0
cretrans_rec( supplier->amt30, x )
case x = 3 .and. supplier->amt60 != 0
cretrans_rec( supplier->amt60, x )
case x = 4 .and. supplier->amt90 != 0
cretrans_rec( supplier->amt90, x )
endcase
next
supplier->op_it := TRUE
endcase
supplier->( dbskip() )
enddo
SysAudit( 'ChangeCred' + if ( mchoice=1, 'OI->BBF','BBF->OI' ) )
Isready( 12, , 'Procedure finished!' )
endif
endif
endif
endif
endif
endif
endif
dbcloseall()
Box_Restore( sscr )
return nil
*
Function cretrans_rec( mamt, mtage )
Add_rec( 'cretrans' )
cretrans->code := supplier->code
cretrans->tage := mtage
cretrans->ttype := if( mamt>0, 4, 5 ) //Db / Cr Journal
cretrans->date := Bvars( B_DATE )
cretrans->tnum := 'ADJUST'
cretrans->amt := mamt
cretrans->comment := 'Created by Type Change'
return nil