8. Invoices
Introduction:
In invoices we are handling bidirectional synchronization that means we comparing any invoices which have changed since the last successful sync then pushing changes to the older invoice. Xero API supports the “If-modified-since” header parameter, which allows you to pull back only the records which are changed since the last successful sync.
for this bidirectional sync we maintainedd a foreign key relationship between the invoice in our application and the one in Xero. we stored the InvoiceID returned by Xero in our application. based on the xero invoice id we are maintained synchronization between invoices in our application and the invoices in xero.
Creation of Invoices:
To create or modify an invoice go to invoice details layout, fill the details then press the button “Push to xero”.
The following are the required fields to create an invoice
- Invoice Type
- Invoice Status
- Contact
- Due date
- Line Items
Invoice Type
In xero we have 2 types of invoices tyes are
- ACCPAY: A bill – commonly known as a Accounts Payable or supplier invoice.
- ACCREC: A sales invoice – commonly known as an Accounts Receivable or customer invoice.
In configuration we are handled which type of invoices we need to push/pull based on the user preference.
Invoice Status:
- DRAFT: The default status.
- AUTHORISED: The “approved” state of an invoice ready for sending to a customer
- PAID: The invoice has been fully paid the system will move it to the PAID status automatically.
- DELETED: You can delete a DRAFT invoice by updating the Status to DELETED.
- VOIDED: AUTHORISED invoices cannot be deleted but you can set it’s status to VOIDED.
NOTE:
We can create new invoice with status only draft or authorised from the FM.
Invoice status changes:
Existing Status | New Status |
---|---|
DRAFT | AUTHORISED / DELETED |
AUTHORISED | VOIDED |
DELETED | – |
VOIDED | – |
Contact
To create invoice we need a valid contact information.
Due date
Due date of invoice is required at the time of invoice creation
Line Items
Line items is required at the time of creation of invoice
Elements for lineitems are
- Item code
- Description
- Quantity
- Unit price
- Account code
- Tax rate
Retrieving the online invoice url:
We can retrieve the online invoice URL for sales (ACCREC) invoices.
Note:
We cannot retrieve an online invoice url for DRAFT invoices.
Script:
In invoices we have two different scripts for accessing the information from the xero and sending information to the xero.
- Pull invoices from xero:
We are using this script to accessing the invoices information from the xero. We are sending the request API URL based on the filemaker version using Base Elements plugin functions or FileMaker functions with parameters like API key, Method as invoices. Then we got a response which consists of all invoices information from the Xero in a json formate. By using that information we are creating the records in FM.
Example JSON :
“method”: “invoices”
“Quantity”: “10”,
“UnitAmount”: “100.00”,
“AccountCode”: “200”,
“DiscountRate”: “20”
Create_invoices_from_xero:
We are using this script to create or update the records in FileMaker by using Base Elements functions and FileMaker functions.
Invoice_get_call_with_xero_id:
We are using this script to accessing the particular invoice information from the xero. We are sending the request API URL based on the FileMaker version using Base Elements plugin functions or FileMaker functions with parameters like API key, Method as invoices and Xero invoice id. Then we got a response which consists of that invoice information from the Xero in json formate. By using that information we are updating the records in FM.
Online_invoce_url_call:
We are using this script to accessing the particular invoice URL information from the xero. We are sending the request API URL based on the FileMaker version using Base Elements plugin functions or FileMaker functions with parameters like API key, Method as invoices and Xero invoice id and “OnlineInvoice”. Then we got a response which consists of that invoice URL information from the Xero in json formate. By using that information we are updating the records in FM.
<Type>ACCREC</Type>
<Contact >
<ContactID> eaa28f49-6028-4b6e-bb12-d8f6278073fc </ContactID>
</Contact >
<Date> 2009-08-30</Date>
<DueDate> 2009-09-20</DueDate>
<LineAmountTypes> Exclusive</LineAmountTypes>
<LineItems>
<LineItem>
<Description> Consulting services as agreed </Description>
<Quantity> 5.0000</Quantity>
<UnitAmount> 120.00</UnitAmount>
<AccountCode> 200</AccountCode>
</LineItem>
</LineItems>
</Invoice>
- Push Invoices to xero:
We are using this script to sending the invoices information to the xero. We are sending the request API URL based on the FileMaker version using Base Elements plugin functions or FileMaker functions with parameters like API key, Method as invoices and XML of the invoice. Here we are creating the XML for every record and sending to the xero then we got a response like success or error . We are displaying the response in the invoices layout to know the status to the user.
“method”: “invoices”,
“xml”: <Invoice>
<Type>ACCREC</Type>
<Contact >
<ContactID> eaa28f49-6028-4b6e-bb12-d8f6278073fc </ContactID>
</Contact >
<Date> 2009-08-30</Date>
<DueDate> 2009-09-20</DueDate>
<LineAmountTypes> Exclusive</LineAmountTypes>
<LineItems>
<LineItem>
<Description> Consulting services as agreed </Description>
<Quantity> 5.0000</Quantity>
<UnitAmount> 120.00</UnitAmount>
<AccountCode> 200</AccountCode>
</LineItem>
</LineItems>
</Invoice>
- Invoice_delete:
We are using this script to accessing the invoices information with account payment is empty from the xero. We are sending the request API URL based on the filemaker version using Base Elements plugin functions or FileMaker functions with parameters like API key, Method as invoices, Xero contact id and amount paid = 0. Then we got a response which consists of all invoices information from the Xero in a json formate. Then we are performing the invoice_post_call_delete script to change the status. Based on the script result we are deleting the records in FileMaker.
- Invoice_post_call_delete
We are using this script to changing the invoices status in FileMaker. And sending the request API URL based on the filemaker version using Base Elements plugin functions or FileMaker functions with parameters like API key, Method as invoices and XML. Then we got a response which consists of all invoices information from the Xero in a json formate. By using that information we are deleting the records in FM.
Example XML:
<Invoice>
<InvoiceID> 64673ff4-669a-4adb-ac73-77b557348953 </InvoiceID>
<InvoiceNumber> INV15856</InvoiceNumber>
<Status> DELETED</Status>
</Invoice>
</Invoices>