KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > ipanema > accounting > Account


1 /*
2  * Created on 27.10.2004
3  */

4 package com.nightlabs.ipanema.accounting;
5
6 import com.nightlabs.ipanema.trade.LegalEntity;
7 import com.nightlabs.ipanema.transfer.Anchor;
8 import com.nightlabs.ipanema.transfer.Transfer;
9
10 /**
11  * @author Marco Schulze - marco at nightlabs dot de
12  * @author Alexander Bieber <alex [AT] nightlabs [DOT] de>
13  *
14  * @jdo.persistence-capable
15  * identity-type = "application"
16  * persistence-capable-superclass = "com.nightlabs.ipanema.transfer.Anchor"
17  * detachable = "true"
18  *
19  * @jdo.inheritance strategy = "new-table"
20  */

21 public class Account extends Anchor
22 {
23     /**
24      * Used as midfix for the AnchorID of creditor-type accounts
25      */

26     public static final String JavaDoc PARTNER_ACCOUNT_TYPE_VENDOR = "Vendor";
27     /**
28      * Used as midfix for the AnchorID of debitor-type accounts
29      */

30     public static final String JavaDoc PARTNER_ACCOUNT_TYPE_CUSTOMER = "Customer";
31     
32     
33     private LegalEntity owner;
34     private Currency currency;
35     private long balance = 0;
36 // private Accountant accountant = null;
37
private boolean statistical;
38
39     protected Account() { }
40
41     public Account(String JavaDoc organisationID, String JavaDoc anchorID, Currency currency, boolean statistical) {
42         super(organisationID, anchorID);
43
44         if (currency == null)
45             throw new NullPointerException JavaDoc("currency must not be null!");
46
47         this.currency = currency;
48     }
49 // /**
50
// * The accountant who is responsible for MoneyTransfers from and to this Account. The Accountant
51
// * is able to split money and forward the amounts to other accounts.
52
// *
53
// * @return Returns the accountant.
54
// */
55
// public Accountant getAccountant()
56
// {
57
// return accountant;
58
// }
59
/**
60      * The balance in the smallest unit available in the Currency of this Account. This is e.g.
61      * Cent for EUR.
62      *
63      * @return Returns the balance.
64      */

65     public long getBalance()
66     {
67         return balance;
68     }
69     /**
70      * @return Returns the currency.
71      */

72     public Currency getCurrency()
73     {
74         return currency;
75     }
76     /**
77      * Whether or not this Account is statistical. If this account is statistical, money that is
78      * received here is not subtracted from the other "real" account. This means, basically, money
79      * in a statistical Account does not exist.
80      *
81      * @return Returns the statistical.
82      */

83     public boolean isStatistical()
84     {
85         return statistical;
86     }
87
88     /**
89      * Adjusts the balance according to the Transfer if it is a MoneyTransfer.
90      *
91      * @see com.nightlabs.ipanema.transfer.Anchor#internalBookTransfer(com.nightlabs.ipanema.transfer.Transfer)
92      */

93     protected void internalBookTransfer(Transfer transfer)
94     {
95         if (transfer == null)
96             throw new NullPointerException JavaDoc("transfer must not be null!");
97
98         if (!(transfer instanceof MoneyTransfer))
99             throw new ClassCastException JavaDoc("Account cannot book another Transfer (\""+transfer.getPrimaryKey()+"\" with type "+transfer.getClass().getName()+") than MoneyTransfer!");
100
101         MoneyTransfer mt = (MoneyTransfer) transfer;
102         
103         if (!mt.getCurrency().getCurrencyID().equals(this.getCurrency().getCurrencyID()))
104             throw new IllegalArgumentException JavaDoc("Attempt to book MoneyTransfer with different currency than currency of this Account!");
105         
106         boolean isDebit = mt.getFrom().getPrimaryKey().equals(this.getPrimaryKey());
107         
108         if (isDebit)
109             this.balance -= mt.getAmount();
110         else
111             this.balance += mt.getAmount();
112     }
113
114     public LegalEntity getOwner() {
115         return owner;
116     }
117     
118     public void setOwner(LegalEntity owner) {
119         this.owner = owner;
120     }
121 }
122
Popular Tags