Skip to content

Commit 1260244

Browse files
committed
add AST samples
1 parent 65cefed commit 1260244

File tree

6 files changed

+258
-4
lines changed

6 files changed

+258
-4
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
<groupId>com.intuit.quickbooks-online</groupId>
99
<artifactId>ipp-v3-java-devkit</artifactId>
1010
<classifier>jar-with-dependencies</classifier>
11-
<version>4.0.2</version>
11+
<version>4.0.5</version>
1212
</dependency>
1313
<dependency>
1414
<groupId>com.intuit.quickbooks-online</groupId>
1515
<artifactId>ipp-v3-java-data</artifactId>
16-
<version>4.0.2</version>
16+
<version>4.0.5</version>
1717
</dependency>
1818
<!-- for logging -->
1919
<dependency>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package com.intuit.developer.sampleapp.crud.entities.invoice;
2+
3+
import java.text.ParseException;
4+
import java.util.List;
5+
6+
import com.intuit.developer.sampleapp.crud.helper.InvoiceHelper;
7+
import com.intuit.developer.sampleapp.crud.qbo.DataServiceFactory;
8+
import com.intuit.ipp.data.Error;
9+
import com.intuit.ipp.data.Invoice;
10+
import com.intuit.ipp.data.Preferences;
11+
import com.intuit.ipp.exception.FMSException;
12+
import com.intuit.ipp.services.DataService;
13+
import com.intuit.ipp.services.QueryResult;
14+
import com.intuit.ipp.util.Logger;
15+
16+
/**
17+
* Demonstrates methods to create invoice for AST company
18+
* 1. Check prefrences to determine if company is AST enabled
19+
* 2. Create dummy tax code if needed
20+
* 3. Create invoice
21+
*
22+
* @author dderose
23+
*
24+
*/
25+
public class ASTInvoiceCreate {
26+
27+
private static final org.slf4j.Logger LOG = Logger.getLogger();
28+
29+
public static void main(String[] args) {
30+
try {
31+
createInvoice();
32+
} catch (Exception e) {
33+
LOG.error("Error during CRUD", e.getCause());
34+
}
35+
}
36+
37+
public static void createInvoice() throws Exception {
38+
39+
try {
40+
41+
DataService service = DataServiceFactory.getDataService();
42+
43+
//check preferences to determine if company is AST enabled
44+
if(isASTEnabledCompany()) {
45+
46+
// add invoice
47+
Invoice invoice = InvoiceHelper.getASTInvoiceFields(service);
48+
Invoice savedInvoice = service.add(invoice);
49+
LOG.info("Invoice created: " + savedInvoice.getId() + " ::invoice total tax: " + savedInvoice.getTxnTaxDetail().getTotalTax());
50+
}
51+
} catch (FMSException e) {
52+
List<Error> list = e.getErrorList();
53+
list.forEach(error -> LOG.error("Error while calling entity add:: " + error.getMessage()));
54+
}
55+
56+
}
57+
58+
private static boolean isASTEnabledCompany() throws FMSException, ParseException {
59+
60+
try {
61+
62+
DataService service = DataServiceFactory.getDataService();
63+
64+
// get all preferences
65+
String sql = "select * from preferences";
66+
QueryResult queryResult = service.executeQuery(sql);
67+
if (!queryResult.getEntities().isEmpty() && queryResult.getEntities().size() > 0) {
68+
Preferences preferences = (Preferences) queryResult.getEntities().get(0);
69+
if(preferences.getTaxPrefs().isPartnerTaxEnabled()) {
70+
return true;
71+
}
72+
LOG.info("Preferences -> SalesFormsPrefs - > DefaultCustomerMessage: " + preferences.getSalesFormsPrefs().getDefaultCustomerMessage());
73+
}
74+
75+
} catch (FMSException e) {
76+
List<Error> list = e.getErrorList();
77+
list.forEach(error -> LOG.error("Error while calling executeQuery :: " + error.getMessage()));
78+
}
79+
return false;
80+
81+
}
82+
83+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package com.intuit.developer.sampleapp.crud.entities.invoice;
2+
3+
import java.text.ParseException;
4+
import java.util.List;
5+
6+
import com.intuit.developer.sampleapp.crud.helper.InvoiceHelper;
7+
import com.intuit.developer.sampleapp.crud.qbo.DataServiceFactory;
8+
import com.intuit.ipp.data.Error;
9+
import com.intuit.ipp.data.Invoice;
10+
import com.intuit.ipp.data.Preferences;
11+
import com.intuit.ipp.exception.FMSException;
12+
import com.intuit.ipp.services.DataService;
13+
import com.intuit.ipp.services.QueryResult;
14+
import com.intuit.ipp.util.Logger;
15+
16+
/**
17+
* Demonstrates methods to create invoice for AST company
18+
* 1. Check prefrences to determine if company is AST enabled
19+
* 2. Create invoice by overriding tax amount
20+
*
21+
* @author dderose
22+
*
23+
*/
24+
public class ASTOverrideInvoiceCreate {
25+
26+
private static final org.slf4j.Logger LOG = Logger.getLogger();
27+
28+
public static void main(String[] args) {
29+
try {
30+
createInvoice();
31+
} catch (Exception e) {
32+
LOG.error("Error during CRUD", e.getCause());
33+
}
34+
}
35+
36+
public static void createInvoice() throws Exception {
37+
38+
try {
39+
40+
DataService service = DataServiceFactory.getDataService();
41+
42+
//check preferences to determine if company is AST enabled
43+
if(isASTEnabledCompany()) {
44+
45+
// add invoice
46+
Invoice invoice = InvoiceHelper.getASTOverrideFields(service);
47+
Invoice savedInvoice = service.add(invoice);
48+
LOG.info("Invoice created: " + savedInvoice.getId() + " ::invoice total tax: " + savedInvoice.getTxnTaxDetail().getTotalTax());
49+
}
50+
} catch (FMSException e) {
51+
List<Error> list = e.getErrorList();
52+
list.forEach(error -> LOG.error("Error while calling entity add:: " + error.getMessage()));
53+
}
54+
55+
}
56+
57+
private static boolean isASTEnabledCompany() throws FMSException, ParseException {
58+
59+
try {
60+
61+
DataService service = DataServiceFactory.getDataService();
62+
63+
// get all preferences
64+
String sql = "select * from preferences";
65+
QueryResult queryResult = service.executeQuery(sql);
66+
if (!queryResult.getEntities().isEmpty() && queryResult.getEntities().size() > 0) {
67+
Preferences preferences = (Preferences) queryResult.getEntities().get(0);
68+
if(preferences.getTaxPrefs().isPartnerTaxEnabled()) {
69+
return true;
70+
}
71+
LOG.info("Preferences -> SalesFormsPrefs - > DefaultCustomerMessage: " + preferences.getSalesFormsPrefs().getDefaultCustomerMessage());
72+
}
73+
74+
} catch (FMSException e) {
75+
List<Error> list = e.getErrorList();
76+
list.forEach(error -> LOG.error("Error while calling executeQuery :: " + error.getMessage()));
77+
}
78+
return false;
79+
80+
}
81+
82+
}

src/main/java/com/intuit/developer/sampleapp/crud/helper/Address.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,12 @@ public static WebSiteAddress getWebSiteAddress() {
3030
webSite.setTag("Business");
3131
return webSite;
3232
}
33+
34+
public static PhysicalAddress getAddressForAST() {
35+
PhysicalAddress billingAdd = new PhysicalAddress();
36+
billingAdd.setLine1("2700 Coast Ave");
37+
billingAdd.setLine2("MountainView, CA 94043");
38+
return billingAdd;
39+
}
3340

3441
}

