001: /*
002: *
003: * JMoney - A Personal Finance Manager
004: * Copyright (c) 2004 Nigel Westbury <westbury@users.sourceforge.net>
005: *
006: *
007: * This program is free software; you can redistribute it and/or modify
008: * it under the terms of the GNU General Public License as published by
009: * the Free Software Foundation; either version 2 of the License, or
010: * (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
020: *
021: */
022:
023: package net.sf.jmoney.reconciliation;
024:
025: import java.util.Collection;
026: import java.util.Date;
027: import java.util.HashMap;
028: import java.util.Map;
029:
030: import net.sf.jmoney.model2.CurrencyAccount;
031: import net.sf.jmoney.model2.Entry;
032: import net.sf.jmoney.model2.PropertyAccessor;
033: import net.sf.jmoney.model2.Transaction;
034:
035: import org.eclipse.swt.widgets.Shell;
036:
037: /**
038: * An implementation of this interface must be provided by all
039: * extensions to the net.sf.jmoney.bankstatements extension point.
040: *
041: * @author Nigel Westbury
042: */
043: public interface IBankStatementSource {
044:
045: /**
046: * @param account
047: * the account into which the entries are being imported.
048: * Implementations of this method do not generally need to know
049: * the account because the entry data are returned in a
050: * collection of EntryData objects and it is up to the caller to
051: * merge the data into the datastore. However, there are
052: * instances where information from the account is needed. For
053: * example, knowing the currency of the account may affect the
054: * way amounts are interpreted or implementations may add
055: * properties to the account objects that affect the import
056: * process.
057: * @return a collection of EntryData objects if entries are available for
058: * importing, or null if the user cancelled the operation or if an
059: * error occured.
060: */
061: Collection<EntryData> importEntries(Shell shell,
062: CurrencyAccount account);
063:
064: class EntryData {
065: private Date clearedDate = null;
066: private Date valueDate = null;
067: private String check = null;
068: private String memo = null;
069: private String name = null;
070: private String payee = null;
071: private long amount = 0;
072: private String uniqueId = null;
073: private Map<PropertyAccessor, Object> propertyMap = new HashMap<PropertyAccessor, Object>();
074:
075: public void setClearedDate(Date clearedDate) {
076: this .clearedDate = clearedDate;
077: }
078:
079: public void setValueDate(Date valueDate) {
080: this .valueDate = valueDate;
081: }
082:
083: public void setCheck(String check) {
084: this .check = check;
085: }
086:
087: public void setMemo(String memo) {
088: this .memo = memo;
089: }
090:
091: public void setName(String name) {
092: this .name = name;
093: }
094:
095: public void setPayee(String payee) {
096: this .payee = payee;
097: }
098:
099: public void setAmount(long amount) {
100: this .amount = amount;
101: }
102:
103: public void setUniqueId(String uniqueId) {
104: this .uniqueId = uniqueId;
105: }
106:
107: public void setProperty(PropertyAccessor propertyAccessor,
108: Object value) {
109: propertyMap.put(propertyAccessor, value);
110: }
111:
112: /**
113: * This method is given a transaction with two entries.
114: * This method assigns the properties from the bank statement
115: * import to the properties in the transaction.
116: * <P>
117: * Other than the account and memo properties, no properties
118: * will have been set in the transaction before this method
119: * is called.
120: *
121: * @param transaction
122: * @param entry1 the entry in the bank account. The account
123: * property will already have been set
124: * @param entry2 the other entry, typically an entry in an
125: * income and expense account
126: */
127: public void assignPropertyValues(Transaction transaction,
128: Entry entry1, Entry entry2) {
129: if (valueDate == null) {
130: transaction.setDate(clearedDate);
131: entry1.setValuta(clearedDate);
132: } else {
133: transaction.setDate(valueDate);
134: entry1.setValuta(clearedDate);
135: }
136:
137: entry1.setCheck(check);
138: entry1.setPropertyValue(ReconciliationEntryInfo
139: .getUniqueIdAccessor(), uniqueId);
140:
141: entry1.setAmount(amount);
142: entry2.setAmount(-amount);
143: }
144:
145: @Override
146: public String toString() {
147: return "[a:" + amount + ";n:" + name + "]";
148: }
149:
150: /**
151: * Returns the text that is to be used for pattern matching.
152: * The patterns entered by the user are matched against the text
153: * returned by this method.
154: *
155: * @return the text which may be empty but must never be null
156: */
157: public String getTextToMatch() {
158: String text = "";
159: if (memo != null) {
160: text += "memo=" + memo;
161: }
162: if (name != null) {
163: text += "name=" + name;
164: }
165: if (payee != null) {
166: text += "payee=" + payee;
167: }
168: return text;
169: }
170:
171: public String getName() {
172: return name;
173: }
174:
175: /**
176: * The memo if no patterns match
177: */
178: public String getDefaultMemo() {
179: return memo == null ? (name == null ? payee : name) : memo;
180: }
181:
182: /**
183: * The description if no patterns match
184: */
185: public String getDefaultDescription() {
186: return payee == null ? (memo == null ? name : memo) : payee;
187: }
188: }
189: }
|