# Journal Entry Item

## Overview  
Journal Entry Items are the individual line items that make up a journal entry. While the journal entry represents a complete accounting transaction, each item represents one side of that transaction - a specific amount being debited or credited to a specific account.

Each item specifies which general ledger account is affected and whether it's a debit or credit. The amount shows how much the account changes. Together, all the items in a journal entry must balance - total debits must equal total credits. This is the fundamental rule of double-entry accounting, and the system enforces it.

Line items often include descriptions that explain their purpose within the journal entry. While the journal entry as a whole has a description, line-level descriptions can provide additional context about each specific account being affected. This is helpful when reviewing entries later or during audits.

In complex journal entries, you might have many line items affecting different accounts. For example, a month-end closing entry might adjust multiple revenue accounts, expense accounts, and balance sheet accounts in a single transaction. Each adjustment is captured as a separate journal entry item, giving you line-by-line detail about what changed and why.

The relationship between journal entries and their items is one-to-many - each journal entry contains multiple items. When you query a journal entry through the GraphQL API, you'll typically include the items to see the complete picture. This lets you understand not just that an entry was made, but exactly which accounts were affected and by how much.

Journal entry items are created when the journal entry is created and can be modified while the entry is in draft status. Once the journal entry is posted, the items become locked and create the actual general ledger entries. This ensures that posted accounting transactions are immutable, maintaining the integrity of your financial records.

---

### GraphQL API  
The `journalEntryItem` collection provides access to journalEntryItem data via the GraphQL API. All queries use the Relay connection specification with cursor-based pagination.

**Query Name:**`journalEntryItemViewConnection`

**Available Features:**

- Cursor-based pagination (first/last/after/before)
- 3 relations to other collections

## Query Examples  
### Basic Query  
The `journalEntryItem` collection is accessed via the `journalEntryItemViewConnection` query, which returns a Relay-style connection with pagination support.

```graphql
query {
  journalEntryItemViewConnection(first: 10) {
    edges {
      node {
        accountingClass
        amount
        effectiveDateAvgCost
        expectedAverageCost
        itemIndex
      }
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
}
```

### Pagination  
Use cursor-based pagination to retrieve large datasets:

```graphql
# First page
query {
  journalEntryItemViewConnection(first: 50) {
    edges {
      node { accountingClass }
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
}

# Subsequent pages
query {
  journalEntryItemViewConnection(first: 50, after: "cursor-from-previous-page") {
    edges {
      node { accountingClass }
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
}
```

### Relations  
Query related data:

```graphql
query {
  journalEntryItemViewConnection(first: 10) {
    edges {
      node {
        accountingClass
        creditAccount {
          name
          glAccountUrl
        }
      }
    }
  }
}
```

## Summary and Aggregation  
This collection supports data aggregation and dimensional analysis through the `summary` field. You can calculate metrics (like totals, averages, counts) and group them by dimensions.

### Query Structure  
```graphql
journalEntryItemViewConnection(filters...) {
  summary {
    errorCode
    errorMessage
    groupBy {
      # Group by dimensions
    }
    metrics {
      # Calculated metrics
    }
  }
}
```

### Available Metrics  
This collection provides 25 metrics that can be aggregated:

| Metric | Parameters | Description |
| --- | --- | --- |
| `journalEntryTotalAmount` | `transform`, `operator` | journalEntryTotalAmount for journalEntryItem |
| `productNeqPerUnit` | `transform`, `operator` | productNeqPerUnit for journalEntryItem |
| `productLastPurchaseLandedCostPerUnit` | `transform`, `operator` | productLastPurchaseLandedCostPerUnit for journalEntryItem |
| `productLastPurchasePrice` | `transform`, `operator` | productLastPurchasePrice for journalEntryItem |
| `productAverageGrossSalesPerUnit` | `transform`, `operator`, `dateRange`, `facilityUrlList` | productAverageGrossSalesPerUnit for journalEntryItem |
| `productAverageUnitsPerSale` | `transform`, `operator`, `dateRange`, `facilityUrlList` | productAverageUnitsPerSale for journalEntryItem |
| `productCogsSales` | `transform`, `operator`, `dateRange`, `facilityUrlList` | productCogsSales for journalEntryItem |
| `productCountSales` | `transform`, `operator`, `dateRange`, `facilityUrlList` | productCountSales for journalEntryItem |
| `productGrossSales` | `transform`, `operator`, `dateRange`, `facilityUrlList` | productGrossSales for journalEntryItem |
| `productMarginSales` | `transform`, `operator`, `dateRange`, `facilityUrlList` | productMarginSales for journalEntryItem |
| `productUnitSales` | `transform`, `operator`, `dateRange`, `facilityUrlList` | productUnitSales for journalEntryItem |
| `productUnitSalesForSalesVelocity` | `transform`, `operator`, `dateRange`, `facilityUrlList` | productUnitSalesForSalesVelocity for journalEntryItem |
| `productReorderQuantityToOrder` | `transform`, `operator`, `facilityUrlList`, `facilityUrl`, `reservedSublocationFacilityUrlList` | productReorderQuantityToOrder for journalEntryItem |
| `productReorderQuantityToOrderEditable` | `transform`, `operator`, `facilityUrlList`, `facilityUrl`, `reservedSublocationFacilityUrlList` | productReorderQuantityToOrderEditable for journalEntryItem |
| `productReplenishmentQuantityToOrder` | `transform`, `operator`, `facilityUrlList`, `facilityUrl`, `reservedSublocationFacilityUrlList` | productReplenishmentQuantityToOrder for journalEntryItem |
| `productReplenishmentQuantityToOrderEditable` | `transform`, `operator`, `facilityUrlList`, `facilityUrl`, `reservedSublocationFacilityUrlList` | productReplenishmentQuantityToOrderEditable for journalEntryItem |
| `productStock` | `transform`, `operator`, `aggregate`, `count`, `facilityUrlList`, `includeBom`, `includeSupplier`, `lotIdSearch`, `stockType` | productStock for journalEntryItem |
| `productStockOnHand` | `transform`, `operator`, `aggregate`, `count`, `facilityUrlList`, `includeBom`, `includeSupplier`, `lotIdSearch`, `reservedSublocationFacilityUrlList` | productStockOnHand for journalEntryItem |
| `productStockReserved` | `transform`, `operator`, `aggregate`, `count`, `facilityUrlList`, `includeBom`, `lotIdSearch`, `reservationType` | productStockReserved for journalEntryItem |
| `productStockOnOrder` | `transform`, `operator`, `aggregate`, `count`, `facilityUrlList`, `includeBom`, `lotIdSearch` | productStockOnOrder for journalEntryItem |
| `productStockAvailable` | `transform`, `operator`, `aggregate`, `count`, `facilityUrlList`, `includeBom`, `includeSupplier`, `lotIdSearch`, `reservedSublocationFacilityUrlList` | productStockAvailable for journalEntryItem |
| `productStockRemaining` | `transform`, `operator`, `aggregate`, `count`, `facilityUrlList`, `includeBom`, `includeSupplier`, `lotIdSearch` | productStockRemaining for journalEntryItem |
| `productAverageCost` | `transform`, `operator` | productAverageCost for journalEntryItem |
| `productValuation` | `transform`, `operator`, `facilityUrlList`, `lotIdSearch` | productValuation for journalEntryItem |
| `count` | None | Count of items in the result set |

