# Journal Entry

## Overview

Journal Entries are manual accounting entries that directly update the General Ledger without corresponding to physical transactions. They're used for adjustments, corrections, period-end accruals, and other accounting operations that don't flow from normal business transactions like shipments or invoices.

The primary use case is accounting adjustments. If you discover an error in a previous entry, a journal entry can correct it. If you need to accrue expenses at month-end that haven't been invoiced yet, a journal entry records the accrual. If you need to reclassify amounts from one account to another, a journal entry makes the move. These manual entries give your accounting team the flexibility to keep books accurate despite the complexities of real-world business.

Each journal entry contains multiple line items - typically at least two, since debits must equal credits. Each line specifies a GL account, whether it's a debit or credit, and the amount. The entry as a whole has a date (when it applies) and a description (explaining what it's for). This structure follows standard double-entry accounting and ensures the books stay balanced.

Consolidation journal entries are a special type created automatically by the system. When multiple shipments or invoices are consolidated, the system creates a consolidation journal entry that aggregates their GL impact into a single entry. This reduces GL clutter while preserving transaction detail. Consolidation entries are marked with a special type so they can be identified and excluded from certain reports.

Journal entries support period-end accounting processes. At the end of a month or year, you might need to record depreciation, accrue unbilled revenue, adjust prepaid expenses, or make other timing adjustments. Journal entries handle these non-transactional accounting needs, ensuring your financial statements accurately reflect your financial position even when the timing of business transactions doesn't perfectly align with accounting periods.

The workflow for journal entries typically involves creating them in a draft state, reviewing them for accuracy, and then posting them to make them permanent. Once posted, they create the actual GL entries and become locked. If a posted journal entry needs to be corrected, you can't edit it - you must void it (creating reversing entries) and create a new correct entry, maintaining a complete audit trail.

### GraphQL API

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

**Query Name:**`journalEntryViewConnection`

**Available Features:**

- Cursor-based pagination (first/last/after/before)
- 14 filter options
- 15 sortable fields
- 5 relations to other collections

## Query Examples

### Basic Query

The `journalEntry` collection is accessed via the `journalEntryViewConnection` query, which returns a Relay-style connection with pagination support.

GraphQL

```graphql
query {
  journalEntryViewConnection(first: 10) {
    edges {
      node {
        consolidationCustomer
        consolidationDescription
        consolidationPeriod
        consolidationSaleSource
        date
      }
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
}
```

### Pagination

Use cursor-based pagination to retrieve large datasets:

GraphQL

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

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

### Filtering

Apply filters to narrow results:

GraphQL

```graphql
query {
  journalEntryViewConnection(
    first: 10
    connectionRelationErrorDates: { begin: "2024-01-01", end: "2024-12-31" }
  ) {
    edges {
      node { journalEntryId }
    }
  }
}
```

### Sorting

Sort results by one or more fields:

GraphQL

```graphql
query {
  journalEntryViewConnection(
    first: 10
    sort: [{ field: "consolidationCustomer", mode: "desc" }]
  ) {
    edges {
      node {
        journalEntryId
        consolidationCustomer
      }
    }
  }
}
```

### Relations

Query related data:

GraphQL

```graphql
query {
  journalEntryViewConnection(first: 10) {
    edges {
      node {
        journalEntryId
        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 (like category, date, status).

### Query Structure

GraphQL

```graphql
journalEntryViewConnection(filters...) {
  summary {
    errorCode
    errorMessage
    groupBy {
      # Group by dimensions (see table below)
    }
    metrics {
      # Calculated metrics (see table below)
    }
  }
}
```

### Available Metrics

This collection provides 25 metrics that can be aggregated:

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

### GroupBy Dimensions

Group metrics by these dimensions:

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

### Simple Fields

These fields return values directly without additional options.

#### `consolidationCustomer`
The customer party associated with a consolidated transaction journal entry. Retrieved from the consolidatedTransactionDescriptorList by looking up the consolidationPartyUrl and validating the party has a CUSTOMER role type.

**Label:** Consolidation customer

**Sortable:** Yes

**Default Formatter:**`html`

**Example Query:**

```graphql
{
  journalEntry(journalEntryUrl: "example-url") {
    consolidationCustomer    # Uses default formatter: html
    consolidationCustomerRaw: consolidationCustomer(formatter: "none")  # Get raw value
  }
}
```

#### `date`
The transaction date of the journal entry. Used for filtering and sorting journal entries chronologically.

**Label:** Effective date

**Sortable:** Yes

**Enum Fields**

- `averageCostChangeWarning`
- `consolidationPeriod`
- `status`
- `type`

## Relations

### `creditAccount`
- **Related Collection:** [generalLedgerAccount](https://developer.finaleinventory.com/reference/graphql-general-ledger-account)
- **Label:** Credit account

#### Example Query:

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

### Filtering Example

```graphql
query {
  journalEntryViewConnection(
    first: 10
    date: { begin: "2024-01-01", end: "2024-12-31" }
  ) {
    edges {
      node {
        journalEntryId
        date
      }
    }
  }
}
```

### Last updated

```graphql
query {
  journalEntryViewConnection(
    first: 10
    recordLastUpdated: {
      begin: "2024-01-01"
      end: "2024-12-31"
    }
  ) {
    edges {
      node {
        journalEntryId
        recordLastUpdated
      }
    }
  }
}
```
