}//memberReport // Scenario: Request Accounts Payable Report private void accountsPayableReport() { try { //Get the end date DateTime endDate = ui.promptForDate("End date of week (" + UserInterface.DATE_FORMAT + "): "); //Generate report for specified week AccountsPayableReportGenerator generator = new AccountsPayableReportGenerator(endDate); AccountsPayableReport report = generator.getReport(); //Display the report report.display(ui); //"Print" (save the report to a file) if the user wishes String answer = ui.promptForString ("Save the report? (Y)es or (N)o: "); if (answer != null && answer.Length >= 1 && Char.ToUpper(answer[0]) == 'Y') { report.print("Accounts Payable"); ui.message("The report has been saved as " + report.getFileName() + "\n"); } else { ui.message("Report not saved"); } } catch (FileNotFoundException ex) { //occurs if the file cannot be created ui.errorMessage(ex.Message); } }//accountsPayableReport
/** Creates a new accounts payable report generator which creates a new * accounts payable report * @param endDate a date within the week for which the report is to be * generated * @throws FileNotFoundException if the file cannot be created. */ public AccountsPayableReportGenerator(DateTime endDate) { Claims claims = null; Services services = null; Providers providers = null; //create a new accounts payable report report = new AccountsPayableReport(endDate); try { //create and open claims, services and providers collections claims = new Claims(); claims.open(); services = new Services(); services.open(); providers = new Providers(); providers.open(); int totalNoConsultations = 0; //accumulates number of consultations int providerCount = 0; //counts number of providers to be paid double grandTotalFee = 0; //accumulates all fees payable //get all providers List <Person> allProviders = providers.getAll(); //for each provider foreach (Person person in allProviders) { int noConsultations = 0; //counts this provider's claims double totalFee = 0; //accumulates fees payable to this provider Provider provider = (Provider)person; //get all claims submitted by this provider List <Claim> providerClaims = claims.findByProvider(provider.getNumber()); //for each claim foreach (Claim nextClaim in providerClaims) { //test whether within date range if (nextClaim.getSubmissionDate() > (report.getStartDateRange()) && nextClaim.getSubmissionDate() < (report.getEndDateRange())) { //get service fee double serviceFee; Service service = services.find(nextClaim.getServiceCode()); if (service == null) { serviceFee = 0; //indicates invalid code } else { serviceFee = service.getFee(); } //increment number of consultations noConsultations++; //accumulate fees payable totalFee += serviceFee; } //if date in specified week } //for each claim if (noConsultations > 0) { //add provider detauls to report report.addDetail(provider.getNumber(), noConsultations , totalFee, provider.getName()); //accumulate number of consultations for all providers totalNoConsultations += noConsultations; //accumulate fees payable for all providers grandTotalFee += totalFee; //increment provider count providerCount++; } }//for each provider //add summary to report report.addSummary(totalNoConsultations, grandTotalFee , providerCount); }//try catch (Exception ex) { report.addErrorMessage(ex.Message); } finally { if (claims != null) { claims.close(); } if (providers != null) { providers.close(); } if (services != null) { services.close(); } } }//constructor