transactionManager = new TransactionManager();
transactionSet = transactionManager.GetTransactions(start, finish);
} catch (IOException ex) {
result = false;
Logger.getLogger(TransactionReport.class.getName()).log(Level.SEVERE, null, ex);
throw new AppException(ex.getMessage(), "[TransactionReport::generateReport]", ex);
} catch (DataAccessException ex) {
result = false;
Logger.getLogger(TransactionReport.class.getName()).log(Level.SEVERE, null, ex);
throw new AppException(ex.getMessage(), "[TransactionReport::generateReport]", ex);
} finally {
transactionManager = null;
}
//String reportFormat = "%1$3d\t%2$4d\t%3$15s\t%4$20s\t%5$50s%6$50s\t%7$4d\t%8$20s\t%9$50s\n";
BufferedWriter bw = null;
try {
Calendar calendar = Calendar.getInstance();
Date date = calendar.getTime();
bw = FileUtil.getBufferedWriter(getFileOutputName(), false);
bw.write(getReportTitle());
bw.newLine();
bw.write("Report Date: " + new SimpleDateFormat("dd-MMM-yyyy").format(date));
bw.write("\n\n");
if (isShowHeader()) {
bw.newLine();
bw.write(getHeader());
bw.newLine();
} else {
bw.newLine();
bw.write(getDefaultHeader());
bw.newLine();
}
if (transactionSet != null) {
DateFormat df = new SimpleDateFormat(TRANSACTION_DATEFORMAT);
//"%1$5s\t%2$4s\t%3$15s\t%4$20s\t%5$50s%6$50s\t%7$4s\t%8$20s\t%9$50s\n";
for (int i = 0; i < transactionSet.size(); i++) {
String transactionSeq = String.valueOf(i+1);
Transaction transactionDataObject = transactionSet.get(i);
String transactionID = String.valueOf(transactionDataObject.getTransactionId());
String productID = transactionDataObject.getProductId();
String memberID = transactionDataObject.getMemberId();
String quantity = String.valueOf(transactionDataObject.getQuantity());
//String transactionDate = String.valueOf(transactionDataObject.getPurchasedDate());
String transactionDate = df.format(transactionDataObject.getPurchasedDate());//String.valueOf(transactionDataObject.getPurchasedDate());
MemberManager memberDataObjectManager = new MemberManager();
Member memberDataObject = memberDataObjectManager.selectMember(memberID);
String memberName = "";
if (memberDataObject != null) {
memberName = memberDataObject.getMemberName();
}
ProductManager productDataObjectManager = new ProductManager();
Product productDataObject = productDataObjectManager.selectProduct(productID);
String productName = "";
String productDesc = "";
if (productDataObject != null) {
productName = productDataObject.getProductName();
productDesc = productDataObject.getProductDescription();
}
String output = String.format(TRANSACTION_REPORT_FORMAT, transactionSeq, transactionID, transactionDate, productID, productName, productDesc, quantity, memberID, memberName);
bw.write(output);
//debugging purpose
//System.out.format(output);
memberDataObject = null;
productDataObjectManager = null;
transactionDataObject = null;
}
}
bw.write("\n\n");
if (isShowFooter()) {
bw.write(getFooter());
} else {
bw.write(getDefaultFooter());
}
} catch (IOException ex) {
result = false;
Logger.getLogger(TransactionReport.class.getName()).log(Level.SEVERE, null, ex);
throw new AppException(ex.getMessage(), "[TransactionReport::generateReport]", ex);
} finally {
try {
if (bw!=null) {
bw.flush();
bw.close();