From 90874d882064e09cc03cb4cc7e4ebbaef9599d88 Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 11 Dec 2019 20:58:24 -0500 Subject: [PATCH 01/12] New zones and tax types to enable predefined Canada taxes. Based on https://github.com/monosolutions/tax/tree/CanadianTaxes. * Fixed errors in zone files: - administrative-area whould only have the proince letters - errors in generic names (ex. BC is not on HST, but has its own provincial tax) * Fixed errors in tax types: - outdated values were updated (using this official page as a reference: https://www.canada.ca/en/revenue-agency/services/tax/businesses/topics/gst-hst-businesses/charge-collect-which-rate/calculator.html) - generic labels were fixed to display real spellings (ex. PST in Manitoba is called RST) --- resources/tax_type/ca_ab_gst.json | 20 ++++++++++++++++++++ resources/tax_type/ca_bc_gst.json | 20 ++++++++++++++++++++ resources/tax_type/ca_bc_pst.json | 20 ++++++++++++++++++++ resources/tax_type/ca_mb_gst.json | 20 ++++++++++++++++++++ resources/tax_type/ca_mb_rst.json | 26 ++++++++++++++++++++++++++ resources/tax_type/ca_nb_hst.json | 27 +++++++++++++++++++++++++++ resources/tax_type/ca_nl_hst.json | 26 ++++++++++++++++++++++++++ resources/tax_type/ca_ns_hst.json | 20 ++++++++++++++++++++ resources/tax_type/ca_nt_gst.json | 20 ++++++++++++++++++++ resources/tax_type/ca_nu_gst.json | 20 ++++++++++++++++++++ resources/tax_type/ca_on_hst.json | 20 ++++++++++++++++++++ resources/tax_type/ca_pe_hst.json | 26 ++++++++++++++++++++++++++ resources/tax_type/ca_qc_gst.json | 20 ++++++++++++++++++++ resources/tax_type/ca_qc_qst.json | 20 ++++++++++++++++++++ resources/tax_type/ca_sk_gst.json | 20 ++++++++++++++++++++ resources/tax_type/ca_sk_pst.json | 26 ++++++++++++++++++++++++++ resources/tax_type/ca_yt_gst.json | 20 ++++++++++++++++++++ resources/zone/ca_ab.json | 13 +++++++++++++ resources/zone/ca_bc.json | 13 +++++++++++++ resources/zone/ca_mb.json | 13 +++++++++++++ resources/zone/ca_nb.json | 13 +++++++++++++ resources/zone/ca_nl.json | 13 +++++++++++++ resources/zone/ca_ns.json | 13 +++++++++++++ resources/zone/ca_nt.json | 13 +++++++++++++ resources/zone/ca_nu.json | 13 +++++++++++++ resources/zone/ca_on.json | 13 +++++++++++++ resources/zone/ca_pe.json | 13 +++++++++++++ resources/zone/ca_qc.json | 13 +++++++++++++ resources/zone/ca_sk.json | 13 +++++++++++++ resources/zone/ca_yt.json | 13 +++++++++++++ 30 files changed, 540 insertions(+) create mode 100755 resources/tax_type/ca_ab_gst.json create mode 100755 resources/tax_type/ca_bc_gst.json create mode 100755 resources/tax_type/ca_bc_pst.json create mode 100755 resources/tax_type/ca_mb_gst.json create mode 100755 resources/tax_type/ca_mb_rst.json create mode 100755 resources/tax_type/ca_nb_hst.json create mode 100755 resources/tax_type/ca_nl_hst.json create mode 100755 resources/tax_type/ca_ns_hst.json create mode 100755 resources/tax_type/ca_nt_gst.json create mode 100755 resources/tax_type/ca_nu_gst.json create mode 100755 resources/tax_type/ca_on_hst.json create mode 100755 resources/tax_type/ca_pe_hst.json create mode 100755 resources/tax_type/ca_qc_gst.json create mode 100755 resources/tax_type/ca_qc_qst.json create mode 100755 resources/tax_type/ca_sk_gst.json create mode 100755 resources/tax_type/ca_sk_pst.json create mode 100755 resources/tax_type/ca_yt_gst.json create mode 100755 resources/zone/ca_ab.json create mode 100755 resources/zone/ca_bc.json create mode 100755 resources/zone/ca_mb.json create mode 100755 resources/zone/ca_nb.json create mode 100755 resources/zone/ca_nl.json create mode 100755 resources/zone/ca_ns.json create mode 100755 resources/zone/ca_nt.json create mode 100755 resources/zone/ca_nu.json create mode 100755 resources/zone/ca_on.json create mode 100755 resources/zone/ca_pe.json create mode 100755 resources/zone/ca_qc.json create mode 100755 resources/zone/ca_sk.json create mode 100755 resources/zone/ca_yt.json diff --git a/resources/tax_type/ca_ab_gst.json b/resources/tax_type/ca_ab_gst.json new file mode 100755 index 0000000..6c6d290 --- /dev/null +++ b/resources/tax_type/ca_ab_gst.json @@ -0,0 +1,20 @@ +{ + "name": "Canada - Alberta", + "generic_label": "GST", + "zone": "ca_ab", + "tag": "CA", + "rates": [ + { + "id": "ca_ab_gst_standard", + "name": "Standard", + "default": true, + "amounts": [ + { + "id": "ca_ab_gst_standard_2013", + "amount": 0.05, + "start_date": "2013-04-01" + } + ] + } + ] +} diff --git a/resources/tax_type/ca_bc_gst.json b/resources/tax_type/ca_bc_gst.json new file mode 100755 index 0000000..cf45c1f --- /dev/null +++ b/resources/tax_type/ca_bc_gst.json @@ -0,0 +1,20 @@ +{ + "name": "Canada - British Columbia", + "generic_label": "GST", + "zone": "ca_bc", + "tag": "CA", + "rates": [ + { + "id": "ca_bc_gst_standard", + "name": "Standard", + "default": true, + "amounts": [ + { + "id": "ca_bc_gst_standard_2013", + "amount": 0.05, + "start_date": "2013-04-01" + } + ] + } + ] +} diff --git a/resources/tax_type/ca_bc_pst.json b/resources/tax_type/ca_bc_pst.json new file mode 100755 index 0000000..105011b --- /dev/null +++ b/resources/tax_type/ca_bc_pst.json @@ -0,0 +1,20 @@ +{ + "name": "Canada - British Columbia", + "generic_label": "PST", + "zone": "ca_bc", + "tag": "CA", + "rates": [ + { + "id": "ca_bc_pst_standard", + "name": "Standard", + "default": true, + "amounts": [ + { + "id": "ca_bc_pst_standard_2013", + "amount": 0.07, + "start_date": "2013-04-01" + } + ] + } + ] +} diff --git a/resources/tax_type/ca_mb_gst.json b/resources/tax_type/ca_mb_gst.json new file mode 100755 index 0000000..d2ce5d0 --- /dev/null +++ b/resources/tax_type/ca_mb_gst.json @@ -0,0 +1,20 @@ +{ + "name": "Canada - Manitoba", + "generic_label": "GST", + "zone": "ca_mb", + "tag": "CA", + "rates": [ + { + "id": "ca_mb_gst_standard", + "name": "Standard", + "default": true, + "amounts": [ + { + "id": "ca_mb_gst_standard_2013", + "amount": 0.05, + "start_date": "2013-04-01" + } + ] + } + ] +} diff --git a/resources/tax_type/ca_mb_rst.json b/resources/tax_type/ca_mb_rst.json new file mode 100755 index 0000000..cd4475d --- /dev/null +++ b/resources/tax_type/ca_mb_rst.json @@ -0,0 +1,26 @@ +{ + "name": "Canada - Manitoba", + "generic_label": "RST", + "zone": "ca_mb", + "tag": "CA", + "rates": [ + { + "id": "ca_mb_rst_standard", + "name": "Standard", + "default": true, + "amounts": [ + { + "id": "ca_mb_rst_standard_2013", + "amount": 0.08, + "start_date": "2013-07-01", + "end_date": "2019-06-30" + }, + { + "id": "ca_mb_rst_standard_2019", + "amount": 0.07, + "start_date": "2019-07-01" + } + ] + } + ] +} diff --git a/resources/tax_type/ca_nb_hst.json b/resources/tax_type/ca_nb_hst.json new file mode 100755 index 0000000..9046b71 --- /dev/null +++ b/resources/tax_type/ca_nb_hst.json @@ -0,0 +1,27 @@ +{ + "name": "Canada - New Brunswick", + "generic_label": "HST", + "zone": "ca_nb", + "tag": "CA", + "compound": false, + "rates": [ + { + "id": "ca_nb_hst_standard", + "name": "hst", + "default": true, + "amounts": [ + { + "id": "ca_nb_hst_standard_2013", + "amount": 0.13, + "start_date": "2013-04-01", + "end_date": "2016-06-30" + }, + { + "id": "ca_nb_hst_standard_2016", + "amount": 0.15, + "start_date": "2016-07-01" + } + ] + } + ] +} diff --git a/resources/tax_type/ca_nl_hst.json b/resources/tax_type/ca_nl_hst.json new file mode 100755 index 0000000..2369357 --- /dev/null +++ b/resources/tax_type/ca_nl_hst.json @@ -0,0 +1,26 @@ +{ + "name": "Canada - Newfoundland and Labrador", + "generic_label": "HST", + "zone": "ca_nl", + "tag": "CA", + "rates": [ + { + "id": "ca_nl_hst_standard", + "name": "Standard", + "default": true, + "amounts": [ + { + "id": "ca_nl_hst_standard_2013", + "amount": 0.13, + "start_date": "2013-04-01", + "end_date": "2015-12-31" + }, + { + "id": "ca_nl_hst_standard_2016", + "amount": 0.15, + "start_date": "2016-01-01" + } + ] + } + ] +} diff --git a/resources/tax_type/ca_ns_hst.json b/resources/tax_type/ca_ns_hst.json new file mode 100755 index 0000000..c50714b --- /dev/null +++ b/resources/tax_type/ca_ns_hst.json @@ -0,0 +1,20 @@ +{ + "name": "Canada - Nova Scotia", + "generic_label": "HST", + "zone": "ca_ns", + "tag": "CA", + "rates": [ + { + "id": "ca_ns_hst_standard", + "name": "Standard", + "default": true, + "amounts": [ + { + "id": "ca_ns_hst_standard_2013", + "amount": 0.15, + "start_date": "2013-04-01" + } + ] + } + ] +} diff --git a/resources/tax_type/ca_nt_gst.json b/resources/tax_type/ca_nt_gst.json new file mode 100755 index 0000000..d8dd5f2 --- /dev/null +++ b/resources/tax_type/ca_nt_gst.json @@ -0,0 +1,20 @@ +{ + "name": "Canada - Northwest Territories", + "generic_label": "GST", + "zone": "ca_nt", + "tag": "CA", + "rates": [ + { + "id": "ca_nt_gst_standard", + "name": "Standard", + "default": true, + "amounts": [ + { + "id": "ca_nt_gst_standard_2013", + "amount": 0.05, + "start_date": "2013-04-01" + } + ] + } + ] +} diff --git a/resources/tax_type/ca_nu_gst.json b/resources/tax_type/ca_nu_gst.json new file mode 100755 index 0000000..a8d72cf --- /dev/null +++ b/resources/tax_type/ca_nu_gst.json @@ -0,0 +1,20 @@ +{ + "name": "Canada - Nunavut", + "generic_label": "GST", + "zone": "ca_nu", + "tag": "CA", + "rates": [ + { + "id": "ca_nu_gst_standard", + "name": "Standard", + "default": true, + "amounts": [ + { + "id": "ca_nu_gst_standard_2013", + "amount": 0.05, + "start_date": "2013-04-01" + } + ] + } + ] +} diff --git a/resources/tax_type/ca_on_hst.json b/resources/tax_type/ca_on_hst.json new file mode 100755 index 0000000..d8f2d28 --- /dev/null +++ b/resources/tax_type/ca_on_hst.json @@ -0,0 +1,20 @@ +{ + "name": "Canada - Ontario", + "generic_label": "HST", + "zone": "ca_on", + "tag": "CA", + "rates": [ + { + "id": "ca_on_hst_standard", + "name": "Standard", + "default": true, + "amounts": [ + { + "id": "ca_on_hst_standard_2013", + "amount": 0.13, + "start_date": "2013-04-01" + } + ] + } + ] +} diff --git a/resources/tax_type/ca_pe_hst.json b/resources/tax_type/ca_pe_hst.json new file mode 100755 index 0000000..0421e8c --- /dev/null +++ b/resources/tax_type/ca_pe_hst.json @@ -0,0 +1,26 @@ +{ + "name": "Canada - Prince Edward Island", + "generic_label": "HST", + "zone": "ca_pe", + "tag": "CA", + "rates": [ + { + "id": "ca_pe_hst_standard", + "name": "Standard", + "default": true, + "amounts": [ + { + "id": "ca_pe_hst_standard_2013", + "amount": 0.14, + "start_date": "2013-04-01", + "end_date": "2016-09-30" + }, + { + "id": "ca_pe_hst_standard_2016", + "amount": 0.15, + "start_date": "2016-10-01" + } + ] + } + ] +} diff --git a/resources/tax_type/ca_qc_gst.json b/resources/tax_type/ca_qc_gst.json new file mode 100755 index 0000000..359fdf2 --- /dev/null +++ b/resources/tax_type/ca_qc_gst.json @@ -0,0 +1,20 @@ +{ + "name": "Canada - Quebec", + "generic_label": "GST", + "zone": "ca_qc", + "tag": "CA", + "rates": [ + { + "id": "ca_qc_gst_standard", + "name": "Standard", + "default": true, + "amounts": [ + { + "id": "ca_qc_gst_standard_2013", + "amount": 0.05, + "start_date": "2013-04-01" + } + ] + } + ] +} diff --git a/resources/tax_type/ca_qc_qst.json b/resources/tax_type/ca_qc_qst.json new file mode 100755 index 0000000..9acf684 --- /dev/null +++ b/resources/tax_type/ca_qc_qst.json @@ -0,0 +1,20 @@ +{ + "name": "Canada - Quebec", + "generic_label": "QST", + "zone": "ca_qc", + "tag": "CA", + "rates": [ + { + "id": "ca_qc_qst_standard", + "name": "Standard", + "default": true, + "amounts": [ + { + "id": "ca_qc_qst_standard_2013", + "amount": 0.09975, + "start_date": "2013-04-01" + } + ] + } + ] +} diff --git a/resources/tax_type/ca_sk_gst.json b/resources/tax_type/ca_sk_gst.json new file mode 100755 index 0000000..820d870 --- /dev/null +++ b/resources/tax_type/ca_sk_gst.json @@ -0,0 +1,20 @@ +{ + "name": "Canada - Saskatchewan", + "generic_label": "GST", + "zone": "ca_sk", + "tag": "CA", + "rates": [ + { + "id": "ca_sk_gst_standard", + "name": "Standard", + "default": true, + "amounts": [ + { + "id": "ca_sk_gst_standard_2013", + "amount": 0.05, + "start_date": "2013-04-01" + } + ] + } + ] +} diff --git a/resources/tax_type/ca_sk_pst.json b/resources/tax_type/ca_sk_pst.json new file mode 100755 index 0000000..ec9b525 --- /dev/null +++ b/resources/tax_type/ca_sk_pst.json @@ -0,0 +1,26 @@ +{ + "name": "Canada - Saskatchewan", + "generic_label": "PST", + "zone": "ca_sk", + "tag": "CA", + "rates": [ + { + "id": "ca_sk_pst_standard", + "name": "Standard", + "default": true, + "amounts": [ + { + "id": "ca_sk_pst_standard_2006", + "amount": 0.05, + "start_date": "2006-10-28", + "end_date": "2017-03-22" + }, + { + "id": "ca_sk_pst_standard_2017", + "amount": 0.06, + "start_date": "2017-03-23" + } + ] + } + ] +} diff --git a/resources/tax_type/ca_yt_gst.json b/resources/tax_type/ca_yt_gst.json new file mode 100755 index 0000000..c8d9657 --- /dev/null +++ b/resources/tax_type/ca_yt_gst.json @@ -0,0 +1,20 @@ +{ + "name": "Canada - Yukon", + "generic_label": "GST", + "zone": "ca_yt", + "tag": "CA", + "rates": [ + { + "id": "ca_yt_gst_standard", + "name": "Standard", + "default": true, + "amounts": [ + { + "id": "ca_yt_gst_standard_2013", + "amount": 0.05, + "start_date": "2013-04-01" + } + ] + } + ] +} diff --git a/resources/zone/ca_ab.json b/resources/zone/ca_ab.json new file mode 100755 index 0000000..1dbf388 --- /dev/null +++ b/resources/zone/ca_ab.json @@ -0,0 +1,13 @@ +{ + "name": "Canada - Alberta (GST)", + "scope": "tax", + "members": [ + { + "type": "country", + "id": "ca_ab", + "name": "Canada - Alberta", + "country_code": "CA", + "administrative_area": "AB" + } + ] +} diff --git a/resources/zone/ca_bc.json b/resources/zone/ca_bc.json new file mode 100755 index 0000000..5b8965b --- /dev/null +++ b/resources/zone/ca_bc.json @@ -0,0 +1,13 @@ +{ + "name": "Canada - British Columbia (GST + PST)", + "scope": "tax", + "members": [ + { + "type": "country", + "id": "ca_bc", + "name": "Canada - British Columbia", + "country_code": "CA", + "administrative_area": "BC" + } + ] +} diff --git a/resources/zone/ca_mb.json b/resources/zone/ca_mb.json new file mode 100755 index 0000000..146c0c9 --- /dev/null +++ b/resources/zone/ca_mb.json @@ -0,0 +1,13 @@ +{ + "name": "Canada - Manitoba (GST + RST)", + "scope": "tax", + "members": [ + { + "type": "country", + "id": "ca_mb", + "name": "Canada - Manitoba", + "country_code": "CA", + "administrative_area": "MB" + } + ] +} diff --git a/resources/zone/ca_nb.json b/resources/zone/ca_nb.json new file mode 100755 index 0000000..b1f886b --- /dev/null +++ b/resources/zone/ca_nb.json @@ -0,0 +1,13 @@ +{ + "name": "Canada - New Brunswick (HST)", + "scope": "tax", + "members": [ + { + "type": "country", + "id": "ca_nb", + "name": "Canada - New Brunswick", + "country_code": "CA", + "administrative_area": "NB" + } + ] +} diff --git a/resources/zone/ca_nl.json b/resources/zone/ca_nl.json new file mode 100755 index 0000000..24c5258 --- /dev/null +++ b/resources/zone/ca_nl.json @@ -0,0 +1,13 @@ +{ + "name": "Canada - Newfoundland and Labrador (HST)", + "scope": "tax", + "members": [ + { + "type": "country", + "id": "ca_nl", + "name": "Canada - Newfoundland and Labrador", + "country_code": "CA", + "administrative_area": "NL" + } + ] +} diff --git a/resources/zone/ca_ns.json b/resources/zone/ca_ns.json new file mode 100755 index 0000000..4a78fe2 --- /dev/null +++ b/resources/zone/ca_ns.json @@ -0,0 +1,13 @@ +{ + "name": "Canada - Nova Scotia (HST)", + "scope": "tax", + "members": [ + { + "type": "country", + "id": "ca_ns", + "name": "Canada - Nova Scotia", + "country_code": "CA", + "administrative_area": "NS" + } + ] +} diff --git a/resources/zone/ca_nt.json b/resources/zone/ca_nt.json new file mode 100755 index 0000000..f3c94a3 --- /dev/null +++ b/resources/zone/ca_nt.json @@ -0,0 +1,13 @@ +{ + "name": "Canada - Northwest Territories (GST)", + "scope": "tax", + "members": [ + { + "type": "country", + "id": "ca_nt", + "name": "Canada - Northwest Territories", + "country_code": "CA", + "administrative_area": "NT" + } + ] +} diff --git a/resources/zone/ca_nu.json b/resources/zone/ca_nu.json new file mode 100755 index 0000000..57180dc --- /dev/null +++ b/resources/zone/ca_nu.json @@ -0,0 +1,13 @@ +{ + "name": "Canada - Nunavut (GST)", + "scope": "tax", + "members": [ + { + "type": "country", + "id": "ca_ns", + "name": "Canada - Nunavut", + "country_code": "CA", + "administrative_area": "NU" + } + ] +} diff --git a/resources/zone/ca_on.json b/resources/zone/ca_on.json new file mode 100755 index 0000000..9f5c37f --- /dev/null +++ b/resources/zone/ca_on.json @@ -0,0 +1,13 @@ +{ + "name": "Canada - Ontario (HST)", + "scope": "tax", + "members": [ + { + "type": "country", + "id": "ca_on", + "name": "Canada - Ontario", + "country_code": "CA", + "administrative_area": "ON" + } + ] +} diff --git a/resources/zone/ca_pe.json b/resources/zone/ca_pe.json new file mode 100755 index 0000000..97a164f --- /dev/null +++ b/resources/zone/ca_pe.json @@ -0,0 +1,13 @@ +{ + "name": "Canada - Prince Edward Island (HST)", + "scope": "tax", + "members": [ + { + "type": "country", + "id": "ca_pe", + "name": "Canada - Prince Edward Island", + "country_code": "CA", + "administrative_area": "PE" + } + ] +} diff --git a/resources/zone/ca_qc.json b/resources/zone/ca_qc.json new file mode 100755 index 0000000..d4737ed --- /dev/null +++ b/resources/zone/ca_qc.json @@ -0,0 +1,13 @@ +{ + "name": "Canada - Quebec (GST + QST)", + "scope": "tax", + "members": [ + { + "type": "country", + "id": "ca_qc", + "name": "Canada - Quebec", + "country_code": "CA", + "administrative_area": "QC" + } + ] +} diff --git a/resources/zone/ca_sk.json b/resources/zone/ca_sk.json new file mode 100755 index 0000000..27406f6 --- /dev/null +++ b/resources/zone/ca_sk.json @@ -0,0 +1,13 @@ +{ + "name": "Canada - Saskatchewan (GST + PST)", + "scope": "tax", + "members": [ + { + "type": "country", + "id": "ca_sk", + "name": "Canada - Saskatchewan", + "country_code": "CA", + "administrative_area": "SK" + } + ] +} diff --git a/resources/zone/ca_yt.json b/resources/zone/ca_yt.json new file mode 100755 index 0000000..e178476 --- /dev/null +++ b/resources/zone/ca_yt.json @@ -0,0 +1,13 @@ +{ + "name": "Canada - Yukon (GST)", + "scope": "tax", + "members": [ + { + "type": "country", + "id": "ca_yt", + "name": "Canada - Yukon", + "country_code": "CA", + "administrative_area": "YT" + } + ] +} From e35f23f14643dc53e8e14bc0f5bfb7547542cf88 Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 12 Dec 2019 00:48:20 -0500 Subject: [PATCH 02/12] Resolver for canadian taxes has been fixed and improved: * If Store and Client are based in different provinces, provincial tax can only be collected by Store if it's registered in Client's province. * GST and HST can (and have to) be collected everytime by Store from Client in Canada. --- .../TaxType/CanadaTaxTypeResolver.php | 147 ++++++++++-------- 1 file changed, 86 insertions(+), 61 deletions(-) diff --git a/src/Resolver/TaxType/CanadaTaxTypeResolver.php b/src/Resolver/TaxType/CanadaTaxTypeResolver.php index 826a783..f3a2e92 100644 --- a/src/Resolver/TaxType/CanadaTaxTypeResolver.php +++ b/src/Resolver/TaxType/CanadaTaxTypeResolver.php @@ -1,71 +1,96 @@ taxTypeRepository = $taxTypeRepository; - } + /** + * The tax type repository. + * + * @param TaxTypeRepositoryInterface + */ + protected $taxTypeRepository; - /** - * {@inheritdoc} - */ - public function resolve(TaxableInterface $taxable, Context $context) - { - $customerAddress = $context->getCustomerAddress(); - $storeAddress = $context->getStoreAddress(); - if ($customerAddress->getCountryCode() != 'CA' || $storeAddress->getCountryCode() != 'CA') { - // The customer or the store is not in Canada. - return []; - } + /** + * Creates a CanadaTaxTypeResolver instance. + * + * @param TaxTypeRepositoryInterface $taxTypeRepository The tax type repository. + */ + public function __construct(TaxTypeRepositoryInterface $taxTypeRepository) + { + $this->taxTypeRepository = $taxTypeRepository; + } - // Canadian tax types are matched by the customer address. - // If the customer is from Ontario, the tax types are for Ontario. - $taxTypes = $this->getTaxTypes(); - $results = []; - foreach ($taxTypes as $taxType) { - $zone = $taxType->getZone(); - if ($zone->match($customerAddress)) { - $results[] = $taxType; - } - } + /** + * {@inheritdoc} + */ + public function resolve(TaxableInterface $taxable, Context $context) + { + $customerAddress = $context->getCustomerAddress(); + $storeAddress = $context->getStoreAddress(); + if ($customerAddress->getCountryCode() != 'CA' || $storeAddress->getCountryCode() != 'CA') { + // The customer or the store is not in Canada. + return []; + } - return $results; - } + // Canadian tax types are divided in two seperate levels: + // FEDERAL - GST and HST always apply between canadian stores and clients + // PROVINCIAL - PST, QST and RST only apply when the store is registered in the client's province + $taxTypes = $this->getTaxTypes(); + $storeProvince = $storeAddress->getAdministrativeArea(); + $results = []; + foreach ($taxTypes as $taxType) { + $zone = $taxType->getZone(); + if ($zone->match($customerAddress)) { - /** - * Returns the Canadian tax types. - * - * @return TaxTypeInterface[] An array of Canadian tax types. - */ - protected function getTaxTypes() - { - $taxTypes = $this->taxTypeRepository->getAll(); - $taxTypes = array_filter($taxTypes, function ($taxType) { - return $taxType->getTag() == 'CA'; - }); + // Federal taxes (GST or HST) + if($taxType->getGenericLabel() == 'GST' || $taxType->getGenericLabel() == 'HST') { + $results[] = $taxType; + } - return $taxTypes; - } -} + // Provincial taxes (PST, QST, RST), where the store is registered + $storeRegistrationTaxProvinces = $context->getStoreRegistrations(); + // Add store's province of origin + $storeRegistrationTaxProvinces[] = !in_array($storeProvince, $storeRegistrationTaxProvinces) ? $storeProvince : ''; + if(!empty($storeRegistrationTaxProvinces)) { + foreach ($storeRegistrationTaxProvinces as $province) { + if ($zone->getMembers()->first()->getAdministrativeArea() == $province) { + $results[] = $taxType; + } + } + } + } + } + + return $results; + } + + /** + * Returns the Canadian tax types. + * + * @return TaxTypeInterface[] An array of Canadian tax types. + */ + protected function getTaxTypes() + { + $taxTypes = $this->taxTypeRepository->getAll(); + $taxTypes = array_filter($taxTypes, function ($taxType) { + return $taxType->getTag() == 'CA'; + }); + + return $taxTypes; + } + } From e661a828a6b7bfbf45311c9b8944ee956b6a5de2 Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 12 Dec 2019 00:55:06 -0500 Subject: [PATCH 03/12] Fixed indentation. --- .../TaxType/CanadaTaxTypeResolver.php | 154 +++++++++--------- 1 file changed, 76 insertions(+), 78 deletions(-) diff --git a/src/Resolver/TaxType/CanadaTaxTypeResolver.php b/src/Resolver/TaxType/CanadaTaxTypeResolver.php index f3a2e92..7ec3ad3 100644 --- a/src/Resolver/TaxType/CanadaTaxTypeResolver.php +++ b/src/Resolver/TaxType/CanadaTaxTypeResolver.php @@ -1,96 +1,94 @@ taxTypeRepository = $taxTypeRepository; + } - /** - * Creates a CanadaTaxTypeResolver instance. - * - * @param TaxTypeRepositoryInterface $taxTypeRepository The tax type repository. - */ - public function __construct(TaxTypeRepositoryInterface $taxTypeRepository) - { - $this->taxTypeRepository = $taxTypeRepository; + /** + * {@inheritdoc} + */ + public function resolve(TaxableInterface $taxable, Context $context) + { + $customerAddress = $context->getCustomerAddress(); + $storeAddress = $context->getStoreAddress(); + if ($customerAddress->getCountryCode() != 'CA' || $storeAddress->getCountryCode() != 'CA') { + // The customer or the store is not in Canada. + return []; } + // Canadian tax types are divided in two seperate levels: + // FEDERAL - GST and HST always apply between canadian stores and clients + // PROVINCIAL - PST, QST and RST only apply when the store is registered in the client's province + $taxTypes = $this->getTaxTypes(); + $storeProvince = $storeAddress->getAdministrativeArea(); + $results = []; + foreach ($taxTypes as $taxType) { + $zone = $taxType->getZone(); + if ($zone->match($customerAddress)) { - /** - * {@inheritdoc} - */ - public function resolve(TaxableInterface $taxable, Context $context) - { - $customerAddress = $context->getCustomerAddress(); - $storeAddress = $context->getStoreAddress(); - if ($customerAddress->getCountryCode() != 'CA' || $storeAddress->getCountryCode() != 'CA') { - // The customer or the store is not in Canada. - return []; - } - - // Canadian tax types are divided in two seperate levels: - // FEDERAL - GST and HST always apply between canadian stores and clients - // PROVINCIAL - PST, QST and RST only apply when the store is registered in the client's province - $taxTypes = $this->getTaxTypes(); - $storeProvince = $storeAddress->getAdministrativeArea(); - $results = []; - foreach ($taxTypes as $taxType) { - $zone = $taxType->getZone(); - if ($zone->match($customerAddress)) { - - // Federal taxes (GST or HST) - if($taxType->getGenericLabel() == 'GST' || $taxType->getGenericLabel() == 'HST') { - $results[] = $taxType; - } - - // Provincial taxes (PST, QST, RST), where the store is registered - $storeRegistrationTaxProvinces = $context->getStoreRegistrations(); - // Add store's province of origin - $storeRegistrationTaxProvinces[] = !in_array($storeProvince, $storeRegistrationTaxProvinces) ? $storeProvince : ''; - if(!empty($storeRegistrationTaxProvinces)) { - foreach ($storeRegistrationTaxProvinces as $province) { - if ($zone->getMembers()->first()->getAdministrativeArea() == $province) { - $results[] = $taxType; - } + // Federal taxes (GST or HST) + if ($taxType->getGenericLabel() == 'GST' || $taxType->getGenericLabel() == 'HST') { + $results[] = $taxType; + } + // Provincial taxes (PST, QST, RST), where the store is registered + $storeRegistrationTaxProvinces = $context->getStoreRegistrations(); + // Add store's province of origin + $storeRegistrationTaxProvinces[] = !in_array($storeProvince, $storeRegistrationTaxProvinces) ? $storeProvince : ''; + if (!empty($storeRegistrationTaxProvinces)) { + foreach ($storeRegistrationTaxProvinces as $province) { + if ($zone->getMembers()->first()->getAdministrativeArea() == $province) { + $results[] = $taxType; } } } } - - return $results; } - /** - * Returns the Canadian tax types. - * - * @return TaxTypeInterface[] An array of Canadian tax types. - */ - protected function getTaxTypes() - { - $taxTypes = $this->taxTypeRepository->getAll(); - $taxTypes = array_filter($taxTypes, function ($taxType) { - return $taxType->getTag() == 'CA'; - }); + return $results; + } - return $taxTypes; - } + /** + * Returns the Canadian tax types. + * + * @return TaxTypeInterface[] An array of Canadian tax types. + */ + protected function getTaxTypes() + { + $taxTypes = $this->taxTypeRepository->getAll(); + $taxTypes = array_filter($taxTypes, function ($taxType) { + return $taxType->getTag() == 'CA'; + }); + + return $taxTypes; } +} From 09336fa77fa7a6e0665f891ab0bc28da2cc1a333 Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 12 Dec 2019 00:57:29 -0500 Subject: [PATCH 04/12] Removed unused trait. --- src/Resolver/TaxType/CanadaTaxTypeResolver.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Resolver/TaxType/CanadaTaxTypeResolver.php b/src/Resolver/TaxType/CanadaTaxTypeResolver.php index 7ec3ad3..8b1b6cf 100644 --- a/src/Resolver/TaxType/CanadaTaxTypeResolver.php +++ b/src/Resolver/TaxType/CanadaTaxTypeResolver.php @@ -16,8 +16,6 @@ */ class CanadaTaxTypeResolver implements TaxTypeResolverInterface { - use StoreRegistrationCheckerTrait; - /** * The tax type repository. * From 732677249a6e63f4ea0d1481cc4aa5b920f98581 Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 12 Dec 2019 01:01:23 -0500 Subject: [PATCH 05/12] Improved comments and fixed a typo. --- src/Resolver/TaxType/CanadaTaxTypeResolver.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Resolver/TaxType/CanadaTaxTypeResolver.php b/src/Resolver/TaxType/CanadaTaxTypeResolver.php index 8b1b6cf..82fc0c2 100644 --- a/src/Resolver/TaxType/CanadaTaxTypeResolver.php +++ b/src/Resolver/TaxType/CanadaTaxTypeResolver.php @@ -7,7 +7,7 @@ use CommerceGuys\Tax\Resolver\Context; /** - * Resolver for Canada's tax types (HST, PST, GST). + * Resolver for Canada's tax types: * GST Goods and Services Tax * HST Harmonized Sales Tax * PST Provincial Sales Tax (generic provincial label) @@ -44,7 +44,7 @@ public function resolve(TaxableInterface $taxable, Context $context) // The customer or the store is not in Canada. return []; } - // Canadian tax types are divided in two seperate levels: + // Canadian tax types are divided in two separate levels: // FEDERAL - GST and HST always apply between canadian stores and clients // PROVINCIAL - PST, QST and RST only apply when the store is registered in the client's province $taxTypes = $this->getTaxTypes(); @@ -60,7 +60,7 @@ public function resolve(TaxableInterface $taxable, Context $context) } // Provincial taxes (PST, QST, RST), where the store is registered $storeRegistrationTaxProvinces = $context->getStoreRegistrations(); - // Add store's province of origin + // Add store's province of origin, as it should always be registered there $storeRegistrationTaxProvinces[] = !in_array($storeProvince, $storeRegistrationTaxProvinces) ? $storeProvince : ''; if (!empty($storeRegistrationTaxProvinces)) { foreach ($storeRegistrationTaxProvinces as $province) { From ad1441650def839cda15792350d9ff2ee653f453 Mon Sep 17 00:00:00 2001 From: Vincent Date: Fri, 13 Dec 2019 22:33:48 -0500 Subject: [PATCH 06/12] Bumped version to 0.9.0. --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 79a185e..fbb28a4 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,6 @@ { "name": "commerceguys/tax", + "version": "0.9.0", "type": "library", "description": "Tax library with a flexible data model, predefined tax rates, powerful resolving logic.", "keywords": ["tax", "vat"], From c31fc9a8e513f93df0ac36693ed0bc6e706235da Mon Sep 17 00:00:00 2001 From: Vincent Date: Sun, 26 Jan 2020 18:06:19 -0500 Subject: [PATCH 07/12] Fixed New Brunswick tax_type: name was wrong. --- resources/tax_type/ca_nb_hst.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/tax_type/ca_nb_hst.json b/resources/tax_type/ca_nb_hst.json index 9046b71..b39bc0a 100755 --- a/resources/tax_type/ca_nb_hst.json +++ b/resources/tax_type/ca_nb_hst.json @@ -7,7 +7,7 @@ "rates": [ { "id": "ca_nb_hst_standard", - "name": "hst", + "name": "Standard", "default": true, "amounts": [ { From 099d88a759b531b377c9b2cae9542d26cf2bb04a Mon Sep 17 00:00:00 2001 From: Vincent Date: Sun, 26 Jan 2020 18:18:24 -0500 Subject: [PATCH 08/12] Updated version requirement in composer. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index fbb28a4..66b3581 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "require": { "php": ">=5.5.0", "commerceguys/addressing": "~1.0", - "commerceguys/zone": "~0.8", + "commerceguys/zone": "~0.9", "doctrine/collections": "~1.0" }, "require-dev": { From 6dc30f91b12a93da62a50169ec6563eeb6376d9e Mon Sep 17 00:00:00 2001 From: Vincent Date: Mon, 27 Jan 2020 11:25:42 -0500 Subject: [PATCH 09/12] Matched changes made on original project (v8.2). --- .editorconfig | 19 ++++++++ .travis.yml | 3 +- composer.json | 2 +- resources/tax_type/gr_x_vat.json | 45 +++++++++++++++++++ resources/zone/gr_vat.json | 4 +- resources/zone/gr_x_vat.json | 4 +- src/Repository/TaxTypeRepositoryInterface.php | 2 + src/Resolver/Context.php | 4 +- src/Resolver/TaxResolverInterface.php | 3 ++ .../TaxType/CanadaTaxTypeResolver.php | 1 + .../TaxType/ChainTaxTypeResolverInterface.php | 1 + .../TaxType/DefaultTaxTypeResolver.php | 1 + 12 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 .editorconfig create mode 100644 resources/tax_type/gr_x_vat.json diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..b0d34dc --- /dev/null +++ b/.editorconfig @@ -0,0 +1,19 @@ +; top-most EditorConfig file +root = true + +; Unix-style newlines +[*] +charset = utf-8 +end_of_line = LF +insert_final_newline = true +trim_trailing_whitespace = true + +[*.{php,html,twig}] +indent_style = space +indent_size = 4 + +[*.md] +max_line_length = 80 + +[COMMIT_EDITMSG] +max_line_length = 0 \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index dfea229..e5a8b24 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,11 @@ language: php php: + - 7.3 + - 7.2 - 7.1 - 7.0 - 5.6 - - 5.5 install: - composer self-update diff --git a/composer.json b/composer.json index 66b3581..63660f5 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ }, "require-dev": { "phpunit/phpunit": "~4.0", - "mikey179/vfsStream": "1.*" + "mikey179/vfsstream": "1.*" }, "autoload": { "psr-4": { "CommerceGuys\\Tax\\": "src" } diff --git a/resources/tax_type/gr_x_vat.json b/resources/tax_type/gr_x_vat.json new file mode 100644 index 0000000..4d9594b --- /dev/null +++ b/resources/tax_type/gr_x_vat.json @@ -0,0 +1,45 @@ +{ + "name": "Greek Islands VAT", + "generic_label": "vat", + "display_inclusive": true, + "zone": "gr_x_vat", + "tag": "EU", + "rates": [ + { + "id": "gr_x_vat_standard", + "name": "Standard", + "default": true, + "amounts": [ + { + "id": "gr_x_vat_standard_2016_06", + "amount": 0.17, + "start_date": "2016-06-01" + } + ] + }, + { + "id": "gr_x_vat_intermediate", + "name": "Intermediate", + "amounts": [ + + { + "id": "gr_x_vat_intermediate_2011", + "amount": 0.09, + "start_date": "2011-01-01" + } + ] + }, + { + "id": "gr_x_vat_reduced", + "name": "Reduced", + "amounts": [ + + { + "id": "gr_x_vat_reduced_2015", + "amount": 0.04, + "start_date": "2015-07-01" + } + ] + } + ] +} \ No newline at end of file diff --git a/resources/zone/gr_vat.json b/resources/zone/gr_vat.json index 02a65b0..8788d7e 100644 --- a/resources/zone/gr_vat.json +++ b/resources/zone/gr_vat.json @@ -5,9 +5,9 @@ { "type": "country", "id": "gr_vat_0", - "name": "Greece (ex. Thassos, Samothrace, Skiros, Northern Sporades, Lesbos, Chios, The Cyclades, The Dodecanese)", + "name": "Greece (ex. Lesbos, Chios, Samos, Kos, Leros)", "country_code": "GR", - "excluded_postal_codes": "\/640 ?04|680 ?02|340 ?07|((370|811|821|840|851) ?[0-9]{2})\/" + "excluded_postal_codes": "\/(811|821|831|853|854) ?[0-9]{2}\/" } ] } diff --git a/resources/zone/gr_x_vat.json b/resources/zone/gr_x_vat.json index 2f953a1..f2c5981 100644 --- a/resources/zone/gr_x_vat.json +++ b/resources/zone/gr_x_vat.json @@ -5,9 +5,9 @@ { "type": "country", "id": "gr_x_vat_0", - "name": "Thassos, Samothrace, Skiros, Northern Sporades, Lesbos, Chios, The Cyclades, The Dodecanese", + "name": "Lesbos, Chios, Samos, Kos, Leros", "country_code": "GR", - "included_postal_codes": "\/640 ?04|680 ?02|340 ?07|((370|811|821|840|851) ?[0-9]{2})\/" + "included_postal_codes": "\/(811|821|831|853|854) ?[0-9]{2}\/" } ] } diff --git a/src/Repository/TaxTypeRepositoryInterface.php b/src/Repository/TaxTypeRepositoryInterface.php index faa872c..f1c364f 100644 --- a/src/Repository/TaxTypeRepositoryInterface.php +++ b/src/Repository/TaxTypeRepositoryInterface.php @@ -2,6 +2,8 @@ namespace CommerceGuys\Tax\Repository; +use CommerceGuys\Tax\Model\TaxTypeInterface; + /** * Tax type repository interface. */ diff --git a/src/Resolver/Context.php b/src/Resolver/Context.php index 414fcc1..0b623f6 100644 --- a/src/Resolver/Context.php +++ b/src/Resolver/Context.php @@ -45,7 +45,7 @@ class Context /** * The calculation date. * - * @var DateTime + * @var \DateTime */ protected $date; @@ -162,7 +162,7 @@ public function setStoreRegistrations(array $storeRegistrations) /** * Gets the calculation date. * - * @return DateTime The calculation date. + * @return \DateTime The calculation date. */ public function getDate() { diff --git a/src/Resolver/TaxResolverInterface.php b/src/Resolver/TaxResolverInterface.php index 661f495..e78505a 100644 --- a/src/Resolver/TaxResolverInterface.php +++ b/src/Resolver/TaxResolverInterface.php @@ -2,6 +2,9 @@ namespace CommerceGuys\Tax\Resolver; +use CommerceGuys\Tax\Model\TaxRateAmountInterface; +use CommerceGuys\Tax\Model\TaxRateInterface; +use CommerceGuys\Tax\Model\TaxTypeInterface; use CommerceGuys\Tax\TaxableInterface; /** diff --git a/src/Resolver/TaxType/CanadaTaxTypeResolver.php b/src/Resolver/TaxType/CanadaTaxTypeResolver.php index 82fc0c2..9d545de 100644 --- a/src/Resolver/TaxType/CanadaTaxTypeResolver.php +++ b/src/Resolver/TaxType/CanadaTaxTypeResolver.php @@ -2,6 +2,7 @@ namespace CommerceGuys\Tax\Resolver\TaxType; +use CommerceGuys\Tax\Model\TaxTypeInterface; use CommerceGuys\Tax\TaxableInterface; use CommerceGuys\Tax\Repository\TaxTypeRepositoryInterface; use CommerceGuys\Tax\Resolver\Context; diff --git a/src/Resolver/TaxType/ChainTaxTypeResolverInterface.php b/src/Resolver/TaxType/ChainTaxTypeResolverInterface.php index 5faae9e..9b247cd 100644 --- a/src/Resolver/TaxType/ChainTaxTypeResolverInterface.php +++ b/src/Resolver/TaxType/ChainTaxTypeResolverInterface.php @@ -4,6 +4,7 @@ use CommerceGuys\Tax\TaxableInterface; use CommerceGuys\Tax\Resolver\Context; +use CommerceGuys\Tax\Model\TaxTypeInterface; use CommerceGuys\Tax\Resolver\TaxType\TaxTypeResolverInterface; /** diff --git a/src/Resolver/TaxType/DefaultTaxTypeResolver.php b/src/Resolver/TaxType/DefaultTaxTypeResolver.php index 3384614..1256139 100644 --- a/src/Resolver/TaxType/DefaultTaxTypeResolver.php +++ b/src/Resolver/TaxType/DefaultTaxTypeResolver.php @@ -2,6 +2,7 @@ namespace CommerceGuys\Tax\Resolver\TaxType; +use CommerceGuys\Tax\Model\TaxTypeInterface; use CommerceGuys\Tax\TaxableInterface; use CommerceGuys\Tax\Repository\TaxTypeRepositoryInterface; use CommerceGuys\Tax\Resolver\Context; From c10a411b10f8fc2d0b6a7e2869665fde264ce7e1 Mon Sep 17 00:00:00 2001 From: Vincent Date: Mon, 27 Jan 2020 16:10:19 -0500 Subject: [PATCH 10/12] Moved back to v0.8.1 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 63660f5..aef74c7 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "commerceguys/tax", - "version": "0.9.0", + "version": "0.8.1", "type": "library", "description": "Tax library with a flexible data model, predefined tax rates, powerful resolving logic.", "keywords": ["tax", "vat"], From 7fdaab4f42333315620ae24c63ab33d7b69c9be0 Mon Sep 17 00:00:00 2001 From: Dom Morgan Date: Mon, 24 Feb 2025 16:00:09 +0000 Subject: [PATCH 11/12] Fix unit tests --- resources/tax_type/ca_ab_gst.json | 2 +- resources/tax_type/ca_bc_gst.json | 2 +- resources/tax_type/ca_mb_gst.json | 2 +- resources/tax_type/ca_nb_hst.json | 2 +- resources/tax_type/ca_nl_hst.json | 2 +- resources/tax_type/ca_ns_hst.json | 2 +- resources/tax_type/ca_nt_gst.json | 2 +- resources/tax_type/ca_nu_gst.json | 2 +- resources/tax_type/ca_on_hst.json | 2 +- resources/tax_type/ca_pe_hst.json | 2 +- resources/tax_type/ca_qc_gst.json | 2 +- resources/tax_type/ca_sk_gst.json | 2 +- resources/tax_type/ca_yt_gst.json | 2 +- resources/tax_type/id_gst.json | 2 +- src/Resolver/TaxType/CanadaTaxTypeResolver.php | 3 +-- .../Resolver/TaxRate/DefaultTaxRateResolverTest.php | 2 ++ tests/Resolver/TaxType/CanadaTaxTypeResolverTest.php | 12 ++++++------ 17 files changed, 23 insertions(+), 22 deletions(-) diff --git a/resources/tax_type/ca_ab_gst.json b/resources/tax_type/ca_ab_gst.json index 6c6d290..98b8f11 100755 --- a/resources/tax_type/ca_ab_gst.json +++ b/resources/tax_type/ca_ab_gst.json @@ -1,6 +1,6 @@ { "name": "Canada - Alberta", - "generic_label": "GST", + "generic_label": "gst", "zone": "ca_ab", "tag": "CA", "rates": [ diff --git a/resources/tax_type/ca_bc_gst.json b/resources/tax_type/ca_bc_gst.json index cf45c1f..69cd8a9 100755 --- a/resources/tax_type/ca_bc_gst.json +++ b/resources/tax_type/ca_bc_gst.json @@ -1,6 +1,6 @@ { "name": "Canada - British Columbia", - "generic_label": "GST", + "generic_label": "gst", "zone": "ca_bc", "tag": "CA", "rates": [ diff --git a/resources/tax_type/ca_mb_gst.json b/resources/tax_type/ca_mb_gst.json index d2ce5d0..484d369 100755 --- a/resources/tax_type/ca_mb_gst.json +++ b/resources/tax_type/ca_mb_gst.json @@ -1,6 +1,6 @@ { "name": "Canada - Manitoba", - "generic_label": "GST", + "generic_label": "gst", "zone": "ca_mb", "tag": "CA", "rates": [ diff --git a/resources/tax_type/ca_nb_hst.json b/resources/tax_type/ca_nb_hst.json index b39bc0a..fae13b2 100755 --- a/resources/tax_type/ca_nb_hst.json +++ b/resources/tax_type/ca_nb_hst.json @@ -1,6 +1,6 @@ { "name": "Canada - New Brunswick", - "generic_label": "HST", + "generic_label": "hst", "zone": "ca_nb", "tag": "CA", "compound": false, diff --git a/resources/tax_type/ca_nl_hst.json b/resources/tax_type/ca_nl_hst.json index 2369357..4b65661 100755 --- a/resources/tax_type/ca_nl_hst.json +++ b/resources/tax_type/ca_nl_hst.json @@ -1,6 +1,6 @@ { "name": "Canada - Newfoundland and Labrador", - "generic_label": "HST", + "generic_label": "hst", "zone": "ca_nl", "tag": "CA", "rates": [ diff --git a/resources/tax_type/ca_ns_hst.json b/resources/tax_type/ca_ns_hst.json index c50714b..cb16ba6 100755 --- a/resources/tax_type/ca_ns_hst.json +++ b/resources/tax_type/ca_ns_hst.json @@ -1,6 +1,6 @@ { "name": "Canada - Nova Scotia", - "generic_label": "HST", + "generic_label": "hst", "zone": "ca_ns", "tag": "CA", "rates": [ diff --git a/resources/tax_type/ca_nt_gst.json b/resources/tax_type/ca_nt_gst.json index d8dd5f2..f9638ee 100755 --- a/resources/tax_type/ca_nt_gst.json +++ b/resources/tax_type/ca_nt_gst.json @@ -1,6 +1,6 @@ { "name": "Canada - Northwest Territories", - "generic_label": "GST", + "generic_label": "gst", "zone": "ca_nt", "tag": "CA", "rates": [ diff --git a/resources/tax_type/ca_nu_gst.json b/resources/tax_type/ca_nu_gst.json index a8d72cf..63e0127 100755 --- a/resources/tax_type/ca_nu_gst.json +++ b/resources/tax_type/ca_nu_gst.json @@ -1,6 +1,6 @@ { "name": "Canada - Nunavut", - "generic_label": "GST", + "generic_label": "gst", "zone": "ca_nu", "tag": "CA", "rates": [ diff --git a/resources/tax_type/ca_on_hst.json b/resources/tax_type/ca_on_hst.json index d8f2d28..2d1aea6 100755 --- a/resources/tax_type/ca_on_hst.json +++ b/resources/tax_type/ca_on_hst.json @@ -1,6 +1,6 @@ { "name": "Canada - Ontario", - "generic_label": "HST", + "generic_label": "hst", "zone": "ca_on", "tag": "CA", "rates": [ diff --git a/resources/tax_type/ca_pe_hst.json b/resources/tax_type/ca_pe_hst.json index 0421e8c..64d0be8 100755 --- a/resources/tax_type/ca_pe_hst.json +++ b/resources/tax_type/ca_pe_hst.json @@ -1,6 +1,6 @@ { "name": "Canada - Prince Edward Island", - "generic_label": "HST", + "generic_label": "hst", "zone": "ca_pe", "tag": "CA", "rates": [ diff --git a/resources/tax_type/ca_qc_gst.json b/resources/tax_type/ca_qc_gst.json index 359fdf2..fd1f8d8 100755 --- a/resources/tax_type/ca_qc_gst.json +++ b/resources/tax_type/ca_qc_gst.json @@ -1,6 +1,6 @@ { "name": "Canada - Quebec", - "generic_label": "GST", + "generic_label": "gst", "zone": "ca_qc", "tag": "CA", "rates": [ diff --git a/resources/tax_type/ca_sk_gst.json b/resources/tax_type/ca_sk_gst.json index 820d870..5f692c3 100755 --- a/resources/tax_type/ca_sk_gst.json +++ b/resources/tax_type/ca_sk_gst.json @@ -1,6 +1,6 @@ { "name": "Canada - Saskatchewan", - "generic_label": "GST", + "generic_label": "gst", "zone": "ca_sk", "tag": "CA", "rates": [ diff --git a/resources/tax_type/ca_yt_gst.json b/resources/tax_type/ca_yt_gst.json index c8d9657..57e1b82 100755 --- a/resources/tax_type/ca_yt_gst.json +++ b/resources/tax_type/ca_yt_gst.json @@ -1,6 +1,6 @@ { "name": "Canada - Yukon", - "generic_label": "GST", + "generic_label": "gst", "zone": "ca_yt", "tag": "CA", "rates": [ diff --git a/resources/tax_type/id_gst.json b/resources/tax_type/id_gst.json index 01e60d2..682cfa1 100644 --- a/resources/tax_type/id_gst.json +++ b/resources/tax_type/id_gst.json @@ -1,6 +1,6 @@ { "name": "Indonesian GST", - "generic_label": "GST", + "generic_label": "gst", "display_inclusive": true, "zone": "id_gst", "rates": [ diff --git a/src/Resolver/TaxType/CanadaTaxTypeResolver.php b/src/Resolver/TaxType/CanadaTaxTypeResolver.php index 9d545de..fedd4ca 100644 --- a/src/Resolver/TaxType/CanadaTaxTypeResolver.php +++ b/src/Resolver/TaxType/CanadaTaxTypeResolver.php @@ -54,9 +54,8 @@ public function resolve(TaxableInterface $taxable, Context $context) foreach ($taxTypes as $taxType) { $zone = $taxType->getZone(); if ($zone->match($customerAddress)) { - // Federal taxes (GST or HST) - if ($taxType->getGenericLabel() == 'GST' || $taxType->getGenericLabel() == 'HST') { + if ($taxType->getGenericLabel() == 'gst' || $taxType->getGenericLabel() == 'hst') { $results[] = $taxType; } // Provincial taxes (PST, QST, RST), where the store is registered diff --git a/tests/Resolver/TaxRate/DefaultTaxRateResolverTest.php b/tests/Resolver/TaxRate/DefaultTaxRateResolverTest.php index 9413375..d764b8d 100644 --- a/tests/Resolver/TaxRate/DefaultTaxRateResolverTest.php +++ b/tests/Resolver/TaxRate/DefaultTaxRateResolverTest.php @@ -10,6 +10,8 @@ */ class DefaultTaxRateResolverTest extends TestCase { + private $resolver; + /** * {@inheritdoc} */ diff --git a/tests/Resolver/TaxType/CanadaTaxTypeResolverTest.php b/tests/Resolver/TaxType/CanadaTaxTypeResolverTest.php index adf340a..291e9bd 100644 --- a/tests/Resolver/TaxType/CanadaTaxTypeResolverTest.php +++ b/tests/Resolver/TaxType/CanadaTaxTypeResolverTest.php @@ -23,7 +23,7 @@ class CanadaTaxTypeResolverTest extends TestCase 'name' => 'Ontario HST', 'generic_label' => 'hst', 'tag' => 'CA', - 'zone' => 'ca_on_hst', + 'zone' => 'ca_on', 'rates' => [ [ 'id' => 'ca_on_hst', @@ -42,7 +42,7 @@ class CanadaTaxTypeResolverTest extends TestCase 'name' => 'Nova Scotia HST', 'generic_label' => 'hst', 'tag' => 'CA', - 'zone' => 'ca_ns_hst', + 'zone' => 'ca_ns', 'rates' => [ [ 'id' => 'ca_ns_hst', @@ -65,24 +65,24 @@ class CanadaTaxTypeResolverTest extends TestCase * @var array */ protected $zones = [ - 'ca_on_hst' => [ + 'ca_on' => [ 'name' => 'Ontario (HST)', 'members' => [ [ 'type' => 'country', - 'id' => '1', + 'id' => 'ca_on', 'name' => 'Canada - Ontario', 'country_code' => 'CA', 'administrative_area' => 'ON', ], ], ], - 'ca_ns_hst' => [ + 'ca_ns' => [ 'name' => 'Nova Scotia (HST)', 'members' => [ [ 'type' => 'country', - 'id' => '2', + 'id' => 'ca_ns', 'name' => 'Canada - Nova Scotia', 'country_code' => 'CA', 'administrative_area' => 'NS', From fe239f70d9a590763cb94d7021d13c6621ff6041 Mon Sep 17 00:00:00 2001 From: Dom Morgan Date: Mon, 24 Feb 2025 16:01:53 +0000 Subject: [PATCH 12/12] Code style --- .editorconfig | 2 +- composer.json | 1 - resources/tax_type/gr_x_vat.json | 2 +- .../TaxType/CanadaTaxTypeResolver.php | 134 +++++++++--------- 4 files changed, 69 insertions(+), 70 deletions(-) diff --git a/.editorconfig b/.editorconfig index b0d34dc..d769b46 100644 --- a/.editorconfig +++ b/.editorconfig @@ -16,4 +16,4 @@ indent_size = 4 max_line_length = 80 [COMMIT_EDITMSG] -max_line_length = 0 \ No newline at end of file +max_line_length = 0 diff --git a/composer.json b/composer.json index e83fbba..cd4e942 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,5 @@ { "name": "commerceguys/tax", - "version": "0.8.1", "type": "library", "description": "Tax library with a flexible data model, predefined tax rates, powerful resolving logic.", "keywords": ["tax", "vat"], diff --git a/resources/tax_type/gr_x_vat.json b/resources/tax_type/gr_x_vat.json index 8a7f2b2..4b78463 100644 --- a/resources/tax_type/gr_x_vat.json +++ b/resources/tax_type/gr_x_vat.json @@ -42,4 +42,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/src/Resolver/TaxType/CanadaTaxTypeResolver.php b/src/Resolver/TaxType/CanadaTaxTypeResolver.php index fedd4ca..8c8c0c8 100644 --- a/src/Resolver/TaxType/CanadaTaxTypeResolver.php +++ b/src/Resolver/TaxType/CanadaTaxTypeResolver.php @@ -17,76 +17,76 @@ */ class CanadaTaxTypeResolver implements TaxTypeResolverInterface { - /** - * The tax type repository. - * - * @param TaxTypeRepositoryInterface - */ - protected $taxTypeRepository; + /** + * The tax type repository. + * + * @param TaxTypeRepositoryInterface + */ + protected $taxTypeRepository; - /** - * Creates a CanadaTaxTypeResolver instance. - * - * @param TaxTypeRepositoryInterface $taxTypeRepository The tax type repository. - */ - public function __construct(TaxTypeRepositoryInterface $taxTypeRepository) - { - $this->taxTypeRepository = $taxTypeRepository; - } + /** + * Creates a CanadaTaxTypeResolver instance. + * + * @param TaxTypeRepositoryInterface $taxTypeRepository The tax type repository. + */ + public function __construct(TaxTypeRepositoryInterface $taxTypeRepository) + { + $this->taxTypeRepository = $taxTypeRepository; + } - /** - * {@inheritdoc} - */ - public function resolve(TaxableInterface $taxable, Context $context) - { - $customerAddress = $context->getCustomerAddress(); - $storeAddress = $context->getStoreAddress(); - if ($customerAddress->getCountryCode() != 'CA' || $storeAddress->getCountryCode() != 'CA') { - // The customer or the store is not in Canada. - return []; - } - // Canadian tax types are divided in two separate levels: - // FEDERAL - GST and HST always apply between canadian stores and clients - // PROVINCIAL - PST, QST and RST only apply when the store is registered in the client's province - $taxTypes = $this->getTaxTypes(); - $storeProvince = $storeAddress->getAdministrativeArea(); - $results = []; - foreach ($taxTypes as $taxType) { - $zone = $taxType->getZone(); - if ($zone->match($customerAddress)) { - // Federal taxes (GST or HST) - if ($taxType->getGenericLabel() == 'gst' || $taxType->getGenericLabel() == 'hst') { - $results[] = $taxType; - } - // Provincial taxes (PST, QST, RST), where the store is registered - $storeRegistrationTaxProvinces = $context->getStoreRegistrations(); - // Add store's province of origin, as it should always be registered there - $storeRegistrationTaxProvinces[] = !in_array($storeProvince, $storeRegistrationTaxProvinces) ? $storeProvince : ''; - if (!empty($storeRegistrationTaxProvinces)) { - foreach ($storeRegistrationTaxProvinces as $province) { - if ($zone->getMembers()->first()->getAdministrativeArea() == $province) { - $results[] = $taxType; - } - } - } - } - } + /** + * {@inheritdoc} + */ + public function resolve(TaxableInterface $taxable, Context $context) + { + $customerAddress = $context->getCustomerAddress(); + $storeAddress = $context->getStoreAddress(); + if ($customerAddress->getCountryCode() != 'CA' || $storeAddress->getCountryCode() != 'CA') { + // The customer or the store is not in Canada. + return []; + } + // Canadian tax types are divided in two separate levels: + // FEDERAL - GST and HST always apply between canadian stores and clients + // PROVINCIAL - PST, QST and RST only apply when the store is registered in the client's province + $taxTypes = $this->getTaxTypes(); + $storeProvince = $storeAddress->getAdministrativeArea(); + $results = []; + foreach ($taxTypes as $taxType) { + $zone = $taxType->getZone(); + if ($zone->match($customerAddress)) { + // Federal taxes (GST or HST) + if ($taxType->getGenericLabel() == 'gst' || $taxType->getGenericLabel() == 'hst') { + $results[] = $taxType; + } + // Provincial taxes (PST, QST, RST), where the store is registered + $storeRegistrationTaxProvinces = $context->getStoreRegistrations(); + // Add store's province of origin, as it should always be registered there + $storeRegistrationTaxProvinces[] = !in_array($storeProvince, $storeRegistrationTaxProvinces) ? $storeProvince : ''; + if (!empty($storeRegistrationTaxProvinces)) { + foreach ($storeRegistrationTaxProvinces as $province) { + if ($zone->getMembers()->first()->getAdministrativeArea() == $province) { + $results[] = $taxType; + } + } + } + } + } - return $results; - } + return $results; + } - /** - * Returns the Canadian tax types. - * - * @return TaxTypeInterface[] An array of Canadian tax types. - */ - protected function getTaxTypes() - { - $taxTypes = $this->taxTypeRepository->getAll(); - $taxTypes = array_filter($taxTypes, function ($taxType) { - return $taxType->getTag() == 'CA'; - }); + /** + * Returns the Canadian tax types. + * + * @return TaxTypeInterface[] An array of Canadian tax types. + */ + protected function getTaxTypes() + { + $taxTypes = $this->taxTypeRepository->getAll(); + $taxTypes = array_filter($taxTypes, function ($taxType) { + return $taxType->getTag() == 'CA'; + }); - return $taxTypes; - } + return $taxTypes; + } }