When we are sending a bill to MYOB Essentials, they expect it to have line items. Every line item contains a unit price, quantity and the ID of its tax rate. This means we are neither sending the tax amount nor the total amount to MYOB Essentials. Calculation of the tax amount is done by their system based on the sent ID. Total amount is also calculated by them based on the unit price and the quantity of each line item. The unit price sent by us calculated via a simple formula - line_item.total_amount / line_item.quantity. As you can notice the unit price is not affected by the net amount but only the total. This means every line item generated by us has to contain information for 3 attributes - total amount, quantity, tax rate ID.
Used terminology:
- used_defined_lines - line items defined by the user in the monolith interface
- exchange_rate - difference between the bill currency and the currency in the user's settings
- remaining_amount - the amount left from the bill after the user defined line items
- vat_registered - information from the user's settings if it registered for VAT
- selected_tax_rate - tax_rate chosen by the customer for the bill or from its settings
- zero_tax_rate - constants in the code. For Australian customers is 'FRE', for New Zealands - 'Z'
if user_defined_lines are present
adjust every total_amount with the exchange_rate
if remaining_amount > 0
generate line from it and append it to the user_defined_lines
end
if user is not vat_registered
set every tax_rate to nil
else
if tax_rate is explicitly set to 0
set every tax_rate to zero_tax_rate
else
set every tax_rate to selected_tax_rate
end
end
return user_defined_lines
else
if user is not vat_registered || no tax_rate is selected by the customer
return line with bill.total_amount and tax_rate = nil
end
if bill has no tax_rate && bill.tax_amount == 0
return line with bill.total_amount and zero_tax_rate
else
if bill.tax_amount >= calculated tax_amount based on the bill.total_amount and the selected_tax_rate
return line with bill.total_amount and selected_tax_rate
else # (undertaxed case)
return two lines:
1.
total_amount = calculated based on the bill.tax_amount and the selected_tax_rate
tax_rate = selected_tax_rate
2.
total_amount = remaining total_amount
tax_rate = zero_tax_rate
end
end
For the sake of simplicity let's consider tax rate with ID 'S' hax 10% rate. Zero tax rate ID will be 'Z'.
VAT Registered User
1.
Input:
User Settings:
default tax rate: S
Receipt:
total amount: 110, tax amount: 10, tax rate: S
User Defined Line 1:
total amount: 110, tax amount: 10, tax rate: S, quantity: 1
Output:
Line Item 1:
unit price: 110, tax rate id: S
2.
Input:
User Settings:
default tax rate: S
Receipt:
total amount: 110, tax amount: 10, tax rate: S
User Defined Line 1:
total amount: 110, tax amount: 10, tax rate: S, quantity: 2
Output:
Line Item 1:
unit price: 55, tax rate id: S
3.
Input:
User Settings:
default tax rate: S
Receipt:
total amount: 110, tax amount: 10, tax rate: S
User Defined Line 1:
total amount: 77, tax amount: 7, tax rate: S, quantity: 1
Output:
Line Item 1:
total amount: 77, tax rate id: S
Line Item 2:
total amount: 33, tax rate id: S
4.
Input:
User Settings:
default tax rate: S
Receipt:
total amount: 110, tax amount: 10, tax rate: nil
User Defined Line 1:
total amount: 77, tax amount: 0, tax rate: nil, quantity: 1
Output:
Line Item 1:
total amount: 77, tax rate id: Z
Line Item 2:
total amount: 33, tax rate id: S
5.
Input:
User Settings:
default tax rate: nil
Receipt:
total amount: 110, tax amount: 10, tax rate: nil
User Defined Line 1:
total amount: 77, tax amount: 0, tax rate: nil, quantity: 1
Output:
Line Item 1:
total amount: 77, tax rate id: Z
Line Item 2:
total amount: 33, tax rate id: nil
6.
Input:
User Settings:
default tax rate: nil
Receipt:
total amount: 110, tax amount: 10, tax rate: nil
User Defined Line 1:
total amount: 77, tax amount: 0, tax rate: nil, quantity: 1
Output:
Line Item 1:
total amount: 77, tax rate id: nil
Line Item 2:
total amount: 33, tax rate id: nil
NOT VAT Registered User
1.
Input:
Receipt:
total amount: 110, tax amount: 10, tax rate: S
User Defined Line 1:
total amount: 110, tax amount: 10, tax rate: S, quantity: 1
Output:
Line Item 1:
unit price: 110, tax rate id: nil
2.
Input:
Receipt:
total amount: 110, tax amount: 10, tax rate: S
User Defined Line 1:
total amount: 110, tax amount: 10, tax rate: S, quantity: 2
Output:
Line Item 1:
unit price: 55, tax rate id: nil
3.
Input:
Receipt:
total amount: 110, tax amount: 10, tax rate: S
User Defined Line 1:
total amount: 77, tax amount: 7, tax rate: S, quantity: 1
Output:
Line Item 1:
total amount: 77, tax rate id: nil
Line Item 2:
total amount: 33, tax rate id: nil
1.
Input:
User Settings:
default tax rate: S, vat_registered: true
Receipt:
total amount: 110, tax amount: 10, tax rate: S
Output:
Line Item 1:
unit price: 110, tax rate id: S
2.
Input:
User Settings:
default tax rate: S, vat_registered: true
Receipt:
total amount: 110, tax amount: 10, tax rate: nil
Output:
Line Item 1:
unit price: 110, tax rate id: S
3.
Input:
User Settings:
default tax rate: S, vat_registered: true
Receipt:
total amount: 110, tax amount: 0, tax rate: nil
Output:
Line Item 1:
unit price: 110, tax rate id: Z
4.
Input:
User Settings:
default tax rate: S, vat_registered: true
Receipt:
total amount: 110, tax amount: 7, tax rate: nil
Output:
Line Item 1:
unit price: 77, tax rate id: S
Line Item 2:
unit price: 33, tax rate id: Z
5.
Input:
User Settings:
default tax rate: nil, vat_registered: false
Receipt:
total amount: 110, tax amount: 10, tax rate: nil
Output:
Line Item 1:
unit price: 110, tax rate id: nil
6.
Input:
User Settings:
default tax rate: nil, vat_registered: false
Receipt:
total amount: 110, tax amount: 7, tax rate: nil
Output:
Line Item 1:
unit price: 110, tax rate id: nil