home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / pocketbk / utilsr / scbank23 / src / scbank.opl < prev    next >
Text File  |  1994-12-21  |  87KB  |  3,392 lines

  1. app Scbank
  2.     type $1003 rem s3a
  3. rem s3z    type 3
  4.     path "\bank"
  5.     ext "bnk"
  6.     icon "\opd\scbanka.pic" rem s3a
  7. rem s3z    icon "\opd\scbank.pic"
  8. enda
  9.  
  10. proc main:
  11. rem way too much global stuff :-)
  12. rem sorder% last thing on statement
  13.     global total,stotal,sorder%
  14.     global filepos%,scrpos%,typel$(255),stypel$(255)
  15. rem currency list
  16. rem remember where we are moving from
  17.     global oldpos%
  18. rem for display helpfuls
  19.     global lastpos%
  20.     global mark$(6),scrlen%,statlen%
  21. rem found a repeats file yet
  22.     global nfile$(255),stdstat$(10)
  23. rem indexes
  24.     global chqidx%,stmidx%,curidx%
  25. rem filter info
  26.     global onfilt$(3),filt$(20)
  27. rem font info
  28.     global linehi%,lined%,linea%
  29. rem screensizes
  30.     global scwidth%,schight%
  31.     global dispwin%
  32. rem search string and direction%
  33.     global search$(20),sdir%
  34.     global statwin%,stmwin%
  35.     global stmstat$(3),mrkstat$(3),sttstat$(3)
  36.     global ordstat$(10),why$(3),clkstat$(3)
  37. rem marker so banka: knows to do transfer
  38.     global trans$(3)
  39.     global mrkwin%,sttwin%,tmpfile$(255),stem$(255)
  40.     global version$(25),filenm$(128)
  41.     global statnx%,statmx%,statny%,statmy%
  42. rem fonts for zooming
  43.     global curfont%,zfontid%(4),zfonts%
  44. rem statuswindow type
  45.     global swintp%
  46. rem are we moving a window
  47.     global moving$(3)
  48. rem statement repeats
  49.     global stmrep$(80)
  50. rem last cheque number
  51.     global lastchq&
  52. rem auto cheque numbering
  53.     global chqstat$(3)
  54. rem collapse mark totals
  55.     global clpstat$(3)
  56. rem scroll optimizer
  57.     global doscr%
  58. rem last position where something done
  59.     global zapto%
  60.     local infowin%
  61. rem sc needs optimising
  62.     cache 2000,2000 rem s3a
  63.     version$="Version 2.3"
  64. rem load up extra procs needed if compiling on S3a
  65. rem    loadm "\opo\sceven.opo"
  66. rem    loadm "\opo\scmore.opo"
  67. rem    version$=version$+"(develop)"
  68.     scwidth%=gwidth : schight%=gheight
  69. rem remove text window
  70.     screen 1,1,1,1
  71.     gsetwin 1,1,2,2
  72.     infowin%=strtscr%:
  73. rem setup font array
  74.     zfonts%=4 rem s3a
  75.     zfontid%(1)=9 rem swiss8 rem s3a
  76.     zfontid%(2)=10 rem swiss11 rem s3a
  77.     zfontid%(3)=11 rem swiss13 rem s3a
  78.     zfontid%(4)=12 rem swiss16 rem s3a
  79. rem s3z    tmpfile$=ssdfind$:("\opd\scbank.fon")
  80. rem s3z    if (exist(tmpfile$)=-1)
  81. rem s3z        zfontid%(2)=gloadfont(tmpfile$)
  82. rem s3z        zfonts%=2
  83. rem s3z    else
  84. rem s3z        zfonts%=1
  85. rem s3z    endif
  86. rem s3z    zfontid%(1)=1 rem swiss8
  87.     diaminit 1,"ChqBook","Statmnt" rem s3a
  88. rem set up repeat string
  89.     stmrep$="Daily,Weekly,BiWeekly,Monthly,Quarterly,6Monthly,Yearly"
  90.     fset:(cmd$(3),cmd$(2))
  91.     startup:
  92.     gclose infowin%
  93.     mainloop:
  94. endp
  95.  
  96. proc startup: rem things to do when starting up new file
  97. rem start without repeats window
  98.     stmstat$="On"
  99. rem start without mark window
  100.     mrkstat$="On"
  101. rem start without statistics window
  102.     sttstat$="On"
  103. rem we dont start off moving transaction
  104.     moving$="Off"
  105. rem start without a display filter
  106.     onfilt$="On"
  107. rem start in chequebook mode
  108.     ordstat$="Statement"
  109. rem make sure the diamond is in the right place
  110.     diampos 1 rem s3a
  111. rem dont do transfer till we say
  112.     trans$="Off"
  113.     statwin%=gcreate(2,12,1,schight%-16,1,1) rem s3a
  114. rem s3z    statwin%=gcreate(2,12,1,schight%-16,1)
  115.     dispwin%=statwin%
  116.     while (findval%:<>1)
  117.     endwh
  118. rem display titles
  119.     sizewin:
  120. rem current index as chqbk
  121.     curidx%=chqidx%
  122. rem mark lastchq& as unset
  123.     lastchq&=-1
  124. rem set jump place to c/f initially
  125.     zapto%=0
  126.     guse dispwin%
  127.     bankp:
  128. endp
  129.  
  130. proc foninfo: rem font size info
  131.     local info%(32)
  132.     gfont zfontid%(curfont%)
  133.     ginfo info%()
  134.     linehi%=info%(3)+1 rem how high is this font
  135.     lined%=info%(4)+1 rem font descent
  136.     linea%=info%(5)+1 rem font ascent
  137. endp
  138.  
  139. proc sizewin: rem determine size of main window
  140.     local extent%(4),tamm$(10)
  141.     statwininfo(-1,extent%()) rem s3a
  142.     statnx%=0
  143.     statmx%=extent%(1) rem s3a
  144. rem s3z    statmx%=scwidth%
  145.     guse statwin%
  146.     foninfo:
  147.     gsetwin statnx%,0,statmx%,schight%
  148.     statny%=linehi%+3
  149.     statmy%=schight%-statny%-1
  150.     statlen%=statmy%/linehi%
  151.     statmy%=statlen%*linehi% rem make sue we don't have any left over
  152. rem    gsetwin statnx%+2,statny%,statmx%-4,statmy%
  153.     if (onfilt$="On")
  154.         if (ordstat$="Statement")
  155.             tamm$="ChequeBook"
  156.         else
  157.             tamm$="Statement"
  158.         endif
  159.         dottl:("Date","Type","Amount",tamm$,"Mark","",79,statmx%-232,statmx%-160,statmx%-63,statmx%-24,statmx%-10,79) rem s3a
  160. rem s3z        dottl:("Date","Type","Amount",tamm$,"Mrk","",53,statmx%-139,statmx%-95,statmx%-34,statmx%-14,statmx%-9,53)
  161.     else
  162.         dottl:("Date","filter="+filt$,"Amount","","Mark","",79,statmx%-232,statmx%-160,statmx%-63,statmx%-24,statmx%-10,79) rem s3a
  163. rem s3z        dottl:("Date","filter="+filt$,"Amount","","Mrk","",53,statmx%-139,statmx%-95,statmx%-34,statmx%-14,statmx%-9,53)
  164.     endif
  165.     guse dispwin%
  166.     gfont zfontid%(curfont%)
  167.     scrlen%=statlen%
  168. endp
  169.  
  170. proc stmzwin: rem determine size of repeats window
  171.     guse stmwin%
  172.     foninfo:
  173.     statnx%=5 rem s3a
  174. rem s3z    statnx%=0
  175.     statny%=7
  176.     statmx%=scwidth%-11 rem s3a
  177. rem s3z    statmx%=scwidth%
  178.     statmy%=schight%-10
  179.     statlen%=(statmy%-linehi%-4)/linehi%
  180.     statmy%=statlen%*linehi% rem make sue we don't have any left over
  181.     gsetwin statnx%,statny%,statmx%,statmy%+linehi%+6
  182.     dottl:("Statement","Description","Amount","Process","Type","Until",83,185,256,329,386,460,460) rem s3a
  183. rem s3z    dottl:("Statement","Desc","Amount","Process","Type","Until",53,77,112,160,185,232,232)
  184.     guse dispwin%
  185.     gfont zfontid%(curfont%)
  186.     scrlen%=statlen%
  187. endp
  188.  
  189. proc mrkzwin: rem determine size of mark totals window
  190.     guse mrkwin%
  191.     foninfo:
  192.     statnx%=5
  193.     statny%=5
  194.     statmx%=200
  195.     statmy%=schight%-5
  196.     statlen%=(statmy%-linehi%-4)/linehi%
  197.     statmy%=statlen%*linehi% rem make sue we don't have any left over
  198.     gsetwin statnx%,statny%,statmx%,statmy%+linehi%+4
  199.     dottl:("Mark","Total","","","","",60,statmx%-24,statmx%-10,60,60,60,60)
  200.     guse dispwin%
  201.     gfont zfontid%(curfont%)
  202.     scrlen%=statlen%
  203. endp
  204.  
  205. proc sttzwin: rem determine size of statistics window
  206.     guse sttwin%
  207.     foninfo:
  208.     statnx%=5
  209.     statny%=5
  210.     statmx%=300 rem s3a
  211. rem s3z    statmx%=230
  212.     statmy%=schight%-5
  213.     statlen%=(statmy%-linehi%-4)/linehi%
  214.     statmy%=statlen%*linehi% rem make sue we don't have any left over
  215.     gsetwin statnx%,statny%,statmx%,statmy%+linehi%+4
  216.     dottl:("Month","Year","Type","Total","","",50,100,220,290,290,290,290) rem s3a
  217. rem s3z    dottl:("Month","Year","Type","Total","","",40,75,145,222,222,222,222)
  218.     guse dispwin%
  219.     gfont zfontid%(curfont%)
  220.     scrlen%=statlen%
  221. endp
  222.  
  223. proc createb:(file$,dire$) rem create account file
  224.     trap create file$,A,date$,desc$,amm$,state$,order$,sorder$,total$,stotal$,type$,stm$
  225.     if err
  226. rem it could be just no directory
  227.         trap mkdir dire$
  228.         if err rem give up
  229.             showerr:(err)
  230.             stop
  231.         else
  232.             trap create file$,A,date$,desc$,amm$,state$,order$,sorder$,total$,stotal$,type$,stm$
  233.             if err rem give up
  234.                 showerr:(err)
  235.                 stop
  236.             endif
  237.         endif
  238.     endif
  239. endp
  240.  
  241. proc fset:(opt$,file$) rem parse command line args
  242.     local p%(6),x%(6)
  243.     parse$("",file$,x%())
  244.     stem$=mid$(file$,1,x%(5))
  245.     nfile$=stem$+"stm"
  246.     if opt$="C"
  247.         stdstat$="NoFile"
  248.         createb:(file$,mid$(file$,1,x%(4)-1))
  249.         wrcf:(days(day,month,year),"c/f",0.0,"On,2,2,On",0,0,"delta,hiw,visa,chq,dd,bc,dep,trf,amex,bp,text","food,petrol,computer,invest,sport,work,clothes,goodies,general,text"," ","x")
  250.         append
  251.     elseif opt$="O"
  252.         if (exist(nfile$)=-1)
  253.             trap open nfile$,B,sdate$,pdate$,desc$,amm$,type$,rep$,always$,until$
  254.             if err
  255.                 showerr:(err)
  256.                 stop
  257.             endif
  258.             stdstat$="File"
  259.         else
  260.             stdstat$="NoFile"
  261.         endif
  262.         trap open file$,A,date$,desc$,amm$,state$,order$,sorder$,total$,stotal$,type$,stm$
  263.         if err
  264.             showerr:(err)
  265.             stop
  266.         endif
  267.     endif
  268.     filenm$=file$
  269.     setname file$
  270.     use A
  271. endp
  272.  
  273. proc strtscr%: rem start up screen
  274.     local infowin%
  275.     infowin%=gcreate(statnx%+90,statny%+5,250,120,1,1) rem s3a
  276. rem s3z    infowin%=gcreate(statnx%+45,statny%+1,130,60,1)
  277.     gxborder 1,1 rem s3a
  278. rem s3z    gborder 1
  279.     gat 5,40 rem s3a
  280. rem s3z    gat 5,17
  281.     gfont 12 rem s3a
  282. rem s3z    gfont 2
  283.     gstyle 8
  284.     gprintb "SCBank",240,3 rem s3a
  285.     gat 5,60 rem s3a
  286.     gfont 11 rem s3a
  287.     gstyle 0 rem s3a
  288.     gprintb version$,240,3 rem s3a
  289.     gat 5,80 rem s3a
  290.     gprintb "¸ Susan Carter 1994",240,3 rem s3a
  291.     gat 5,110 rem s3a
  292.     gprintb "Sue@squish.demon.co.uk",240,3 rem s3a
  293. rem s3z    gprintb "SCBank",120,3
  294. rem s3z    gat 5,30
  295. rem s3z    gfont 1
  296. rem s3z    gstyle 0
  297. rem s3z    gprintb version$,120,3
  298. rem s3z    gat 5,44
  299. rem s3z    gprintb "¸ Susan Carter 1994",120,3
  300. rem s3z    gat 5,55
  301. rem s3z    gprintb "Sue@squish.demon.co.uk",120,3
  302.     return infowin%
  303. endp
  304.  
  305. proc getnth$:(list$,num%) rem get nth item from list
  306.     local i%,j%,first%,second%
  307.     i%=1:j%=1
  308.     while (j%<>num%)
  309.         while (mid$(list$,i%,1)<>",")and(i%<=len(list$))
  310.             i%=i%+1
  311.         endwh
  312.         if (i%>=len(list$)) rem there wasn't as many items as we thought
  313.             return "NotFound"
  314.         endif
  315.         j%=j%+1
  316.         i%=i%+1
  317.     endwh
  318.     first%=i%
  319.     while ((i%<=len(list$))and(mid$(list$,i%,1)<>","))
  320.         i%=i%+1
  321.     endwh
  322.     second%=i%
  323.     return (mid$(list$,first%,(second%-first%)))
  324. endp
  325.  
  326. proc which%:(list$,item$) rem return position in list
  327.     local i%,j%,first%,second%
  328.     first%=1:second%=1
  329.     i%=1:j%=1
  330.     while (i%<len(list$))
  331.         i%=i%+1
  332.         if ((mid$(list$,i%,1)=",")or(i%=len(list$)))
  333.             if (mid$(list$,first%,i%-first%)=item$)
  334.                 return (j%)
  335.             else
  336.                 j%=j%+1
  337.                 i%=i%+1
  338.                 first%=i%
  339.             endif
  340.         endif
  341.     endwh
  342.     return (-1)
  343. endp
  344.  
  345. proc wrinit:(date&,desc$,amm,state$,order%,sorder%,total,stotal,type$,stm$,rate,default,symbol$) rem assign record fields for account
  346.     local date$(10),amm$(10),order$(8),sorder$(8)
  347.     local temp%,yr%,mo%,dy%
  348.     secstodate ((date&-days(1,1,1970))*60*60*24),yr%,mo%,dy%,temp%,temp%,temp%,temp%
  349.     date$=right$("0"+num$(dy%,2),2)+"/"+right$("0"+num$(mo%,2),2)+"/"+right$(num$(yr%,4),2)
  350.     A.date$=date$
  351.     A.desc$=desc$
  352.     if (rate>0) rem foriegn currancy
  353.         A.amm$="$,"+fix$(amm,2,10)+","+fix$(rate,2,10)+","+fix$(default,2,10)+","+symbol$
  354.     else
  355.         A.amm$=fix$(amm,2,10)
  356.     endif
  357.     A.state$=state$
  358.     A.order$=num$(order%,10)
  359.     A.sorder$=num$(sorder%,10)
  360.     A.total$=fix$(total,2,10)
  361.     A.stotal$=fix$(stotal,2,10)
  362.     A.type$=type$
  363.     A.stm$=stm$
  364. endp
  365.  
  366. proc wrcf:(date&,desc$,amm,state$,order%,sorder%,typel$,stypel$,type$,stm$) rem assign record fields for c/f line
  367.     local date$(10),amm$(10),order$(8),sorder$(8)
  368.     local temp%,yr%,mo%,dy%
  369.     secstodate ((date&-days(1,1,1970))*60*60*24),yr%,mo%,dy%,temp%,temp%,temp%,temp%
  370.     date$=right$("0"+num$(dy%,2),2)+"/"+right$("0"+num$(mo%,2),2)+"/"+right$(num$(yr%,4),2)
  371.     A.date$=date$
  372.     A.desc$=desc$
  373.     A.amm$=fix$(amm,2,10)
  374.     A.state$=state$
  375.     A.order$=num$(order%,10)
  376.     A.sorder$=num$(sorder%,10)
  377.     A.total$=typel$
  378.     A.stotal$=stypel$
  379.     A.type$=type$
  380.     A.stm$=stm$
  381. endp
  382.  
  383. proc wrstm:(ds&,dsday%,dp&,dpday%,desc$,amm,type$,rep$,always$,until&) rem assign record fields for repeats
  384.     local date$(13),amm$(10)
  385.     local temp%,yr%,mo%,dy%
  386.     secstodate ((dp&-days(1,1,1970))*60*60*24),yr%,mo%,dy%,temp%,temp%,temp%,temp%
  387.     date$=right$("0"+num$(dy%,2),2)+"/"+right$("0"+num$(mo%,2),2)+"/"+right$(num$(yr%,4),2)
  388.     if (dpday%>=29) rem potential end of month problem
  389.         date$=date$+"*"+num$(dpday%,2)
  390.     endif
  391.     B.pdate$=date$
  392.     secstodate ((ds&-days(1,1,1970))*60*60*24),yr%,mo%,dy%,temp%,temp%,temp%,temp%
  393.     date$=right$("0"+num$(dy%,2),2)+"/"+right$("0"+num$(mo%,2),2)+"/"+right$(num$(yr%,4),2)
  394.     if (dsday%>=29) rem potential end of month problem
  395.         date$=date$+"*"+num$(dsday%,2)
  396.     endif
  397.     B.sdate$=date$
  398.     B.desc$=desc$
  399.     B.amm$=fix$(amm,2,10)
  400.     B.type$=type$
  401.     B.rep$=rep$
  402.     B.always$=always$
  403.     secstodate ((until&-days(1,1,1970))*60*60*24),yr%,mo%,dy%,temp%,temp%,temp%,temp%
  404.     date$=right$("0"+num$(dy%,2),2)+"/"+right$("0"+num$(mo%,2),2)+"/"+right$(num$(yr%,4),2)
  405.     B.until$=date$
  406. endp
  407.  
  408. proc shutd: rem shut everything down
  409.     if (mrkstat$="Off")
  410.         markj:
  411.     elseif (stmstat$="Off")
  412.         stmt:
  413.     elseif (sttstat$="Off")
  414.         stth:
  415.     endif
  416.     gclose statwin%
  417.     if (stdstat$<>"NoFile")
  418.         use B
  419.         trap close
  420.         if err
  421.             showerr:(err)
  422.         endif
  423.     endif
  424.     use A
  425.     trap close
  426.     if err
  427.         showerr:(err)
  428.     endif
  429.     freealloc chqidx% rem s3a
  430.     freealloc stmidx% rem s3a
  431. rem s3z    call($0381,0,chqidx%)
  432. rem s3z    call($0381,0,stmidx%)
  433. endp
  434.  
  435. proc mainloop: rem main control loop
  436.     local k%,mod%,h$(30),hu$(30),a$(6),a%(6),t$(1),file$(128),pname$(6),zaptmp%,line%
  437.     filepos%=count-1
  438.     lastpos%=filepos%
  439.     if (count<scrlen%)
  440.         scrpos%=count
  441.     else
  442.         scrpos%=scrlen%
  443.     endif
  444.     while 1
  445.         gat 2,(scrpos%-1)*linehi%+linea%+linehi%+3
  446. rem s3z        if moving$="Off"
  447.         gprint ""
  448. rem s3z        else
  449. rem s3z            gprint chr$($0a)
  450. rem s3z        endif
  451.         ggrey 1 rem s3a
  452.         if moving$="Off" rem s3a
  453.             gat 2,(scrpos%-1)*linehi%+1+linehi%+3 rem s3a
  454.             gfill scwidth%,linehi%-1,2 rem s3a
  455.         else rem s3a
  456.             gat 2,(scrpos%)*linehi%+linehi%+3 rem s3a
  457.             gtmode 2 rem s3a
  458.             gprint rept$(chr$($0d),255) rem s3a
  459.         endif rem s3a
  460.         ggrey 0 rem s3a
  461.         getevent a%()
  462.         gat 2,(scrpos%-1)*linehi%+linea%+linehi%+3
  463. rem s3z        if moving$="Off"
  464.         gprintb " ",gtwidth("")-1
  465. rem s3z        else
  466. rem s3z            gprintb "",gtwidth(chr$($0a))-1
  467. rem s3z        endif
  468.         ggrey 1 rem s3a
  469.         if moving$="Off" rem s3a
  470.             gat 2,(scrpos%-1)*linehi%+1+linehi%+3 rem s3a
  471.             gfill scwidth%,linehi%-1,2 rem s3a
  472.         else rem s3a
  473.             gat 2,(scrpos%)*linehi%+linehi%+3 rem s3a
  474.             gtmode 2 rem s3a
  475.             gprint rept$(chr$($0d),255) rem s3a
  476.         endif rem s3a
  477.         ggrey 0 rem s3a
  478.         if ((a%(1) and $400)<>0) rem not keypress
  479.             if a%(1)=$404 rem system action
  480.                 file$=getcmd$
  481.                 t$=left$(file$,1)
  482.                 file$=mid$(file$,2,128)
  483.                 if t$="X"
  484.                     bankx:
  485.                 elseif t$="C" or t$="O"
  486.                     shutd:
  487.                     fset:(t$,file$)
  488.                     startup:
  489.                 endif
  490.             endif
  491.         else rem a keypress sc should optimise this
  492.             k%=a%(1)
  493.             mod%=a%(2) and $00ff
  494.             if (mrkstat$="Off")
  495.                 h$="cijnoxz" REM Hot keys
  496.                 hu$="Z" rem upper case hot keys rem s3a
  497.                 pname$="mark"
  498.             elseif (sttstat$="Off")
  499.                 h$="aihnorxz" REM Hot keys
  500.                 hu$="Z" rem upper case hot keys rem s3a
  501.                 pname$="stt"
  502.             elseif (stmstat$="Off")
  503.                 h$="adeinoptwxz" REM Hot keys
  504.                 hu$="Z" rem upper case hot keys rem s3a
  505.                 pname$="stm"
  506.             elseif (moving$="On")
  507.                 h$="ainoxvz" REM Hot keys
  508.                 hu$="Z" rem upper case hot keys rem s3a
  509.                 pname$="move"
  510.             elseif (onfilt$="Off")
  511.                 h$="cdeinomxz*-" REM Hot keys
  512.                 hu$="OCZ" rem upper case hot keys rem s3a
  513. rem s3z                hu$=""
  514. rem should be able to use the standard bank procedures in filter mode
  515.                 pname$="bank"
  516.             elseif (stmstat$="On")
  517.                 h$="acdefghijklmnopqrstvuwxyz" REM Hot keys rem s3a
  518. rem s3z                h$="acdefghijklmnopqrstvuwxyz*-" REM Hot keys
  519.                 hu$="OCZ" rem upper case hot keys rem s3a
  520. rem s3z                hu$=""
  521.                 pname$="bank"
  522.             endif
  523.             if k%=$122 rem menu key
  524. rem only on main screen
  525.                 if ((mod%=4)and(mrkstat$="On")and(stmstat$="On")and(sttstat$="On"))
  526.                     if (swintp%=0) rem s3a
  527.                         swintp%=2 rem s3a
  528.                         statuswin on, swintp% rem s3a
  529.                     elseif (swintp%=1) rem s3a
  530.                         swintp%=0 rem s3a
  531.                         statuswin off rem s3a
  532.                     else rem s3a
  533.                         swintp%=1 rem s3a
  534.                         statuswin on, swintp% rem s3a
  535.                     endif rem s3a
  536.                     sizewin:
  537.                     display:(filepos%,scrpos%)
  538.                 else
  539.                     minit
  540.                     if (mrkstat$="Off")
  541.                         mcard "File","New File...",%n,"Open File...",%o
  542.                         mcard "Edit","Check",%c rem s3a
  543. rem s3z                        mcard "Edit","Check",%c
  544.                         mcard "View","Info...",%i,"Mark totals "+mrkstat$+"...",%j
  545.                         mcard "Special","Exit",-%x,"Zoom in",%z,"Zoom out",%Z rem s3a
  546. rem s3z                        mcard "Special","Exit",%x,"Zoom Font",%z
  547.                     elseif (sttstat$="Off")
  548.                         mcard "File","New File...",%n,"Open File...",-%o,"Order",%r,"Save stats as...",%a rem s3a
  549. rem s3z                        mcard "File","New File...",%n,"Open File...",%o,"Order",%r,"Save stats as...",%a
  550.                         mcard "View","Info...",%i,"Statistics "+sttstat$+"...",%h
  551.                         mcard "Special","Exit",-%x,"Zoom in",%z,"Zoom out",%Z rem s3a
  552. rem s3z                        mcard "Special","Exit",%x,"Zoom Font",%z
  553.                     elseif (stmstat$="Off")
  554.                         mcard "File","New File...",%n,"Open File...",-%o,"Process repeats",%p rem s3a
  555. rem s3z                        mcard "File","New File...",%n,"Open File...",%o,"Process repeats",%p
  556.                         mcard "Edit","Add...",%a,"Edit...",%e,"Delete",%d
  557.                         mcard "View","Spend Type "+why$,%w,"Info...",%i,"Repeats "+stmstat$+"...",%t
  558.                         mcard "Special","Exit",-%x,"Zoom in",%z,"Zoom out",%Z rem s3a
  559. rem s3z                        mcard "Special","Exit",%x,"Zoom Font",%z
  560.                     elseif (moving$="On")
  561.                         mcard "File","New File...",%n,"Open File...",%o
  562.                         mcard "Edit","Place",%a,"Quit Moving",%v
  563.                         mcard "View","Info...",%i
  564.                         mcard "Special","Exit",-%x,"Zoom in",%z,"Zoom out",%Z rem s3a
  565. rem s3z                        mcard "Special","Exit",%x,"Zoom Font",%z
  566.                     elseif (onfilt$="Off")
  567.                         mcard "File","New File...",%n,"Open File...",%o
  568.                         mcard "Edit","Edit...",%e,"Delete",-%d,"Check",%c,"Check Off",-%C,"Mark...",%m rem s3a
  569. rem s3z                        mcard "Edit","Edit...",%e,"Delete",%d,"Check",%c,"Check Off",%-,"Mark...",%m
  570.                         mcard "Search","Filter "+onfilt$+"...",%O rem s3a
  571. rem s3z                        mcard "Search","Filter "+onfilt$+"...",%*
  572.                         mcard "View","Info...",%i
  573.                         mcard "Special","Exit",-%x,"Zoom in",%z,"Zoom out",%Z rem s3a
  574. rem s3z                        mcard "Special","Exit",%x,"Zoom Font",%z
  575.                     elseif (stmstat$="On")
  576.                         mcard "File","New File...",%n,"Open File...",-%o,"Compress",%s,"Archive...",%k,"Merge...",%y,"Recalc",-%l,"Process repeats",%p,"Statistics "+sttstat$,%h rem s3a
  577. rem s3z                        mcard "File","New File...",%n,"Open File...",%o,"Compress",%s,"Archive...",%k,"Merge...",%y,"Recalc",%l
  578. rem s3z                        mcard "2","Process repeats",%p,"Statistics "+sttstat$,%h,ordstat$+" view",%r
  579.                         mcard "Edit","Add...",%a,"Edit...",%e,"Delete",%d,"Transfer...",-%u,"Check",%c,"Check Off",-%C,"Mark...",%m,"Move...",%v rem s3a
  580. rem s3z                        mcard "Edit","Add...",%a,"Edit...",%e,"Delete",%d,"Transfer...",%u,"Check",%c,"Check Off",%-
  581. rem s3z                        mcard "2","Mark...",%m,"Move...",%v
  582.                         mcard "Search","Find...",%f,"Find again",%g,"Filter "+onfilt$+"...",%O rem s3a
  583. rem s3z                        mcard "Search","Find...",%f,"Find again",%g,"Filter "+onfilt$+"...",%*
  584.                         mcard "View","Spend Type "+why$,%w,"Info...",%i,"Repeats "+stmstat$+"...",%t,"Mark totals "+mrkstat$+"...",%j
  585.                         mcard "Special","Set preferences...",-%q,"Exit",-%x,"Zoom in",%z,"Zoom out",%Z rem s3a
  586. rem s3z                        mcard "Special","Set preferences...",%q,"Exit",%x,"Zoom Font",%z
  587.                         mcard chr$(4),ordstat$+" view",%r rem s3a
  588.                     endif
  589.                     lock on
  590.                     k%=menu
  591.                     lock off
  592.                     if ((k%>=%A)and(k%<=%Z)) rem s3a
  593.                         if loc(hu$,chr$(k%))
  594.                             a$=pname$+"u"+chr$(k%)
  595.                             @(a$):
  596.                         endif
  597.                     else rem s3a
  598.                         if k% and (loc(h$,chr$(k%))<>0)
  599.                             if (k%=%*)
  600.                                 a$=pname$+"st"
  601.                             elseif (k%=%-)
  602.                                 a$=pname$+"sr"
  603.                             else
  604.                                 a$=pname$+chr$(k%)
  605.                             endif
  606.                             @(a$):
  607.                         endif
  608.                     endif rem s3a
  609.                 endif
  610.             elseif k% and $200 rem hot key
  611.                 k%=k%-$200
  612.                 if ((mod% and 2)=2) rem s3a
  613.                     if loc(hu$,chr$(k%))
  614.                         a$=pname$+"u"+chr$(k%)
  615.                         @(a$):
  616.                     endif
  617.                 else rem s3a
  618.                     if loc(h$,chr$(k%))
  619.                         if (k%=%*)
  620.                             a$=pname$+"st"
  621.                         elseif (k%=%-)
  622.                             a$=pname$+"sr"
  623.                         else
  624.                             a$=pname$+chr$(k%)
  625.                         endif
  626.                         @(a$):
  627.                     endif
  628.                 endif rem s3a
  629.             elseif (k%=13) rem enter does add
  630.                 if (loc(h$,chr$(%a))) rem only do it if a valid command for this mode
  631.                     @(pname$+"a"):
  632.                 endif
  633.             elseif (k%=8) rem delete key
  634.                 if (loc(h$,chr$(%d))) rem only do it if a valid command for this mode
  635.                     @(pname$+"d"):
  636.                 endif
  637.             elseif ((k%=260)and((mod% and 4)=4))
  638.                 currkey:(262) rem same as home
  639.             elseif ((k%=261)and((mod% and 4)=4))
  640.                 currkey:(263) rem same as home
  641. rem spacebar
  642.             elseif ((k%=32)and(mrkstat$="On")and(stmstat$="On")and(sttstat$="On"))
  643.                 lastpos%=filepos%
  644.                 zaptmp%=zapto%
  645.                 zapto%=filepos%
  646.                 line%=scrlen%/2
  647.                 display:(zaptmp%,line%)
  648. rem diamond key
  649.             elseif ((k%=292)and(mrkstat$="On")and(stmstat$="On")and(sttstat$="On")and(onfilt$="On")) rem s3a
  650.                 bankr: rem s3a
  651. rem help key
  652.             elseif (k%=291)
  653.                 trap loadm ssdfind$:("\opo\sys$sch.opo")
  654.                 if err
  655.                     giprint "Help module not found"
  656.                 else
  657.                     if (schelp%:(ssdfind$:("\opd\scbank.hlp"))=-1)
  658.                         giprint "Help not available"
  659.                     endif
  660.                     unloadm ssdfind$:("\opo\sys$sch.opo")
  661.                     guse dispwin%
  662.                 endif
  663.             else
  664. rem process any cursor key
  665.                 currkey:(k%)
  666.             endif
  667.         endif
  668.     endwh
  669. rem never get here!
  670. endp
  671.  
  672. proc ssdfind$:(file$) rem find file on ssd devices
  673.     local lfile$(128),ssd$(4),i%
  674.     ssd$="mabc"
  675.     i%=1
  676.     while (i%<=4)
  677.         lfile$=mid$(ssd$,i%,1)+":"+file$
  678.         if exist(lfile$)
  679.             return lfile$
  680.         endif
  681.         i%=i%+1
  682.     endwh
  683.     return file$ rem just in case
  684. endp
  685.  
  686. proc currkey:(k%) rem do a cursor movement
  687.     local moved%
  688.     if (k%=262) rem home
  689.         lastpos%=filepos%
  690.         filepos%=0
  691.         posfp%:(0,1)
  692.         display:(filepos%,1)
  693.     elseif (k%=263) rem end
  694.         lastpos%=filepos%
  695.         filepos%=count
  696.         posfp%:(0,-1)
  697.         display:(filepos%,scrlen%)
  698.     elseif ((k%=257)and(filepos%<count-1)) rem down arrow
  699. rem alert(num$(filepos%,10),num$(count,10))
  700.         if (posfp%:(1,1))
  701.             if (scrpos%=scrlen%)
  702.                 doscr%=1
  703.                 display:(filepos%,scrlen%)
  704.             else
  705.                 scrpos%=scrpos%+1
  706.             endif
  707.         endif
  708.     elseif ((k%=261)and(filepos%<count-1)) rem page down
  709.         if (scrpos%=scrlen%)
  710.             if (posfp%:(scrlen%-1,1)<>0)
  711.                 display:(filepos%,scrlen%)
  712.             endif
  713.         else
  714.             moved%=posfp%:(-scrpos%+scrlen%,1)
  715. rem alert(num$(filepos%,10)+"*"+num$(moved%,10),num$(count,10))
  716.             scrpos%=scrpos%+moved%
  717.         endif
  718.     elseif ((k%=256)and(filepos%>0)) rem up arrow
  719.         if (posfp%:(1,-1)<>0)
  720.             if (scrpos%=1)
  721.                 doscr%=1
  722.                 display:(filepos%,1)
  723.             else
  724.                 scrpos%=scrpos%-1
  725.             endif
  726.         endif
  727.     elseif ((k%=260)and(filepos%>0)) rem page up
  728.         if (scrpos%=1)
  729.             if (posfp%:(scrlen%-1,-1)<>0)
  730.                 display:(filepos%,1)
  731.             endif
  732.         else
  733.             if (posfp%:(scrpos%-1,-1)<>0)
  734.                 scrpos%=1
  735.             endif
  736.         endif
  737.     endif
  738. endp
  739.  
  740. proc showerr:(val%)
  741.     alert ("Error "+err$(val%))
  742.     busy off
  743. endp
  744.  
  745. proc bankj: rem mark totals
  746.     local mrknx%,mrkmx%,mrkny%,mrkmy%,mrklen%,line&,val%,win%
  747.     tmpfile$=stem$+"mrk"
  748.     if (exist(tmpfile$)=-1)
  749.         delete tmpfile$
  750.     endif
  751.     trap create tmpfile$,C,mark$,amm$,stm$
  752.     if err
  753.         showerr:(err)
  754.         return
  755.     endif
  756.     use A
  757.     first
  758.     win%=createg%:("Mark Totals...")
  759.     while not eof
  760. rem only bother with transactions that have marks and not the c/f line
  761.         if ((A.state$<>" ")and(A.order$<>"0"))
  762.             use C
  763.             first
  764.             while not eof
  765.                 if (A.state$=C.mark$)
  766.                     C.amm$=fix$((getamm:(A.amm$)+val(C.amm$)),2,10)
  767.                     if (A.stm$<>C.stm$)
  768.                         C.stm$="?"
  769.                     endif
  770.                     update
  771.                     break
  772.                 endif
  773.                 next
  774.             endwh
  775.             if eof
  776.                 C.mark$=A.state$
  777.                 C.amm$=fix$(getamm:(A.amm$),2,10)
  778.                 C.stm$=A.stm$
  779.                 append
  780.             endif
  781.             use A
  782.         endif
  783.         next
  784.         line&=pos
  785.         val%=line&*100/count
  786.         dispg:(win%,val%)
  787.     endwh
  788.     delg:(win%)
  789.     mrkstat$="Off"
  790.     mrknx%=10 rem s3a
  791.     mrkny%=10 rem s3a
  792.     mrkmx%=scwidth%-300 rem s3a
  793.     mrkmy%=schight%-30 rem s3a
  794.     mrkwin%=gcreate(mrknx%+2,mrkny%+linehi%+3,mrkmx%-4,mrkmy%-linehi%-4,1,1) rem s3a
  795. rem s3z    mrknx%=10
  796. rem s3z    mrkny%=10
  797. rem s3z    mrkmx%=210
  798. rem s3z    mrkmy%=schight%-30
  799. rem s3z    mrkwin%=gcreate(mrknx%+2,mrkny%+linehi%+3,mrkmx%-4,mrkmy%-linehi%-4,1)
  800.     dispwin%=mrkwin%
  801.     mrkzwin:
  802.     scrpos%=1
  803.     filepos%=0
  804.     lastpos%=filepos%
  805.     use C
  806.     reorder:("Mark")
  807.     use C
  808.     display:(filepos%,scrpos%)
  809. endp
  810.  
  811. proc bankh: rem statistics
  812.     local d&,yr%,mo%,junk%,c1%,c2%,c3%,c4%,win%,line&,val%
  813.     dinit "Statistics by"
  814.     dchoice c1%,"Month","Yes,No"
  815.     dchoice c2%,"Year","Yes,No"
  816.     dchoice c3%,"Spend Type","Yes,No"
  817.     dchoice c4%,"Order Output","Yes,No"
  818.     if dialog
  819.         tmpfile$=stem$+"stt"
  820.         if (exist(tmpfile$)=-1)
  821.             delete tmpfile$
  822.         endif
  823.         trap create tmpfile$,C,type$,mon$,yr$,amm$
  824.         if err
  825.             showerr:(err)
  826.             return
  827.         endif
  828.         use A
  829.         first
  830.         win%=createg%:("Statistics...")
  831.         while not eof
  832. rem not the c/f line
  833.             if (A.order$<>"0")
  834.                 d&=strtod&:(A.date$,"/")
  835.                 secstodate ((d&-days(1,1,1970))*60*60*24),yr%,mo%,junk%,junk%,junk%,junk%,junk%
  836.                 use C
  837.                 first
  838.                 while not eof
  839.                     if ((A.type$=C.type$)or(c3%=2))
  840.                         if ((yr%=val(C.yr$))or(c2%=2))
  841.                             if ((mo%=val(C.mon$))or(c1%=2))
  842.                                 C.amm$=fix$((getamm:(a.amm$)+val(C.amm$)),2,10)
  843.                                 update
  844.                                 break
  845.                             endif
  846.                         endif
  847.                     endif
  848.                     next
  849.                 endwh
  850.                 if eof
  851.                     if (c1%=1)
  852.                         C.mon$=num$(mo%,10)
  853.                     else
  854.                         C.mon$="0"
  855.                     endif
  856.                     if (c2%=1)
  857.                         C.yr$=num$(yr%,10)
  858.                     else
  859.                         C.yr$="0"
  860.                     endif
  861.                     if (c3%=1)
  862.                         C.type$=A.type$
  863.                     endif
  864.                     C.amm$=fix$(getamm:(A.amm$),2,10)
  865.                     append
  866.                 endif
  867.                 use A
  868.             endif
  869.             next
  870.             line&=pos
  871.             val%=line&*100/count
  872.             dispg:(win%,val%)
  873.         endwh
  874.         delg:(win%)
  875.         sttstat$="Off"
  876.         use C
  877.         if (c4%=1) rem want to order file
  878.             reorder:("Stats")
  879.         endif
  880.         use A
  881. rem s3z        sttwin%=gcreate(0,3,4,4,1)
  882.         sttwin%=gcreate(0,3,4,4,1,1) rem s3a
  883.         dispwin%=sttwin%
  884.         sttzwin:
  885.         scrpos%=1
  886.         filepos%=0
  887.         lastpos%=filepos%
  888.         use C
  889.         display:(filepos%,scrpos%)
  890.     endif
  891. endp
  892.  
  893. proc bankz: rem font resize up
  894.     curfont%=curfont%+1
  895.     if (curfont%>zfonts%)
  896.         curfont%=1
  897.     endif
  898. rem if displaying repeats window
  899.     if (stmstat$="Off")
  900.         stmzwin:
  901.     elseif (mrkstat$="Off")
  902.         mrkzwin:
  903.     elseif (sttstat$="Off")
  904.         sttzwin:
  905.     else
  906.         sizewin:
  907.     endif
  908.     display:(filepos%,scrpos%)
  909. endp
  910.  
  911. proc bankuz: rem font resize down
  912.     curfont%=curfont%-1
  913.     if (curfont%<1)
  914.         curfont%=zfonts%
  915.     endif
  916. rem if displaying repeats window
  917.     if (stmstat$="Off")
  918.         stmzwin:
  919.     elseif (mrkstat$="Off")
  920.         mrkzwin:
  921.     elseif (sttstat$="Off")
  922.         sttzwin:
  923.     else
  924.         sizewin:
  925.     endif
  926.     display:(filepos%,scrpos%)
  927. endp
  928.  
  929. proc bankv: rem move transaction
  930.     position rptr%:(curidx%,filepos%)
  931.     if (A.order$="0")
  932.         alert ("You can't move the c/f line!")
  933.         return
  934.     endif
  935.     if ((ordstat$="ChequeBook") and (val(A.sorder$)=-1))
  936.         alert("Doesn't make sense to move transactions","not on statement in statement mode")
  937.         return
  938.     endif
  939.     if ((clpstat$="Off")and(ordstat$="ChequeBook")and(onfilt$="On")and(A.state$<>" ")and(A.order$<>"0")and(A.stm$="x"))
  940.         alert("Can't move a collapsed Mark Total","Turn off Mark Totals")
  941.         return
  942.     endif
  943.     moving$="On"
  944.     oldpos%=filepos%
  945.     lastpos%=filepos%
  946.     display:(filepos%,scrpos%)
  947. endp
  948.  
  949. proc bankk: rem archive to file
  950.     local delto%,arctotal,d&,date$(20),file$(128)
  951.     local handle%,ret%,mode%,txt$(255),address%
  952.     local c1%,c2%,c3%,delim&,i%,j%,line&,val%,win%
  953.     position rptr%:(curidx%,filepos%)
  954.     if (A.stm$<>"x")
  955.         alert ("Only archive transactions on statement")
  956.         return
  957.     endif
  958.     if (A.order$="0")
  959.         alert ("You want to archive more than just the c/f line!")
  960.         return
  961.     endif
  962.     delim&=asc(",")
  963.     file$="\Bank\Archive.bnk"
  964.     dinit "Archive to"
  965.     dfile file$,"",3
  966.     dchoice c1%,"Archive as","Bank,Text"
  967.     dchoice c3%,"Delimiter","Tab,Comma,Semicolon,Other"
  968.     dlong delim&,"Delimiter code",0,255
  969.     dchoice c2%,"Archive","Copy to file and delete entries,Copy to file,Delete entries"
  970.     if dialog
  971.         if ((c2%=1)or(c2%=2)) rem Copy to file requested
  972.             if (c1%=1) rem Archive in native bank format
  973.                 trap create file$,D,date$,desc$,amm$,state$,order$,sorder$,total$,stotal$,type$,stm$
  974.                 if err
  975.                     showerr:(err)
  976.                     return
  977.                 endif
  978.                 use A
  979.             elseif (c1%=2) rem Archive in text format using delimiter
  980.                 if (c3%<>4) rem special delimiter
  981.                     if (c3%=1)
  982.                         delim&=asc("    ")
  983.                     endif
  984.                     if (c3%=2)
  985.                         delim&=asc(",")
  986.                     endif
  987.                     if (c3%=3)
  988.                         delim&=asc(";")
  989.                     endif
  990.                 endif
  991.                 mode%=$0100 or $0020 or $0001
  992.                 ret%=ioopen(handle%,file$,mode%)
  993.                 if ret%<0
  994.                     showerr:(ret%)
  995.                     return
  996.                 endif
  997.                 address%=addr(txt$)
  998.             endif
  999.         endif
  1000.         win%=createg%:("Archiving...")
  1001.         position rptr%:(curidx%,filepos%)
  1002.         arctotal=0
  1003.         delto%=val(A.sorder$)
  1004.         date$=A.date$
  1005.         i%=0
  1006.         while (i%<=delto%)
  1007.             position rptr%:(stmidx%,i%)
  1008.             arctotal=arctotal+getamm:(a.amm$)
  1009.             if ((c2%=1)or(c2%=2)) rem Copy to file requested
  1010.                 if (c1%=1) rem Archive in native bank format
  1011.                     D.date$=A.date$
  1012.                     D.desc$=A.desc$
  1013.                     D.amm$=A.amm$
  1014.                     D.state$=A.state$
  1015.                     D.order$=A.order$
  1016.                     D.sorder$=A.sorder$
  1017.                     D.total$=A.total$
  1018.                     D.stotal$=A.stotal$
  1019.                     D.type$=A.type$
  1020.                     D.stm$=A.stm$
  1021.                     use D
  1022.                     append
  1023.                     use A
  1024.                 elseif (c1%=2) rem Archive in text format using delimiter
  1025.                     if (i%=0) rem c/f line
  1026.                         txt$=A.date$+chr$(delim&)+A.desc$+chr$(delim&)+fix$(getamm:(A.amm$),2,10)+chr$(delim&)+fix$(getamm:(A.amm$),2,10)+chr$(delim&)+fix$(getamm:(A.amm$),2,10)+chr$(delim&)+A.order$+chr$(delim&)+A.sorder$+chr$(delim&)+" "+chr$(delim&)+A.type$
  1027.                         txt$=txt$+chr$(delim&)+A.stm$
  1028.                     else
  1029.                         txt$=A.date$+chr$(delim&)+A.desc$+chr$(delim&)+fix$(getamm:(A.amm$),2,10)+chr$(delim&)+A.total$+chr$(delim&)+A.stotal$+chr$(delim&)+A.order$+chr$(delim&)+A.sorder$+chr$(delim&)+A.state$+chr$(delim&)+A.type$+chr$(delim&)+A.stm$
  1030.                     endif
  1031.                     ret%=iowrite(handle%,address%+1,len(txt$))
  1032.                     if ret%<0
  1033.                         showerr:(ret%)
  1034.                         return
  1035.                     endif
  1036.                 endif
  1037.             endif
  1038.             i%=i%+1
  1039.             line&=i%
  1040.             val%=line&*100/delto%/2 rem the first half
  1041.             if (c2%=2)
  1042.                 val%=val%*2
  1043.             endif
  1044.             dispg:(win%,val%)
  1045.         endwh
  1046.         if ((c2%=1)or(c2%=2)) rem Copy to file requested
  1047.             if (c1%=1) rem Archive in native bank format
  1048.                 use D
  1049.                 close
  1050.                 use A
  1051.             elseif (c1%=2) rem Archive in text format using delimiter
  1052.                 ret%=ioclose(handle%)
  1053.                 if ret%
  1054.                     showerr:(ret%)
  1055.                 endif
  1056.             endif
  1057.             giprint "Archive file written"
  1058.         endif
  1059.         if ((c2%=1)or(c2%=3)) rem delete archived entries
  1060. rem go to the c/f line and write new value
  1061.             i%=0
  1062.             j%=count
  1063.             first
  1064.             while (i%<j%)
  1065.                 if (val(A.sorder$)=0) rem the c/f line
  1066.                     d&=strtod&:(date$,"/")
  1067.                     wrcf:(d&,"c/f",arctotal,A.state$,0,0,typel$,stypel$," ","x")
  1068.                     update
  1069.                 elseif ((val(A.sorder$)<=delto%)and(A.stm$="x")) rem to be archived
  1070.                     erase
  1071.                 else
  1072.                     update
  1073.                 endif
  1074.                 i%=i%+1
  1075.                 line&=i%
  1076.                 val%=line&*100/j%/2+50 rem the second half
  1077.                 dispg:(win%,val%)
  1078.                 first
  1079.             endwh
  1080.             freealloc chqidx% rem s3a
  1081.             freealloc stmidx% rem s3a
  1082.             chqidx%=alloc(count*2) rem s3a
  1083.             stmidx%=alloc(count*2) rem s3a
  1084. rem s3z            call($0381,0,chqidx%)
  1085. rem s3z            call($0381,0,stmidx%)
  1086. rem s3z            chqidx%=call($0081,0,count*2)
  1087. rem s3z            stmidx%=call($0081,0,count*2)
  1088.             if ((chqidx%=0)or(stmidx%=0))
  1089.                 alert ("Not enough memory to allocate index","Account file preserved")
  1090.                 stop
  1091.             endif
  1092.             altcurp:
  1093.             calc:
  1094.             sizewin:
  1095.             display:(0,1)
  1096.         endif
  1097.         delg:(win%)
  1098.     endif
  1099. endp
  1100.  
  1101. proc bankn: rem new file option
  1102.     local file$(128),off%(6)
  1103.     file$="\bank\"
  1104.     dinit "Create new file"
  1105.     dfile file$,"",1+16+64
  1106.     if dialog
  1107.         shutd:
  1108.         file$=parse$(file$,"\bank\*.bnk",off%())
  1109.         fset:("C",file$)
  1110.         startup:
  1111.     endif
  1112. endp
  1113.  
  1114. proc banko: rem open file option
  1115.     local file$(128)
  1116.     file$="\bank\*.bnk"
  1117.     dinit "Open file"
  1118.     dfile file$,"",64
  1119.     if dialog
  1120.         shutd:
  1121.         fset:("O",file$)
  1122.         startup:
  1123.     endif
  1124. endp
  1125.  
  1126. proc bankp: rem process repeats
  1127.     local dp&,ds&,du&,today&,amm,date$(20)
  1128.     local dsday%,dpday%
  1129.     local yr%,mo%,dy%,temp%
  1130.     local i%,changed%,deleted%,many%
  1131.     if (stdstat$<>"NoFile")
  1132.         busy "Repeats ..."
  1133.         use B
  1134.         many%=0
  1135.         today&=days(day,month,year)
  1136.         do
  1137.             changed%=0
  1138.             i%=1
  1139.             while (i%<=count)
  1140.                 first
  1141.                 deleted%=0
  1142.                 dp&=strtod&:(B.pdate$,"/")
  1143.                 if (dp&<=today&)
  1144.                     ds&=strtod&:(B.sdate$,"/")
  1145.                     du&=strtod&:(B.until$,"/")
  1146.                     amm=val(B.amm$)
  1147.                     total=total+amm
  1148.                     use A
  1149.                     wrinit:(ds&,B.desc$,amm," ",count,-1,total,0.0,B.type$," ",-1.0,-1.0,"")
  1150.                     append
  1151.                     addptr:
  1152.                     many%=many%+1
  1153.                     if (B.rep$="Monthly")
  1154.                         secstodate ((ds&-days(1,1,1970))*60*60*24),yr%,mo%,dy%,temp%,temp%,temp%,temp%
  1155.                         if mo%=12
  1156.                             mo%=1
  1157.                             yr%=yr%+1
  1158.                         else
  1159.                             mo%=mo%+1
  1160.                         endif
  1161.                         if (mid$(B.sdate$,9,1)="*") rem end of month condition
  1162.                             dy%=val(right$(B.sdate$,2))
  1163.                         endif
  1164.                         dsday%=dy%
  1165.                         ds&=((scdtos&:(yr%,mo%,dy%))/24/60/60)+days(1,1,1970)
  1166.                         secstodate ((dp&-days(1,1,1970))*60*60*24),yr%,mo%,dy%,temp%,temp%,temp%,temp%
  1167.                         if mo%=12
  1168.                             mo%=1
  1169.                             yr%=yr%+1
  1170.                         else
  1171.                             mo%=mo%+1
  1172.                         endif
  1173.                         if (mid$(B.pdate$,9,1)="*") rem end of month condition
  1174.                             dy%=val(right$(B.pdate$,2))
  1175.                         endif
  1176.                         dpday%=dy%
  1177.                         dp&=((scdtos&:(yr%,mo%,dy%))/24/60/60)+days(1,1,1970)
  1178.                     elseif (B.rep$="Quarterly")
  1179.                         secstodate ((ds&-days(1,1,1970))*60*60*24),yr%,mo%,dy%,temp%,temp%,temp%,temp%
  1180.                         mo%=mo%+3
  1181.                         if (mo%>12)
  1182.                             mo%=mo%-12
  1183.                             yr%=yr%+1
  1184.                         endif
  1185.                         if (mid$(B.sdate$,9,1)="*") rem end of month condition
  1186.                             dy%=val(right$(B.sdate$,2))
  1187.                         endif
  1188.                         dsday%=dy%
  1189.                         ds&=((scdtos&:(yr%,mo%,dy%))/24/60/60)+days(1,1,1970)
  1190.                         secstodate ((dp&-days(1,1,1970))*60*60*24),yr%,mo%,dy%,temp%,temp%,temp%,temp%
  1191.                         mo%=mo%+3
  1192.                         if (mo%>12)
  1193.                             mo%=mo%-12
  1194.                             yr%=yr%+1
  1195.                         endif
  1196.                         if (mid$(B.pdate$,9,1)="*") rem end of month condition
  1197.                             dy%=val(right$(B.pdate$,2))
  1198.                         endif
  1199.                         dpday%=dy%
  1200.                         dp&=((scdtos&:(yr%,mo%,dy%))/24/60/60)+days(1,1,1970)
  1201.                     elseif (B.rep$="6Monthly")
  1202.                         secstodate ((ds&-days(1,1,1970))*60*60*24),yr%,mo%,dy%,temp%,temp%,temp%,temp%
  1203.                         mo%=mo%+6
  1204.                         if (mo%>12)
  1205.                             mo%=mo%-12
  1206.                             yr%=yr%+1
  1207.                         endif
  1208.                         if (mid$(B.sdate$,9,1)="*") rem end of month condition
  1209.                             dy%=val(right$(B.sdate$,2))
  1210.                         endif
  1211.                         dsday%=dy%
  1212.                         ds&=((scdtos&:(yr%,mo%,dy%))/24/60/60)+days(1,1,1970)
  1213.                         secstodate ((dp&-days(1,1,1970))*60*60*24),yr%,mo%,dy%,temp%,temp%,temp%,temp%
  1214.                         mo%=mo%+6
  1215.                         if (mo%>12)
  1216.                             mo%=mo%-12
  1217.                             yr%=yr%+1
  1218.                         endif
  1219.                         if (mid$(B.pdate$,9,1)="*") rem end of month condition
  1220.                             dy%=val(right$(B.pdate$,2))
  1221.                         endif
  1222.                         dpday%=dy%
  1223.                         dp&=((scdtos&:(yr%,mo%,dy%))/24/60/60)+days(1,1,1970)
  1224.                     elseif (B.rep$="Yearly")
  1225.                         secstodate ((ds&-days(1,1,1970))*60*60*24),yr%,mo%,dy%,temp%,temp%,temp%,temp%
  1226.                         yr%=yr%+1
  1227.                         dsday%=dy%
  1228.                         ds&=((scdtos&:(yr%,mo%,dy%))/24/60/60)+days(1,1,1970)
  1229.                         secstodate ((dp&-days(1,1,1970))*60*60*24),yr%,mo%,dy%,temp%,temp%,temp%,temp%
  1230.                         yr%=yr%+1
  1231.                         dpday%=dy%
  1232.                         dp&=((scdtos&:(yr%,mo%,dy%))/24/60/60)+days(1,1,1970)
  1233.                     elseif (B.rep$="Daily")
  1234.                         ds&=ds&+1
  1235.                         dsday%=0
  1236.                         dp&=dp&+1
  1237.                         dpday%=0
  1238.                     elseif (B.rep$="Weekly")
  1239.                         ds&=ds&+7
  1240.                         dsday%=0
  1241.                         dp&=dp&+7
  1242.                         dpday%=0
  1243.                     elseif (B.rep$="BiWeekly")
  1244.                         ds&=ds&+14
  1245.                         dsday%=0
  1246.                         dp&=dp&+14
  1247.                         dpday%=0
  1248.                     endif
  1249.                     use B
  1250.                     if ((B.always$="No")and(du&<dp&)) rem times up
  1251.                         erase
  1252.                         deleted%=1
  1253.                     else
  1254.                         wrstm:(ds&,dsday%,dp&,dpday%,B.desc$,amm,B.type$,B.rep$,B.always$,du&)
  1255.                     endif
  1256.                     changed%=1
  1257.                 endif
  1258.                 if (deleted%=0)
  1259.                     update
  1260.                 endif
  1261.                 i%=i%+1
  1262.             endwh
  1263.         until (changed%=0)
  1264.         busy off
  1265.         if (many%<>0) rem things have been added
  1266.             giprint num$(many%,10)+" transactions added"
  1267.         endif
  1268.         if (stmstat$="On")
  1269.             use A
  1270.             setpos:
  1271.         else
  1272.             use B
  1273.             filepos%=count-1
  1274.             scrpos%=scrlen%
  1275.         endif
  1276.     else
  1277.         setpos:
  1278.     endif
  1279.     display:(filepos%,scrpos%)
  1280. endp
  1281.  
  1282. proc bankt:
  1283.     local stmnx%,stmmx%,stmny%,stmmy%,stmlen%
  1284.     if (stdstat$="NoFile")
  1285.         if (sure%:("Create Repeats File?"))
  1286.             trap create nfile$,B,sdate$,pdate$,desc$,amm$,type$,rep$,always$,until$
  1287.             if err
  1288.                 showerr:(err)
  1289.                 return
  1290.             endif
  1291.             stdstat$="File"
  1292.         else
  1293.             return
  1294.         endif
  1295.     endif
  1296.     stmnx%=5
  1297.     stmny%=10
  1298.     stmmx%=scwidth%-10
  1299.     stmmy%=schight%-10
  1300.     stmwin%=gcreate(stmnx%+2,stmny%+linehi%+3,stmmx%-4,stmmy%-linehi%-4,1,1) rem s3a
  1301. rem s3z    stmwin%=gcreate(stmnx%+2,stmny%+linehi%+3,stmmx%-4,stmmy%-linehi%-4,1)
  1302.     dispwin%=stmwin%
  1303.     stmzwin:
  1304.     scrpos%=1
  1305.     filepos%=0
  1306.     lastpos%=filepos%
  1307.     stmstat$="Off"
  1308.     use B
  1309.     display:(filepos%,scrpos%)
  1310. endp
  1311.  
  1312. proc banki:
  1313.     local k%,infowin%
  1314.     infowin%=strtscr%:
  1315.     k%=get
  1316.     gclose infowin%
  1317.     guse dispwin%
  1318. endp
  1319.  
  1320. proc bankd: rem delete entry
  1321.     local i%,oldchq%,oldstm%,thispos%,x%,extra%,pval%
  1322.     position rptr%:(curidx%,filepos%)
  1323.     if (A.order$<>"0")
  1324.         if (sure%:("Delete entry?"))
  1325.             zapto%=filepos%
  1326.             busy "Deleting entry ..."
  1327.             if (A.stm$="x")
  1328.                 stotal=stotal-getamm:(a.amm$)
  1329.                 sorder%=sorder%-1
  1330.             endif
  1331.             total=total-getamm:(a.amm$)
  1332.             oldchq%=val(A.order$)
  1333.             oldstm%=val(A.sorder$)
  1334.             erase
  1335.             freealloc chqidx% rem s3a
  1336.             freealloc stmidx% rem s3a
  1337.             chqidx%=alloc(count*2) rem s3a
  1338.             stmidx%=alloc(count*2) rem s3a
  1339. rem s3z            call($0381,0,chqidx%)
  1340. rem s3z            call($0381,0,stmidx%)
  1341. rem s3z            chqidx%=call($0081,0,count*2)
  1342. rem s3z            stmidx%=call($0081,0,count*2)
  1343.             if ((chqidx%=0)or(stmidx%=0))
  1344.                 alert ("Not enough memory to allocate index","Account file preserved")
  1345.                 stop
  1346.             endif
  1347.             i%=0
  1348.             extra%=1
  1349.             while (i%<count)
  1350.                 first
  1351.                 x%=val(A.order$)
  1352.                 if (x%>=oldchq%)
  1353.                     x%=x%-1
  1354.                 endif
  1355.                 wptr:(chqidx%,x%,i%+1)
  1356.                 A.order$=fix$(x%,0,10)
  1357.                 x%=val(A.sorder$)
  1358.                 pval%=x%
  1359.                 if (x%=-1) rem not on statement
  1360.                     pval%=sorder%+extra%
  1361.                     extra%=extra%+1
  1362.                 else
  1363.                     if ((x%>=oldstm%)and(oldstm%<>-1))
  1364.                         x%=x%-1
  1365.                         pval%=x%
  1366.                     endif
  1367.                 endif
  1368.                 wptr:(stmidx%,pval%,i%+1)
  1369.                 A.sorder$=fix$(x%,0,10)
  1370.                 update
  1371.                 i%=i%+1
  1372.             endwh
  1373.             altcurp:
  1374.             if((posfp%:(0,1)=0)and(onfilt$="Off")) rem nothing to filter
  1375.                 busy off
  1376.                 bankuo: rem turn off filter
  1377.             else
  1378.                 lastpos%=filepos%
  1379.                 position rptr%:(curidx%,filepos%)
  1380.                 busy off
  1381.                 display:(filepos%,scrpos%)
  1382.             endif
  1383.         endif
  1384.     else
  1385.         alert("Can't delete the c/f line!")
  1386.     endif
  1387. endp
  1388.  
  1389. proc sure%:(disp$) rem a yes/no tester
  1390.     local k%
  1391.     dinit disp$
  1392.     dbuttons "No",%N,"Yes",%Y
  1393.     k%=dialog
  1394.     if (k%=%y)
  1395.         return 1
  1396.     endif
  1397.     return 0
  1398. endp
  1399.  
  1400. proc bankf:
  1401.     local found%,line%,c%
  1402.     c%=(3-sdir%)/2
  1403.     dinit "Find"
  1404.     dedit search$,"Search for"
  1405.     dchoice c%,"Direction","Forwards,Backwards"
  1406.     lock on
  1407.     if dialog
  1408.         zapto%=filepos%
  1409.         sdir%=c%*(-2)+3
  1410.         found%=ptrfind%:(filepos%,search$,sdir%)
  1411.         if (found%<>-1)
  1412.             line%=int(scrlen%/2)
  1413.             position rptr%:(curidx%,found%)
  1414.             display:(found%,line%)
  1415.         else
  1416.             giprint "Not found"
  1417.         endif
  1418.     endif
  1419.     lock off
  1420. endp
  1421.  
  1422. proc bankg:
  1423.     local found%,line%
  1424.     found%=ptrfind%:(filepos%,search$,sdir%)
  1425.     if (found%<>-1)
  1426.         line%=int(scrlen%/2)
  1427.         position rptr%:(curidx%,found%)
  1428.         display:(found%,line%)
  1429.     else
  1430.         giprint "Not found"
  1431.     endif
  1432. endp
  1433.  
  1434. proc bankw:
  1435.     if (why$="On")
  1436.         why$="Off"
  1437.     else
  1438.         why$="On"
  1439.     endif
  1440.     display:(filepos%,scrpos%)
  1441. endp
  1442.  
  1443. proc bankm: rem mark transaction
  1444.     position rptr%:(curidx%,filepos%)
  1445.     if (A.order$="0")
  1446.         alert ("You can't mark the c/f line!")
  1447.         return
  1448.     endif
  1449.     if ((clpstat$="Off")and(ordstat$="ChequeBook")and(onfilt$="On")and(A.state$<>" ")and(A.order$<>"0")and(A.stm$="x"))
  1450.         alert("Can't change Mark on a collapsed Mark Total","Switch to ChequeBook mode")
  1451.         return
  1452.     endif
  1453.     dinit "Marker"
  1454.     dedit mark$,"Mark",6
  1455.     lock on
  1456.     if dialog
  1457.         zapto%=filepos%
  1458.         if (A.order$<>"0") rem not the c/f line
  1459.             A.state$=mark$
  1460.             update
  1461.             upidx:(filepos%)
  1462.             display:(filepos%,scrpos%)
  1463.         else
  1464.             alert("Not the c/f line")
  1465.         endif
  1466.     endif
  1467.     lock off
  1468. endp
  1469.  
  1470. proc bankl: rem recalc
  1471.     calc:
  1472.     setpos:
  1473.     display:(filepos%,scrpos%)
  1474. endp
  1475.  
  1476. proc bankx: rem exit
  1477.     stop
  1478. endp
  1479.  
  1480. proc bankr: rem switch display modes
  1481.     dottl:("Date","Type","Amount",ordstat$,"Mark","",79,statmx%-232,statmx%-160,statmx%-63,statmx%-24,statmx%-10,79) rem s3a
  1482. rem s3z    dottl:("Date","Type","Amount",ordstat$,"Mrk","",53,statmx%-139,statmx%-95,statmx%-34,statmx%-14,statmx%-9,53)
  1483.     guse dispwin%
  1484.     if (ordstat$="Statement")
  1485.         ordstat$="ChequeBook"
  1486.         diampos 2 rem s3a
  1487.         curidx%=stmidx%
  1488.         display:(sorder%,2)
  1489.     else
  1490.         ordstat$="Statement"
  1491.         diampos 1 rem s3a
  1492.         curidx%=chqidx%
  1493.         display:(count-1,scrlen%)
  1494.     endif
  1495. endp
  1496.  
  1497. rem sceven.opl begins here
  1498. proc setpos:
  1499.     if (ordstat$="Statement")
  1500.         filepos%=count-1
  1501.         scrpos%=scrlen%
  1502.     else
  1503.         filepos%=sorder%
  1504.         scrpos%=2
  1505.     endif
  1506. endp
  1507.  
  1508. proc bankq:
  1509.     local c1%,c2%,c3%,c4%,c5%,switch$(10),quest$(5),x%,font$(40),swinch$(40)
  1510.     switch$="Off,On"
  1511.     font$="Small,Medium,Large,XLarge" rem s3a
  1512. rem s3z    font$="Large,Small"
  1513.     swinch$="Off,Small,Large"
  1514.     c1%=which%:("On,Off",why$)
  1515.     c2%=curfont%
  1516.     c3%=swintp%+1
  1517.     c4%=which%:("On,Off",chqstat$)
  1518.     c5%=which%:("On,Off",clpstat$)
  1519.     dinit "Set preferences"
  1520.     dchoice c1%,"Spend type",switch$
  1521.     dchoice c2%,"Font Size",font$
  1522.     dchoice c3%,"Status Window",swinch$ rem s3a
  1523.     dchoice c4%,"Auto cheque numbers",switch$
  1524.     dchoice c5%,"Collapse Mark Totals",switch$
  1525.     dedit typel$,"Transaction type",20
  1526.     dedit stypel$,"Spend type",0
  1527.     lock on
  1528.     if dialog
  1529.         position rptr%:(curidx%,0)
  1530.         A.total$=typel$
  1531.         A.stotal$=stypel$
  1532.         A.state$=getnth$:(switch$,c1%)+","+num$(c2%,2)+","+num$(c3%-1,2)+","+getnth$:(switch$,c4%)+","+getnth$:(switch$,c5%)
  1533.         update
  1534.         upidx:(0)
  1535.         getpref:
  1536.         sizewin:
  1537.         display:(filepos%,scrpos%)
  1538.     endif
  1539.     lock off
  1540. endp
  1541.  
  1542. proc banky: rem merge
  1543.     local file$(128),line%
  1544.     local lorder%,lsorder%,cftot,win%,line&,val%
  1545.     file$="\bank\*.bnk"
  1546.     dinit "Merge with file"
  1547.     dfile file$,"",64
  1548.     if dialog
  1549.         lorder%=count-1
  1550.         lsorder%=sorder%
  1551.         trap open file$,D,date$,desc$,amm$,state$,order$,sorder$,total$,stotal$,type$,stm$
  1552.         if err
  1553.             showerr:(err)
  1554.             stop
  1555.         endif
  1556.         win%=createg%:("Merging...")
  1557. rem find the c/f line in new file
  1558.         first
  1559.         cftot=0
  1560.         while not eof
  1561.             if (D.desc$="c/f")
  1562.                 cftot=val(D.amm$)
  1563.                 break
  1564.             endif
  1565.             next
  1566.         endwh
  1567.         use D
  1568.         first
  1569.         while not eof
  1570. rem assume both files are correctly calced
  1571.             if (D.desc$<>"c/f") rem dont do anything for c/f line
  1572.                 A.date$=D.date$
  1573.                 A.desc$=D.desc$
  1574.                 A.amm$=D.amm$
  1575.                 A.state$=D.state$
  1576.                 A.order$=num$(val(D.order$)+lorder%,10)
  1577.                 if (val(D.sorder$)=-1) rem not on statement
  1578.                     A.sorder$="-1"
  1579.                 else
  1580.                     A.sorder$=num$(val(D.sorder$)+lsorder%,10)
  1581.                     if (val(A.sorder$)>sorder%) rem greater than old sorder%
  1582.                         sorder%=val(A.sorder$)
  1583.                     endif
  1584.                 endif
  1585.                 A.total$=fix$(val(D.total$)-cftot+total,2,10)
  1586.                 if (val(D.sorder$)=-1) rem not on statement
  1587.                     A.stotal$="0.0"
  1588.                 else
  1589.                     A.stotal$=fix$(val(D.stotal$)-cftot+stotal,2,10)
  1590.                 endif
  1591.                 A.type$=D.type$
  1592.                 A.stm$=D.stm$
  1593.                 use A
  1594.                 append
  1595.                 use D
  1596.             endif
  1597.             next
  1598.             line&=pos
  1599.             val%=line&*100/count
  1600.             dispg:(win%,val%)
  1601.         endwh
  1602.         use D
  1603.         trap close
  1604.         if err
  1605.             showerr:(err)
  1606.         endif
  1607.         use A
  1608.         delg:(win%)
  1609.         freealloc chqidx% rem s3a
  1610.         freealloc stmidx% rem s3a
  1611. rem s3z        call($0381,0,chqidx%)
  1612. rem s3z        call($0381,0,stmidx%)
  1613.         while (findval%:<>1)
  1614.         endwh
  1615.         altcurp:
  1616.         line%=int(scrlen%/2)
  1617.         display:(lorder%,line%)
  1618.     endif
  1619. endp
  1620.  
  1621. proc banks: rem compress
  1622. rem close and open file to compress it
  1623.     busy "Compressing ..."
  1624.     use A
  1625.     close
  1626.     open filenm$,A,date$,desc$,amm$,state$,order$,sorder$,total$,stotal$,type$,stm$
  1627.     busy off
  1628. endp
  1629.  
  1630. proc bankc: rem check onto statement
  1631.     local x%,oldstat%
  1632.     position rptr%:(curidx%,filepos%)
  1633.     if ((clpstat$="Off")and(ordstat$="ChequeBook")and(onfilt$="On")and(A.state$<>" ")and(A.order$<>"0")and(A.stm$="x"))
  1634.         alert("Can't check on a collapsed Mark Total","Aleady on statement")
  1635.         return
  1636.     endif
  1637.     zapto%=filepos%
  1638.     if A.stm$<>"x"
  1639.         checkon:
  1640.         if (ordstat$="ChequeBook")
  1641.             filepos%=sorder%
  1642.             scrpos%=2
  1643.         endif
  1644.         display:(filepos%,scrpos%)
  1645.     else
  1646.         alert("Already on statement!")
  1647.     endif
  1648. endp
  1649.  
  1650. rem s3zproc banksr:
  1651. rem s3z    bankuc:
  1652. rem s3zendp
  1653.  
  1654. proc bankuc: rem check off statement
  1655.     local i%,lorder%,lamm
  1656.     position rptr%:(curidx%,filepos%)
  1657.     if (A.order$="0")
  1658.         alert ("You can't check off the c/f line!")
  1659.         return
  1660.     endif
  1661.     if ((clpstat$="Off")and(ordstat$="ChequeBook")and(onfilt$="On")and(A.state$<>" ")and(A.order$<>"0")and(A.stm$="x"))
  1662.         alert("Can't check off a collapsed Mark Total","Check off individually")
  1663.         return
  1664.     endif
  1665.     zapto%=filepos%
  1666.     if (A.stm$="x")
  1667.         if (sure%:("Remove from statement?"))
  1668.             busy "Checking off ..."
  1669.             lorder%=val(A.sorder$)
  1670.             lamm=getamm:(A.amm$)
  1671.             sorder%=sorder%-1
  1672.             stotal=stotal-getamm:(A.amm$)
  1673.             i%=1
  1674.             while (i%<=count)
  1675.                 first
  1676.                 if (val(A.sorder$)>lorder%)
  1677.                     A.sorder$=num$((val(A.sorder$)-1),10)
  1678.                 elseif (val(A.sorder$)=lorder%)
  1679.                     A.sorder$="-1"
  1680.                     A.stm$=" "
  1681.                     A.stotal$="0.00"
  1682.                 endif
  1683.                 update
  1684.                 i%=i%+1
  1685.             endwh
  1686.             busy off
  1687.             buildidx:
  1688.             display:(filepos%,scrpos%)
  1689.         endif
  1690.     else
  1691.         alert("Not on statement!")
  1692.     endif
  1693. endp
  1694.  
  1695. proc checkon: rem check a transaction onto a statement
  1696.     sorder%=sorder%+1
  1697.     stotal=stotal+getamm:(A.amm$)
  1698.     A.sorder$=num$(sorder%,10)
  1699.     A.stotal$=fix$(stotal,2,10)
  1700.     A.stm$="x"
  1701.     update
  1702. rem might it be quicker to be clever here?
  1703.     buildidx:
  1704. endp
  1705.  
  1706. proc upidx:(uppos%)
  1707.     local i%,oldpos%
  1708.     busy "Updating Index..."
  1709.     oldpos%=rptr%:(curidx%,uppos%)
  1710.     i%=0
  1711.     while (i%<count)
  1712.         if (rptr%:(chqidx%,i%)=oldpos%)
  1713.             wptr:(chqidx%,i%,count)
  1714.         elseif (rptr%:(chqidx%,i%)>oldpos%)
  1715.             wptr:(chqidx%,i%,(rptr%:(chqidx%,i%))-1)
  1716.         endif
  1717.         if (rptr%:(stmidx%,i%)=oldpos%)
  1718.             wptr:(stmidx%,i%,count)
  1719.         elseif (rptr%:(stmidx%,i%)>oldpos%)
  1720.             wptr:(stmidx%,i%,(rptr%:(stmidx%,i%))-1)
  1721.         endif
  1722.         i%=i%+1
  1723.     endwh
  1724.     busy off
  1725. endp
  1726.  
  1727. proc getamm:(amm$) rem get the amount coping with foreign currency
  1728.     if (left$(amm$,1)="$") rem foriegn currency
  1729.         return val(getnth$:(amm$,4))
  1730.     else
  1731.         return val(amm$)
  1732.     endif
  1733. endp
  1734.  
  1735. proc banke:
  1736.     local d&,c%,ttype$(60),d%,stype$(60),amm,state$(20),order&,sorder&,desc$(60),type$(60),lorder%,lsorder%,ltotal,lstotal,stm$(1)
  1737.     local rate,default,symbol$(5),oamm,orate,odef,chq&,namm
  1738.     position rptr%:(curidx%,filepos%)
  1739.     if ((clpstat$="Off")and(ordstat$="ChequeBook")and(onfilt$="On")and(A.state$<>" ")and(A.order$<>"0")and(A.stm$="x"))
  1740.         alert("Can't edit a collapsed Mark Total","Switch to ChequeBook mode")
  1741.         return
  1742.     endif
  1743.     d&=strtod&:(A.date$,"/")
  1744.     desc$=A.desc$
  1745.     order&=val(A.order$)
  1746.     sorder&=val(A.sorder$)
  1747.     if (order&>0) rem ordinary transaction
  1748.         chq&=-1
  1749.         if (left$(desc$,3)="chq")
  1750.             chq&=findnum&:(desc$)
  1751.             if (chq&>=0)
  1752.                 desc$="chq"
  1753.             endif
  1754.         endif
  1755.         type$=A.type$
  1756.         c%=which%:(typel$,desc$)
  1757.         d%=which%:(stypel$,A.type$)
  1758.         state$=A.state$
  1759.         stm$=A.stm$
  1760.         ltotal=val(A.total$)
  1761.         lstotal=val(A.stotal$)
  1762.         if (left$(A.amm$,1)="$") rem foriegn currency
  1763.             amm=val(getnth$:(A.amm$,2))
  1764.             rate=val(getnth$:(A.amm$,3))
  1765.             default=val(getnth$:(A.amm$,4))
  1766.             oamm=amm
  1767.             orate=rate
  1768.             odef=default
  1769.             symbol$=getnth$:(A.amm$,5)
  1770.         else
  1771.             amm=val(A.amm$)
  1772.             rate=-1
  1773.             default=-1
  1774.             symbol$=""
  1775.         endif
  1776.         dinit "Transaction details"
  1777.         ddate d&,"Date",0,days(31,12,2100)
  1778.         dchoice c%,"Trans type",typel$
  1779.         if (chq&>=0) rem auto cheque numbering
  1780.             dlong chq&,"Chq No.",0,1e9
  1781.         endif
  1782.         dfloat amm,"Amount",-1E13,1E13
  1783.         dchoice d%,"Spend type",stypel$
  1784.         if (left$(A.amm$,1)="$") rem foriegn currency
  1785. rem s3z            lock on
  1786. rem s3z            if dialog
  1787. rem s3z                dinit "Currency details"
  1788.             dfloat rate,"Exchange rate",-1e13,1e13
  1789.             dfloat default,"Amount in default",-1e13,1e13
  1790.             dedit symbol$,"Currency symbol"
  1791. rem s3z            else
  1792. rem s3z                return
  1793. rem s3z            endif
  1794.         endif
  1795.         lock on rem s3a
  1796.         if dialog
  1797.             zapto%=filepos%
  1798.             ttype$=getnth$:(typel$,c%)
  1799.             stype$=getnth$:(stypel$,d%)
  1800.             if ttype$="text"
  1801.                 dinit "Enter free text description"
  1802.                 dedit desc$,"Trans Type"
  1803.                 if dialog
  1804.                     ttype$=desc$
  1805.                 endif
  1806.             endif
  1807.             if stype$="text"
  1808.                 dinit "Enter free text description"
  1809.                 dedit type$,"Spend Type"
  1810.                 if dialog
  1811.                     stype$=type$
  1812.                 endif
  1813.             endif
  1814.             if (left$(A.amm$,1)="$") rem foriegn currency
  1815.                 if (oamm<>amm) rem changed amoutnt recalc default using rate
  1816.                     giprint "Recalc default from new amount"
  1817.                     if (rate=0)
  1818.                         rate=1
  1819.                     endif
  1820.                     default=amm/rate
  1821.                 elseif (odef<>default) rem changed the defualt amount recalc rate
  1822.                     giprint "Recalc rate from new default amount"
  1823.                     if (default=0)
  1824.                         default=1
  1825.                     endif
  1826.                     rate=amm/default
  1827.                 elseif (orate<>rate) rem changed the rate recalc default
  1828.                     giprint "Recalc default from new rate"
  1829.                     if (rate=0)
  1830.                         rate=1
  1831.                     endif
  1832.                     default=amm/rate
  1833.                 endif
  1834.                 namm=default
  1835.             else
  1836.                 namm=amm
  1837.             endif
  1838.             if (getamm:(A.amm$)<>namm)
  1839.                 ltotal=ltotal+namm-getamm:(A.amm$)
  1840.                 if stm$="x"
  1841.                     lstotal=lstotal+namm-getamm:(A.amm$)
  1842.                 endif
  1843.                 if (val(A.order$)<>count-1)
  1844.                     giprint "Do a recalc to be safe :-)"
  1845.                 endif
  1846.             endif
  1847.             if (chq&>=0) rem did we have a chq no.
  1848.                 ttype$=ttype$+"("+num$(chq&,8)+")"
  1849.             endif
  1850.             lorder%=order&
  1851.             lsorder%=sorder&
  1852.             wrinit:(d&,ttype$,amm,state$,lorder%,lsorder%,ltotal,lstotal,stype$,stm$,rate,default,symbol$)
  1853.             update
  1854.             upidx:(filepos%)
  1855.             display:(filepos%,scrpos%)
  1856.         endif
  1857.         lock off
  1858.     else rem edit the c/f line
  1859.         amm=val(A.amm$)
  1860.         ltotal=val(A.amm$)
  1861.         lstotal=val(A.amm$)
  1862.         dinit "Carried forward details"
  1863.         ddate d&,"Date",0,days(31,12,2100)
  1864.         dfloat ltotal,"c/f",-1E13,1E13
  1865.         lock on
  1866.         if dialog
  1867.             total=total+ltotal-val(A.amm$)
  1868.             stotal=stotal+lstotal-val(A.amm$)
  1869.             if (count<>1)
  1870.                 giprint "Do a recalc to be safe :-)"
  1871.             endif
  1872.             wrcf:(d&,"c/f",ltotal,A.state$,0,0,typel$,stypel$," ","x")
  1873.             update
  1874.             upidx:(filepos%)
  1875.             lastpos%=filepos%
  1876.             display:(filepos%,scrpos%)
  1877.         endif
  1878.         lock off
  1879.     endif
  1880. endp
  1881.  
  1882. rem s3zproc bankst:
  1883. rem s3z    bankuo:
  1884. rem s3zendp
  1885.  
  1886. proc bankuo: rem filter on/off
  1887.     local found%,tamm$(10)
  1888.     if (onfilt$="On")
  1889.         dinit "Filter string"
  1890.         dedit filt$,""
  1891.         lock on
  1892.         if dialog
  1893.             position rptr%:(curidx%,0)
  1894.             found%=ptrfind%:(0,filt$,1)
  1895.             if (found%<>-1)
  1896.                 onfilt$="Off"
  1897.                 filepos%=found%
  1898.                 lastpos%=filepos%
  1899.                 sizewin:
  1900.             else
  1901.                 giprint filt$+" not found"
  1902.             endif
  1903.         endif
  1904. rem alert (num$(filepos%,10)+num$(found%,10)+num$(count,10))
  1905.         lock off
  1906.     else
  1907.         onfilt$="On"
  1908.         lastpos%=filepos%
  1909.         sizewin:
  1910.     endif
  1911. rem alert (num$(filepos%,10))
  1912.     display:(filepos%,scrpos%)
  1913. endp
  1914.  
  1915. proc ptrfind%:(from%,fstr$,direct%)
  1916.     local i%,txt$(255),disp$(20)
  1917.     i%=from%+direct%
  1918.     if ((i%<1) or (i%>count-1))
  1919.         return -1
  1920.     endif
  1921.     do
  1922.         position rptr%:(curidx%,i%)
  1923.         txt$=A.date$+":"+A.desc$+":"+A.amm$+":"+A.state$+":"+A.type$
  1924.         if ((loc(txt$,fstr$))<>0)
  1925.             return i%
  1926.         endif
  1927.         i%=i%+direct%
  1928.     until ((i%>=count)or(i%<1)or(direct%=0))
  1929.     return -1
  1930. endp
  1931.  
  1932. proc banka:
  1933.     local d&,c%,ttype$(20),d%,stype$(20),amm,state$(10),order&,sorder&,file$(128)
  1934.     local e%,ctype$(20),rate,basic,symbol$(5),orate,odef,currl$(255),loc%
  1935.     d&=days(day,month,year)
  1936.     currl$="Default,"
  1937.     if (exist(ssdfind$:("\bank\currency.dbf"))=-1)
  1938.         trap open ssdfind$:("\bank\currency.dbf"),D,text$,rate$,symbol$
  1939.         if err
  1940.             showerr:(err)
  1941.             stop
  1942.         endif
  1943.         first
  1944.         while not eof
  1945.             currl$=currl$+D.text$+","
  1946.             next
  1947.         endwh
  1948.         close
  1949.         use A
  1950.     endif
  1951.     currl$=currl$+"Other"
  1952.     dinit "Transaction details"
  1953.     ddate d&,"Date",0,days(31,12,2100)
  1954.     dchoice c%,"Trans type",typel$
  1955.     dfloat amm,"Amount",-1E13,1E13
  1956.     dchoice d%,"Spend type",stypel$
  1957.     dchoice e%,"Currency",currl$
  1958.     if (trans$="On")
  1959. rem s3z        lock on
  1960. rem s3z        if dialog
  1961. rem s3z            dinit "Transfer details"
  1962.         file$="\bank\*.bnk"
  1963.         dfile file$,"Transfer to",64
  1964. rem s3z        else
  1965. rem s3z            return
  1966. rem s3z        endif
  1967.     endif
  1968.     lock on
  1969.     if dialog
  1970.         zapto%=filepos%
  1971.         if (trans$="On")
  1972.             trap open file$,D,date$,desc$,amm$,state$,order$,sorder$,total$,stotal$,type$,stm$
  1973.             if err
  1974.                 alert("Unable to open as bank file",file$)
  1975.                 lock off
  1976.                 return
  1977.             endif
  1978.             close
  1979.         endif
  1980.         ttype$=getnth$:(typel$,c%)
  1981.         stype$=getnth$:(stypel$,d%)
  1982.         ctype$=getnth$:(currl$,e%)
  1983.         if ttype$="text"
  1984.             dinit "Enter free text transaction type"
  1985.             dedit ttype$,"Trans Type"
  1986.             dialog
  1987.         endif
  1988.         if stype$="text"
  1989.             dinit "Enter free text spend type"
  1990.             dedit stype$,"Spend Type"
  1991.             dialog
  1992.         endif
  1993.         if (chqstat$="Off") rem are we doing autonumbering
  1994.             if (ttype$="chq") rem special case for cheque autonumbering
  1995.                 if (lastchq&=-1) rem dont have the last chq number
  1996.                     lastchq&=valchq&:
  1997.                 endif
  1998.                 lastchq&=lastchq&+1
  1999.                 dinit "Cheque Number"
  2000.                 dlong lastchq&,"",0,1e9
  2001.                 if dialog
  2002.                     ttype$=ttype$+"("+num$(lastchq&,8)+")"
  2003.                 endif
  2004.             endif
  2005.         endif
  2006.         if (ctype$<>"Default")
  2007.             if (ctype$="Other") rem a user entered currency
  2008.                 symbol$="Ï"
  2009.                 rate=1
  2010.                 basic=amm
  2011.             else rem must have come from currency file
  2012.                 if (exist(ssdfind$:("\bank\currency.dbf"))=-1)
  2013.                     trap open ssdfind$:("\bank\currency.dbf"),D,text$,rate$,symbol$
  2014.                     if err
  2015.                         showerr:(err)
  2016.                         stop
  2017.                     endif
  2018.                     position e%-1
  2019.                     rate=val(D.rate$)
  2020.                     if (rate=0)
  2021.                         rate=1
  2022.                     endif
  2023.                     basic=amm/rate
  2024. rem get roung bug in dfloat that only shows *last* 10 digits of float num
  2025.                     basic=intf(basic*100)/100
  2026.                     symbol$=D.symbol$
  2027.                     close
  2028.                     use A
  2029.                 endif
  2030.             endif
  2031.             orate=rate
  2032.             odef=basic
  2033. rem sc get details for currency
  2034.             dinit "Foreign Currency"
  2035.             dfloat rate,"Rate",-1e13,1e13
  2036.             dfloat basic,"Amount in default",-1e13,1e13
  2037.             dedit symbol$,"Symbol"
  2038.             if dialog
  2039.                 if (odef<>basic) rem changed the defualt amount recalc rate
  2040.                     giprint "Recalc rate from new default amount"
  2041.                     if (basic=0)
  2042.                         basic=1
  2043.                     endif
  2044.                     rate=amm/basic
  2045.                 elseif (orate<>rate) rem changed the rate recalc default
  2046.                     giprint "Recalc default from new rate"
  2047.                     if (rate=0)
  2048.                         rate=1
  2049.                     endif
  2050.                     basic=amm/rate
  2051.                 endif
  2052.             endif
  2053.         endif
  2054.         if (rate>0)
  2055.             total=total+basic
  2056.         else
  2057.             total=total+amm
  2058.         endif
  2059.         wrinit:(d&,ttype$,amm," ",count,-1,total,0.0,stype$," ",rate,basic,symbol$)
  2060.         append
  2061.         addptr:
  2062. rem do the stuff to add the transfer to other file
  2063.         if (trans$="On")
  2064.             busy "Transfering..."
  2065.             use A
  2066.             close
  2067.             trap open file$,A,date$,desc$,amm$,state$,order$,sorder$,total$,stotal$,type$,stm$
  2068.             if err
  2069.                 alert("Unable to open as bank file",file$)
  2070.                 return
  2071.             endif
  2072. rem find last item in chqbook mode to get total
  2073.             first
  2074.             while not eof
  2075.                 if (val(A.order$)=count-1)
  2076.                     break rem found it
  2077.                 endif
  2078.                 next
  2079.             endwh
  2080.             if (rate>0)
  2081.                 orate=basic
  2082.             else
  2083.                 orate=amm
  2084.             endif
  2085.             wrinit:(d&,ttype$,-amm," ",count,-1,val(A.total$)-orate,0.0,stype$," ",rate,-basic,symbol$)
  2086.             append
  2087.             close
  2088.             open filenm$,A,date$,desc$,amm$,state$,order$,sorder$,total$,stotal$,type$,stm$
  2089.             busy off
  2090.             giprint "Transaction transfered"
  2091.         endif
  2092.         doscr%=1
  2093.         display:(count-1,scrlen%)
  2094.     endif
  2095.     lock off
  2096. endp
  2097.  
  2098. proc banku: rem transfer
  2099. rem all a bit of a hack because too hard to pass para to banka:
  2100.     trans$="On"
  2101.     banka:
  2102.     trans$="Off"
  2103. endp
  2104.  
  2105. proc valchq&:
  2106.     local chqtest&,biggest&
  2107.     busy "Finding cheque..."
  2108.     biggest&=-1
  2109.     first
  2110.     while not eof
  2111.         if (left$(A.desc$,3)="chq")
  2112.             chqtest&=findnum&:(A.desc$)
  2113.             if (chqtest&>biggest&)
  2114.                 biggest&=chqtest&
  2115.             endif
  2116.         endif
  2117.         next
  2118.     endwh
  2119. rem alert("Biggest cheque number",num$(biggest&,10))
  2120.     busy off
  2121.     return biggest&
  2122. endp
  2123.  
  2124. proc findnum&:(desc$)
  2125.     local chqtest$(30),loc%
  2126.     if (right$(A.desc$,1)=")") rem looking good!
  2127.         loc%=loc(A.desc$,"(")
  2128.         if (loc%<>0)
  2129.             chqtest$=mid$(A.desc$,loc%+1,len(A.desc$)-loc%-1)
  2130.             if (isanum%:(chqtest$)=1)
  2131.                 return val(chqtest$)
  2132.             endif
  2133.         endif
  2134.     endif
  2135.     return -1
  2136. endp
  2137.  
  2138. proc isanum%:(chstr$)
  2139.     local i%
  2140.     i%=1
  2141.     while (i%<=len(chstr$))
  2142.         if ((mid$(chstr$,i%,1)<"0")or(mid$(chstr$,i%,1)>"9"))
  2143.             return 0
  2144.         endif
  2145.         i%=i%+1
  2146.     endwh
  2147.     return 1
  2148. endp
  2149.  
  2150. proc addptr:
  2151.     chqidx%=realloc(chqidx%,count*2) rem s3a
  2152.     stmidx%=realloc(stmidx%,count*2) rem s3a
  2153. rem s3z    call($0381,0,chqidx%)
  2154. rem s3z    call($0381,0,stmidx%)
  2155. rem s3z    chqidx%=call($0081,0,(count+1)*2)
  2156. rem s3z    stmidx%=call($0081,0,(count+1)*2)
  2157.     if ((chqidx%=0)or(stmidx%=0))
  2158.         alert ("Not enough memory to allocate index","Account file preserved")
  2159.         stop
  2160.     endif
  2161. rem addresses might have changed, so reassign curidx%
  2162.     altcurp:
  2163. rem s3z    buildidx:
  2164.     wptr:(chqidx%,count-1,count) rem s3a
  2165.     wptr:(stmidx%,count-1,count) rem s3a
  2166. endp
  2167.  
  2168. proc altcurp: rem the addresses might have changed
  2169.     if (ordstat$="ChequeBook")
  2170.         curidx%=stmidx%
  2171.     else
  2172.         curidx%=chqidx%
  2173.     endif
  2174. endp
  2175.  
  2176. proc wptr:(index%,value%,count%) rem write value in address
  2177.     pokew uadd(index%,value%*2),count% rem s3a
  2178. rem s3z    pokew index%+value%*2,count%
  2179. endp
  2180.  
  2181. proc rptr%:(index%,value%) rem read value from address
  2182.     return (peekw(uadd(index%,value%*2))) rem s3a
  2183. rem s3z    return (peekw(index%+value%*2))
  2184. endp
  2185.  
  2186. proc display:(from%,posit%) rem display current screen of entries
  2187.     local i%,j%,k%,pos%,lposit%,disp$(128)
  2188.     local amdisp$(40),tdisp$(50),lstate$(30)
  2189. rem missing used to move lposit% up if lines are missing
  2190.     local missing%,end%
  2191.     local htotal
  2192. rem alert(num$(from%,10),num$(posit%,10))
  2193.     lposit%=posit%
  2194. rem if position beyond start of file, should be unnecessary
  2195.     if (from%<0)
  2196.         filepos%=0
  2197. rem if position beyond end of file, should be unnecessary
  2198.     else
  2199.         filepos%=min(from%,count-1)
  2200.     endif
  2201. rem the following code tries to intelligently place lposit given where
  2202. rem the user suggested and the size of the file. filepos% itself is unaltered
  2203. rem
  2204. rem if the gap between screenpos and end of screen is greater than
  2205. rem gap from file position and end of file then fill up resultant gap on screen
  2206.     if ((scrlen%-lposit%)>(count-filepos%-1))and(onfilt$="On")
  2207. rem if there is enough left over to move downto fill whole screen
  2208.         if (scrlen%<count)
  2209.             lposit%=scrlen%-(count-filepos%-1)
  2210.         else
  2211. rem move down the spare stuff
  2212.             lposit%=filepos%+1
  2213.         endif
  2214.     endif
  2215. rem simple check for small files
  2216.     if ((lposit%>count)and(onfilt$="On"))
  2217.         lposit%=count
  2218.     endif
  2219. rem stop positioning beyond end of screen, should be unnecessary
  2220.     if (lposit%>scrlen%)
  2221.         lposit%=scrlen%
  2222.     endif
  2223. rem alert(num$(lposit%,10),"filepos "+num$(filepos%,10))
  2224. rem i counts position on screen j counts how many printed
  2225. rem j% not always i%+1; see scroll down
  2226.     i%=0:j%=1
  2227.     gupdate off
  2228. rem top of display is current - start
  2229. rem this is right unless we mess about collapsing or filtering
  2230.     pos%=filepos%-lposit%+1
  2231.     if (pos%<0)
  2232.         pos%=0
  2233.         lposit%=filepos%+1
  2234.     endif
  2235. rem alert(num$(oldpos%,10),"filepos "+num$(filepos%,10))
  2236. rem only use indexes for main display
  2237. rem    if ((stmstat$="On")and(mrkstat$="On")and(sttstat$="On"))
  2238.     if ((scrpos%=1)and(lposit%=1)and(doscr%=1))
  2239.         gscroll 0,linehi%,2,linehi%+3,gwidth-10,statmy%-linehi%
  2240.         j%=scrlen%
  2241.     elseif ((scrpos%=scrlen%)and(lposit%=scrlen%)and(doscr%=1))
  2242.         gscroll 0,-linehi%,2,linehi%+3+linehi%,gwidth-10,statmy%-linehi%
  2243.         j%=scrlen%
  2244.         i%=scrlen%-1
  2245.     endif
  2246. rem turn off scroll optimizer
  2247.     doscr%=0
  2248.     gfont zfontid%(curfont%) :gstyle 0
  2249.     if (onfilt$="On")
  2250.         if (pos%<>0)
  2251.             gat (gwidth-8),linea%+linehi%+3 :gprint ""
  2252.         else
  2253.             gat (gwidth-8),linea%+linehi%+3 :gprintb " ",6
  2254.         endif
  2255.     endif
  2256.     missing%=0
  2257. rem only time not k%=0 if scroll down one
  2258.     k%=i%
  2259.     position rptr%:(curidx%,pos%+k%)
  2260. rem alert(clpstat$+ordstat$+A.order$+A.stm$+A.state$+mrkstat$+sttstat$+stmstat$)
  2261. rem what if we are starting half way through a mark total
  2262.     if ((clpstat$="Off")and(ordstat$="ChequeBook")and(onfilt$="On")and(A.order$<>"0")and(A.stm$="x")and(A.state$<>" ")and(mrkstat$="On")and(sttstat$="On")and(stmstat$="On")) rem posibility that there is something above this (defensive coding?)
  2263.         lstate$=A.state$
  2264.         position rptr%:(curidx%,(pos%+k%-1))
  2265. rem alert(lstate$,A.state$)
  2266.         if (lstate$=A.state$) rem already there, dont worry
  2267.             while ((A.state$=lstate$)and(pos%+k%>=1))
  2268.                 k%=k%-1
  2269.                 if (pos%+k%<filepos%) rem should always be true
  2270.                     missing%=missing%-1
  2271.                 endif
  2272.                 lstate$=A.state$
  2273.                 position rptr%:(curidx%,pos%+k%-1)
  2274. rem alert(lstate$+"*"+A.state$+"*",num$(pos%,10))
  2275.             endwh
  2276.         endif
  2277.     endif
  2278. rem alert("missing "+num$(missing%,10))
  2279.     pos%=pos%+k%
  2280.     k%=0
  2281. rem alert(num$(pos%,10))
  2282.     lstate$="Nothing"
  2283.     htotal=0 rem initialise hold total to 0 for mark total compression
  2284.     while ((j%<=scrlen%)and(pos%+k%<count))
  2285.         if ((stmstat$="On")and(mrkstat$="On")and(sttstat$="On"))
  2286.             position rptr%:(curidx%,(pos%+k%))
  2287.         else
  2288.             position pos%+k%+1
  2289.         endif
  2290.         if (mrkstat$="Off")
  2291.             gat 6,(i%*linehi%+linea%+linehi%+3) :gprintb C.mark$,55,3
  2292.             gat 79,(i%*linehi%+linea%+linehi%+3) :gprintb C.amm$,statmx%-104,1
  2293.             gat statmx%-21,(i%*linehi%+linea%+linehi%+3) :gprintb C.stm$,10,3
  2294.         elseif (sttstat$="Off")
  2295. rem dont print month and year if they are 0
  2296.             if (C.mon$<>"0")
  2297.                 gat 2,(i%*linehi%+linea%+linehi%+3) :gprintb C.mon$,28,1 rem s3a
  2298. rem s3z                gat 2,(i%*linehi%+linea%+linehi%+3) :gprintb C.mon$,30,1
  2299.             endif
  2300.             if (C.yr$<>"0")
  2301.                 gat 52,(i%*linehi%+linea%+linehi%+3) :gprintb C.yr$,48,3 rem s3a
  2302. rem s3z                gat 37,(i%*linehi%+linea%+linehi%+3) :gprintb C.yr$,48,3
  2303.             endif
  2304.             gat 102,(i%*linehi%+linea%+linehi%+3) :gprintb C.type$,188,2 rem s3a
  2305.             gat 200,(i%*linehi%+linea%+linehi%+3) :gprintb C.amm$,90,1 rem s3a
  2306. rem s3z            gat 77,(i%*linehi%+linea%+linehi%+3) :gprintb C.type$,120,2
  2307. rem s3z            gat 132,(i%*linehi%+linea%+linehi%+3) :gprintb C.amm$,90,1
  2308.         elseif (stmstat$="Off")
  2309.             if (why$="Off")
  2310.                 disp$=B.desc$+"("+B.type$+")"
  2311.             else
  2312.                 disp$=B.desc$
  2313.             endif
  2314.             gat 8,(i%*linehi%+linea%+linehi%+3) :gprintb left$(B.sdate$,8),80,3 rem s3a
  2315.             gat 90,(i%*linehi%+linea%+linehi%+3) :gprintb disp$,120,2 rem s3a
  2316.             gat 202+(40-gtwidth(B.amm$)),(i%*linehi%+linea%+linehi%+3) :gprintb B.amm$,gtwidth(B.amm$)+10,1 rem s3a
  2317.             gat 254,(i%*linehi%+linea%+linehi%+3) :gprintb left$(B.pdate$,8),78,3 rem s3a
  2318.             gat 334,(i%*linehi%+linea%+linehi%+3) :gprintb B.rep$,126,2 rem s3a
  2319. rem s3z            gat 5,(i%*linehi%+linea%+linehi%+3) :gprintb left$(B.sdate$,8),50,3
  2320. rem s3z            gat 54,(i%*linehi%+linea%+linehi%+3) :gprintb disp$,60,2
  2321. rem s3z            gat 111-gtwidth(B.amm$),(i%*linehi%+linea%+linehi%+3) :gprintb B.amm$,gtwidth(B.amm$)+1,1
  2322. rem s3z            gat 112,(i%*linehi%+linea%+linehi%+3) :gprintb left$(B.pdate$,8),50,3
  2323. rem s3z            gat 162,(i%*linehi%+linea%+linehi%+3) :gprintb B.rep$,70,2
  2324.             if (B.always$="No")
  2325.                 gat 388,(i%*linehi%+linea%+linehi%+3) :gprintb B.until$,71,3 rem s3a
  2326. rem s3z                gat 184,(i%*linehi%+linea%+linehi%+3) :gprintb B.until$,48,3
  2327.             endif
  2328.         else
  2329.             if (why$="Off")
  2330.                 disp$=A.desc$+"("+A.type$+")"
  2331.             else
  2332.                 disp$=A.desc$
  2333.             endif
  2334.             if (left$(A.amm$,1)="$") rem foriegn currancy
  2335.                 disp$=disp$+"("+getnth$:(A.amm$,5)+getnth$:(A.amm$,2)+")"
  2336.                 amdisp$=getnth$:(A.amm$,4)
  2337.             else
  2338.                 amdisp$=A.amm$
  2339.             endif
  2340.             if (onfilt$="Off") rem filters on 
  2341.                 if (ptrfind%:(pos%+k%,filt$,0)<>-1) rem does this line have this string on
  2342.                     displn:(A.date$,disp$,amdisp$,"     ",A.state$,A.stm$,i%)
  2343.                 else
  2344.                     j%=j%-1
  2345.                     i%=i%-1
  2346.                     if (pos%+k%<filepos%)
  2347.                         missing%=missing%+1
  2348.                     endif
  2349.                 endif
  2350.             else rem normal line
  2351.                 if (A.order$="0") rem the c/f line
  2352.                     tdisp$=A.amm$ rem never foriegn currency for the c/f line!
  2353.                 elseif (ordstat$="Statement")
  2354.                     tdisp$=A.total$
  2355.                 else
  2356.                     tdisp$=A.stotal$
  2357.                 endif
  2358.                 if ((clpstat$="Off")and(ordstat$="ChequeBook")and(onfilt$="On")and(A.order$<>"0")and(A.stm$="x")and(A.state$<>" ")) rem are we collapsing
  2359. rem alert(ordstat$+"*"+A.state$+"*"+lstate$+"*"+A.order$)
  2360.                     htotal=0
  2361.                     lstate$=A.state$
  2362.                     while ((lstate$=A.state$)and(A.stm$="x")and(k%<count))
  2363.                         if (left$(A.amm$,1)="$") rem foriegn currancy
  2364.                             disp$=disp$+"("+getnth$:(A.amm$,5)+getnth$:(A.amm$,2)+")"
  2365.                             amdisp$=getnth$:(A.amm$,4)
  2366.                         else
  2367.                             amdisp$=A.amm$
  2368.                         endif
  2369.                         if (pos%+k%<filepos%) rem only interested if before where cursor would be
  2370.                             missing%=missing%+1
  2371.                         endif
  2372.                         htotal=htotal+val(amdisp$)
  2373.                         lstate$=A.state$
  2374.                         k%=k%+1
  2375.                         position rptr%:(curidx%,(pos%+k%))
  2376.                     endwh
  2377.                     k%=k%-1
  2378.                     position rptr%:(curidx%,(pos%+k%))
  2379.                     if (ordstat$="Statement")
  2380.                         tdisp$=A.total$
  2381.                     else
  2382.                         tdisp$=A.stotal$
  2383.                     endif
  2384.                     displn:("     ","Mark "+A.state$+" total",fix$(htotal,2,10),tdisp$,A.state$,A.stm$,i%)
  2385.                     if (pos%+k%<filepos%) rem printed one now
  2386.                         missing%=missing%-1
  2387.                     endif
  2388. rem alert(A.state$,"missing "+num$(missing%,10))
  2389.                 else
  2390.                     displn:(A.date$,disp$,amdisp$,tdisp$,A.state$,A.stm$,i%)
  2391.                 endif
  2392.             endif
  2393.         endif
  2394.         i%=i%+1
  2395.         j%=j%+1
  2396.         k%=k%+1
  2397.     endwh
  2398. rem alert("missing "+num$(missing%,10))
  2399.     end%=pos%+k% rem remember where we were for down arrow printing
  2400. rem alert(num$(i%,10)+"*"+num$(j%,10)+"*"+num$(k%,10)+"*"+num$(pos%,10)+"*"+num$(count,10))
  2401. rem can we go back and fill in gap with rows above
  2402.     if ((clpstat$="Off")and(ordstat$="ChequeBook")and(onfilt$="On"))
  2403.         if ((j%<=scrlen%)and(pos%+k%=count)) rem would we have continued on if not for colapsing
  2404.             k%=1 rem these are subtracted so go to 1 before where we started
  2405.             while ((pos%-k%>=0)and(j%<=scrlen%))
  2406.                 position rptr%:(curidx%,(pos%-k%))
  2407.                 gscroll 0,linehi%,2,linehi%+3,gwidth-10,statmy%-linehi%
  2408.                 missing%=missing%-1
  2409.                 if (why$="Off")
  2410.                     disp$=A.desc$+"("+A.type$+")"
  2411.                 else
  2412.                     disp$=A.desc$
  2413.                 endif
  2414.                 if (left$(A.amm$,1)="$") rem foriegn currancy
  2415.                     disp$=disp$+"("+getnth$:(A.amm$,5)+getnth$:(A.amm$,2)+")"
  2416.                     amdisp$=getnth$:(A.amm$,4)
  2417.                 else
  2418.                     amdisp$=A.amm$
  2419.                 endif
  2420.                 if (A.order$="0") rem the c/f line
  2421.                     tdisp$=A.amm$ rem never foriegn currency for the c/f line!
  2422.                 elseif (ordstat$="Statement")
  2423.                     tdisp$=A.total$
  2424.                 else
  2425.                     tdisp$=A.stotal$
  2426.                 endif
  2427.                 if ((A.state$=" ")or(A.order$="0"))
  2428.                     displn:(A.date$,disp$,amdisp$,tdisp$,A.state$,A.stm$,0)
  2429.                 else
  2430.                     htotal=0
  2431.                     lstate$=A.state$
  2432.                     while (lstate$=A.state$) rem relies on the fact that this will always terminate on a least the c/f line
  2433.                         if (left$(A.amm$,1)="$") rem foriegn currancy
  2434.                             disp$=disp$+"("+getnth$:(A.amm$,5)+getnth$:(A.amm$,2)+")"
  2435.                             amdisp$=getnth$:(A.amm$,4)
  2436.                         else
  2437.                             amdisp$=A.amm$
  2438.                         endif
  2439.                         htotal=htotal+val(amdisp$)
  2440.                         lstate$=A.state$
  2441.                         k%=k%+1
  2442.                         position rptr%:(curidx%,(pos%-k%))
  2443.                     endwh
  2444.                     k%=k%-1
  2445.                     position rptr%:(curidx%,(pos%-k%))
  2446.                     displn:("     ","Mark "+A.state$+" total",fix$(htotal,2,10),tdisp$,A.state$,A.stm$,0)
  2447.                 endif
  2448.                 i%=i%+1
  2449.                 j%=j%+1
  2450.                 k%=k%+1
  2451.             endwh
  2452.         endif
  2453.     endif
  2454. rem can we go back and fill in gap with rows above for filter
  2455.     if (onfilt$="Off")
  2456.         if ((j%<=scrlen%)and(pos%+k%=count)) rem would we have continued on if not for colapsing
  2457.             k%=1 rem these are subtracted so 1 before where we started
  2458.             while ((pos%-k%>=0)and(j%<=scrlen%))
  2459.                 position rptr%:(curidx%,(pos%-k%))
  2460.                 if (why$="Off")
  2461.                     disp$=A.desc$+"("+A.type$+")"
  2462.                 else
  2463.                     disp$=A.desc$
  2464.                 endif
  2465.                 if (ptrfind%:(pos%-k%,filt$,0)<>-1) rem does this line have this string on
  2466.                     gscroll 0,linehi%,2,linehi%+3,gwidth-10,statmy%-linehi%
  2467.                     missing%=missing%-1
  2468.                     if (left$(A.amm$,1)="$") rem foriegn currancy
  2469.                         disp$=disp$+"("+getnth$:(A.amm$,5)+getnth$:(A.amm$,2)+")"
  2470.                         amdisp$=getnth$:(A.amm$,4)
  2471.                     else
  2472.                         amdisp$=A.amm$
  2473.                     endif
  2474.                     displn:(A.date$,disp$,amdisp$,"     ",A.state$,A.stm$,0)
  2475.                     i%=i%+1
  2476.                     j%=j%+1
  2477.                 endif
  2478.                 k%=k%+1
  2479.             endwh
  2480.             pos%=pos%-k%
  2481.         endif
  2482.     endif
  2483.     if (onfilt$="Off")
  2484.         if (ptrfind%:(pos%,filt$,-1)<>-1)
  2485.             gat (gwidth-8),linea%+linehi%+3 :gprint ""
  2486.         else
  2487.             gat (gwidth-8),linea%+linehi%+3 :gprintb " ",6
  2488.         endif
  2489.     endif
  2490.     while (j%<=scrlen%) rem insert blank lines to tidy up any junk
  2491.         gat 4,(i%*linehi%+linea%+linehi%+3) :gprintb " ",statmx%-10,3 rem s3a
  2492. rem s3z        gat 5,(i%*linehi%+linea%+linehi%+3) :gprintb " ",statmx%-10,3
  2493.         i%=i%+1
  2494.         j%=j%+1
  2495.     endwh
  2496.     if (onfilt$="On")
  2497.         if ((end%)<>count)
  2498.             gat (gwidth-8),gheight-lined% :gprint chr$($0d)
  2499.         else
  2500.             gat (gwidth-8),gheight-lined% :gprintb " ",6
  2501.         endif
  2502.     else
  2503.         if (ptrfind%:(end%,filt$,1)<>-1)
  2504.             gat (gwidth-8),gheight-lined% :gprint chr$($0d)
  2505.         else
  2506.             gat (gwidth-8),gheight-lined% :gprintb " ",6
  2507.         endif
  2508.     endif
  2509. rem alert("missing "+num$(missing%,10),"lposit "+num$(lposit%,10))
  2510.     scrpos%=max(lposit%-missing%,1) rem if file is empty
  2511.     gupdate on
  2512.     if ((stmstat$="On")and(mrkstat$="On")and(sttstat$="On"))
  2513.         position rptr%:(curidx%,filepos%)
  2514.     else
  2515.         position filepos%+1
  2516.     endif
  2517.     lastpos%=filepos%
  2518. endp
  2519.  
  2520. proc displn:(date$,disp$,amdisp$,total$,state$,stm$,i%)
  2521.     local ppos%,qpos%,opos%,rpos%,spos%,tpos%
  2522.     local psz%,qsz%,osz%,rsz%,ssz%,tsz%
  2523.     spos%=4 :ssz%=80 rem s3a
  2524.     tpos%=82 :tsz%=statmx%-90 rem s3a
  2525.     opos%=statmx%-201+(40-gtwidth(amdisp$)) rem s3a
  2526.     ppos%=statmx%-124 rem s3a
  2527.     qpos%=statmx%-61 :qsz%=36 rem s3a
  2528.     rpos%=statmx%-21 :rsz%=10 rem s3a
  2529. rem s3z    spos%=5 :ssz%=50
  2530. rem s3z    tpos%=55 :tsz%=100
  2531. rem s3z    opos%=statmx%-95-gtwidth(amdisp$)
  2532. rem s3z    ppos%=statmx%-94
  2533. rem s3z    qpos%=statmx%-33 :qsz%=18
  2534. rem s3z    rpos%=statmx%-13 :rsz%=5
  2535.     gat spos%,(i%*linehi%+linea%+linehi%+3) :gprintb date$,ssz%,3
  2536.     gat tpos%,(i%*linehi%+linea%+linehi%+3) :gprintb disp$,tsz%,2
  2537.     gat opos%,(i%*linehi%+linea%+linehi%+3) :gprintb amdisp$,gtwidth(amdisp$)+1,1
  2538.     gat ppos%,(i%*linehi%+linea%+linehi%+3) :gprintb total$,61,1
  2539.     if (A.order$<>"0") rem the c/f line
  2540.         gat qpos%,(i%*linehi%+linea%+linehi%+3) :gprintb state$,qsz%,3
  2541.     else
  2542.         gat qpos%,(i%*linehi%+linea%+linehi%+3) :gprintb " ",qsz%,3
  2543.     endif
  2544.     gat rpos%,(i%*linehi%+linea%+linehi%+3) :gprintb stm$,rsz%,3
  2545. endp
  2546.  
  2547. proc posfp%:(inc%,direct%)
  2548. rem move file pos by inc% taking into account any filter
  2549.     local i%,b%,lstate$(20),lstm$(1),stpos%
  2550.     lastpos%=filepos%
  2551.     if ((mrkstat$="On")and(sttstat$="On")and(stmstat$="On")and(onfilt$="Off"))
  2552. rem only do for Ordinary view with filter on
  2553.         position rptr%:(curidx%,filepos%)
  2554.         stpos%=-1
  2555.         i%=0
  2556.         b%=0
  2557.         while (((abs(i%)<abs(inc%))or((abs(i%)=abs(inc%))and((ptrfind%:(filepos%+b%,filt$,0)=-1))))and(filepos%+b%>=0)and(filepos%+b%<=count))
  2558.             position rptr%:(curidx%,(filepos%+b%+direct%))
  2559.             if ((ptrfind%:((filepos%+b%+direct%),filt$,0)<>-1))
  2560.                 i%=i%+1
  2561.                 stpos%=filepos%+b%+direct% rem remeber where we last found something
  2562.             endif
  2563.             b%=b%+direct%
  2564. rem alert(num$(i%,5)+" "+num$(b%,5)+" "+num$(direct%,5)+" "+num$(filepos%,5)+" "+num$(inc%,5))
  2565.         endwh
  2566. rem if we were justing looking for a home (ie inc=0) and we haven't found;look in the other direction
  2567.         if ((stpos%=-1)and(inc%=0))
  2568.             b%=0
  2569.             while ((ptrfind%:((filepos%+b%),filt$,0)=-1)and(filepos%+b%>=0)and(filepos%+b%<=count))
  2570.                 position rptr%:(curidx%,(filepos%+b%-direct%))
  2571.                 if ((ptrfind%:((filepos%+b%-direct%),filt$,0)<>-1))
  2572.                     stpos%=filepos%+b%-direct% rem remeber where we last found something
  2573.                     i%=i%+1 rem just so the return works
  2574.                 endif
  2575.                 b%=b%-direct%
  2576.             endwh
  2577.         endif
  2578.         if (stpos%<>-1)
  2579.             filepos%=stpos%
  2580.         endif
  2581.         return i%
  2582.     elseif ((mrkstat$="On")and(sttstat$="On")and(stmstat$="On")and(clpstat$="Off")and(ordstat$="ChequeBook")and(onfilt$="On"))
  2583.         position rptr%:(curidx%,filepos%)
  2584.         stpos%=filepos%
  2585.         lstate$=A.state$
  2586.         lstm$=A.stm$
  2587.         i%=0
  2588.         b%=0
  2589.         while ((abs(i%)<abs(inc%))and(filepos%+b%>=0)and(filepos%+b%<=count-1))
  2590.             if ((filepos%+b%+direct%)<=count-1) rem check we don't go down
  2591.                 position rptr%:(curidx%,(filepos%+b%+direct%))
  2592.                 if ((A.state$<>lstate$)or(A.stm$<>lstm$)or(A.stm$<>"x")or(A.state$=" "))
  2593. rem alert("*"+A.state$+"*","*"+lstate$+"*")
  2594.                     i%=i%+1
  2595.                 endif
  2596.             endif
  2597.             b%=b%+direct%
  2598.             lstate$=A.state$
  2599.             lstm$=A.stm$
  2600. rem alert(num$(i%,5)+" "+num$(b%,5)+" "+num$(direct%,5)+" "+num$(filepos%,5)+" "+num$(inc%,5))
  2601.         endwh
  2602.         filepos%=min(filepos%+b%,count-1)
  2603. rem alert(num$(i%,10),num$(inc%,10))
  2604.         if (i%=0) rem did we move anywhere
  2605.             filepos%=stpos%
  2606.         endif
  2607.         position rptr%:(curidx%,filepos%)
  2608.         return i%
  2609.     else
  2610.         stpos%=filepos%
  2611.         filepos%=min(filepos%+(inc%*direct%),count-1)
  2612.         return (filepos%-stpos%)
  2613.     endif
  2614. endp
  2615.  
  2616. proc buildidx:
  2617.     local x%,extra%
  2618.     busy "Rebuilding Indexes ..."
  2619.     first
  2620.     extra%=1
  2621.     while not eof
  2622.         x%=val(A.order$)
  2623.         wptr:(chqidx%,x%,pos)
  2624.         x%=val(A.sorder$)
  2625.         if (x%=-1) rem not on statement
  2626.             wptr:(stmidx%,sorder%+extra%,pos)
  2627. rem alert(num$(sorder%,10),num$(extra%,10))
  2628.             extra%=extra%+1
  2629.         else
  2630.             wptr:(stmidx%,x%,pos)
  2631.         endif
  2632.         next
  2633.     endwh
  2634.     busy off
  2635. endp
  2636.  
  2637. proc stmw:
  2638.     bankw:
  2639. endp
  2640.  
  2641. proc stmz:
  2642.     bankz:
  2643. endp
  2644.  
  2645. proc stmuz:
  2646.     bankuz:
  2647. endp
  2648.  
  2649. rem scmore.opl begins here
  2650. proc stmp:
  2651.     bankp:
  2652. endp
  2653.  
  2654. proc stmt:
  2655.     gclose stmwin%
  2656.     dispwin%=statwin%
  2657.     stmstat$="On"
  2658. rem process any repeat changes
  2659.     bankp:
  2660.     guse dispwin%
  2661.     use A
  2662. rem need this to redo grey background. A quicker way?
  2663.     sizewin:
  2664.     display:(filepos%,scrpos%)
  2665. endp
  2666.  
  2667. proc stmx:
  2668.     bankx:
  2669. endp
  2670.  
  2671. proc stmd:
  2672.     position filepos%+1
  2673.     if (count>0)
  2674.         if (sure%:("Delete entry?"))
  2675.             erase
  2676.         endif
  2677.     endif
  2678.     display:(filepos%,scrpos%)
  2679. endp
  2680.  
  2681. proc stmi:
  2682.     banki:
  2683. endp
  2684.  
  2685. proc stmo:
  2686.     banko:
  2687. endp
  2688.  
  2689. proc stmn:
  2690.     bankn:
  2691. endp
  2692.  
  2693. proc stme:
  2694.     local ds&,dp&,amm,desc$(20),type$(20),c1%,c2%,until&
  2695.     local dsday%,dpday%,temp%
  2696.     if (count=0) rem nothing here to edit
  2697.         return
  2698.     endif
  2699.     position filepos%+1
  2700.     dp&=strtod&:(B.pdate$,"/")
  2701.     ds&=strtod&:(B.sdate$,"/")
  2702.     desc$=B.desc$
  2703.     type$=B.type$
  2704.     amm=val(B.amm$)
  2705.     c1%=which%:(stmrep$,B.rep$)
  2706.     c2%=which%:("Yes,No",B.always$)
  2707.     until&=strtod&:(B.until$,"/")
  2708.     dinit "Repeats details"
  2709.     ddate ds&,"Statement Date",0,days(31,12,2100)
  2710.     ddate dp&,"Processing Date",0,days(31,12,2100)
  2711.     dedit desc$,"Order type"
  2712.     dfloat amm,"Amount",-1E13,1E13
  2713.     dedit type$,"Spend type"
  2714. rem s3z    lock on
  2715. rem s3z    if dialog
  2716. rem s3z        dinit "Repeats details (cont)"
  2717.     dchoice c1%,"Repeat",stmrep$
  2718.     dchoice c2%,"Forever","Yes,No"
  2719.     ddate until&,"Repeat until",0,days(31,12,2100)
  2720.     lock on rem s3a
  2721.     if dialog
  2722.         if ((until&<dp&)and(c2%=2))
  2723.             alert("Error: until date is before processing date")
  2724.         else
  2725.             secstodate ((ds&-days(1,1,1970))*60*60*24),temp%,temp%,dsday%,temp%,temp%,temp%,temp%
  2726.             secstodate ((dp&-days(1,1,1970))*60*60*24),temp%,temp%,dpday%,temp%,temp%,temp%,temp%
  2727.             wrstm:(ds&,dsday%,dp&,dpday%,desc$,amm,type$,getnth$:(stmrep$,c1%),getnth$:("Yes,No",c2%),until&)
  2728.             update
  2729.             display:(count,scrlen%)
  2730.         endif
  2731.     endif
  2732. rem s3z    endif
  2733.     lock off
  2734. endp
  2735.  
  2736. proc stma:
  2737.     local ds&,dp&,ttype$(20),amm,type$(20),c1%,c2%,until&
  2738.     local dsday%,dpday%,temp%
  2739.     ds&=days(day,month,year)
  2740.     dp&=days(day,month,year)
  2741.     until&=days(day,month,year)
  2742.     dinit "Repeats details"
  2743.     ddate ds&,"Statement Date",0,days(31,12,2100)
  2744.     ddate dp&,"Processing Date",0,days(31,12,2100)
  2745.     dedit ttype$,"Order type"
  2746.     dfloat amm,"Amount",-1E13,1E13
  2747.     dedit type$,"Spend type"
  2748. rem s3z    lock on
  2749. rem s3z    if dialog
  2750. rem s3z        dinit "Repeats details (cont)"
  2751.     c1%=4
  2752.     dchoice c1%,"Repeat",stmrep$
  2753.     dchoice c2%,"Forever","Yes,No"
  2754.     ddate until&,"Repeat until",0,days(31,12,2100)
  2755.     lock on rem s3a
  2756.     if dialog
  2757.         if ((until&<dp&)and(c2%=2))
  2758.             alert("Error: until date is before processing date")
  2759.         else
  2760.             secstodate ((ds&-days(1,1,1970))*60*60*24),temp%,temp%,dsday%,temp%,temp%,temp%,temp%
  2761.             secstodate ((dp&-days(1,1,1970))*60*60*24),temp%,temp%,dpday%,temp%,temp%,temp%,temp%
  2762.             wrstm:(ds&,dsday%,dp&,dpday%,ttype$,amm,type$,getnth$:(stmrep$,c1%),getnth$:("Yes,No",c2%),until&)
  2763.             append
  2764.             doscr%=1
  2765.             display:(count,scrlen%)
  2766.         endif
  2767.     endif
  2768. rem s3z    endif
  2769.     lock off
  2770. endp
  2771.  
  2772. proc markc:
  2773.     local state$(30),i%,oldpos%
  2774.     position filepos%+1
  2775.     if (C.stm$="x")
  2776.         alert("Already on statement!")
  2777.     elseif (C.stm$="?")
  2778.         alert("Some transactions already on statement","Check them on individually")
  2779.     else
  2780.         state$=C.mark$
  2781.         use A
  2782. rem run through in chqbook order
  2783.         i%=0
  2784.         while (i%<count)
  2785.             position rptr%:(chqidx%,i%)
  2786.             if (A.state$=state$)
  2787.                 checkon:
  2788.             endif
  2789.             i%=i%+1
  2790.         endwh
  2791.         use C
  2792.         markj:
  2793.     endif
  2794. endp
  2795.  
  2796. proc markx:
  2797. close
  2798.     delete tmpfile$
  2799.     bankx:
  2800. endp
  2801.  
  2802. proc markj:
  2803.     gclose mrkwin%
  2804.     scrlen%=statlen%
  2805.     dispwin%=statwin%
  2806.     mrkstat$="On"
  2807.     guse dispwin%
  2808.     close
  2809.     delete tmpfile$
  2810.     use A
  2811.     setpos:
  2812.     sizewin:
  2813.     display:(filepos%,scrpos%)
  2814. endp
  2815.  
  2816. proc marki:
  2817.     banki:
  2818. endp
  2819.  
  2820. proc marko:
  2821.     banko:
  2822. endp
  2823.  
  2824. proc markn:
  2825.     bankn:
  2826. endp
  2827.  
  2828. proc markz:
  2829.     bankz:
  2830. endp
  2831.  
  2832. proc markuz:
  2833.     bankuz:
  2834. endp
  2835.  
  2836. proc sttx:
  2837.     close
  2838.     delete tmpfile$
  2839.     bankx:
  2840. endp
  2841.  
  2842. proc stta:
  2843.     local file$(128)
  2844.     local handle%,ret%,mode%,txt$(255),address%
  2845.     local c1%,c2%,delim&
  2846.     delim&=asc(",")
  2847.     file$="\wrd\stats.wrd"
  2848.     dinit "Save as"
  2849.     dfile file$,"",3
  2850.     dchoice c1%,"Delimiter","Tab,Comma,Semicolon,Other"
  2851.     dlong delim&,"Delimiter code",0,255
  2852.     if dialog
  2853.         busy "Writing file ..."
  2854.         if (c1%<>4) rem special delimiter
  2855.             if (c1%=1)
  2856.                 delim&=asc("    ")
  2857.             endif
  2858.             if (c1%=2)
  2859.                 delim&=asc(",")
  2860.             endif
  2861.             if (c1%=3)
  2862.                 delim&=asc(";")
  2863.             endif
  2864.         endif
  2865.         mode%=$0100 or $0020 or $0001
  2866.         ret%=ioopen(handle%,file$,mode%)
  2867.         if ret%<0
  2868.             showerr:(ret%)
  2869.             return
  2870.         endif
  2871.         address%=addr(txt$)
  2872.         first
  2873.         while not eof
  2874.             txt$=C.mon$+chr$(delim&)+C.yr$+chr$(delim&)+C.type$+chr$(delim&)+C.amm$
  2875.             ret%=iowrite(handle%,address%+1,len(txt$))
  2876.             if ret%<0
  2877.                 showerr:(ret%)
  2878.                 return
  2879.             endif
  2880.             next
  2881.         endwh
  2882.         ret%=ioclose(handle%)
  2883.         if ret%
  2884.             showerr:(ret%)
  2885.         endif
  2886.         busy off
  2887.         giprint "File written"
  2888.     endif
  2889. endp
  2890.  
  2891. proc stth:
  2892.     gclose sttwin%
  2893.     scrlen%=statlen%
  2894.     dispwin%=statwin%
  2895.     sttstat$="On"
  2896.     guse dispwin%
  2897.     close
  2898.     delete tmpfile$
  2899.     use A
  2900.     setpos:
  2901.     sizewin:
  2902.     display:(filepos%,scrpos%)
  2903. endp
  2904.  
  2905. proc sttr: rem order stats file
  2906.     reorder:("Stats")
  2907.     use C
  2908.     display:(0,1)
  2909. endp
  2910.  
  2911. proc stti:
  2912.     banki:
  2913. endp
  2914.  
  2915. proc stto:
  2916.     banko:
  2917. endp
  2918.  
  2919. proc sttn:
  2920.     bankn:
  2921. endp
  2922.  
  2923. proc sttz:
  2924.     bankz:
  2925. endp
  2926.  
  2927. proc sttuz:
  2928.     bankuz:
  2929. endp
  2930.  
  2931. proc movev:
  2932.     moving$="Off"
  2933.     lastpos%=filepos%
  2934.     display:(oldpos%,scrpos%)
  2935. endp
  2936.  
  2937. proc movez:
  2938.     bankz:
  2939. endp
  2940.  
  2941. proc moveuz:
  2942.     bankuz:
  2943. endp
  2944.  
  2945. proc movex:
  2946.     bankx:
  2947. endp
  2948.  
  2949. proc movea:
  2950.     local i%
  2951.     position rptr%:(curidx%,filepos%)
  2952.     if ((ordstat$="ChequeBook")and(val(A.sorder$)=-1))
  2953.         alert ("Need to place this somewhere on the statement")
  2954.         return
  2955.     endif
  2956.     busy "Moving..."
  2957.     i%=1
  2958.     while (i%<=count)
  2959.         first
  2960.         if (ordstat$="Statement")
  2961.             if ((val(A.order$)>oldpos%)and(val(A.order$)<=filepos%))
  2962.                 A.order$=num$(val(A.order$)-1,10)
  2963.             elseif ((val(A.order$)<oldpos%)and(val(A.order$)>filepos%))
  2964.                 A.order$=num$(val(A.order$)+1,10)
  2965.             elseif ((val(A.order$)=oldpos%)and(oldpos%>filepos%))
  2966.                 A.order$=num$(filepos%+1,10)
  2967.             elseif ((val(A.order$)=oldpos%)and(oldpos%<filepos%))
  2968.                 A.order$=num$(filepos%,10)
  2969.             endif
  2970.         endif
  2971.         if (ordstat$="ChequeBook")
  2972.             if ((val(A.sorder$)>oldpos%)and(val(A.sorder$)<=filepos%))
  2973.                 A.sorder$=num$(val(A.sorder$)-1,10)
  2974.             elseif ((val(A.sorder$)<oldpos%)and(val(A.sorder$)>filepos%))
  2975.                 A.sorder$=num$(val(A.sorder$)+1,10)
  2976.             elseif ((val(A.sorder$)=oldpos%)and(oldpos%>filepos%))
  2977.                 A.sorder$=num$(filepos%+1,10)
  2978.             elseif ((val(A.sorder$)=oldpos%)and(oldpos%<filepos%))
  2979.                 A.sorder$=num$(filepos%,10)
  2980.             endif
  2981.         endif
  2982.         update
  2983.         i%=i%+1
  2984.     endwh
  2985.     moving$="Off"
  2986.     busy off
  2987.     buildidx:
  2988.     lastpos%=filepos%
  2989.     display:(filepos%,scrpos%)
  2990. endp
  2991.  
  2992. proc movei:
  2993.     banki:
  2994. endp
  2995.  
  2996. proc moveo:
  2997.     banko:
  2998. endp
  2999.  
  3000. proc moven:
  3001.     bankn:
  3002. endp
  3003.  
  3004. proc findval%:
  3005.     local order%,x%,extra%,stmcnt%
  3006.     busy "Creating Indexes ..."
  3007.     order%=-1:sorder%=-1
  3008.     total=0:stotal=0
  3009.     extra%=1
  3010. rem set up indexes
  3011.     chqidx%=alloc(count*2) rem s3a
  3012.     stmidx%=alloc(count*2) rem s3a
  3013. rem s3z    chqidx%=call($0081,0,count*2)
  3014. rem s3z    stmidx%=call($0081,0,count*2)
  3015.     if ((chqidx%=0)or(stmidx%=0))
  3016.         alert ("Not enough memory to allocate index","Account file preserved")
  3017.         stop
  3018.     endif
  3019.     rem unfortunately we have to find sorder% first, so scan for it
  3020.     first
  3021.     while not eof
  3022.         if ((sorder%<(val(A.sorder$)))and(A.stm$="x"))
  3023. rem remember where last thing on statement is
  3024.             sorder%=(val(A.sorder$))
  3025.             if (sorder%=0) rem the c/f line
  3026.                 stotal=getamm:(A.amm$)
  3027.             else
  3028.                 stotal=val(A.stotal$)
  3029.             endif
  3030.         endif
  3031.         next
  3032.     endwh
  3033.     first
  3034.     while not eof
  3035.         x%=val(A.order$)
  3036.         if (x%>=count)
  3037.             alert("Found index value too big ("+num$(x%,10)+")","Doing a recalc")
  3038.             calc:
  3039. rem startagain after recalc
  3040.             freealloc chqidx% rem s3a
  3041.             freealloc stmidx% rem s3a
  3042. rem s3z            call($0381,0,chqidx%)
  3043. rem s3z            call($0381,0,stmidx%)
  3044.             return 0
  3045.         endif
  3046.         wptr:(chqidx%,x%,pos)
  3047.         x%=val(A.sorder$)
  3048.         if ((x%>=count)or(sorder%+extra%>count))
  3049.             alert("Statement index value too big ("+num$(x%,10)+","+num$(sorder%+extra%,10)+")","Doing a recalc")
  3050.             calc:
  3051. rem startagain after recalc
  3052.             freealloc chqidx% rem s3a
  3053.             freealloc stmidx% rem s3a
  3054. rem s3z            call($0381,0,chqidx%)
  3055. rem s3z            call($0381,0,stmidx%)
  3056.             return 0
  3057.         endif
  3058.         if (x%=-1) rem not on statement
  3059.             wptr:(stmidx%,sorder%+extra%,pos)
  3060.             extra%=extra%+1
  3061.         else
  3062.             wptr:(stmidx%,x%,pos)
  3063.         endif
  3064.         if (val(A.order$)=count-1)
  3065.             if (A.order$="0") rem the c/f line
  3066.                 total=getamm:(A.amm$)
  3067.             else
  3068.                 total=val(A.total$)
  3069.             endif
  3070.         endif
  3071.         next
  3072.     endwh
  3073.     getpref:
  3074.     busy off
  3075.     return 1
  3076. endp
  3077.  
  3078. proc getpref: rem get preferences from c/f line
  3079.     local quest$(20)
  3080. rem find options from c/f line
  3081.     position rptr%:(chqidx%,0)
  3082.     typel$=A.total$
  3083.     stypel$=A.stotal$
  3084. rem display spend types
  3085.     quest$=getnth$:(A.state$,1) rem display spend types
  3086.     if (quest$="On")
  3087.         why$="Off"
  3088.     else
  3089.         why$="On"
  3090.     endif
  3091. rem set size off status window
  3092.     quest$=getnth$:(A.state$,3) rem size of status win
  3093.     swintp%=val(quest$) rem s3a
  3094.     if (swintp%=0) rem s3a
  3095.         statuswin off rem s3a
  3096.     else rem s3a
  3097.         statuswin on, swintp% rem s3a
  3098.     endif rem s3a
  3099. rem set font
  3100.     quest$=getnth$:(A.state$,2) rem font size
  3101.     curfont%=val(quest$)
  3102.     if (curfont%>zfonts%)
  3103.         curfont%=zfonts%
  3104.     endif
  3105. rem new from v2.3 so can cope with option not in file. backward compat.
  3106.     quest$=getnth$:(A.state$,4) rem do auto cheque numbering
  3107.     if ((quest$="On")or(quest$="NotFound")) rem old version go to default
  3108.         chqstat$="Off"
  3109.     else
  3110.         chqstat$="On"
  3111.     endif
  3112.     quest$=getnth$:(A.state$,5) rem collapse mark totals
  3113.     if ((quest$="Off")or(quest$="NotFound")) rem old version go to default
  3114.         clpstat$="On"
  3115.     else
  3116.         clpstat$="Off"
  3117.     endif
  3118. endp
  3119.  
  3120. proc reorder:(afield$)
  3121.     local last&,e$(40),e1$(40),f$(40),e%,lpos%,n$(128),c%,win%,altf$(128),val%
  3122.     last :last&=pos
  3123.     if (afield$="Statement")
  3124.         altf$="Chequebook"
  3125.     elseif (afield$="Chequebook")
  3126.         altf$="Statement"
  3127.     elseif (afield$="Stats")
  3128.         altf$="Statistics"
  3129.     elseif (afield$="Mark")
  3130.         altf$="Mark Totals"
  3131.     endif
  3132.     win%=createg%:("Reorder "+altf$+" ...")
  3133.     if count>0 rem not really necessary
  3134.         while last&<>0
  3135.             val%=(100-(last&*100/count))
  3136.             dispg:(win%,val%)
  3137.             position last& :e%=pos
  3138.             if (afield$="Stats")
  3139.                 e$=C.type$
  3140.                 e1$=C.yr$
  3141.                 f$=C.mon$
  3142.                 do
  3143.                     if ((C.type$<e$)or((C.type$=e$)and(val(C.yr$)<val(e1$)))or((C.type$=e$)and(val(C.yr$)=val(e1$))and(val(C.mon$)<=val(f$))))
  3144.                         e$=C.type$ :e%=pos
  3145.                         e1$=C.yr$
  3146.                         f$=C.mon$
  3147.                     endif
  3148.                     lpos%=pos :back
  3149.                 until pos=1 and lpos%=1
  3150.             endif
  3151.             if (afield$="Mark")
  3152.                 e$=C.mark$
  3153.                 do
  3154.                     if C.mark$<=e$
  3155.                         e$=C.mark$ :e%=pos
  3156.                     endif
  3157.                     lpos%=pos :back
  3158.                 until pos=1 and lpos%=1
  3159.             endif
  3160.             if (afield$="Statement")
  3161.                 e$=A.order$
  3162.                 do
  3163.                     if val(A.order$)<=val(e$)
  3164.                         e$=A.order$ :e%=pos
  3165.                     endif
  3166.                     lpos%=pos :back
  3167.                 until pos=1 and lpos%=1
  3168.             endif
  3169.             if (afield$="Chequebook")
  3170.                 e$=A.sorder$
  3171.                 e1$=A.sorder$
  3172.                 if (e1$="-1")
  3173.                     e1$="32000"
  3174.                 endif
  3175.                 do
  3176. rem nasty nasty hack, just need to think about it
  3177.                     f$=A.sorder$
  3178.                     if (f$="-1")
  3179.                         f$="32000"
  3180.                     endif
  3181.                     if ((val(f$)<val(e1$)))
  3182.                         e$=A.sorder$
  3183.                         e1$=f$
  3184.                         e%=pos
  3185.                     endif
  3186.                     lpos%=pos :back
  3187.                 until pos=1 and lpos%=1
  3188.             endif
  3189.             position e%
  3190.             update :last&=last&-1
  3191.         endwh
  3192.     endif
  3193.     delg:(win%)
  3194. rem compress file
  3195.     banks:
  3196. endp
  3197.  
  3198. proc calc:
  3199.     local count%,lorder%
  3200.     count%=1
  3201.     stotal=0
  3202.     reorder:("Chequebook")
  3203.     busy "Totaling ..."
  3204.     first
  3205.     rem first one should be the carried forward
  3206.     if (A.desc$="c/f")
  3207.         stotal=getamm:(A.amm$)
  3208.         A.sorder$="0"
  3209.         update
  3210.         first
  3211.         count%=count%+1
  3212.     else
  3213.         alert("Can't find c/f line")
  3214.     endif
  3215.     lorder%=1
  3216.     while (count%<=count)
  3217.         if (A.stm$="x")
  3218.             stotal=stotal+getamm:(A.amm$)
  3219.             A.stotal$=fix$(stotal,2,10)
  3220.             A.sorder$=num$(lorder%,10)
  3221.             lorder%=lorder%+1
  3222.         else
  3223.             A.stotal$="0.00"
  3224.             A.sorder$="-1"
  3225.         endif
  3226.         count%=count%+1
  3227.         update
  3228.         first
  3229.     endwh
  3230.     count%=1
  3231.     total=0
  3232.     busy off
  3233.     reorder:("Statement")
  3234.     busy "Totalling ..."
  3235.     first
  3236.     rem first one should be the carried forward
  3237.     if (A.desc$="c/f")
  3238.         total=getamm:(A.amm$)
  3239.         A.order$="0"
  3240.         update
  3241.         first
  3242.         count%=count%+1
  3243.     else
  3244.         alert("Can't find c/f line")
  3245.     endif
  3246.     lorder%=1
  3247.     while (count%<=count)
  3248.         total=total+getamm:(A.amm$)
  3249.         A.total$=fix$(total,2,10)
  3250.         A.order$=num$(lorder%,10)
  3251.         lorder%=lorder%+1
  3252.         count%=count%+1
  3253.         update
  3254.         first
  3255.     endwh
  3256.     busy off
  3257. rem compress file
  3258.     banks:
  3259. rem unfortunately sorder% may have changed, so scan for it
  3260.     sorder%=-1
  3261.     first
  3262.     while not eof
  3263.         if ((sorder%<(val(A.sorder$)))and(A.stm$="x"))
  3264. rem remember where last thing on statement is
  3265.             sorder%=(val(A.sorder$))
  3266.             if (sorder%=0) rem the c/f line
  3267.                 stotal=getamm:(A.amm$)
  3268.             else
  3269.                 stotal=val(A.stotal$)
  3270.             endif
  3271.         endif
  3272.         next
  3273.     endwh
  3274.     buildidx:
  3275. endp
  3276.  
  3277. proc createg%:(text$) rem create a guage
  3278.     local win%,id%
  3279.     local midx%,midy%
  3280.     midx%=(scwidth%-0)/2
  3281.     midy%=(schight%-0)/2
  3282.     id%=gidentity
  3283.     win%=gcreate(midx%-100,midy%-20,200,40,1)
  3284.     gborder 1
  3285.     gat 8,15
  3286.     gprintb text$,180,3
  3287.     gat 0,18
  3288.     glineby 200,0
  3289.     gat 10,21
  3290.     gborder $400,180,14
  3291.     guse id%
  3292.     return win%
  3293. endp
  3294.  
  3295. proc dispg:(win%,val%) rem display gauge
  3296.     local i%,id%
  3297.     id%=gidentity
  3298.     guse win%
  3299.     gupdate off
  3300. rem sc this seems to achieve nothing
  3301.     i%=val%+(val%-((val%/2)*2))
  3302.     gat 11,22
  3303.     gfill 178,12,1
  3304.     gfill val%*1.78,12,0
  3305.     gupdate on
  3306.     guse id%
  3307. endp
  3308.  
  3309. proc delg:(win%) rem delete window
  3310.     local id%
  3311.     id%=gidentity
  3312.     guse win%
  3313.     gclose win%
  3314.     guse id%
  3315. endp
  3316.  
  3317. proc strtod&:(date$,sep$)
  3318.     local dy%,mo%,yr%,sep1%,sep2%
  3319.     if (mid$(date$,3,1)=sep$)
  3320.         sep1%=3
  3321.         sep2%=6
  3322.     else
  3323.         sep1%=2
  3324.         sep2%=5
  3325.     endif
  3326.     if (mid$(date$,sep2%,1)<>sep$)
  3327.         sep2%=sep2%-1
  3328.     endif
  3329. rem alert(left$(date$,sep1%-1))
  3330. rem alert(mid$(date$,sep1%+1,sep2%-sep1%-1))
  3331. rem alert(mid$(date$,sep2%+1,2))
  3332.     dy%=val(left$(date$,sep1%-1))
  3333.     mo%=val(mid$(date$,sep1%+1,sep2%-sep1%-1))
  3334.     yr%=val(mid$(date$,sep2%+1,2))
  3335.     return ((scdtos&:(1900+yr%,mo%,dy%))/24/60/60)+days(1,1,1970)
  3336. endp
  3337.  
  3338. proc scdtos&:(yr%,mo%,dy%) rem datetosecs function that handles days like 31/2/94
  3339.     local ldy%,done%,rvalue&
  3340.     ldy%=dy%
  3341.     done%=0
  3342.     onerr decday
  3343.     do
  3344.         rvalue&=datetosecs (yr%,mo%,ldy%,1,1,1)
  3345.         done%=1
  3346.     decday::
  3347.         if (done%<>1)
  3348.             ldy%=ldy%-1
  3349.         else
  3350.             return rvalue&
  3351.         endif
  3352.     until (done%=1)
  3353. endp
  3354.  
  3355. proc dottl:(m$,n$,p$,q$,r$,s$,mpos%,npos%,ppos%,qpos%,rpos%,spos%,tpos%)
  3356.     local tsize%,i%
  3357.     ggrey 2 rem s3a
  3358.     gcls
  3359.     ggrey 0 rem s3a
  3360.     gborder 0
  3361.     tsize%=linehi%+2
  3362.     gat 2,tsize%-lined% :gprintb m$,mpos%-2,3
  3363.     gat mpos%+1,tsize%-lined% :gprintb n$,npos%-mpos%,3
  3364.     gat npos%+1,tsize%-lined% :gprintb p$,ppos%-npos%,3
  3365.     gat ppos%+1,tsize%-lined% :gprintb q$,qpos%-ppos%,3
  3366.     gat qpos%+1,tsize%-lined% :gprintb r$,rpos%-qpos%,3
  3367.     gat rpos%+1,tsize%-lined% :gprintb s$,spos%-rpos%,3
  3368.     gat 0,tsize% :glineby gwidth,0
  3369.     gat mpos%,tsize% :glineby 0,-tsize%
  3370.     gat npos%,tsize% :glineby 0,-tsize%
  3371.     gat ppos%,tsize% :glineby 0,-tsize%
  3372.     gat qpos%,tsize% :glineby 0,-tsize%
  3373.     gat rpos%,tsize% :glineby 0,-tsize%
  3374.     gat spos%,tsize% :glineby 0,-tsize%
  3375.     gat tpos%,tsize% :glineby 0,-tsize%
  3376.     ggrey 1 rem s3a
  3377.     gat mpos%,0 :glineby 0,gheight rem s3a
  3378.     gat npos%,0 :glineby 0,gheight rem s3a
  3379.     gat ppos%,0 :glineby 0,gheight rem s3a
  3380.     gat qpos%,0 :glineby 0,gheight rem s3a
  3381.     gat rpos%,0 :glineby 0,gheight rem s3a
  3382.     gat spos%,0 :glineby 0,gheight rem s3a
  3383.     gat tpos%,0 :glineby 0,gheight rem s3a
  3384.     i%=0 rem s3a
  3385.     do rem s3a
  3386.         gat 0,linehi%*i%+linehi%+3 :glineby gwidth,0 rem s3a
  3387.         i%=i%+1 rem s3a
  3388.     until i%>statlen% rem s3a
  3389. rem    guse dispwin%
  3390.     ggrey 0 rem s3a
  3391. endp
  3392.