1
1
package com .intuit .developer .sampleapp .crud .helper ;
2
2
3
3
import java .math .BigDecimal ;
4
+ import java .util .Date ;
4
5
import java .util .List ;
5
6
7
+ import com .intuit .ipp .services .QueryResult ;
6
8
import org .apache .commons .lang .RandomStringUtils ;
7
9
8
10
import com .intuit .ipp .data .Account ;
11
13
import com .intuit .ipp .data .ReferenceType ;
12
14
import com .intuit .ipp .exception .FMSException ;
13
15
import com .intuit .ipp .services .DataService ;
16
+ import org .apache .commons .lang .StringUtils ;
14
17
15
18
/**
16
19
* @author dderose
19
22
public final class ItemHelper {
20
23
21
24
private ItemHelper () {
22
-
25
+
23
26
}
24
27
25
28
public static Item getItemFields (DataService service ) throws FMSException {
@@ -43,18 +46,58 @@ public static Item getItemFields(DataService service) throws FMSException {
43
46
return item ;
44
47
}
45
48
49
+ public static Item getInvItemFields (DataService service ) throws FMSException {
50
+
51
+ Item invItem = new Item ();
52
+ invItem .setName ("Item" + RandomStringUtils .randomAlphanumeric (5 ));
53
+ invItem .setActive (true );
54
+ invItem .setType (ItemTypeEnum .INVENTORY );
55
+ invItem .setQtyOnHand (new BigDecimal (100 ));
56
+ invItem .setTrackQtyOnHand (true );
57
+ invItem .setInvStartDate (new Date ());
58
+
59
+ String sql = "select * from account where Name = 'Cost of sales'" ;
60
+ QueryResult queryResult = service .executeQuery (sql );
61
+ Account account = (Account ) queryResult .getEntities ().get (0 );
62
+ invItem .setExpenseAccountRef (AccountHelper .getAccountRef (account ));
63
+
64
+ sql = "select * from account where Name = 'Sales of product income'" ;
65
+ queryResult = service .executeQuery (sql );
66
+ account = (Account ) queryResult .getEntities ().get (0 );
67
+ invItem .setIncomeAccountRef (AccountHelper .getAccountRef (account ));
68
+
69
+ invItem .setPurchaseCost (new BigDecimal ("300" ));
70
+
71
+ List <Account > accounts = (List <Account >) service .findAll (new Account ());
72
+ for (int i =0 ; i <=accounts .size ();i ++) {
73
+ if (StringUtils .equals (accounts .get (i ).getName (), "Inventory Asset" )){
74
+ invItem .setAssetAccountRef (AccountHelper .getAccountRef (accounts .get (i )));
75
+ break ;
76
+ }
77
+ }
78
+ return invItem ;
79
+ }
80
+
46
81
public static Item getItem (DataService service ) throws FMSException {
47
82
List <Item > items = (List <Item >) service .findAll (new Item ());
48
- if (!items .isEmpty ()) {
49
- return items .get (0 );
83
+ if (!items .isEmpty ()) {
84
+ return items .get (0 );
50
85
}
51
86
return createItem (service );
52
87
}
53
88
89
+ public static Item getInventoryItem (DataService service ) throws FMSException {
90
+ return createInventoryItem (service );
91
+ }
92
+
54
93
private static Item createItem (DataService service ) throws FMSException {
55
94
return service .add (getItemFields (service ));
56
95
}
57
96
97
+ private static Item createInventoryItem (DataService service ) throws FMSException {
98
+ return service .add (getInvItemFields (service ));
99
+ }
100
+
58
101
public static ReferenceType getItemRef (Item item ) {
59
102
ReferenceType itemRef = new ReferenceType ();
60
103
itemRef .setName (item .getName ());
0 commit comments