{
throw new IllegalStateException("The PlayTrade order file '"+m_file.getCanonicalPath()+"' does not exist");
}
Date youngest_order_date_found = null;
CSVReader csvparser = new CSVReader(getFileAsInputStream(PLAYTRADE_FILE_ENCODING,getDiscardBOM()), FLAT_FILE_DELIMITER, '~'); //need to use a quote char that isnt in the file because csvreader seems to use " be default if one isnt specified, (if file has no delimiter)
String[] headerline = csvparser.readNext();
String[] line = null; //the current line being read from the csv file
while( (line = csvparser.readNext()) != null )
{
if ( line.length != headerline.length )
{
csvparser.close();
throw new Error("The row doesn't have the same number of columns as the header " + line.length + "!=" + headerline.length);
}
OrderReportRow order_record = new OrderReportRow();
order_record.setPaymentsStatus( line[ OrderReport.Header.PAYMENTS_STATUS.getIndex(headerline) ] );
order_record.setOrderId( line[ OrderReport.Header.ORDER_ID.getIndex(headerline) ] );
order_record.setItemName( line[ OrderReport.Header.ITEM_NAME.getIndex(headerline) ] );
order_record.setListingId( line[ OrderReport.Header.LISTING_ID.getIndex(headerline) ] );
order_record.setSku( line[ OrderReport.Header.SKU.getIndex(headerline) ] );
order_record.setDeliveredPriceGbp( line[ OrderReport.Header.DELIVERED_PRICE_GBP.getIndex(headerline) ] );
order_record.setDeliveredPriceEuro( line[ OrderReport.Header.DELIVERED_PRICE_EURO.getIndex(headerline) ] );
order_record.setPurchaseDate( line[ OrderReport.Header.PURCHASE_DATE.getIndex(headerline) ] );
order_record.setBuyerEmail( line[ OrderReport.Header.BUYER_EMAIL.getIndex(headerline) ] );
order_record.setBuyerName( line[ OrderReport.Header.BUYER_NAME.getIndex(headerline) ] );
order_record.setRecipientName( line[ OrderReport.Header.RECIPIENT_NAME.getIndex(headerline) ] );
order_record.setShipAddress1( line[ OrderReport.Header.SHIP_ADDRESS_1.getIndex(headerline) ] );
order_record.setShipAddress2( line[ OrderReport.Header.SHIP_ADDRESS_2.getIndex(headerline) ] );
order_record.setShipCity( line[ OrderReport.Header.SHIP_CITY.getIndex(headerline) ] );
order_record.setShipPostcode( line[ OrderReport.Header.SHIP_POSTCODE.getIndex(headerline) ] );
order_record.setShipCountry( line[ OrderReport.Header.SHIP_COUNTRY.getIndex(headerline) ] );
order_record.setExchangeRate( line[ OrderReport.Header.EXCHANGE_RATE.getIndex(headerline) ] );
order_record.setSaleValueGbp( line[ OrderReport.Header.SALE_VALUE_GBP.getIndex(headerline) ] );
order_record.setSaleValueEuro( line[ OrderReport.Header.SALE_VALUE_EURO.getIndex(headerline) ] );
order_record.setPlaytradeFeesGbp( line[ OrderReport.Header.PLAYTRADE_FEES_GBP.getIndex(headerline) ] );
order_record.setPlaytradeFeesEuro( line[ OrderReport.Header.PLAYTRADE_FEES_EURO.getIndex(headerline) ] );
order_record.setProceedsGbp( line[ OrderReport.Header.PROCEEDS_GBP.getIndex(headerline) ] );
order_record.setProceedsEuro( line[ OrderReport.Header.PROCEEDS_EURO.getIndex(headerline) ] );
order_record.setDispatched( line[ OrderReport.Header.DISPATCHED.getIndex(headerline) ] );
//send this to the listener
listener.found(order_record);
//save the date/time of the youngest order
Date purchasedate = PlayTradeUtils.parsePlayTradeDateTime(order_record.getPurchaseDate());
if ( youngest_order_date_found == null || youngest_order_date_found.before(purchasedate) )
{
youngest_order_date_found = purchasedate;
}
}
csvparser.close();
return youngest_order_date_found;
}