// Accounts Receivable Register // By: Mike Gallant // Does a Accounts Receivable Register on all Accounts #include rms #include stdio #include ssdef #include starlet #include string #include stdlib #include ctype #include processes #include climsgdef #include perror #include math #include time #include #include #include #include "conio.h" #include "invalnum.h" #include "inputreq.h" #include "delay.h" extern void InitializeClientFile(); extern void OpenClient(); extern void CloseClient(); void ErrorExit(char *, char *); extern "C" void ar(char *, char &); void DoRegister(void); void PrintHeadings(int); // Prototypes for COBOL field conversion routines found in CONVPACK.OBJ extern void EnsureAllNumeric(char *); extern void AlignPIC9n(char *, long int, int, char); extern long int PIC9nToNumeric(char *, int, char); extern long int COMP3ToNumeric(char *, int); extern void NumericToCOMP3(char *, long int, int); #define CAnClientRecSize 256 #define CAnClientKeySize 44 struct FAB cClientFIL; struct RAB cClientREC; struct XABKEY cClientXABKEY0, cClientXABKEY1, cClientXABKEY2, cClientXABKEY3, cClientXABKEY4, cClientXABKEY5, cClientXABKEY6, cClientXABKEY7, cClientXABKEY8; struct CAcPrimary { char LastName[12], FirstName[18], MidInit[2]; }; struct CAcSecond { char LastName[12], FirstName[18], MidInit[2]; }; struct CAcAddress { char Street[18], City[18], Province[2], PostalCode[6]; }; struct CAnClient { char AccountId[10], AccountStatus[2]; int IssueDate, ExpiryDate, CardsIssued; struct CAcPrimary cPrimary; struct CAcSecond cSecond; int StatementDay; char PrevBalance[6], CurrentBalance[6], TotalPayments[6], TotalPurchases[6]; int LastPayDate, LastPurchDate; char MinPayDue[6], CreditLimit[6], ActualCrdLimit[6]; struct CAcAddress cAddress; char LangCode[2]; int LastContactDate; char WorkPhone[6], HomePhone[6], InterestOwed[6]; int DateOfBirth; char filler[42]; }; struct CAnClient cClient; static char *psFileName2 = "[comp97.gallantm]client.dat"; ofstream Register("[comp97.gallantm]AR.REG", ios::out); int RMSStatus; char ReportDate[8]; char Prompt; #include "loadclient.cxx" main() { /* External COBOL program to get Valid Date to report from and to serve as a Front-End screen */ ar(ReportDate, Prompt); /* Is operator did not cancel processing of report, do report */ if(Prompt != 'E') { Delay(2); InitializeClientFile(); OpenClient(); if(!Register) { cerr << "Seartons File could not be Opened (OUT)" << endl; exit(1); } DoRegister(); /* Function that produces AR Register */ Register.close(); CloseClient(); } gotoxy(31,15); cout << "Done! Hit Return:" << endl; cin.get(); return 0; } void DoRegister(void) { /* These fields are used to split up the account into two fields */ char fAccountId1[5], fAccountId2[7]; /* LinesDone is the Number of Lines printed on report to check for page bre ak */ /* PageNo is the Page Number that the report is currently printing */ int LinesDone, PageNo; /* 't' prefix means the running total for that field */ long int PrevBalance, InterestOwed, TotalPayments, TotalPurchases; long int ClosingBal, tPrevBalance, tInterestOwed, tTotalPayments; long int tTotalPurchases, tClosingBal; /* A 'd' prefix means that the field is a DOUBLE version of the given named variable. 'dt' means a DOUBLE total of the variable named */ double dPrevBalance, dInterestOwed, dTotalPayments, dTotalPurchases; double dClosingBal, dtPrevBalance, dtInterestOwed, dtTotalPayments; double dtTotalPurchases, dtClosingBal; /* Initialize Fields */ dtTotalPayments = 0; dtTotalPurchases = 0; dtClosingBal = 0; dtPrevBalance = 0; dtInterestOwed = 0; cClientREC.rab$b_krf = 0; // To Access the Branch Id Key RMSStatus = sys$rewind(&cClientREC); /* Move index pointer to beginning of file */ if(RMSStatus != RMS$_NORMAL) ErrorExit("$REWIND", cClientFIL.fab$l_fna); /* Read first record from file */ cClientREC.rab$b_rac = RAB$C_SEQ; cClientREC.rab$w_usz = CAnClientRecSize; cClientREC.rab$l_ubf = (char *) &cClient; RMSStatus = sys$get(&cClientREC); // if(RMSStatus == RMS$_EOF) break; if (RMSStatus != RMS$_NORMAL) ErrorExit("$GET", cClientFIL.fab$l_fna); PageNo = 1; LinesDone = 0; PrintHeadings(PageNo); while(RMSStatus != RMS$_EOF) { strncpy(fAccountId1,cClient.AccountId,4); strncpy(fAccountId2,&(cClient.AccountId[4]),6); fAccountId1[4] = '\0'; fAccountId2[6] = '\0'; LinesDone++; if(LinesDone >= 40) { PageNo++; Register << "----------------------------------------------------"; PrintHeadings(PageNo); LinesDone = 1; } PrevBalance = COMP3ToNumeric(&cClient.PrevBalance[0],6); dPrevBalance = (double)(PrevBalance); TotalPayments = COMP3ToNumeric(&cClient.TotalPayments[0],6); dTotalPayments = (double)(TotalPayments); TotalPurchases = COMP3ToNumeric(&cClient.TotalPurchases[0],6); dTotalPurchases = (double)(TotalPurchases); InterestOwed = COMP3ToNumeric(&cClient.InterestOwed[0],6); dInterestOwed = (double)(InterestOwed); ClosingBal = (PrevBalance + TotalPurchases - TotalPayments + InterestOwe d); dClosingBal = (double)(ClosingBal); Register << " " << fAccountId1 << "-" << fAccountId2 << " " << setiosflags(ios::fixed | ios::showpoint) << setw(11) << setprecision( 2) << ((dPrevBalance / 100) + 0.004) << " " << setw(11) << setprecision(2 ) << ((dTotalPurchases / 100) + 0.004) << " " << setw(11) << setprecision (2) << ((dTotalPayments / 100) + 0.004) << " " << setw(11) << setprecision( 2) << ((dInterestOwed / 100) + 0.004) << " " << setw(15) << setprecision( 2) << ((dClosingBal / 100) + 0.004) << endl; dtClosingBal += dClosingBal; dtPrevBalance += dPrevBalance; dtTotalPayments += dTotalPayments; dtTotalPurchases += dTotalPurchases; dtInterestOwed += dInterestOwed; RMSStatus = sys$get(&cClientREC); if(RMSStatus == RMS$_EOF) break; else if (RMSStatus != RMS$_NORMAL) ErrorExit("$GET", cClientFIL.fab$l_fna); } Register << "\n" << " TOTALS" << '\n'; Register << " OPENING BALANCE : " << setw(14) << setprecision(2) << ((dtPrevBalance / 100) + 0.004) << '\n'; Register << " PURCHASES : " << setw(14) << setprecision(2) << ((dtTotalPurchases / 100) + 0.004) << '\n'; Register << " PAYMENTS : " << setw(14) << setprecision(2) << ((dtTotalPayments / 100) + 0.004) << '\n'; Register << " CREDIT CHARGES : " << setw(14) << setprecision(2) << ((dtInterestOwed / 100) + 0.004) << '\n'; Register << " CLOSING BALANCE : " << setw(14) << setprecision(2) << ((dtClosingBal / 100) + 0.004) << '\n'; } void PrintHeadings(int PageNo) { char RepDate[11]; /* To store date in Format 9999-99-99 */ /* Code that moves the Report Date into the field given above this line */ strncpy(RepDate,ReportDate,4); strncpy(&(RepDate[5]),&(ReportDate[4]),2); strncpy(&(RepDate[8]),&(ReportDate[6]),2); RepDate[4] = '-'; RepDate[7] = '-'; RepDate[10] = '\0'; /* Print Heading Information */ Register << '\f' << setw(54) << "SEARTONS CHARGE CARD SYSTEM" << "\n\n" << setw(55) << "ACCOUNTS RECEIVABLE REGISTER" << "\n"; Register << setw(55) << "----------------------------" << "\n\n"; Register << " Date: " << RepDate << setw(60) << "Page: " << PageNo << "\n\n"; Register << " ACCOUNT ID OPENING BAL + PURCHASES - PAYMENTS" << " + CR. CHARGES = CLOSING BALANCE" << '\n'; Register << "------------------------------------------------------" << "------------------------------------" << '\n'; } /* Used to Display RMS Error Messages */ void ErrorExit(char *psOperation, char *psFileName) { printf("RMSEXP2 - file %s failed (%s)\n", psFileName, psOperation); exit(RMSStatus); }