Skip to content

Commit

Permalink
Add unitdp param
Browse files Browse the repository at this point in the history
add Create CreditNote and Create Receipts wtih unitdp param so you can set decimal point up to 4 places on line items.
  • Loading branch information
SidneyAllen committed May 1, 2018
1 parent 72d1fde commit 25d20d3
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Add this dependency and repository to your POM.xml
<dependency>
<groupId>com.xero</groupId>
<artifactId>xero-java-sdk</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
</dependency>

<repositories>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.xero</groupId>
<artifactId>xero-java-sdk</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
<version>1.0.1</version>
<name>Xero-Java SDK</name>
<url>http://maven.apache.org</url>
<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/xero/api/JsonConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public String getAccessTokenUrl() {

@Override
public String getUserAgent() {
return USER_AGENT + " [Xero-Java-1.0.0]";
return USER_AGENT + " " + CONSUMER_KEY + " [Xero-Java-1.0.1]";
}

@Override
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/com/xero/api/XeroClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,16 @@ public List<CreditNote> createCreditNotes(List<CreditNote> objects) throws IOExc
array.getCreditNote().addAll(objects);
return put("CreditNote", objFactory.createCreditNotes(array)).getCreditNotes().getCreditNote();
}


public List<CreditNote> createCreditNotes(List<CreditNote> objects, String unitdp) throws IOException {
Map<String, String> params = new HashMap<>();
addToMapIfNotNull(params, "unitdp", unitdp);

ArrayOfCreditNote array = new ArrayOfCreditNote();
array.getCreditNote().addAll(objects);
return put("CreditNote", objFactory.createCreditNotes(array),params).getCreditNotes().getCreditNote();
}

