Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<dependency>
<groupId>com.intuit.quickbooks-online</groupId>
<artifactId>ipp-v3-java-devkit</artifactId>
<version>6.1.1</version>
<version>6.4.1</version>
</dependency>
<dependency>
<groupId>com.intuit.quickbooks-online</groupId>
<artifactId>ipp-v3-java-data</artifactId>
<version>6.1.1</version>
<version>6.4.1</version>
</dependency>
<!-- for logging -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.intuit.developer.sampleapp.crud.entities.inventoryadjustment;

import com.intuit.developer.sampleapp.crud.helper.InventoryAdjustmentHelper;
import com.intuit.developer.sampleapp.crud.qbo.DataServiceFactory;
import com.intuit.ipp.data.Error;
import com.intuit.ipp.data.InventoryAdjustment;
import com.intuit.ipp.exception.FMSException;
import com.intuit.ipp.services.DataService;
import com.intuit.ipp.util.Logger;

import java.util.List;

/**
* Demonstrates methods to create inventory adjustment
* 1. Using mandatory fields
* 2. Using all fields
*
* @author sramadass
*
*/
public class InventoryAdjustmentCreate {

private static final org.slf4j.Logger LOG = Logger.getLogger();

public static void main(String[] args) {
try {
createInventoryAdjustment();
} catch (Exception e) {
LOG.error("Error during CRUD", e.getCause());
}
}

public static void createInventoryAdjustment() throws Exception {

try {

DataService service = DataServiceFactory.getDataService();

// add Inventory Adjustment
InventoryAdjustment inventoryAdjustment = InventoryAdjustmentHelper.getInvAdjFields(service);
InventoryAdjustment savedInventoryAdjustment = service.add(inventoryAdjustment);
LOG.info("Inventory Adjustment created: " + savedInventoryAdjustment.getId());

} catch (FMSException e) {
List<Error> list = e.getErrorList();
list.forEach(error -> LOG.error("Error while calling entity add:: " + error.getMessage()));
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.intuit.developer.sampleapp.crud.entities.inventoryadjustment;

import com.intuit.developer.sampleapp.crud.helper.InventoryAdjustmentHelper;
import com.intuit.developer.sampleapp.crud.qbo.DataServiceFactory;
import com.intuit.ipp.data.Error;
import com.intuit.ipp.data.InventoryAdjustment;
import com.intuit.ipp.exception.FMSException;
import com.intuit.ipp.services.DataService;
import com.intuit.ipp.util.Logger;

import java.text.ParseException;
import java.util.List;

/**
* Demonstrates methods to delete inventory adjustment
* Note: We'll create an entity first and then delete the same
*
* @author sramadass
*
*/
public class InventoryAdjustmentDelete {

private static final org.slf4j.Logger LOG = Logger.getLogger();

public static void main(String[] args) {
try {
deleteInventoryAdjustment();
} catch (Exception e) {
LOG.error("Error during CRUD", e.getCause());
}
}

public static void deleteInventoryAdjustment() throws ParseException {

try {
DataService service = DataServiceFactory.getDataService();

// add Inventory Adjustment
InventoryAdjustment inventoryAdjustment = InventoryAdjustmentHelper.getInvAdjFields(service);
InventoryAdjustment savedInventoryAdjustment = service.add(inventoryAdjustment);
LOG.info("Inventory Adjustment created: " + savedInventoryAdjustment.getId());

// delete Inventory Adjustment
InventoryAdjustment deletedInventoryAdjustment = service.delete(savedInventoryAdjustment);
LOG.info("Inventory Adjustment deleted : " + deletedInventoryAdjustment.getId() + " status ::: " + deletedInventoryAdjustment.getStatus());

} catch (FMSException e) {
List<Error> list = e.getErrorList();
list.forEach(error -> LOG.error("Error while deleting entity :: " + error.getMessage()));
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.intuit.developer.sampleapp.crud.entities.inventoryadjustment;

import com.intuit.developer.sampleapp.crud.helper.InventoryAdjustmentHelper;
import com.intuit.developer.sampleapp.crud.qbo.DataServiceFactory;
import com.intuit.ipp.data.Error;
import com.intuit.ipp.data.InventoryAdjustment;
import com.intuit.ipp.exception.FMSException;
import com.intuit.ipp.services.DataService;
import com.intuit.ipp.util.Logger;

import java.util.List;

/**
* Demonstrates methods to read InventoryAdjustment using Inventory Adjustment id
* Note: We'll create an entity first and then read the same
*
* @author sramadass
*
*/
public class InventoryAdjustmentRead {

private static final org.slf4j.Logger LOG = Logger.getLogger();

public static void main(String[] args) {
try {
getInventoryAdjustment();
} catch (Exception e) {
LOG.error("Error during CRUD", e.getCause());
}
}

public static void getInventoryAdjustment() {

try {

DataService service = DataServiceFactory.getDataService();

// add Inventory Adjustment
InventoryAdjustment inventoryAdjustment = InventoryAdjustmentHelper.getInvAdjFields(service);
InventoryAdjustment savedInventoryAdjustment = service.add(inventoryAdjustment);
LOG.info("Inventory Adjustment created: " + savedInventoryAdjustment.getId());

InventoryAdjustment inventoryAdjustmentOut = service.findById(savedInventoryAdjustment);
LOG.info("Inventory Adjustment ID: " + inventoryAdjustmentOut.getId());

} catch (FMSException e) {
List<Error> list = e.getErrorList();
list.forEach(error -> LOG.error("Error while calling entity findById:: " + error.getMessage()));
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.intuit.developer.sampleapp.crud.entities.inventoryadjustment;

import com.intuit.developer.sampleapp.crud.helper.InventoryAdjustmentHelper;
import com.intuit.developer.sampleapp.crud.qbo.DataServiceFactory;
import com.intuit.ipp.data.Error;
import com.intuit.ipp.data.InventoryAdjustment;
import com.intuit.ipp.exception.FMSException;
import com.intuit.ipp.services.DataService;
import com.intuit.ipp.util.Logger;

import java.util.List;

/**
* Demonstrates methods to update inventory adjustment
* Sparse update with limited fields
*
* @author sramadass
*
*/
public class InventoryAdjustmentUpdate {

private static final org.slf4j.Logger LOG = Logger.getLogger();

public static void main(String[] args) {
try {
updateInventoryAdjustment();
} catch (Exception e) {
LOG.error("Error during CRUD", e.getCause());
}
}

public static void updateInventoryAdjustment() {

try {

DataService service = DataServiceFactory.getDataService();

// create Inventory Adjustment
InventoryAdjustment inventoryAdjustment = InventoryAdjustmentHelper.getInvAdjFields(service);
InventoryAdjustment savedInventoryAdjustment = service.add(inventoryAdjustment);
LOG.info("Inventory Adjustment created: " + savedInventoryAdjustment.getId() + " private note ::: " + savedInventoryAdjustment.getPrivateNote());

// sparse update Inventory Adjustment
savedInventoryAdjustment.setSparse(true);
savedInventoryAdjustment.setPrivateNote("Update Note");
InventoryAdjustment updatedInventoryAdjustment = service.update(savedInventoryAdjustment);
LOG.info("Inventory Adjustment sparse updated: " + updatedInventoryAdjustment.getId() + " private note ::: " + updatedInventoryAdjustment.getPrivateNote());

} catch (FMSException e) {
List<Error> list = e.getErrorList();
list.forEach(error -> LOG.error("Error while calling entity update:: " + error.getMessage()));
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.intuit.developer.sampleapp.crud.helper;

import com.intuit.ipp.data.*;
import com.intuit.ipp.exception.FMSException;
import com.intuit.ipp.services.DataService;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
* @author sramadass
*
*/
public final class InventoryAdjustmentHelper {

private InventoryAdjustmentHelper() {

}

public static InventoryAdjustment getInvAdjFields(DataService service) throws FMSException {

InventoryAdjustment inventoryAdjustment = new InventoryAdjustment();

Account account = AccountHelper.getAssetAccount(service);
inventoryAdjustment.setAdjustAccountRef(AccountHelper.getAccountRef(account));

inventoryAdjustment.setPrivateNote("Memo 1");

List<Line> invLine = new ArrayList<Line>();
Line line = new Line();
line.setDetailType(LineDetailTypeEnum.ITEM_ADJUSTMENT_LINE_DETAIL);

ItemAdjustmentLineDetail itemAdjustmentLineDetail = new ItemAdjustmentLineDetail();
itemAdjustmentLineDetail.setQtyDiff(new BigDecimal(3));

Item invItem = ItemHelper.getInventoryItem(service);
itemAdjustmentLineDetail.setItemRef(ItemHelper.getItemRef(invItem));
line.setItemAdjustmentLineDetail(itemAdjustmentLineDetail);
invLine.add(line);
inventoryAdjustment.setLine(invLine);

return inventoryAdjustment;
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
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;
Expand All @@ -11,6 +13,7 @@
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
Expand All @@ -19,7 +22,7 @@
public final class ItemHelper {

private ItemHelper() {

}

public static Item getItemFields(DataService service) throws FMSException {
Expand All @@ -43,18 +46,58 @@ public static Item getItemFields(DataService service) throws FMSException {
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);
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());
Expand Down