انتقل إلى المحتوى الرئيسي

Tax Transactions

Overview

The Tax Transactions API provides endpoints for querying posted tax transactions generated from general ledger journals. These transactions represent the calculated taxes based on the intersection of Tax Groups and Tax Item Groups assigned to journal lines.

Base URL

/api/v1/general-ledger/general-journals

Authentication

All endpoints require authentication. Include the JWT token in the Authorization header:

Authorization: Bearer <jwt-token>

Endpoints

Get Tax Transactions for Journal

Retrieves all tax transactions associated with a posted journal. Tax transactions are created during the posting process and represent the calculated tax amounts based on the intersection logic between Tax Groups and Tax Item Groups.

Endpoint: GET /general-journals/{journalId}/tax-transactions

Parameters:

  • journalId (UUID, required): The unique identifier of the posted journal

Request Example:

GET /api/v1/general-ledger/general-journals/a1b2c3d4-e5f6-7a8b-9c0d-e1f2a3b4c5d6/tax-transactions
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Accept: application/json

Success Response:

  • Code: 200 OK
  • Content-Type: application/json
[
{
"id": "f1e2d3c4-b5a6-7f8e-9d0c-1b2a3f4e5d6c",
"generalJournalEntryId": "a1b2c3d4-e5f6-7a8b-9c0d-e1f2a3b4c5d6",
"voucher": "TAX-V-001",
"transactionDate": "2025-10-01T10:00:00.000Z",
"currencyCode": "AED",
"taxAmount": 50.00,
"sourceAmount": 1000.00,
"taxValue": 5.00,
"taxDirection": "Input",
"source": "GeneralJournal",
"taxCodeId": "a6b7c8d9-e0f1-8901-23ab-cdef45678901",
"taxCodeCode": "STD_5",
"taxCodeName": "Standard Tax 5%",
"taxGroupId": "e6f7a8b9-c0d1-8901-23ef-abcd45678901",
"taxGroupCode": "RETAIL_STD",
"taxItemGroupId": "d1e2f3a4-b5c6-3456-78de-fabc90123456",
"taxItemGroupCode": "SCENT_OILS_STANDARD"
}
]

Response Fields:

FieldTypeDescription
idUUIDUnique identifier of the tax transaction
generalJournalEntryIdUUIDReference to the parent general journal entry
voucherstringVoucher number from the original journal line
transactionDatedatetimeTransaction date from the original journal line
currencyCodestringCurrency code for all monetary amounts
taxAmountdecimalCalculated tax amount for this tax code
sourceAmountdecimalOriginal transaction amount before tax
taxValuedecimalTax percentage rate applied (e.g., 5.00 for 5%)
taxDirectionstringDirection of tax flow: "Input" (receivable) or "Output" (payable)
sourcestringSource type of the transaction (e.g., "GeneralJournal", "SalesInvoice")
taxCodeIdUUIDIdentifier of the applied tax code
taxCodeCodestringCode of the applied tax code
taxCodeNamestringName of the applied tax code
taxGroupIdUUIDIdentifier of the tax group from the transaction
taxGroupCodestringCode of the tax group
taxItemGroupIdUUIDIdentifier of the tax item group from the transaction
taxItemGroupCodestringCode of the tax item group

Error Responses:

  • Code: 404 Not Found

    {
    "error": "Journal with ID a1b2c3d4-e5f6-7a8b-9c0d-e1f2a3b4c5d6 not found"
    }
  • Code: 400 Bad Request

    {
    "error": "Invalid journal ID format"
    }

Tax Calculation Logic

Intersection-Based Tax Determination

The system uses an intersection model (Venn diagram logic) to determine which tax codes apply to a transaction:

  1. Tax Group contains tax codes applicable to the entity (Customer, Vendor, etc.)
  2. Tax Item Group contains tax codes applicable to the item/service
  3. Effective Tax Codes are the intersection of codes from both groups
  4. Each effective tax code generates a separate TaxTransaction record

Example Scenario

Tax Group: RETAIL_STD

  • Contains: STD_5 (5%), STD_10 (10%), CITY_TAX (2%)

Tax Item Group: SCENT_OILS_STANDARD

  • Contains: STD_5 (5%), IMPORT_DUTY (3%)

Intersection (Applied Taxes):

  • STD_5 (5%) - Present in both groups

Result:

  • Only one TaxTransaction is created for STD_5 at 5%
  • Transaction amount: 1000 AED
  • Tax amount: 50 AED (1000 × 5%)

Tax Direction

Tax direction is determined by the account type and transaction type:

  • Input Tax (Receivable): Tax paid on purchases, recorded as an asset

    • Example: VAT paid when purchasing goods
    • GL Account: Tax Receivable (Asset)
  • Output Tax (Payable): Tax collected on sales, recorded as a liability

    • Example: VAT collected when selling goods
    • GL Account: Tax Payable (Liability)

Usage Examples

Successful Query - Single Tax Transaction

