Initial commit of content
This commit is contained in:
parent
d6297a06c9
commit
fc95acf2de
133
README.md
133
README.md
@ -1,3 +1,132 @@
|
||||
# ttaxt
|
||||
# Tidy Tax Table (ttaxt)
|
||||
|
||||
## Purpose
|
||||
This repository contains SQL scripts to set up a database for managing VAT, sales tax, and country-related data.
|
||||
The database is designed to help businesses, especially those operating internationally, manage tax compliance
|
||||
for multiple jurisdictions, including:
|
||||
|
||||
- **VAT management** (including reverse charge mechanisms for EU transactions).
|
||||
- **U.S. sales tax compliance**, based on state-specific nexus thresholds.
|
||||
- **Country and currency tracking**, to support proper tax calculations based on customer and vendor location.
|
||||
|
||||
The system helps in tracking when sales thresholds are reached for U.S. states, managing VAT for EU customers and vendors,
|
||||
and ensuring tax compliance across different jurisdictions.
|
||||
|
||||
## Inspiration
|
||||
This project was inspired by the discussions with chatgpt around simplifying tax compliance for businesses based abroad, particularly in the EU, that need to handle VAT, U.S. sales tax, and payments to global vendors.
|
||||
|
||||
The goal is to create a flexible, lightweight solution that minimizes manual tax management while integrating with existing systems like WooCommerce and Stripe for payments and tax reporting.
|
||||
|
||||
## Solution Providers Discussed
|
||||
Some of the best solutions discussed for managing taxes and payments include:
|
||||
- **Avalara**: A comprehensive service for handling U.S. state sales tax compliance, filing, and reporting.
|
||||
- **TaxJar**: A simpler alternative to Avalara, also providing sales tax calculation and reporting.
|
||||
- **Stripe Tax**: An option for businesses using Stripe Connect, allowing for automated sales tax and VAT calculation.
|
||||
|
||||
This setup would be used as a set up to those solutions before there is sufficient income or investment to justify a full-service solution. It would rather need to be integrated with WooCommerce (+ Dokan, etc.) and Stripe and Stripe Connect and Xero or similar as a lower cost solution.
|
||||
|
||||
Later on, Avalara could be used if thresholds set in the us_sales_tax_compliance table are reached as it would justify the investment. Similar thresholds could be set for other countries or globally to reach similar conclusions.
|
||||
|
||||
## Setup
|
||||
The SQL script provided in this repository will create the following tables:
|
||||
1. **vat_rules**: To manage VAT rates and reverse charge mechanisms.
|
||||
2. **customer_rules**: Tracks VAT registration status and applicable VAT rates for customers.
|
||||
3. **vendor_rules**: Similar to customer rules but applies to vendors.
|
||||
4. **us_sales_tax_compliance**: Manages U.S. sales tax nexus thresholds and rates.
|
||||
5. **countries**: Stores country-specific data such as ISO country code, continent, and currency.
|
||||
|
||||
## Usage
|
||||
1. Run the SQL script to create the tables in your preferred database system (e.g., SQLite, PostgreSQL).
|
||||
2. Populate the tables with relevant data (e.g., VAT rates, U.S. state sales tax thresholds, country data).
|
||||
3. Use the tables to track tax compliance, apply appropriate VAT rates, and manage sales tax obligations.
|
||||
|
||||
## Example Queries for Ttaxt (Tidy Tax Table):
|
||||
|
||||
1. Query to Find VAT Rate for a Specific Country:
|
||||
This query retrieves the VAT rate and reverse charge status for a specific country (e.g., Netherlands - "NL").
|
||||
|
||||
```sql
|
||||
Copy code
|
||||
SELECT vat_rate, reverse_charge
|
||||
FROM vat_rules
|
||||
WHERE country_code = 'NL';
|
||||
Expected Result:
|
||||
vat_rate: 21.0%, reverse_charge: TRUE
|
||||
```
|
||||
|
||||
2. Query to Get U.S. Sales Tax Rate and Thresholds for a State:
|
||||
This query returns the sales tax rate, sales threshold, and transaction threshold for a specific U.S. state (e.g., California - "CA").
|
||||
|
||||
```sql
|
||||
Copy code
|
||||
SELECT sales_tax_rate, sales_threshold, transaction_threshold
|
||||
FROM us_sales_tax_compliance
|
||||
WHERE state_code = 'CA';
|
||||
Expected Result:
|
||||
sales_tax_rate: 7.25%, sales_threshold: $100,000, transaction_threshold: 200
|
||||
```
|
||||
|
||||
3. Query to Track Total Sales in a U.S. State:
|
||||
This query helps track the total sales and transactions in a specific state (e.g., New York - "NY") to monitor whether the nexus threshold has been met.
|
||||
|
||||
```sql
|
||||
Copy code
|
||||
SELECT total_sales, total_transactions
|
||||
FROM us_sales_tax_compliance
|
||||
WHERE state_code = 'NY';
|
||||
Expected Result:
|
||||
total_sales: $80,000, total_transactions: 150
|
||||
```
|
||||
|
||||
4. Query to Identify Countries with Reverse Charge VAT:
|
||||
This query retrieves all countries where the reverse charge mechanism applies for VAT.
|
||||
|
||||
```sql
|
||||
SELECT country_code, vat_rate
|
||||
FROM vat_rules
|
||||
WHERE reverse_charge = TRUE;
|
||||
Expected Result:
|
||||
country_code: 'NL', vat_rate: 21.0
|
||||
country_code: 'GB', vat_rate: 20.0
|
||||
```
|
||||
|
||||
5. Query to Check Whether a State Has Reached Sales Tax Threshold:
|
||||
This query checks if sales in a particular U.S. state (e.g., Texas - "TX") have reached the sales or transaction threshold.
|
||||
|
||||
```sql
|
||||
SELECT threshold_reached
|
||||
FROM us_sales_tax_compliance
|
||||
WHERE state_code = 'TX';
|
||||
Expected Result:
|
||||
threshold_reached: FALSE
|
||||
```
|
||||
|
||||
6. Query to Block Sales Once Threshold is Reached:
|
||||
Once a state has reached the sales or transaction threshold, this query can be used to block further sales until compliance is established.
|
||||
|
||||
```sql
|
||||
Copy code
|
||||
UPDATE us_sales_tax_compliance
|
||||
SET sales_block = TRUE
|
||||
WHERE state_code = 'CA' AND threshold_reached = TRUE;
|
||||
Expected Result:
|
||||
Sales in California will be blocked until compliance is managed.
|
||||
```
|
||||
|
||||
7. Query to Get VAT-Registered Customers and Their Rates:
|
||||
This query returns a list of VAT-registered customers and the applicable VAT rate.
|
||||
|
||||
```sql
|
||||
Copy code
|
||||
SELECT country_code, vat_rate
|
||||
FROM customer_rules
|
||||
WHERE customer_vat_registered = TRUE;
|
||||
Expected Result:
|
||||
country_code: 'FR', vat_rate: 20.0
|
||||
country_code: 'DE', vat_rate: 19.0
|
||||
```
|
||||
|
||||
These queries are examples generated by chatgpt atm and not yet tested or based on any real data.
|
||||
|
||||
Feel free to modify or extend the script to suit your specific business needs.
|
||||
|
||||
Tidy Tax Table
|
47
tax_compliance_setup.sql
Normal file
47
tax_compliance_setup.sql
Normal file
@ -0,0 +1,47 @@
|
||||
|
||||
-- SQL script to create tables for VAT, sales tax, and country information
|
||||
|
||||
-- Create table for VAT rates and rules
|
||||
CREATE TABLE vat_rules (
|
||||
country_code TEXT PRIMARY KEY,
|
||||
vat_rate REAL DEFAULT NULL,
|
||||
reverse_charge BOOLEAN DEFAULT NULL
|
||||
);
|
||||
|
||||
-- Create table for customer rules related to VAT
|
||||
CREATE TABLE customer_rules (
|
||||
country_code TEXT,
|
||||
customer_vat_registered BOOLEAN DEFAULT NULL,
|
||||
vat_rate REAL DEFAULT NULL,
|
||||
reverse_charge BOOLEAN DEFAULT NULL,
|
||||
FOREIGN KEY (country_code) REFERENCES vat_rules(country_code)
|
||||
);
|
||||
|
||||
-- Create table for vendor rules related to VAT
|
||||
CREATE TABLE vendor_rules (
|
||||
country_code TEXT,
|
||||
vendor_vat_registered BOOLEAN DEFAULT NULL,
|
||||
vat_rate REAL DEFAULT NULL,
|
||||
reverse_charge BOOLEAN DEFAULT NULL,
|
||||
FOREIGN KEY (country_code) REFERENCES vat_rules(country_code)
|
||||
);
|
||||
|
||||
-- Create table for U.S. sales tax compliance
|
||||
CREATE TABLE us_sales_tax_compliance (
|
||||
state_code TEXT PRIMARY KEY, -- U.S. state code (e.g., CA, NY)
|
||||
sales_threshold REAL, -- Sales threshold in USD (e.g., 100000)
|
||||
transaction_threshold INTEGER, -- Number of transactions threshold (e.g., 200)
|
||||
sales_tax_rate REAL, -- State sales tax rate (e.g., 7.25)
|
||||
threshold_reached BOOLEAN, -- True/False if threshold is reached
|
||||
sales_block BOOLEAN, -- True/False if sales to this state are blocked
|
||||
total_sales REAL DEFAULT 0, -- Total sales in the state
|
||||
total_transactions INTEGER DEFAULT 0 -- Total number of transactions in the state
|
||||
);
|
||||
|
||||
-- Create table for country and currency details
|
||||
CREATE TABLE countries (
|
||||
country_code TEXT PRIMARY KEY,
|
||||
country_name TEXT,
|
||||
continent TEXT,
|
||||
currency TEXT
|
||||
);
|
Loading…
Reference in New Issue
Block a user