src/main/java/com/intuit/developer/sampleapp/crud/helper/InvoiceHelper.java

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ public static Invoice getInvoiceFields(DataService service) throws FMSException,
5454

5555
List<Line> invLine = new ArrayList<Line>();
5656
Line line = new Line();
57-
line.setDescription("test");
57+
line.setDescription("New test (14.48mm)\nGiftBox: Red Heart Gift Box [ £ 3.00]");
5858
line.setAmount(new BigDecimal("10000"));
5959
line.setDetailType(LineDetailTypeEnum.SALES_ITEM_LINE_DETAIL);
6060

61+
6162
SalesItemLineDetail silDetails = new SalesItemLineDetail();
6263

6364
Item item = ItemHelper.getItem(service);
@@ -75,6 +76,79 @@ public static Invoice getInvoiceFields(DataService service) throws FMSException,
7576

7677
return invoice;
7778
}
79+
80+
public static Invoice getASTInvoiceFields(DataService service) throws FMSException, ParseException {
81+
Invoice invoice = new Invoice();
82+
83+
//add customer
84+
Customer customer = CustomerHelper.getCustomer(service);
85+
invoice.setCustomerRef(CustomerHelper.getCustomerRef(customer));
86+
87+
// add line
88+
List<Line> invLine = new ArrayList<Line>();
89+
Line line = new Line();
90+
line.setAmount(new BigDecimal("100"));
91+
line.setDetailType(LineDetailTypeEnum.SALES_ITEM_LINE_DETAIL);
92+
93+
SalesItemLineDetail silDetails = new SalesItemLineDetail();
94+
95+
Item item = ItemHelper.getItem(service);
96+
silDetails.setItemRef(ItemHelper.getItemRef(item));
97+
98+
//set line item as taxable
99+
silDetails.setTaxCodeRef(TaxCodeInfo.getTaxCodeRef("TAX"));
100+
101+
line.setSalesItemLineDetail(silDetails);
102+
invLine.add(line);
103+
invoice.setLine(invLine);
104+
105+
TxnTaxDetail txnTaxDetail = new TxnTaxDetail();
106+
//pass dummy tax code
107+
TaxCode taxcode = TaxCodeInfo.getTaxCode(service);
108+
txnTaxDetail.setTxnTaxCodeRef(TaxCodeInfo.getTaxCodeRef(taxcode));
109+
invoice.setTxnTaxDetail(txnTaxDetail);
110+
111+
//set shipping address
112+
invoice.setShipAddr(Address.getAddressForAST());
113+
114+
return invoice;
115+
}
116+
117+
public static Invoice getASTOverrideFields(DataService service) throws FMSException, ParseException {
118+
Invoice invoice = new Invoice();
119+
120+
//add customer
121+
Customer customer = CustomerHelper.getCustomer(service);
122+
invoice.setCustomerRef(CustomerHelper.getCustomerRef(customer));
123+
124+
// add line
125+
List<Line> invLine = new ArrayList<Line>();
126+
Line line = new Line();
127+
line.setAmount(new BigDecimal("100"));
128+
line.setDetailType(LineDetailTypeEnum.SALES_ITEM_LINE_DETAIL);
129+
130+
SalesItemLineDetail silDetails = new SalesItemLineDetail();
131+
132+
Item item = ItemHelper.getItem(service);
133+
silDetails.setItemRef(ItemHelper.getItemRef(item));
134+
135+
//set line item as taxable
136+
silDetails.setTaxCodeRef(TaxCodeInfo.getTaxCodeRef("TAX"));
137+
138+
line.setSalesItemLineDetail(silDetails);
139+
invLine.add(line);
140+
invoice.setLine(invLine);
141+
142+
TxnTaxDetail txnTaxDetail = new TxnTaxDetail();
143+
//override tax value
144+
txnTaxDetail.setTotalTax(new BigDecimal("12"));
145+
invoice.setTxnTaxDetail(txnTaxDetail);
146+
147+
//set shipping address
148+
invoice.setShipAddr(Address.getAddressForAST());
149+
150+
return invoice;
151+
}
78152

79153
public static Invoice getInvoice(DataService service) throws FMSException, ParseException {
80154
List<Invoice> invoices = (List<Invoice>) service.findAll(new Invoice());
@@ -93,6 +167,8 @@ public static ReferenceType getInvoiceRef(Invoice invoice) {
93167
ReferenceType invoiceRef = new ReferenceType();
94168
invoiceRef.setValue(invoice.getId());
95169
return invoiceRef;
96-
}
170+
}
171+
172+
97173

98174
}

src/main/java/com/intuit/developer/sampleapp/crud/helper/TaxCodeInfo.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,11 @@ public static ReferenceType getTaxCodeRef(TaxCode taxcode) {
2828
taxcodeRef.setValue(taxcode.getId());
2929
return taxcodeRef;
3030
}
31+
32+
public static ReferenceType getTaxCodeRef(String taxcode) {
33+
ReferenceType taxcodeRef = new ReferenceType();
34+
taxcodeRef.setValue(taxcode);
35+
return taxcodeRef;
36+
}
3137

3238
}

0 commit comments

Comments
 (0)