-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathItemHelper.java
108 lines (84 loc) · 3.25 KB
/
ItemHelper.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
package com.intuit.developer.sampleapp.crud.helper;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import com.intuit.ipp.services.QueryResult;
import org.apache.commons.lang.RandomStringUtils;
import com.intuit.ipp.data.Account;
import com.intuit.ipp.data.Item;
import com.intuit.ipp.data.ItemTypeEnum;
import com.intuit.ipp.data.ReferenceType;
import com.intuit.ipp.exception.FMSException;
import com.intuit.ipp.services.DataService;
import org.apache.commons.lang.StringUtils;
/**
* @author dderose
*
*/
public final class ItemHelper {
private ItemHelper() {
}
public static Item getItemFields(DataService service) throws FMSException {
Item item = new Item();
item.setName("Item" + RandomStringUtils.randomAlphanumeric(5));
item.setActive(true);
item.setTaxable(false);
item.setUnitPrice(new BigDecimal("200"));
item.setType(ItemTypeEnum.SERVICE);
Account incomeAccount = AccountHelper.getIncomeBankAccount(service);
item.setIncomeAccountRef(AccountHelper.getAccountRef(incomeAccount));
item.setPurchaseCost(new BigDecimal("300"));
Account expenseAccount = AccountHelper.getExpenseBankAccount(service);
item.setExpenseAccountRef(AccountHelper.getAccountRef(expenseAccount));
item.setTrackQtyOnHand(false);
return item;
}
public static Item getInvItemFields(DataService service) throws FMSException {
Item invItem = new Item();
invItem.setName("Item" + RandomStringUtils.randomAlphanumeric(5));
invItem.setActive(true);
invItem.setType(ItemTypeEnum.INVENTORY);
invItem.setQtyOnHand(new BigDecimal(100));
invItem.setTrackQtyOnHand(true);
invItem.setInvStartDate(new Date());
String sql = "select * from account where Name = 'Cost of sales'";
QueryResult queryResult = service.executeQuery(sql);
Account account = (Account) queryResult.getEntities().get(0);
invItem.setExpenseAccountRef(AccountHelper.getAccountRef(account));
sql = "select * from account where Name = 'Sales of product income'";
queryResult = service.executeQuery(sql);
account = (Account) queryResult.getEntities().get(0);
invItem.setIncomeAccountRef(AccountHelper.getAccountRef(account));
invItem.setPurchaseCost(new BigDecimal("300"));
List<Account> accounts = (List<Account>) service.findAll(new Account());
for(int i=0; i<=accounts.size();i++) {
if(StringUtils.equals(accounts.get(i).getName(), "Inventory Asset")){
invItem.setAssetAccountRef(AccountHelper.getAccountRef(accounts.get(i)));
break;
}
}
return invItem;
}
public static Item getItem(DataService service) throws FMSException {
List<Item> items = (List<Item>) service.findAll(new Item());
if (!items.isEmpty()) {
return items.get(0);
}
return createItem(service);
}
public static Item getInventoryItem(DataService service) throws FMSException {
return createInventoryItem(service);
}
private static Item createItem(DataService service) throws FMSException {
return service.add(getItemFields(service));
}
private static Item createInventoryItem(DataService service) throws FMSException {
return service.add(getInvItemFields(service));
}
public static ReferenceType getItemRef(Item item) {
ReferenceType itemRef = new ReferenceType();
itemRef.setName(item.getName());
itemRef.setValue(item.getId());
return itemRef;
}
}