public List<CreditNote> updateCreditNote(List<CreditNote> objects) throws IOException {
ArrayOfCreditNote array = new ArrayOfCreditNote();
Expand Down Expand Up @@ -1410,7 +1420,16 @@ public List<Receipt> createReceipts(List<Receipt> objects) throws IOException {
array.getReceipt().addAll(objects);
return put("Receipts", objFactory.createReceipts(array)).getReceipts().getReceipt();
}

public List<Receipt> createReceipts(List<Receipt> objects, String unitdp) throws IOException {
Map<String, String> params = new HashMap<>();
addToMapIfNotNull(params, "unitdp", unitdp);

ArrayOfReceipt array = new ArrayOfReceipt();
array.getReceipt().addAll(objects);
return put("Receipts", objFactory.createReceipts(array),params).getReceipts().getReceipt();
}

public List<Receipt> updateReceipt(List<Receipt> objects) throws IOException {
ArrayOfReceipt array = new ArrayOfReceipt();
array.getReceipt().addAll(objects);
Expand Down
53 changes: 30 additions & 23 deletions src/main/java/com/xero/example/RequestResourceServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -389,6 +388,36 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
/* CREDIT NOTE */
try {


List<CreditNote> newCreditNote = client.createCreditNotes(SampleData.loadCreditNote().getCreditNote());
messages.add("Create a new CreditNote ID : " + newCreditNote.get(0).getCreditNoteID() );

List<CreditNote> newCreditNote4dp = client.createCreditNotes(SampleData.loadCreditNote4dp().getCreditNote(),"4");
messages.add("Create a new CreditNote ID 4dp: " + newCreditNote4dp.get(0).getCreditNoteID() );


List<CreditNote> CreditNoteWhere = client.getCreditNotes(null,"Status==\"DRAFT\"",null);
if(CreditNoteWhere.size() > 0) {
messages.add("Get a CreditNote with WHERE clause - ID: " + CreditNoteWhere.get(0).getCreditNoteID());
}

List<CreditNote> CreditNotePage = client.getCreditNotes(null,"Status==\"DRAFT\"",null,"1");
if(CreditNotePage.size() > 0) {
messages.add("Get a CreditNote with PAGE=1 clause - ID: " + CreditNoteWhere.get(0).getCreditNoteID());
}

List<CreditNote> CreditNoteList = client.getCreditNotes();
int num = SampleData.findRandomNum(CreditNoteList.size());
messages.add("Get a random CreditNote - ID : " + CreditNoteList.get(num).getCreditNoteID());

CreditNote CreditNoteOne = client.getCreditNote(CreditNoteList.get(num).getCreditNoteID());
messages.add("Get a single CreditNote - ID : " + CreditNoteOne.getCreditNoteID());

newCreditNote.get(0).setReference("My updated Credit Note");
List<CreditNote> updateCreditNote = client.updateCreditNote(newCreditNote);
messages.add("Update CreditNote - ID: " + updateCreditNote.get(0).getCreditNoteID() + " - Reference: " + updateCreditNote.get(0).getReference());


List<CreditNote> CreditNoteListForPdf = client.getCreditNotes();

// GET PDF of CREDIT NOTE
Expand Down Expand Up @@ -417,29 +446,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
String saveFilePath = dirPath + File.separator + fileName;
messages.add("Get a PDF copy of CreditNote - save it here: " + saveFilePath);

List<CreditNote> newCreditNote = client.createCreditNotes(SampleData.loadCreditNote().getCreditNote());
messages.add("Create a new CreditNote ID : " + newCreditNote.get(0).getCreditNoteID() );

List<CreditNote> CreditNoteWhere = client.getCreditNotes(null,"Status==\"DRAFT\"",null);
if(CreditNoteWhere.size() > 0) {
messages.add("Get a CreditNote with WHERE clause - ID: " + CreditNoteWhere.get(0).getCreditNoteID());
}

List<CreditNote> CreditNotePage = client.getCreditNotes(null,"Status==\"DRAFT\"",null,"1");
if(CreditNotePage.size() > 0) {
messages.add("Get a CreditNote with PAGE=1 clause - ID: " + CreditNoteWhere.get(0).getCreditNoteID());
}

List<CreditNote> CreditNoteList = client.getCreditNotes();
int num = SampleData.findRandomNum(CreditNoteList.size());
messages.add("Get a random CreditNote - ID : " + CreditNoteList.get(num).getCreditNoteID());

CreditNote CreditNoteOne = client.getCreditNote(CreditNoteList.get(num).getCreditNoteID());
messages.add("Get a single CreditNote - ID : " + CreditNoteOne.getCreditNoteID());

newCreditNote.get(0).setReference("My updated Credit Note");
List<CreditNote> updateCreditNote = client.updateCreditNote(newCreditNote);
messages.add("Update CreditNote - ID: " + updateCreditNote.get(0).getCreditNoteID() + " - Reference: " + updateCreditNote.get(0).getReference());

} catch (XeroApiException e) {
System.out.println(e.getResponseCode());
Expand Down
49 changes: 49 additions & 0 deletions src/main/java/com/xero/example/SampleData.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,22 @@ public static ArrayOfCreditNote loadCreditNote() throws IOException {
array.getCreditNote().add(cn);
return array;
}

public static ArrayOfCreditNote loadCreditNote4dp() throws IOException {
ArrayOfCreditNote array = new ArrayOfCreditNote();

CreditNote cn = new CreditNote();
cn.setType(CreditNoteType.ACCPAYCREDIT);
cn.setDate(loadDate());
cn.setLineAmountTypes(LineAmountType.INCLUSIVE);
cn.setLineItems(loadLineItem4dp());
cn.setContact(loadSingleContact());
array.getCreditNote().add(cn);
return array;
}




// EMPLOYEE
public static ArrayOfEmployee loadEmployee() {
Expand Down Expand Up @@ -623,6 +639,39 @@ private static ArrayOfLineItem loadLineItem() throws IOException{
return array;
}

private static ArrayOfLineItem loadLineItem4dp() throws IOException{
List<Account> accountDirectCosts = client.getAccounts(null,"Type==\"DIRECTCOSTS\"",null);

ArrayOfLineItem array = new ArrayOfLineItem();
LineItem line = new LineItem();
line.setDescription("Yearly Bank Account Fee");
line.setQuantity(new BigDecimal("1.00"));
line.setUnitAmount(new BigDecimal("20.0344"));
line.setLineAmount(new BigDecimal("20.0344"));
line.setAccountCode(accountDirectCosts.get(0).getCode());


List<TrackingCategory> TrackingCategoryList = client.getTrackingCategories();
if (TrackingCategoryList.size() > 0) {
int num10 = SampleData.findRandomNum(TrackingCategoryList.size());

ArrayOfTrackingCategory trackingCategories = new ArrayOfTrackingCategory();
TrackingCategory trackingCategory = new TrackingCategory();

trackingCategory.setTrackingCategoryID(TrackingCategoryList.get(num10).getTrackingCategoryID());
trackingCategory.setName(TrackingCategoryList.get(num10).getName());
trackingCategory.setOption(TrackingCategoryList.get(num10).getOptions().getOption().get(0).getName());

trackingCategories.getTrackingCategory().add(trackingCategory);

line.setTracking(trackingCategories);

}

array.getLineItem().add(line);
return array;
}

private static ArrayOfLineItem loadLineItemForOverpayment() throws IOException{
List<Account> accountDebtors = client.getAccounts(null,"SystemAccount==\"DEBTORS\"",null);

Expand Down

0 comments on commit 25d20d3

Please sign in to comment.