Skip to content

Commit c2504e8

Browse files
author
sramadass
committed
Adding Inventory Adjustment CRUD Operations
1 parent 7b15b3a commit c2504e8

File tree

7 files changed

+307
-5
lines changed

7 files changed

+307
-5
lines changed

Diff for: pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
<dependency>
88
<groupId>com.intuit.quickbooks-online</groupId>
99
<artifactId>ipp-v3-java-devkit</artifactId>
10-
<version>6.1.1</version>
10+
<version>6.4.1</version>
1111
</dependency>
1212
<dependency>
1313
<groupId>com.intuit.quickbooks-online</groupId>
1414
<artifactId>ipp-v3-java-data</artifactId>
15-
<version>6.1.1</version>
15+
<version>6.4.1</version>
1616
</dependency>
1717
<!-- for logging -->
1818
<dependency>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.intuit.developer.sampleapp.crud.entities.inventoryadjustment;
2+
3+
import com.intuit.developer.sampleapp.crud.helper.InventoryAdjustmentHelper;
4+
import com.intuit.developer.sampleapp.crud.qbo.DataServiceFactory;
5+
import com.intuit.ipp.data.Error;
6+
import com.intuit.ipp.data.InventoryAdjustment;
7+
import com.intuit.ipp.exception.FMSException;
8+
import com.intuit.ipp.services.DataService;
9+
import com.intuit.ipp.util.Logger;
10+
11+
import java.util.List;
12+
13+
/**
14+
* Demonstrates methods to create inventory adjustment
15+
* 1. Using mandatory fields
16+
* 2. Using all fields
17+
*
18+
* @author sramadass
19+
*
20+
*/
21+
public class InventoryAdjustmentCreate {
22+
23+
private static final org.slf4j.Logger LOG = Logger.getLogger();
24+
25+
public static void main(String[] args) {
26+
try {
27+
createInventoryAdjustment();
28+
} catch (Exception e) {
29+
LOG.error("Error during CRUD", e.getCause());
30+
}
31+
}
32+
33+
public static void createInventoryAdjustment() throws Exception {
34+
35+
try {
36+
37+
DataService service = DataServiceFactory.getDataService();
38+
39+
// add Inventory Adjustment
40+
InventoryAdjustment inventoryAdjustment = InventoryAdjustmentHelper.getInvAdjFields(service);
41+
InventoryAdjustment savedInventoryAdjustment = service.add(inventoryAdjustment);
42+
LOG.info("Inventory Adjustment created: " + savedInventoryAdjustment.getId());
43+
44+
} catch (FMSException e) {
45+
List<Error> list = e.getErrorList();
46+
list.forEach(error -> LOG.error("Error while calling entity add:: " + error.getMessage()));
47+
}
48+
49+
}
50+
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.intuit.developer.sampleapp.crud.entities.inventoryadjustment;
2+
3+
import com.intuit.developer.sampleapp.crud.helper.InventoryAdjustmentHelper;
4+
import com.intuit.developer.sampleapp.crud.qbo.DataServiceFactory;
5+
import com.intuit.ipp.data.Error;
6+
import com.intuit.ipp.data.InventoryAdjustment;
7+
import com.intuit.ipp.exception.FMSException;
8+
import com.intuit.ipp.services.DataService;
9+
import com.intuit.ipp.util.Logger;
10+
11+
import java.text.ParseException;
12+
import java.util.List;
13+
14+
/**
15+
* Demonstrates methods to delete inventory adjustment
16+
* Note: We'll create an entity first and then delete the same
17+
*
18+
* @author sramadass
19+
*
20+
*/
21+
public class InventoryAdjustmentDelete {
22+
23+
private static final org.slf4j.Logger LOG = Logger.getLogger();
24+
25+
public static void main(String[] args) {
26+
try {
27+
deleteInventoryAdjustment();
28+
} catch (Exception e) {
29+
LOG.error("Error during CRUD", e.getCause());
30+
}
31+
}
32+
33+
public static void deleteInventoryAdjustment() throws ParseException {
34+
35+
try {
36+
DataService service = DataServiceFactory.getDataService();
37+
38+
// add Inventory Adjustment
39+
InventoryAdjustment inventoryAdjustment = InventoryAdjustmentHelper.getInvAdjFields(service);
40+
InventoryAdjustment savedInventoryAdjustment = service.add(inventoryAdjustment);
41+
LOG.info("Inventory Adjustment created: " + savedInventoryAdjustment.getId());
42+
43+
// delete Inventory Adjustment
44+
InventoryAdjustment deletedInventoryAdjustment = service.delete(savedInventoryAdjustment);
45+
LOG.info("Inventory Adjustment deleted : " + deletedInventoryAdjustment.getId() + " status ::: " + deletedInventoryAdjustment.getStatus());
46+
47+
} catch (FMSException e) {
48+
List<Error> list = e.getErrorList();
49+
list.forEach(error -> LOG.error("Error while deleting entity :: " + error.getMessage()));
50+
}
51+
}
52+
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.intuit.developer.sampleapp.crud.entities.inventoryadjustment;
2+
3+
import com.intuit.developer.sampleapp.crud.helper.InventoryAdjustmentHelper;
4+
import com.intuit.developer.sampleapp.crud.qbo.DataServiceFactory;
5+
import com.intuit.ipp.data.Error;
6+
import com.intuit.ipp.data.InventoryAdjustment;
7+
import com.intuit.ipp.exception.FMSException;
8+
import com.intuit.ipp.services.DataService;
9+
import com.intuit.ipp.util.Logger;
10+
11+
import java.util.List;
12+
13+
/**
14+
* Demonstrates methods to read InventoryAdjustment using Inventory Adjustment id
15+
* Note: We'll create an entity first and then read the same
16+
*
17+
* @author sramadass
18+
*
19+
*/
20+
public class InventoryAdjustmentRead {
21+
22+
private static final org.slf4j.Logger LOG = Logger.getLogger();
23+
24+
public static void main(String[] args) {
25+
try {
26+
getInventoryAdjustment();
27+
} catch (Exception e) {
28+
LOG.error("Error during CRUD", e.getCause());
29+
}
30+
}
31+
32+
public static void getInventoryAdjustment() {
33+
34+
try {
35+
36+
DataService service = DataServiceFactory.getDataService();
37+
38+
// add Inventory Adjustment
39+
InventoryAdjustment inventoryAdjustment = InventoryAdjustmentHelper.getInvAdjFields(service);
40+
InventoryAdjustment savedInventoryAdjustment = service.add(inventoryAdjustment);
41+
LOG.info("Inventory Adjustment created: " + savedInventoryAdjustment.getId());
42+
43+
InventoryAdjustment inventoryAdjustmentOut = service.findById(savedInventoryAdjustment);
44+
LOG.info("Inventory Adjustment ID: " + inventoryAdjustmentOut.getId());
45+
46+
} catch (FMSException e) {
47+
List<Error> list = e.getErrorList();
48+
list.forEach(error -> LOG.error("Error while calling entity findById:: " + error.getMessage()));
49+
}
50+
51+
}
52+
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.intuit.developer.sampleapp.crud.entities.inventoryadjustment;
2+
3+
import com.intuit.developer.sampleapp.crud.helper.InventoryAdjustmentHelper;
4+
import com.intuit.developer.sampleapp.crud.qbo.DataServiceFactory;
5+
import com.intuit.ipp.data.Error;
6+
import com.intuit.ipp.data.InventoryAdjustment;
7+
import com.intuit.ipp.exception.FMSException;
8+
import com.intuit.ipp.services.DataService;
9+
import com.intuit.ipp.util.Logger;
10+
11+
import java.util.List;
12+
13+
/**
14+
* Demonstrates methods to update inventory adjustment
15+
* Sparse update with limited fields
16+
*
17+
* @author sramadass
18+
*
19+
*/
20+
public class InventoryAdjustmentUpdate {
21+
22+
private static final org.slf4j.Logger LOG = Logger.getLogger();
23+
24+
public static void main(String[] args) {
25+
try {
26+
updateInventoryAdjustment();
27+
} catch (Exception e) {
28+
LOG.error("Error during CRUD", e.getCause());
29+
}
30+
}
31+
32+
public static void updateInventoryAdjustment() {
33+
34+
try {
35+
36+
DataService service = DataServiceFactory.getDataService();
37+
38+
// create Inventory Adjustment
39+
InventoryAdjustment inventoryAdjustment = InventoryAdjustmentHelper.getInvAdjFields(service);
40+
InventoryAdjustment savedInventoryAdjustment = service.add(inventoryAdjustment);
41+
LOG.info("Inventory Adjustment created: " + savedInventoryAdjustment.getId() + " private note ::: " + savedInventoryAdjustment.getPrivateNote());
42+
43+
// sparse update Inventory Adjustment
44+
savedInventoryAdjustment.setSparse(true);
45+
savedInventoryAdjustment.setPrivateNote("Update Note");
46+
InventoryAdjustment updatedInventoryAdjustment = service.update(savedInventoryAdjustment);
47+
LOG.info("Inventory Adjustment sparse updated: " + updatedInventoryAdjustment.getId() + " private note ::: " + updatedInventoryAdjustment.getPrivateNote());
48+
49+
} catch (FMSException e) {
50+
List<Error> list = e.getErrorList();
51+
list.forEach(error -> LOG.error("Error while calling entity update:: " + error.getMessage()));
52+
}
53+
54+
}
55+
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.intuit.developer.sampleapp.crud.helper;
2+
3+
import com.intuit.ipp.data.*;
4+
import com.intuit.ipp.exception.FMSException;
5+
import com.intuit.ipp.services.DataService;
6+
7+
import java.math.BigDecimal;
8+
import java.util.ArrayList;
9+
import java.util.List;
10+
11+
/**
12+
* @author sramadass
13+
*
14+
*/
15+
public final class InventoryAdjustmentHelper {
16+
17+
private InventoryAdjustmentHelper() {
18+
19+
}
20+
21+
public static InventoryAdjustment getInvAdjFields(DataService service) throws FMSException {
22+
23+
InventoryAdjustment inventoryAdjustment = new InventoryAdjustment();
24+
25+
Account account = AccountHelper.getAssetAccount(service);
26+
inventoryAdjustment.setAdjustAccountRef(AccountHelper.getAccountRef(account));
27+
28+
inventoryAdjustment.setPrivateNote("Memo 1");
29+
30+
List<Line> invLine = new ArrayList<Line>();
31+
Line line = new Line();
32+
line.setDetailType(LineDetailTypeEnum.ITEM_ADJUSTMENT_LINE_DETAIL);
33+
34+
ItemAdjustmentLineDetail itemAdjustmentLineDetail = new ItemAdjustmentLineDetail();
35+
itemAdjustmentLineDetail.setQtyDiff(new BigDecimal(3));
36+
37+
Item invItem = ItemHelper.getInventoryItem(service);
38+
itemAdjustmentLineDetail.setItemRef(ItemHelper.getItemRef(invItem));
39+
line.setItemAdjustmentLineDetail(itemAdjustmentLineDetail);
40+
invLine.add(line);
41+
inventoryAdjustment.setLine(invLine);
42+
43+
return inventoryAdjustment;
44+
}
45+
46+
}

Diff for: src/main/java/com/intuit/developer/sampleapp/crud/helper/ItemHelper.java

+46-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.intuit.developer.sampleapp.crud.helper;
22

33
import java.math.BigDecimal;
4+
import java.util.Date;
45
import java.util.List;
56

7+
import com.intuit.ipp.services.QueryResult;
68
import org.apache.commons.lang.RandomStringUtils;
79

810
import com.intuit.ipp.data.Account;
@@ -11,6 +13,7 @@
1113
import com.intuit.ipp.data.ReferenceType;
1214
import com.intuit.ipp.exception.FMSException;
1315
import com.intuit.ipp.services.DataService;
16+
import org.apache.commons.lang.StringUtils;
1417

1518
/**
1619
* @author dderose
@@ -19,7 +22,7 @@
1922
public final class ItemHelper {
2023

2124
private ItemHelper() {
22-
25+
2326
}
2427

2528
public static Item getItemFields(DataService service) throws FMSException {
@@ -43,18 +46,58 @@ public static Item getItemFields(DataService service) throws FMSException {
4346
return item;
4447
}
4548

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+
4681
public static Item getItem(DataService service) throws FMSException {
4782
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);
5085
}
5186
return createItem(service);
5287
}
5388

89+
public static Item getInventoryItem(DataService service) throws FMSException {
90+
return createInventoryItem(service);
91+
}
92+
5493
private static Item createItem(DataService service) throws FMSException {
5594
return service.add(getItemFields(service));
5695
}
5796

97+
private static Item createInventoryItem(DataService service) throws FMSException {
98+
return service.add(getInvItemFields(service));
99+
}
100+
58101
public static ReferenceType getItemRef(Item item) {
59102
ReferenceType itemRef = new ReferenceType();
60103
itemRef.setName(item.getName());

0 commit comments

Comments
 (0)