Skip to content

Commit

Permalink
v2.0.3
Browse files Browse the repository at this point in the history
Signed-off-by: Valerian Saliou <[email protected]>
  • Loading branch information
valeriansaliou committed Dec 21, 2017
1 parent ee37d49 commit b83b658
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 64 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,23 @@ Also, ensure that you consume correctly the `charge` values that get returned. I

### :white_check_mark: Specify the country you charge from

**Prototype:** `SalesTax.setTaxOriginCountry(countryCode<string>)<undefined>`
**Prototype:** `SalesTax.setTaxOriginCountry(countryCode<string>, useRegionalTax<boolean?>)<undefined>`

:fr: **Charge customers from France** (thus `international`, `regional` and `national` VAT gets calculated from a French point of view):
:fr: **Charge customers from France** if liable to VAT MOSS (thus `international`, `regional` and `national` VAT gets calculated from a French point of view):

```javascript
SalesTax.setTaxOriginCountry("FR")
```

:fr: **Charge customers from France** if not liable to VAT MOSS (thus `international`, `regional` and `national` VAT gets calculated from a French point of view):

```javascript
// Set the 'useRegionalTax' argument to false if not liable to VAT MOSS (eg. not enough turnover in another regional country)
SalesTax.setTaxOriginCountry("FR", false)
```

:fr: **Charge customers from France** (thus `international`, `regional` and `national` VAT gets calculated from a French point of view):

:triangular_flag_on_post: **Unset your origin country** (use default origin, full VAT rates will be applied for all countries worldwide — **_this is obviously not usable for your invoices_**):

```javascript
Expand Down
37 changes: 27 additions & 10 deletions lib/sales_tax.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ var regex_ca_vat = /^[0-9]{9}$/;
var tax_rates = require("../res/sales_tax_rates.json");
var region_countries = require("../res/region_countries.json");

var tax_default_object = {
type : "none",
rate : 0.00
};


/**
* SalesTax
Expand All @@ -33,6 +38,7 @@ var region_countries = require("../res/region_countries.json");
*/
var SalesTax = function() {
this.taxOriginCountry = null;
this.useRegionalTax = true;
this.enabledTaxNumberValidation = true;
this.enabledTaxNumberFraudCheck = false;
};
Expand Down Expand Up @@ -91,15 +97,22 @@ SalesTax.prototype.getSalesTax = function(
stateCode = (stateCode || "").toUpperCase();
taxNumber = (taxNumber || null);

// Acquire target tax area
var targetArea = self.__getTargetArea(countryCode);

// Acquire sales tax for country, or default (if no known sales tax)
var countryTax = tax_rates[countryCode] || {
type : "none",
rate : 0.00
};
var stateTax = (countryTax.states || {})[stateCode] || {
type : "none",
rate : 0.00
};
// Notice: if regional tax is ignored, force national tax \
// (eg. EU w/o VAT MOSS)
var countryTax, stateTax;

if (targetArea === "regional" && this.useRegionalTax === false &&
this.taxOriginCountry !== null) {
countryTax = (tax_rates[this.taxOriginCountry] || tax_default_object);
stateTax = tax_default_object;
} else {
countryTax = (tax_rates[countryCode] || tax_default_object);
stateTax = ((countryTax.states || {})[stateCode] || tax_default_object);
}

if (countryTax.rate > 0 || stateTax.rate > 0) {
return self.getTaxExchangeStatus(countryCode, stateCode, taxNumber)
Expand Down Expand Up @@ -331,9 +344,13 @@ SalesTax.prototype.getTaxExchangeStatus = function(
* @return {undefined}
*/
SalesTax.prototype.setTaxOriginCountry = function(
countryCode
countryCode, useRegionalTax
) {
this.taxOriginCountry = (countryCode || null);
this.taxOriginCountry = ((countryCode || "").toUpperCase() || null);

if (typeof useRegionalTax === "boolean") {
this.useRegionalTax = useRegionalTax;
}
};


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sales-tax",
"description": "International sales tax calculator for Node (offline, but provides optional online VAT number fraud check). Tax rates are kept up-to-date.",
"version": "2.0.2",
"version": "2.0.3",
"homepage": "https://github.com/valeriansaliou/node-sales-tax",
"license": "MIT",
"author": {
Expand Down
Loading

0 comments on commit b83b658

Please sign in to comment.