Identify orders entered in a different GL period than when placed and generate revenue adjustment entries
harbor run -t snowflake-labs/late-arriving-orders-reconciliationharbor download snowflake-labs/late-arriving-orders-reconciliationIn enterprise accounting systems, orders sometimes arrive in the system after the accounting period in which they were actually placed. This creates revenue recognition issues - the revenue should be recognized in the period when the order was placed (ORDERED_AT), not when it was entered into the system (CREATED_AT).
Your company needs to identify these late-arriving orders and generate adjustment entries to correct the revenue allocation across GL periods.
Identify orders that were entered into the system in a different GL period than when they were actually ordered, and calculate the necessary adjustment entries to correct the revenue recognition for each affected period.
This task supports both DuckDB and Snowflake. Run echo $DB_TYPE in a shell BEFORE you write any code or spawn any subagents — the live env determines which backend the verifier runs against. Do NOT assume a default from this prose. Both /app/dbt_models_duckdb/ and /app/dbt_models_snowflake/ exist on disk; the verifier only checks the project matching the live $DB_TYPE.
DB_TYPE=duckdb$DUCKDB_PATH (default: /app/database/retail.duckdb)DB_TYPE=snowflakeSNOWFLAKE_ACCOUNTSNOWFLAKE_USERSNOWFLAKE_PASSWORDSNOWFLAKE_DATABASE - The clone database to useSNOWFLAKE_SCHEMASNOWFLAKE_WAREHOUSESNOWFLAKE_ROLE (optional)Note: For Snowflake, the entrypoint automatically creates a clone database and sets SNOWFLAKE_DATABASE. The clone is destroyed when the task completes.
You must connect to the database based on DB_TYPE:
Use duckdb.connect() with the path from $DUCKDB_PATH.
Use snowflake.connector.connect() with password authentication:
The database contains the following tables:
ORDERS.ORDERS - Order data with identifiers, timestamps (ORDERED_AT, CREATED_AT), monetary amounts (GRAND_TOTAL), currency information (CURRENCY_CODE, EXCHANGE_RATE), and status. Explore the table to understand all available columns.
FINANCE.GL_PERIODS - Accounting periods with period identifiers, names (YYYY-MM format), fiscal year/month, date boundaries (START_DATE, END_DATE), and status. Explore the table to understand all available columns.
FINANCE.CURRENCY_EXCHANGE_RATES - Historical exchange rates with currency pairs and effective dates. Explore the table to understand all available columns.
Identify late-arriving orders:
Calculate revenue adjustments:
Handle multi-currency orders:
Calculate cumulative impact:
Output columns (CSV format):
period_id: The GL period IDperiod_name: Period name (YYYY-MM format)adjustment_type: 'REVERSAL' (negative, removes revenue from created_at period) or 'RECOGNITION' (positive, adds revenue to ordered_at period)order_count: Number of orders in this adjustmentoriginal_amount_local: Sum of GRAND_TOTAL in original currenciesadjusted_amount_usd: Sum of GRAND_TOTAL converted to USDvariance_reason: Description of why adjustment is neededInclude summary row:
adjustment_type = 'SUMMARY'Output file: /app/late_orders_adjustments.csv
period_id, not PERIOD_ID)DATEDIFF('day', start, end) instead of date subtraction for cross-DB compatibilityCAST(col AS DATE) or CAST(col AS TIMESTAMP) for date type conversionsDB_TYPE environment variable to determine which backend to connect to