Download the PHP package azaharizaman/nexus-tax without Composer
On this page you can find all versions of the php package azaharizaman/nexus-tax. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download azaharizaman/nexus-tax
More information about azaharizaman/nexus-tax
Files in azaharizaman/nexus-tax
Package nexus-tax
Short Description Framework-agnostic tax calculation engine with multi-jurisdiction support, temporal rate resolution, hierarchical tax structure, reverse charge mechanism, economic nexus determination, partial exemptions, and place-of-supply rules for cross-border services
License MIT
Informations about the package nexus-tax
Nexus\Tax
A framework-agnostic, stateless tax calculation engine with multi-jurisdiction support, temporal rate resolution, hierarchical tax structure, reverse charge mechanism, economic nexus determination, partial exemptions, place-of-supply rules for cross-border services, currency conversion for compliance reporting, and audit-ready immutable logging.
Table of Contents
- Overview
- Installation
- Core Concepts
- Tax Jurisdiction
- Economic Nexus
- Place of Supply
- Effective Dating & Temporal Queries
- Reverse Charge Mechanism
- Tax Holidays
- Partial Exemptions
- Hierarchical Tax Structure
- Immutable Audit Log
- Architecture
- Folder Structure
- Value Objects
- Enums
- Interfaces
- Usage Examples
- Basic Tax Calculation
- Jurisdiction Resolution with Place of Supply
- Nexus Checking
- Partial Exemption Application
- Reverse Charge Scenario
- Multi-Currency Compliance Reporting
- Tax Adjustment via Contra-Transaction
- Preview Mode Pattern
- Integration Patterns
- Performance Characteristics
- Compliance Features
- Future Enhancements
- License
Overview
The Nexus\Tax package provides a comprehensive, framework-agnostic tax calculation engine designed for global ERP systems requiring multi-jurisdiction tax compliance. It handles complex scenarios including:
- Multi-level compound taxes (Federal → State → Local cascading)
- Temporal rate lookups with effective dating for historical accuracy
- Economic nexus determination for US state sales tax compliance
- Place-of-supply rules for cross-border digital services (EU VAT, Australia GST)
- Reverse charge mechanism for B2B cross-border transactions
- Partial tax exemptions with certificate management
- Multi-currency compliance reporting with automatic conversion
- Immutable audit logs ensuring 7-10 year retention compliance
Key Principle: This package is a pure calculation engine. It defines what needs to be calculated but remains stateless regarding data persistence. The consuming application layer implements repositories and handles audit log persistence.
Installation
Dependencies
This package requires the following Nexus packages:
azaharizaman/nexus-finance- GL account integrationazaharizaman/nexus-currency- Multi-currency support and conversionazaharizaman/nexus-geo- Geocoding for jurisdiction resolutionazaharizaman/nexus-party- Customer/vendor address dataazaharizaman/nexus-product- Product tax categoriesazaharizaman/nexus-tenant- Multi-tenancy contextazaharizaman/nexus-audit-logger- Optional audit trail loggingazaharizaman/nexus-telemetry- Optional telemetry trackingazaharizaman/nexus-storage- Optional exemption certificate PDF storage
Core Concepts
Tax Jurisdiction
A tax jurisdiction represents the geographic and administrative scope where a specific tax regime applies. Jurisdictions can be hierarchical:
- Federal/National (e.g., Canada GST, Malaysia SST)
- State/Province (e.g., California sales tax, Ontario PST)
- Local/Municipal (e.g., Denver city tax, Toronto municipal tax)
The TaxJurisdictionResolverInterface determines the applicable jurisdiction based on transaction details (ship-from address, ship-to address, service classification).
Economic Nexus
Economic nexus is the legal obligation to collect and remit sales tax in a jurisdiction where the business has sufficient "economic presence," even without physical presence.
Example: A US state may require sales tax collection if annual revenue exceeds $100,000 OR transaction count exceeds 200.
The TaxNexusManagerInterface checks historical transaction data against jurisdiction-specific thresholds via the NexusThreshold Value Object.
Key Decision: Nexus determination is stateful (requires historical data analysis) and therefore belongs in the application layer implementation, not the stateless tax engine.
Place of Supply
Place of supply rules determine where a transaction is considered to occur for tax purposes. This is critical for cross-border services:
- Digital Services (e.g., SaaS, streaming): Destination-based (taxed where customer is located)
- Physical Goods: Origin or destination-based depending on jurisdiction rules
- Professional Services (e.g., consulting): Supplier location-based
The ServiceClassification enum drives place-of-supply resolution in the TaxJurisdictionResolver.
Effective Dating & Temporal Queries
Tax rates change frequently. All tax rate lookups MUST include an effective date to ensure historical accuracy for audits and reporting.
Tax holidays (temporary rate reductions) are modeled as standard TaxRate records with 0.00% or reduced rate during the holiday period's effectiveStartDate and effectiveEndDate.
Reverse Charge Mechanism
Reverse charge (RCM) is a tax deferral mechanism for B2B cross-border transactions (common in EU VAT). Instead of the supplier charging VAT, the customer self-assesses the tax.
Critical: Reverse charge is NOT an exemption (tax still applies), it's a calculation method where:
- Tax amount = $0.00 on invoice
- Liability deferred to buyer
- Special GL account tracks deferred liability
The TaxCalculationMethod::ReverseCharge enum case triggers this logic.
Tax Holidays
Temporary tax rate reductions (e.g., back-to-school sales tax holidays). Modeled as standard TaxRate records with:
The temporal query system automatically applies the correct rate based on transaction date.
Partial Exemptions
Some entities have partial tax exemptions (e.g., 50% exempt for agricultural cooperatives). The ExemptionCertificate Value Object includes:
The calculation engine reduces the taxable base by the exemption percentage before applying tax rates:
Hierarchical Tax Structure
Compound taxes (tax-on-tax) require hierarchical calculation. The TaxBreakdown Value Object supports nested TaxLine objects:
Each TaxRate has an applicationOrder: int property. The calculator:
- Fetches applicable rates
- Sorts by
applicationOrder - Applies sequentially, building hierarchy
Immutable Audit Log
The Tax Audit Log is immutable. No UPDATE or DELETE operations are permitted. Adjustments require:
- Contra-Transaction Pattern: Create a new transaction with negative amounts
- New Calculation: Pass updated
TaxContextto calculator - Negative Result: Returns
TaxBreakdownwith negative amounts - Persist as New Record: Application layer saves new audit log entry
This ensures complete audit trail with original calculation + correction linkage.
Architecture
Stateless Calculation Engine Pattern
Key Principles:
- Dependency Inversion: Package defines interfaces, application implements
- Statelessness: No database queries, no file I/O, pure calculation
- Temporal Queries: All repository methods require
\DateTimeInterface - Decorator Pattern: Caching, storage, notifications added by application
Folder Structure
Value Objects
All Value Objects are final readonly classes using BCMath for precision.
TaxContext
Encapsulates all inputs required for tax calculation.
TaxRate
Represents a single tax rate with temporal validity.
Key Property: applicationOrder controls calculation sequence for compound taxes.
TaxBreakdown
Hierarchical structure representing calculated tax.
TaxLine
Individual tax line within breakdown (supports nesting).
ExemptionCertificate
Tax exemption certificate metadata.
NexusThreshold
Economic nexus threshold for a jurisdiction.
Enums
All enums use native PHP 8.3 enum with business logic methods.
TaxType
TaxCalculationMethod
ServiceClassification
Interfaces
TaxCalculatorInterface
TaxRateRepositoryInterface
TaxJurisdictionResolverInterface
TaxNexusManagerInterface
TaxExemptionManagerInterface
TaxReportingInterface
Usage Examples
Basic Tax Calculation
Jurisdiction Resolution with Place of Supply
Nexus Checking
Partial Exemption Application
Reverse Charge Scenario
Multi-Currency Compliance Reporting
Tax Adjustment via Contra-Transaction
Preview Mode Pattern
Integration Patterns
Sales Package Adapter
Caching Decorator for Jurisdiction Resolver
Exemption Certificate Storage Decorator
Performance Characteristics
BCMath Precision Overhead
Tax calculations use bcmath extension for arbitrary precision arithmetic to avoid floating-point errors. This adds ~10-20% overhead vs native float operations but ensures audit-accurate calculations.
Caching Recommendations
High Cache Value:
- Jurisdiction Resolution: Geocoding API calls expensive (100-500ms). Cache by address hash for 24 hours.
- Nexus Threshold Lookup: Rarely changes. Cache by jurisdiction for 7 days.
- Tax Rate Lookup: Moderate cache value. Cache by code+date for 1 hour (invalidate on rate updates).
Low Cache Value:
- Exemption Validation: Fast database lookup (<10ms). Caching optional.
- Tax Calculation: Pure computation (<5ms). Don't cache results.
Recommended Indexes
Compliance Features
7-10 Year Retention
MANDATE: Tax audit logs must be retained for 7-10 years depending on jurisdiction.
Implementation: Use Nexus\Scheduler to automate archival:
EventStream Publishing Mandate
REQUIREMENT: Application layer MUST publish TaxCalculatedEvent after audit log persistence for real-time data warehouse sync.
Rate Change Monitoring
REQUIREMENT: Application layer monitors future-dated tax rates and triggers notifications.
Future Enhancements
Phase 2 Roadmap
- Tax Treaty Support - International withholding tax treaties (
TaxTreatyManagerInterface) - Tax Incentive Zones - SEZ/Free Zone reduced rates (extend
TaxJurisdictionVO) - Cascading Tax - Tax-on-tax for specific jurisdictions (extend calculation logic)
- VAT Registration Validation - VIES number checking (
TaxRegistrationValidatorInterface) - Split Payment Mechanism - Italy VAT split payment (extend calculation method)
- Real-time Rate API Integration - Avalara/TaxJar sync (
TaxRateProviderInterface) - Tax Exemption OCR - Certificate PDF parsing (integrate
Nexus\DataProcessor)
📖 Documentation
Package Documentation
- Getting Started Guide - Quick start guide with prerequisites and basic configuration
- API Reference - Complete documentation of all interfaces and components
- Integration Guide - Laravel and Symfony integration examples
- Basic Usage Example - Simple usage patterns
- Advanced Usage Example - Advanced scenarios
Additional Resources
IMPLEMENTATION_SUMMARY.md- Implementation progress and metricsREQUIREMENTS.md- Detailed requirementsTEST_SUITE_SUMMARY.md- Test coverage and resultsVALUATION_MATRIX.md- Package valuation metrics- See root
ARCHITECTURE.mdfor overall system architecture
License
MIT License. See LICENSE file for details.
Package Version: 1.0.0
Last Updated: November 24, 2025
Maintained By: Nexus Architecture Team
All versions of nexus-tax with dependencies
psr/cache Version ^3.0
psr/log Version ^3.0
azaharizaman/nexus-common Version dev-main