-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathAccountHelper.java
269 lines (236 loc) · 9.67 KB
/
AccountHelper.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
package com.intuit.developer.sampleapp.crud.helper;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.lang.RandomStringUtils;
import com.intuit.ipp.data.Account;
import com.intuit.ipp.data.AccountClassificationEnum;
import com.intuit.ipp.data.AccountSubTypeEnum;
import com.intuit.ipp.data.AccountTypeEnum;
import com.intuit.ipp.data.ReferenceType;
import com.intuit.ipp.exception.FMSException;
import com.intuit.ipp.services.DataService;
/**
* @author dderose
*
*/
public final class AccountHelper {
private AccountHelper() {
}
public static Account createBankAccount(DataService service) throws FMSException, ParseException {
return service.add(getBankAccountFields());
}
public static Account getBankAccountFields() throws FMSException {
Account account = new Account();
account.setName("Ba" + RandomStringUtils.randomAlphanumeric(7));
account.setSubAccount(false);
account.setFullyQualifiedName(account.getName());
account.setActive(true);
account.setClassification(AccountClassificationEnum.ASSET);
account.setAccountType(AccountTypeEnum.BANK);
account.setCurrentBalance(new BigDecimal("0"));
account.setCurrentBalanceWithSubAccounts(new BigDecimal("0"));
account.setTxnLocationType("FranceOverseas");
account.setAcctNum("B" + RandomStringUtils.randomAlphanumeric(6));
return account;
}
public static ReferenceType getAccountRef(Account account) {
ReferenceType accountRef = new ReferenceType();
accountRef.setName(account.getName());
accountRef.setValue(account.getId());
return accountRef;
}
public static Account getAssetAccount(DataService service) throws FMSException{
List<Account> accounts = (List<Account>) service.findAll(new Account());
if (!accounts.isEmpty()) {
Iterator<Account> itr = accounts.iterator();
while (itr.hasNext()) {
Account account = itr.next();
if (account.getAccountType().equals(AccountTypeEnum.OTHER_CURRENT_ASSET)) {
return account;
}
}
}
return createOtherCurrentAssetAccount(service);
}
private static Account createOtherCurrentAssetAccount(DataService service) throws FMSException {
return service.add(getOtherCurrentAssetAccountFields());
}
public static Account getOtherCurrentAssetAccountFields() throws FMSException {
Account account = new Account();
account.setName("Other CurrentAsse" + RandomStringUtils.randomAlphanumeric(5));
account.setSubAccount(false);
account.setFullyQualifiedName(account.getName());
account.setActive(true);
account.setClassification(AccountClassificationEnum.ASSET);
account.setAccountType(AccountTypeEnum.OTHER_CURRENT_ASSET);
account.setAccountSubType(AccountSubTypeEnum.OTHER_CURRENT_ASSETS.value());
account.setCurrentBalance(new BigDecimal("0"));
account.setCurrentBalanceWithSubAccounts(new BigDecimal("0"));
ReferenceType currencyRef = new ReferenceType();
currencyRef.setName("United States Dollar");
currencyRef.setValue("USD");
account.setCurrencyRef(currencyRef);
return account;
}
public static Account getCashBankAccount(DataService service) throws FMSException, ParseException {
List<Account> accounts = (List<Account>) service.findAll(new Account());
if (!accounts.isEmpty()) {
Iterator<Account> itr = accounts.iterator();
while (itr.hasNext()) {
Account account = itr.next();
if (account.getAccountType().equals(AccountTypeEnum.BANK)) {
return account;
}
}
}
return createBankAccount(service);
}
public static Account getCreditCardBankAccount(DataService service) throws FMSException {
List<Account> accounts = (List<Account>) service.findAll(new Account());
if (!accounts.isEmpty()) {
Iterator<Account> itr = accounts.iterator();
while (itr.hasNext()) {
Account account = itr.next();
if (account.getAccountType().equals(AccountTypeEnum.CREDIT_CARD)) {
return account;
}
}
}
return createCreditCardBankAccount(service);
}
private static Account createCreditCardBankAccount(DataService service) throws FMSException {
return service.add(getCreditCardBankAccountFields());
}
public static Account getCreditCardBankAccountFields() throws FMSException {
Account account = new Account();
account.setName("CreditCa" + RandomStringUtils.randomAlphabetic(5));
account.setSubAccount(false);
account.setFullyQualifiedName(account.getName());
account.setActive(true);
account.setClassification(AccountClassificationEnum.LIABILITY);
account.setAccountType(AccountTypeEnum.CREDIT_CARD);
account.setAccountSubType(AccountSubTypeEnum.CREDIT_CARD.value());
account.setCurrentBalance(new BigDecimal("0"));
account.setCurrentBalanceWithSubAccounts(new BigDecimal("0"));
ReferenceType currencyRef = new ReferenceType();
currencyRef.setName("United States Dollar");
currencyRef.setValue("USD");
account.setCurrencyRef(currencyRef);
return account;
}
public static Account getIncomeBankAccount(DataService service) throws FMSException {
List<Account> accounts = (List<Account>) service.findAll(new Account());
if (!accounts.isEmpty()) {
Iterator<Account> itr = accounts.iterator();
while (itr.hasNext()) {
Account account = itr.next();
if (account.getAccountType().equals(AccountTypeEnum.INCOME)) {
return account;
}
}
}
return createIncomeBankAccount(service);
}
private static Account createIncomeBankAccount(DataService service) throws FMSException {
return service.add(getIncomeBankAccountFields());
}
public static Account getIncomeBankAccountFields() throws FMSException {
Account account = new Account();
account.setName("Incom" + RandomStringUtils.randomAlphabetic(5));
account.setSubAccount(false);
account.setFullyQualifiedName(account.getName());
account.setActive(true);
account.setClassification(AccountClassificationEnum.REVENUE);
account.setAccountType(AccountTypeEnum.INCOME);
account.setAccountSubType(AccountSubTypeEnum.SERVICE_FEE_INCOME.value());
account.setCurrentBalance(new BigDecimal("0"));
account.setCurrentBalanceWithSubAccounts(new BigDecimal("0"));
ReferenceType currencyRef = new ReferenceType();
currencyRef.setName("United States Dollar");
currencyRef.setValue("USD");
account.setCurrencyRef(currencyRef);
return account;
}
public static Account getExpenseBankAccount(DataService service) throws FMSException {
List<Account> accounts = (List<Account>) service.findAll(new Account());
if (!accounts.isEmpty()) {
Iterator<Account> itr = accounts.iterator();
while (itr.hasNext()) {
Account account = itr.next();
if (account.getAccountType().equals(AccountTypeEnum.EXPENSE)) {
return account;
}
}
}
return createExpenseBankAccount(service);
}
private static Account createExpenseBankAccount(DataService service) throws FMSException {
return service.add(getExpenseBankAccountFields());
}
public static Account getExpenseBankAccountFields() throws FMSException {
Account account = new Account();
account.setName("Expense" + RandomStringUtils.randomAlphabetic(5));
account.setSubAccount(false);
account.setFullyQualifiedName(account.getName());
account.setActive(true);
account.setClassification(AccountClassificationEnum.EXPENSE);
account.setAccountType(AccountTypeEnum.EXPENSE);
account.setAccountSubType(AccountSubTypeEnum.ADVERTISING_PROMOTIONAL.value());
account.setCurrentBalance(new BigDecimal("0"));
account.setCurrentBalanceWithSubAccounts(new BigDecimal("0"));
ReferenceType currencyRef = new ReferenceType();
currencyRef.setName("United States Dollar");
currencyRef.setValue("USD");
account.setCurrencyRef(currencyRef);
return account;
}
public static Account getLiabilityBankAccount(DataService service) throws FMSException {
List<Account> accounts = (List<Account>) service.findAll(new Account());
if (!accounts.isEmpty()) {
Iterator<Account> itr = accounts.iterator();
while (itr.hasNext()) {
Account account = itr.next();
if (account.getAccountType().equals(AccountTypeEnum.ACCOUNTS_PAYABLE)
&& account.getClassification().equals(AccountClassificationEnum.LIABILITY)) {
return account;
}
}
}
return createLiabilityBankAccount(service);
}
private static Account createLiabilityBankAccount(DataService service) throws FMSException {
return service.add(getLiabilityBankAccountFields());
}
public static Account getLiabilityBankAccountFields() throws FMSException {
Account account = new Account();
account.setName("Equity" + RandomStringUtils.randomAlphabetic(5));
account.setSubAccount(false);
account.setFullyQualifiedName(account.getName());
account.setActive(true);
account.setClassification(AccountClassificationEnum.LIABILITY);
account.setAccountType(AccountTypeEnum.ACCOUNTS_PAYABLE);
account.setAccountSubType(AccountSubTypeEnum.ACCOUNTS_PAYABLE.value());
account.setCurrentBalance(new BigDecimal("3000"));
account.setCurrentBalanceWithSubAccounts(new BigDecimal("3000"));
ReferenceType currencyRef = new ReferenceType();
currencyRef.setName("United States Dollar");
currencyRef.setValue("USD");
account.setCurrencyRef(currencyRef);
return account;
}
public static Account getCheckBankAccount(DataService service) throws FMSException, ParseException {
List<Account> accounts = (List<Account>) service.findAll(new Account());
if (!accounts.isEmpty()) {
Iterator<Account> itr = accounts.iterator();
while (itr.hasNext()) {
Account account = itr.next();
if (account.getAccountType().equals(AccountTypeEnum.BANK)) {
return account;
}
}
}
return createBankAccount(service);
}
}