From: Anneli <an...@us...> - 2005-01-11 17:12:30
|
Update of /cvsroot/redpos/RedPOS/src/org/redpos/client/receipt In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11881/src/org/redpos/client/receipt Modified Files: ReceiptStorage.java ReceiptSession.java Log Message: New function, save and find receipt Index: ReceiptStorage.java =================================================================== RCS file: /cvsroot/redpos/RedPOS/src/org/redpos/client/receipt/ReceiptStorage.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ReceiptStorage.java 23 Nov 2004 16:02:31 -0000 1.1 --- ReceiptStorage.java 11 Jan 2005 17:11:36 -0000 1.2 *************** *** 73,77 **** public static final String DB_COLUMN_NAME_TALLIED = "tallied"; ! public static final String allColumnNames[] = {DB_COLUMN_NAME_RECEIPTID, DB_COLUMN_NAME_REGISTERID, DB_COLUMN_NAME_STOREID, --- 73,77 ---- public static final String DB_COLUMN_NAME_TALLIED = "tallied"; ! public static final String allColumnNames[] = {DB_COLUMN_NAME_RECEIPTID, DB_COLUMN_NAME_REGISTERID, DB_COLUMN_NAME_STOREID, *************** *** 353,356 **** --- 353,458 ---- /** + * Finds all receipts that has a date that is greater than the given one + * + * @jmx.managed-operation + * @param addedDate + * @param status + * @return + * @throws SQLException + */ + public Vector findReceiptsByDateGreaterThan(final java.util.Date addedDate, final java.lang.Integer status) + throws SQLException + { + StringBuffer sql = new StringBuffer("SELECT "); + for(int i = 0; i < allColumnNames.length; i++) + { + if(i > 0) + sql.append(","); + + sql.append(allColumnNames[i]); + } + sql.append(" FROM "); + sql.append(DB_TABLE_NAME); + sql.append(" WHERE "); + sql.append(DB_COLUMN_NAME_ADDEDDATE); + sql.append(" > ?"); + sql.append(" AND "); + sql.append(DB_COLUMN_NAME_RECEIPTSTATUS); + sql.append(" = ?"); + sql.append(" ORDER BY "); + sql.append(DB_COLUMN_NAME_ADDEDDATE); + sql.append(" DESC "); + + // prepare statement + PreparedStatement ps = getConnection().prepareStatement(sql.toString()); + try + { + ps.setDate(1, new java.sql.Date(addedDate.getTime())); + ps.setInt(2, status.intValue()); + + // execute statement + ResultSet rs = ps.executeQuery(); + Vector redPosRows = new Vector(); + // parse result set + while(rs.next()) + { + RedPOSRow row = new RedPOSRow(); + // get value for every column + for(int i = 0; i < allColumnNames.length; i++) + { + Object value = rs.getObject(allColumnNames[i]); + row.addValue(allColumnNames[i], value); + } + // add row to result + redPosRows.add(row); + } + // convert rows to ReceiptData object + Vector receiptDatas = new Vector(); + for(Iterator iter = redPosRows.iterator(); iter.hasNext();) + { + RedPOSRow row = (RedPOSRow)iter.next(); + receiptDatas.add(this.createReceiptData(row)); + } + + return receiptDatas; + } + finally + { + ps.close(); + } + } + + /** + * Finds all receipts that has the given id + * + * @jmx.managed-operation + * @param receiptId + * @return + * @throws SQLException + */ + public Vector findReceiptsById(final String receiptId) throws SQLException + { + // create column names for where clause + String where[] = {DB_COLUMN_NAME_RECEIPTID}; + // create values for where clause + Object values[] = {receiptId}; + // create column names for order by + String orderBy[] = {DB_COLUMN_NAME_RECEIPTID}; + // call select in table + Vector result = receiptTable.select(getConnection(), where, values, + orderBy, false, true); + + Vector receipts = new Vector(); + for(Iterator iter = result.iterator(); iter.hasNext();) + { + RedPOSRow row = (RedPOSRow)iter.next(); + receipts.add(createReceiptData(row)); + } + + return receipts; + } + + + /** * Removes receipt with given id from the database * Index: ReceiptSession.java =================================================================== RCS file: /cvsroot/redpos/RedPOS/src/org/redpos/client/receipt/ReceiptSession.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ReceiptSession.java 11 Jan 2005 11:32:12 -0000 1.2 --- ReceiptSession.java 11 Jan 2005 17:11:37 -0000 1.3 *************** *** 30,33 **** --- 30,34 ---- import java.io.PrintStream; import java.util.Calendar; + import java.util.Collection; import java.util.Date; import java.util.HashMap; *************** *** 46,49 **** --- 47,51 ---- import org.redpos.client.contract.properties.PropertiesUtility; import org.redpos.client.contract.receipt.DiscountReceiptRow; + import org.redpos.client.contract.receipt.FreetextReceiptRow; import org.redpos.client.contract.receipt.PaymentReceiptRow; import org.redpos.client.contract.receipt.ProductReceiptRow; *************** *** 210,214 **** /** * Returns receipt rows ! * * @jmx.managed-attribute * @return --- 212,216 ---- /** * Returns receipt rows ! * * @jmx.managed-attribute * @return *************** *** 257,261 **** throws ReceiptException { ! return newOfType(register, storeId, cashier, pricelistId, ReceiptConstants.TYPE_RECEIPT_RETURN); } --- 259,263 ---- throws ReceiptException { ! return newOfType(register, storeId, cashier, pricelistId, ReceiptConstants.TYPE_RECEIPT_RETURN); } *************** *** 274,278 **** throws ReceiptException { ! return newOfType(register, storeId, cashier, pricelistId, ReceiptConstants.TYPE_RECEIPT_COMPLAINT); } --- 276,280 ---- throws ReceiptException { ! return newOfType(register, storeId, cashier, pricelistId, ReceiptConstants.TYPE_RECEIPT_COMPLAINT); } *************** *** 291,297 **** throws ReceiptException { ! return newOfType(register, storeId, cashier, pricelistId, ReceiptConstants.TYPE_RECEIPT_CORRECTION); } /** --- 293,346 ---- throws ReceiptException { ! return newOfType(register, storeId, cashier, pricelistId, ReceiptConstants.TYPE_RECEIPT_CORRECTION); } + + /** + * Starts a reopened receipt + * + * @jmx.managed-operation + * @param receipt + * @return + * @throws ReceiptException + */ + public String newReopening(final ReceiptData receipt) throws ReceiptException + { + return newOfTypeReopen(receipt); + } + + /** + * Starts an existing receipt + * + * @jmx.managed-operation + * @param receipt + * @return + * @throws ReceiptException + */ + public String newOfTypeReopen(final ReceiptData receipt) throws ReceiptException + { + // init fields + addedDate = new Date(); + receiptId = receipt.getReceiptId(); + registerId = receipt.getRegisterId(); + this.storeId = receipt.getStoreId(); + this.cashier = receipt.getCashier(); + this.pricelistId = receipt.getPriceListId(); + receiptType = receipt.getReceiptType(); + receiptStatus = receipt.getReceiptStatus(); + + // create notification data + ReceiptNotificationData data = new ReceiptNotificationData(); + data.receiptId = receipt.getReceiptId(); + data.receiptType = receipt.getReceiptType(); + data.registerId = receipt.getRegisterId(); + data.cashier = receipt.getCashier(); + data.receiptDate = receipt.getAddedDate(); + + // send notification + fireNotification(ReceiptConstants.NOTIFICATION_RECEIPT_STARTED, data); + + return receiptId; + } /** *************** *** 307,311 **** public String newOfType(final String register, final String storeId, final String cashier, final String pricelistId, ! int type) throws ReceiptException { if(isStarted()) --- 356,360 ---- public String newOfType(final String register, final String storeId, final String cashier, final String pricelistId, ! int type ) throws ReceiptException { if(isStarted()) *************** *** 463,466 **** --- 512,523 ---- // count total updateTotal(); + + // send notification + fireNotification(ReceiptConstants.NOTIFICATION_RECEIPT_CLOSED, data); + + // clear attributes + reset(); + + } catch(Exception e) *************** *** 876,880 **** if(rr instanceof ProductReceiptRow && (receiptType == ReceiptConstants.TYPE_RECEIPT_COMPLAINT ! || receiptType == ReceiptConstants.TYPE_RECEIPT_RETURN || receiptType == ReceiptConstants.TYPE_RECEIPT_CORRECTION)) { // negate receipt row quantity cause of receipt type --- 933,938 ---- if(rr instanceof ProductReceiptRow && (receiptType == ReceiptConstants.TYPE_RECEIPT_COMPLAINT ! || receiptType == ReceiptConstants.TYPE_RECEIPT_RETURN ! || receiptType == ReceiptConstants.TYPE_RECEIPT_CORRECTION)) { // negate receipt row quantity cause of receipt type *************** *** 932,935 **** --- 990,1092 ---- /** + * Adds saved rows to reopened receipt + * + * @jmx.managed-operation + * @param receiptRowData + * @return completed ReceiptRow object + * @throws ReceiptException + */ + public ReceiptRow addRowToReopenedReceipt(Collection receiptRowData) throws ReceiptException + { + + // go through all rows + for(Iterator iter = receiptRowData.iterator(); iter.hasNext();) + { + ReceiptRowData element = (ReceiptRowData)iter.next(); + + if (element.getType() == (ReceiptConstants.TYPE_RECEIPTROW_PRODUCT) + && element.getStatus() == (ReceiptConstants.STATUS_RECEIPT_ACTIVE)) + { + ProductReceiptRow rr = new ProductReceiptRow(); + + rr.setAmount(element.getAmount()); + rr.setObject(element.getObject()); + rr.setOrder(element.getOrder()); + rr.setQuantity(element.getQuantity()); + rr.setReceiptId(element.getReceiptId()); + rr.setReference(element.getReference()); + rr.setStatus(element.getStatus()); + rr.setTaxAmount(element.getTaxAmount()); + rr.setTaxPercentage(element.getTaxPercentage()); + rr.setText(element.getText()); + rr.setType(element.getType()); + + // save row + rowsInCurrentReceipt.add(rr); + + // create notification data + ReceiptNotificationData data = new ReceiptNotificationData(); + data.receiptId = element.getReceiptId(); + data.receiptRow = rr; + + // send notification + fireNotification(ReceiptConstants.NOTIFICATION_RECEIPTROW_ADDED, data); + + // increase order counter + nextRowOrder = element.getOrder(); + + // select row + selectRow(rr); + + } + if (element.getType() == (ReceiptConstants.TYPE_RECEIPTROW_FREETEXT) + && element.getStatus() == (ReceiptConstants.STATUS_RECEIPT_ACTIVE)) + { + FreetextReceiptRow rr = new FreetextReceiptRow(element.getText()); + + // save row + rowsInCurrentReceipt.add(rr); + + // create notification data + ReceiptNotificationData data = new ReceiptNotificationData(); + data.receiptId = element.getReceiptId(); + data.receiptRow = rr; + + // send notification + fireNotification(ReceiptConstants.NOTIFICATION_RECEIPTROW_ADDED, data); + + // increase order counter + nextRowOrder = element.getOrder(); + + // select row + selectRow(rr); + + } + if (element.getType() != (ReceiptConstants.TYPE_RECEIPTROW_PRODUCT) + && element.getType() != (ReceiptConstants.TYPE_RECEIPTROW_FREETEXT)) + { + // increase order counter + nextRowOrder = element.getOrder(); + } + + if (element.getType() == (ReceiptConstants.TYPE_RECEIPTROW_PRODUCT) + || element.getType() == (ReceiptConstants.TYPE_RECEIPTROW_FREETEXT) + && element.getStatus() != (ReceiptConstants.STATUS_RECEIPT_ACTIVE)) + { + // increase order counter + nextRowOrder = element.getOrder(); + } + + } + // count total + updateTotal(); + + nextRowOrder++; + + ReceiptRow rr= null;; + return rr; + } + + /** * Updates given receipt row in the receipt * *************** *** 1145,1149 **** double totalDiscountPercent = 0; boolean paymentAdded = false; - // go through all receipt rows // --- 1302,1305 ---- *************** *** 1161,1165 **** else if(element instanceof ProductReceiptRow) { ! // Product receipt row, add amount to total Amount temp = (Amount)element.getAmount().clone(); temp.multiply(element.getQuantity()); --- 1317,1321 ---- else if(element instanceof ProductReceiptRow) { ! // Product receipt row, add amount to total Amount temp = (Amount)element.getAmount().clone(); temp.multiply(element.getQuantity()); *************** *** 1391,1395 **** { selectedRow = receiptRow; ! // create notification data ReceiptNotificationData data = new ReceiptNotificationData(); --- 1547,1551 ---- { selectedRow = receiptRow; ! // create notification data ReceiptNotificationData data = new ReceiptNotificationData(); |