curl -X GET \
"https://api.example.com/api/v1/general-ledger/general-journals/a1b2c3d4-e5f6-7a8b-9c0d-e1f2a3b4c5d6/tax-transactions" \
-H "Authorization: Bearer <token>" \
-H "Accept: application/json"

Response:

[
{
"id": "f1e2d3c4-b5a6-7f8e-9d0c-1b2a3f4e5d6c",
"generalJournalEntryId": "a1b2c3d4-e5f6-7a8b-9c0d-e1f2a3b4c5d6",
"voucher": "TAX-V-001",
"transactionDate": "2025-10-01T10:00:00.000Z",
"currencyCode": "AED",
"taxAmount": 50.00,
"sourceAmount": 1000.00,
"taxValue": 5.00,
"taxDirection": "Input",
"source": "GeneralJournal",
"taxCodeId": "a6b7c8d9-e0f1-8901-23ab-cdef45678901",
"taxCodeCode": "STD_5",
"taxCodeName": "Standard Tax 5%",
"taxGroupId": "e6f7a8b9-c0d1-8901-23ef-abcd45678901",
"taxGroupCode": "RETAIL_STD",
"taxItemGroupId": "d1e2f3a4-b5c6-3456-78de-fabc90123456",
"taxItemGroupCode": "SCENT_OILS_STANDARD"
}
]

Successful Query - Multiple Tax Transactions

When a journal has multiple lines with different tax configurations:

[
{
"id": "f1e2d3c4-b5a6-7f8e-9d0c-1b2a3f4e5d6c",
"voucher": "TAX-V-002",
"taxAmount": 25.00,
"sourceAmount": 500.00,
"taxValue": 5.00,
"taxCodeCode": "STD_5"
},
{
"id": "a2b3c4d5-e6f7-8a9b-0c1d-2e3f4a5b6c7d",
"voucher": "TAX-V-002",
"taxAmount": 37.50,
"sourceAmount": 750.00,
"taxValue": 5.00,
"taxCodeCode": "STD_5"
}
]

Query with No Tax Transactions

If the journal has no taxable lines (no tax groups specified):

Response:

[]

Integration with Journal Posting

Pre-Posting

During journal line creation:

  1. Client specifies optional tax_group_id and tax_item_group_id
  2. System validates that both IDs exist
  3. System calculates and stores tax amount and rate on the journal line
  4. No TaxTransaction records are created yet

During Posting

When the journal is posted:

  1. System reads the stored tax information from each journal line
  2. For each line with tax data:
    • Creates a GeneralJournalEntry record
    • Creates corresponding TaxTransaction records
    • Links tax transactions to the journal entry
  3. Tax transactions become immutable after posting

Post-Posting

After posting:

  1. Tax transactions can be queried via this endpoint
  2. Tax transactions are included in tax reports and settlements
  3. Tax transactions cannot be modified or deleted
  4. Tax transactions are included in audit trails

Business Rules

  1. Journal Must Be Posted: Tax transactions are only created during posting
  2. Tax Group Intersection: Only tax codes in both groups are applied
  3. One Transaction Per Tax Code: Each effective tax code creates one transaction per journal line
  4. Immutability: Tax transactions cannot be modified after creation
  5. Currency Consistency: All amounts use the transaction's currency
  6. Audit Trail: All tax transactions are fully auditable with source references
  • POST /general-journals/{journalId}/transactions - Add journal line with tax
  • PUT /general-journals/{journalId}/post - Post journal and create tax transactions
  • GET /tax/tax-groups/{taxGroupId} - Get tax group details
  • GET /tax/tax-item-groups/{taxItemGroupId} - Get tax item group details
  • POST /general-journals/preview-sales-tax - Preview tax before posting

Testing Considerations

Test Scenarios

  1. Single Taxable Line

    • Create journal with one line
    • Assign both tax groups
    • Verify single tax transaction created
  2. Multiple Taxable Lines

    • Create journal with multiple lines
    • Use different tax group combinations
    • Verify correct number of transactions
  3. Mixed Taxable and Non-Taxable

    • Some lines with tax groups
    • Some lines without tax groups
    • Verify only taxable lines create transactions
  4. Zero Intersection

    • Tax groups with no common tax codes
    • Verify no tax transactions created
  5. Multiple Tax Codes

    • Tax groups with multiple common codes
    • Verify multiple transactions per line

Verification Checklist

  • Tax amounts calculated correctly (source × rate)
  • Tax direction set appropriately
  • All reference IDs populated correctly
  • Voucher numbers match journal lines
  • Transaction dates match journal lines
  • Currency codes consistent
  • No tax transactions for non-taxable lines
  • Tax transactions immutable after posting

Performance Considerations

  • Query is optimized for posted journals
  • Indexes on general_journal_entry_id and voucher
  • Consider pagination for journals with many lines
  • Tax calculations performed during posting, not during query
  • Response time typically < 100ms for standard journals

Security Considerations

  • Requires authentication for all requests
  • Only authorized users can query tax transactions
  • Tax transactions are read-only via this endpoint
  • Audit logging for all tax transaction queries
  • No sensitive tax calculation logic exposed in responses