**Common Parameters:**
- `operator` \- Aggregation function: `sum`, `mean`, `min`, `max`
- `transform` \- Mathematical transformation: `abs`
- `dateRange` \- Filter to specific date range
- `facilityUrlList` \- Filter to specific facilities

### GroupBy Dimensions  
Group metrics by these dimensions:

| Dimension | Description |
| --- | --- |
| `productCategory` | productCategory for journalEntryItem |
| `productSupplier1` | productSupplier1 for journalEntryItem |
| `productSupplier2` | productSupplier2 for journalEntryItem |
| `productSupplier3` | productSupplier3 for journalEntryItem |

All dimensions accept a `formatter` parameter: "html", "none", "abbreviated", "blank-zero".

### Examples  
#### Example 1: Basic Aggregation  
Calculate metrics for journalEntryItem:

```graphql
query {
  journalEntryItemViewConnection(first: 1) {
    summary {
      errorCode
      errorMessage
      groupBy {
        # Add dimensions here
      }
      metrics {
        totalCount: count
      }
    }
  }
}
```

## Fields  
This collection has 9 fields:

- 9 simple fields
- 0 enum fields
- 0 parameterized fields

### Simple Fields  
#### `accountingClass`  
An optional classification value used to categorize and group journal entry items for accounting purposes. This field stores a text value that represents a configured accounting dimension such as a sales source (e.g., "Amazon", "Shipstation"), product category, or custom field value. The accounting class is automatically computed based on the journal entry type and the system's accounting class configuration, which determines which business dimension (sales source, product category, or custom field) should be used for classification.

**Label:** Accounting class

**Sortable:** No

---

#### `amount`  
The monetary value being transferred between the debit and credit accounts for this journal entry item. This field is required for standard journal entries (JOURNAL_ENTRY type) but is not used for average cost change entries (AVERAGE_COST_CHANGE type). The amount must be a valid currency value with precision to two decimal places (X.XX). Values are automatically rounded to currency precision during import, and negative amounts are permitted to represent reversals or corrections.

**Label:** Amount

**Sortable:** No

---

#### `creditAccount`  
The general ledger account that receives the credit side of the accounting entry for this journal entry item. In double-entry accounting, every transaction affects at least two accounts - one debited and one credited. This field specifies which account is credited for this particular item.

**Label:** Credit account

**Sortable:** No

---

#### `debitAccount`  
The general ledger account to be debited in a journal entry line item. In double-entry accounting, each journal entry item specifies either a debit account or a credit account.

**Label:** Debit account

**Sortable:** No

---

#### `effectiveDateAvgCost`  
The product's average cost as of the journal entry's effective date. This field represents a calculated snapshot of what the product's average cost was at the specific point in time when the journal entry takes effect.

**Label:** Effective date avg cost

**Sortable:** No

---

#### `expectedAverageCost`  
The target average cost value for a product when recording an average cost change. This field is used exclusively in journal entries with type AVERAGE_COST_CHANGE.

**Label:** Expected avg cost

**Sortable:** No

---

#### `itemIndex`  
The sequential position of this item within the journal entry's item list, using 1-based numbering.

**Label:** Item index

**Sortable:** No

---

#### `notes`  
A free-form text field for adding descriptive comments or explanations to individual journal entry line items.

**Label:** Item notes

**Sortable:** No

---

#### `resultingAvgCost`  
The product's average cost after the journal entry takes effect. This read-only calculated field shows what the average cost will be once the journal entry is processed.

**Label:** Resulting avg cost

**Sortable:** No

---

## Relations  
### creditAccount  
- **Related Collection:** generalLedgerAccount  
- **Label:** Credit account

### debitAccount  
- **Related Collection:** generalLedgerAccount  
- **Label:** Debit account

### product  
- **Related Collection:** product  
- **Label:** Product

## Filters  
No filters available.
