-- added fancybox 1.3.1 to project, initially for showing screenshots. See documentat...
[Bookkeeping.git] / src / com / interrupt / bookkeeping / journal / Entries.java
bloba91c64ddf823d1b78e78fa73389dd22305cbad4f
2 package com.interrupt.bookkeeping.journal;
5 import java.text.ParseException;
6 import java.text.SimpleDateFormat;
7 import java.util.ArrayList;
8 import java.util.Date;
9 import java.util.List;
10 import java.util.Iterator;
12 import org.apache.log4j.Logger;
14 import com.interrupt.bookkeeping.account.GCredit;
15 import com.interrupt.bookkeeping.account.GDebit;
16 import com.interrupt.bookkeeping.cc.bkell.Bkell;
17 import com.interrupt.bookkeeping.exception.EntryException;
18 import com.interrupt.bookkeeping.util.Util;
20 import com.interrupt.bob.base.IBob;
21 import com.interrupt.bob.base.IVisitor;
22 import com.interrupt.util.DateUtil;
24 public class Entries extends GEntries {
27 private Logger logger = Logger.getLogger(Entries.class);
29 public Entries() {
31 super();
33 public Entries(String id) {
35 super();
36 this.setId(id);
39 public void addEntry(Entry entry) {
40 this.addEntry((IEntry)entry);
42 public void addEntry(IEntry entry) {
44 if( !((Entry)entry).balances() ) {
46 logger.debug("Entries.addEntry: " + entry.toXML());
47 throw new EntryException("Debits must equal Credits");
50 super.addEntry(entry);
53 public boolean balances() {
55 List entryList = this.allEntry();
56 Iterator iter = entryList.iterator();
57 Entry next = null;
58 while(iter.hasNext()) {
60 next = (Entry)iter.next();
61 if(!next.balances()) {
62 return false;
65 return true;
70 /**
71 * Date Pattern of:
72 * "MM/dd/yyyy HH:mm:ss z"
75 public com.interrupt.bookkeeping.journal.IEntry findEntryByDate(String value) {
78 java.util.Iterator iter = _children.iterator();
79 com.interrupt.bookkeeping.journal.IEntry each = null;
80 while(iter.hasNext()) {
82 Object next = iter.next();
83 if(next instanceof com.interrupt.bookkeeping.journal.IEntry) {
85 each = (com.interrupt.bookkeeping.journal.IEntry)next;
87 String comparator = each.getDate();
90 if(DateUtil.equals(comparator, value)) {
92 //break;
93 return each;
97 return null;
101 public List listEntryBeforeDate(String value) {
104 List dateList = new ArrayList();
105 java.util.Iterator iter = _children.iterator();
106 com.interrupt.bookkeeping.journal.IEntry each = null;
107 while(iter.hasNext()) {
109 Object next = iter.next();
110 if(next instanceof com.interrupt.bookkeeping.journal.IEntry) {
112 each = (com.interrupt.bookkeeping.journal.IEntry)next;
113 String comparator = each.getDate();
114 if(DateUtil.before(comparator, value)) {
116 dateList.add(each);
120 return dateList;
123 public List listEntryAfterDate(String value) {
126 List dateList = new ArrayList();
127 java.util.Iterator iter = _children.iterator();
128 com.interrupt.bookkeeping.journal.IEntry each = null;
129 while(iter.hasNext()) {
131 Object next = iter.next();
132 if(next instanceof com.interrupt.bookkeeping.journal.IEntry) {
134 each = (com.interrupt.bookkeeping.journal.IEntry)next;
136 String comparator = each.getDate();
139 if(DateUtil.after(comparator, value)) {
141 dateList.add(each);
145 return dateList;
149 public static void main( String srgs[] ) {
152 String format_s = "MM/dd/yyyy HH:mm:ss z";
153 SimpleDateFormat dformat = new SimpleDateFormat( format_s );
155 Date date1 = null;
156 Date date2 = null;
157 try {
159 date1 = dformat.parse("08/15/2005 00:00:00 EST");
160 date2 = dformat.parse("09/15/2005 00:00:00 EST");
162 Logger.getLogger(Entries.class).debug( date1.before(date2) );
165 catch( ParseException e ) {
167 e.printStackTrace();