home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / PASCAL / NWTP04 / XACCT / TSTACCT.PAS
Pascal/Delphi Source File  |  1993-12-29  |  6KB  |  150 lines

  1. {$X+,V-,B-}
  2. Program tstacct;
  3.  
  4. { Testprogram for the nwAcct unit / NwTP 0.4 API. (c) 1994, R.Spronk }
  5.  
  6. uses nwBindry,nwConn,nwAcct;
  7.  
  8. CONST testObjName='TEST';
  9.  
  10. Var connId    :byte;
  11.     currServer:string;
  12.     balance,limit,holds      :Longint;
  13.     newBalance,newLimit      :LongInt;
  14.     nCharge,nCancelHoldAmount:Longint;
  15.     oldBalance,Oldholds      :LongInt;
  16.  
  17. begin
  18. If NOT AccountingInstalled
  19.  then begin
  20.       writeln('error#:',nwAcct.result);
  21.       write('Err:Accounting isn''t installed on the current effective server:');
  22.       GetEffectiveConnectionID(ConnID);
  23.       GetFileServerName(connId,currServer);
  24.       writeln(currServer);
  25.       exit; { exit program }
  26.       end;
  27.  
  28. AddAccountingServer('SUPERVISOR',OT_USER);
  29.  
  30.  
  31. IF GetAccountStatus(testObjName,OT_USER,balance,limit,holds)
  32.   then begin
  33.        writeln('Current account status for user ',testObjName,' :');
  34.        writeln('Balance     :',balance);
  35.        writeln('Credit Limit:',limit);
  36.        writeln('Holds       :',holds);
  37.        end
  38.   else writeln('Err: GetAccountStatus failed. error #',nwAcct.result);
  39.  
  40. writeln('Setting new account values..');
  41. newBalance:=1020304;
  42. newLimit:=123456;
  43. IF NOT SetAccountStatus(testObjName,OT_USER,newBalance,newLimit)
  44.  then writeln('Err: SetAccountStatus failed. error #',nwAcct.result);
  45.  
  46. IF GetAccountStatus(testObjName,OT_USER,balance,limit,holds)
  47.   then begin
  48.        writeln('Current account status for user ',testObjName,' :');
  49.        writeln('Balance     :',balance);
  50.        writeln('Credit Limit:',limit);
  51.        writeln('Holds       :',holds);
  52.        if (balance<>newBalance) or (newLimit<>Limit)
  53.         then writeln('Err: the new account values where not set!');
  54.        end
  55.   else writeln('Err: GetAccountStatus failed. error #',nwAcct.result);
  56.  
  57. OldBalance:=balance;
  58. nCharge:=100;
  59. nCancelHoldAmount:=0;
  60. Writeln('Submitting an account charge. charge=',ncharge,',CancelHold=',ncancelholdamount);
  61. IF NOT SubmitAccountCharge(testObjName,OT_USER,nCharge,nCancelHoldAmount,
  62.                            OT_USER,0,'no note')
  63.  then writeln('Err: SubmitAccountCharge failed. error #',nwAcct.result);
  64.  
  65. IF GetAccountStatus(testObjName,OT_USER,balance,limit,holds)
  66.   then begin
  67.        writeln('Current account status for user ',testObjName,' :');
  68.        writeln('Balance     :',balance);
  69.        writeln('Credit Limit:',limit);
  70.        writeln('Holds       :',holds);
  71.        if (balance<>(oldBalance-nCharge))
  72.         then writeln('Err: the account charge was not carried out !');
  73.        end
  74.   else writeln('Err: GetAccountStatus failed. error #',nwAcct.result);
  75.  
  76.  
  77. OldBalance:=balance;
  78. nCharge:=-200;
  79. nCancelHoldAmount:=0;
  80. Writeln('Submitting a NEGATIVE account charge. charge=',ncharge,',CancelHold=',ncancelholdamount);
  81. Writeln(' (in fact increasing the balance of the ',testObjName,' object.');
  82. IF NOT SubmitAccountCharge(testObjName,OT_USER,nCharge,nCancelHoldAmount,
  83.                            OT_USER,0,'no note')
  84.  then writeln('Err: SubmitAccountCharge failed. error #',nwAcct.result);
  85.  
  86. IF GetAccountStatus(testObjName,OT_USER,balance,limit,holds)
  87.   then begin
  88.        writeln('Current account status for user ',testObjName,' :');
  89.        writeln('Balance     :',balance);
  90.        writeln('Credit Limit:',limit);
  91.        writeln('Holds       :',holds);
  92.        if (balance<>(oldBalance-nCharge))
  93.         then writeln('Err: the account charge was not carried out !');
  94.        end
  95.   else writeln('Err: GetAccountStatus failed. error #',nwAcct.result);
  96.  
  97. OldHolds:=holds;
  98. writeln('Submit an hold in the amount of 1234');
  99. IF SubmitAccountHold(testObjName,OT_USER,1234)
  100.  then begin
  101.       GetAccountStatus(testObjName,OT_USER,balance,limit,holds);
  102.       writeln('Current account status for user ',testObjName,' :');
  103.       writeln('Balance     :',balance);
  104.       writeln('Credit Limit:',limit);
  105.       writeln('Holds       :',holds);
  106.  
  107.       if (holds<>(OldHolds+1234))
  108.         then writeln('Err: the account hold was not carried out !');
  109.       end
  110.  else writeln('Err: SubmitAccountHold failed. error #',nwAcct.result);
  111.  
  112. Writeln('Submit a charge of 1000, unhold 1234');
  113. OldHolds:=holds;
  114. nCharge:=1000;
  115. nCancelHoldAmount:=1234;
  116. IF SubmitAccountCharge(testObjName,OT_USER,nCharge,nCancelHoldAmount,
  117.                        OT_USER,0,'no note')
  118.  then begin
  119.       GetAccountStatus(testObjName,OT_USER,balance,limit,holds);
  120.       writeln('Current account status for user ',testObjName,' :');
  121.       writeln('Balance     :',balance);
  122.       writeln('Credit Limit:',limit);
  123.       writeln('Holds       :',holds);
  124.  
  125.       if (holds<>(OldHolds-1234))
  126.         then writeln('Err: the account hold was not carried out !');
  127.       end
  128.  else writeln('Err: SubmitAccountHold failed. error #',nwAcct.result);
  129.  
  130. IF DeleteAccountHolds(testObjName,OT_USER)
  131.  then begin
  132.       writeln('All further holds bythis accounting server were released.');
  133.       GetAccountStatus(testObjName,OT_USER,balance,limit,holds);
  134.       writeln('Current account status for user ',testObjName,' :');
  135.       writeln('Balance     :',balance);
  136.       writeln('Credit Limit:',limit);
  137.       writeln('Holds       :',holds);
  138.       end
  139.  else writeln('Err: DeleteAccountHolds failed. error #',nwAcct.result);
  140.  
  141. IF SubmitAccountNote(testObjName,OT_USER,
  142.                      OT_USER,0,'<<TEST OF ACCOUNTNOTE>>')
  143.    then begin
  144.         writeln('Accountnote was submitted correctly.');
  145.         writeln('Please use a hexeditor and have look at \system\net$acct.dat');
  146.         writeln('to check if the accountnote was added to the file.');
  147.         end
  148.   else writeln('Err: SubmitAccountNote failed. error #',nwAcct.result);
  149.  
  150. end.