Assignments Queries
1. Executive Summary
This document catalogs the query operations that power the assignments domain. The assignments domain supports two categories of data access:
CRUD and lifecycle queries — creating, reading, updating, and deactivating assignment and history records. These operate directly on the
assignmentandassignment_historytables, joined to theuserstable for display-name enrichment.Analytical and gap-detection queries — finding unassigned entities, computing responsibility coverage across the hierarchy, resolving the responsible user for a given entity, and building the full responsibility chain. These are read-heavy operations that join the assignment tables against the broader financial data model (
billing_item,billing_item_detail,deal,party,department,revenue_items,cash_receipt,cash_receipt_split,cash_receipt_worksheet,cash_receipt_application,payment_item, andcash_receipt_reference).
The most architecturally significant pattern in this domain is the hierarchy resolution query, which walks from the most specific entity level (Level 4: Sales Item / Payment Term) to the broadest (Level 1: Department), returning the first active responsibility match. This pattern is expressed both as an iterative per-level lookup (service-layer resolution) and as a set-based CTE computation (unassigned-entity gap detection).
Tables covered: assignment, assignment_history
Data model reference: Assignments Data Model
2. Key Queries
2.1 Assignment CRUD Lookups
2.1.1 Get Assignment by ID
Operation: getAssignmentById
Input Parameters:
assignmentId: UUID (required) —assignment.assignment_id
Tables & Joins:
| Base Table | Join | Joined Table | Condition | Purpose |
|---|---|---|---|---|
assignment | — | — | — | Base record lookup; no joins needed |
Filters:
assignment.assignment_id=:assignmentId
Computed Values:
- None
Returns: One assignment row with all fields, or null if no record matches the given assignment_id.
2.1.2 Get Assignment Display by ID
Operation: getAssignmentDisplayById
Input Parameters:
assignmentId: UUID (required) —assignment.assignment_id
Tables & Joins:
| Base Table | Join | Joined Table | Condition | Purpose |
|---|---|---|---|---|
assignment | LEFT | users | assignment.assigned_to_user_id = users.user_id | Enrich with assignee display name and email |
Filters:
assignment.assignment_id=:assignmentId
Computed Values:
assigned_to_user_name:users.first_name || ' ' || users.last_name— full name of the assigned user
Returns: One enriched assignment display row including all assignment fields plus assigned_to_user_name and assigned_to_user_email, or null if not found.
2.1.3 Get Assignments for User
Operation: getAssignmentsForUser
Input Parameters:
userId: Integer (required) —assignment.assigned_to_user_idassignmentTypeCd: VARCHAR (optional) —assignment.assignment_type_cd; filter toTASKorRESPONSIBILITYtaskStatusCd: VARCHAR (optional) —assignment.task_status_cd; filter toOPEN,WORKING,WAITING,COMPLETE, orCANCELLEDisActiveInd: Boolean (optional) —assignment.is_active_ind
Tables & Joins:
| Base Table | Join | Joined Table | Condition | Purpose |
|---|---|---|---|---|
assignment | LEFT | users | assignment.assigned_to_user_id = users.user_id | Enrich with assignee display name and email |
Filters:
assignment.assigned_to_user_id=:userId— always applied- If
assignmentTypeCdprovided:assignment.assignment_type_cd=:assignmentTypeCd - If
taskStatusCdprovided:assignment.task_status_cd=:taskStatusCd - If
isActiveIndprovided:assignment.is_active_ind=:isActiveInd
Computed Values:
assigned_to_user_name:users.first_name || ' ' || users.last_name— full name of the assigned user
Returns: Array of enriched assignment display rows for the given user, ordered by assignment.created_dt descending.
2.1.4 Get Assignments for Entity
Operation: getAssignmentsForEntity
Input Parameters:
entityTypeCd: VARCHAR (required) —assignment.entity_type_cd; e.g.,DEAL,CLIENT,CASH_RECEIPTentityId: Integer (conditional) —assignment.entity_id; required for integer-keyed entity typesentityReference: VARCHAR (conditional) —assignment.entity_reference; required for string-referenced entity typesmetaDataTypeCd: VARCHAR (conditional) —assignment.meta_data_type_cd; required whenentity_type_cd=META_DATA_PAIRmetaDataValue: VARCHAR (conditional) —assignment.meta_data_value; required whenentity_type_cd=META_DATA_PAIR
Tables & Joins:
| Base Table | Join | Joined Table | Condition | Purpose |
|---|---|---|---|---|
assignment | LEFT | users | assignment.assigned_to_user_id = users.user_id | Enrich with assignee display name and email |
Filters:
assignment.entity_type_cd=:entityTypeCd— always applied- If
entityIdprovided:assignment.entity_id=:entityId - If
entityReferenceprovided:assignment.entity_reference=:entityReference - If
metaDataTypeCdprovided:assignment.meta_data_type_cd=:metaDataTypeCd - If
metaDataValueprovided:assignment.meta_data_value=:metaDataValue
Computed Values:
assigned_to_user_name:users.first_name || ' ' || users.last_name— full name of the assigned user
Returns: Array of enriched assignment display rows for the specified entity (all assignment types), ordered by assignment.created_dt descending.
2.2 Responsibility Lookup
2.2.1 Find Active Responsibility
Operation: findActiveResponsibility
Input Parameters:
entityTypeCd: VARCHAR (required) —assignment.entity_type_cdentityId: Integer (conditional) —assignment.entity_id; for integer-keyed entity typesentityReference: VARCHAR (conditional) —assignment.entity_reference; for string-referenced entity typesmetaDataTypeCd: VARCHAR (conditional) —assignment.meta_data_type_cd; forMETA_DATA_PAIRentitiesmetaDataValue: VARCHAR (conditional) —assignment.meta_data_value; forMETA_DATA_PAIRentities
Tables & Joins:
| Base Table | Join | Joined Table | Condition | Purpose |
|---|---|---|---|---|
assignment | LEFT | users | assignment.assigned_to_user_id = users.user_id | Enrich with assignee display name and email |
Filters:
assignment.entity_type_cd=:entityTypeCd— always applied- If
entityIdprovided:assignment.entity_id=:entityId - If
entityReferenceprovided:assignment.entity_reference=:entityReference - If
metaDataTypeCdprovided:assignment.meta_data_type_cd=:metaDataTypeCd - If
metaDataValueprovided:assignment.meta_data_value=:metaDataValue assignment.assignment_type_cd='RESPONSIBILITY'— always appliedassignment.is_active_ind=true— always applied
Computed Values:
assigned_to_user_name:users.first_name || ' ' || users.last_name— full name of the assigned user
Returns: A single enriched assignment display row for the active responsibility at the given entity, or null if no active responsibility exists.
2.3 Sibling Task Lookup
2.3.1 Find Sibling Tasks
Operation: findSiblingTasks
Input Parameters:
entityTypeCd: VARCHAR (required) —assignment.entity_type_cdentityId: Integer (conditional) —assignment.entity_id; for integer-keyed entity typesentityReference: VARCHAR (conditional) —assignment.entity_reference; for string-referenced entity typesexcludeAssignmentId: UUID (required) —assignment.assignment_id; the assignment to exclude (typically the one just completed)
Tables & Joins:
| Base Table | Join | Joined Table | Condition | Purpose |
|---|---|---|---|---|
assignment | — | — | — | Base record lookup; no joins needed |
Filters:
assignment.entity_type_cd=:entityTypeCd— always applied- If
entityIdprovided:assignment.entity_id=:entityId - If
entityReferenceprovided:assignment.entity_reference=:entityReference assignment.assignment_type_cd='TASK'— always appliedassignment.assignment_id!=:excludeAssignmentId— always applied
Computed Values:
- None
Returns: Array of assignment rows (without user enrichment) for all task assignments on the same entity, excluding the specified assignment; the caller filters further by checking whether each sibling's task_status_cd permits a transition to CANCELLED.
2.4 Hierarchy Resolution
2.4.1 Hierarchy Resolution (Walk-Up Query)
Operation: resolveResponsibleUser
Input Parameters:
salesItemRef: VARCHAR (optional) —assignment.entity_referenceatSALES_ITEMlevel; Level 4paymentTermRef: VARCHAR (optional) —assignment.entity_referenceatPAYMENT_TERMlevel; Level 4metaData: Array (optional) — array of{typeCd, value}pairs matched againstassignment.meta_data_type_cd+assignment.meta_data_value; Level 3dealReference: VARCHAR (optional) —assignment.entity_referenceatDEALlevel; Level 3clientId: Integer (optional) —assignment.entity_idatCLIENTlevel; Level 2buyerId: Integer (optional) —assignment.entity_idatBUYERlevel; Level 2departmentId: Integer (optional) —assignment.entity_idatDEPARTMENTlevel; Level 1
Tables & Joins:
| Base Table | Join | Joined Table | Condition | Purpose |
|---|---|---|---|---|
assignment | LEFT | users | assignment.assigned_to_user_id = users.user_id | Enrich matched result with assignee name |
Filters:
- Per iteration:
assignment.entity_type_cd= level-specific entity type code - Per iteration: entity key filter (
entity_id,entity_reference, ormeta_data_type_cd+meta_data_value) matching the context value for that level assignment.assignment_type_cd='RESPONSIBILITY'— applied at every levelassignment.is_active_ind=true— applied at every level
NOTE
This is not a single SQL statement. It is a structured sequence of up to seven findActiveResponsibility calls (see Section 2.2.1), each targeting a different hierarchy level in order. The algorithm short-circuits on the first match and returns immediately without checking lower levels.
Resolution order: Level 4 SALES_ITEM → Level 4 PAYMENT_TERM → Level 3 META_DATA_PAIR (one call per item in the array) → Level 3 DEAL → Level 2 CLIENT → Level 2 BUYER → Level 1 DEPARTMENT.
Computed Values:
assigned_to_user_name:users.first_name || ' ' || users.last_name— from the matched assignment record
Returns: One resolution record containing the matched user's assigned_to_user_id, assigned_to_user_name, resolved_from_entity_type_cd, resolved_from_level (1–4), and assignment_id, or null/empty if no active responsibility was found at any level.
2.4.2 Responsibility Chain
Operation: buildResponsibilityChain
Input Parameters:
entityTypeCd: VARCHAR (required) — the entity type to start resolution from (e.g.,SALES_ITEM,DEAL,CLIENT,DEPARTMENT)entityId: Integer (conditional) —assignment.entity_idfor integer-keyed starting entitiesentityReference: VARCHAR (conditional) —assignment.entity_referencefor string-referenced starting entities
Tables & Joins:
Phase 1 — parent entity resolution (tables queried depend on the starting entity type):
| Base Table | Join | Joined Table | Condition | Purpose |
|---|---|---|---|---|
department | — | — | — | Starting entity or ancestor lookup |
party | — | — | party.party_id = client or buyer ID | Resolve display name for CLIENT/BUYER levels |
billing_item | — | — | billing_item.client_id or buyer_id | Resolve parent entities from billing context |
deal | — | — | deal.deal_id = billing item deal | Resolve deal-level ancestor |
revenue_items | — | — | revenue_items.revenue_item_id | Resolve sales-item-level ancestor |
Phase 2 — per-level responsibility lookup: calls findActiveResponsibility (see Section 2.2.1) once per resolved ancestor level; no additional joins beyond those used in that query.
Filters:
- Phase 1: entity-type-specific filters to resolve the starting entity and all ancestor entities
- Phase 2: same filters as
findActiveResponsibilityapplied once per hierarchy level; does NOT short-circuit — all levels are queried regardless of match
Computed Values:
effective_user_id: theassigned_to_user_idfrom the most specific level that has an active assignmenteffective_user_name: display name of the effective responsible usereffective_level: integer (1–4) indicating which hierarchy level produced the effective assignmenteffective_entity_type_cd: theentity_type_cdof the effective assignment
Returns: A chain result containing an ordered array of level records (Level 1 broadest to Level 4 most specific), each with level, entity_type_cd, entity key, entity_label, the assignment record if one exists, and an is_selected_level flag; plus top-level effective_user_id, effective_user_name, effective_level, and effective_entity_type_cd.
2.5 Assignment History
2.5.1 Get History for Assignment
Operation: getHistoryForAssignment
Input Parameters:
assignmentId: UUID (required) —assignment_history.assignment_id
Tables & Joins:
| Base Table | Join | Joined Table | Condition | Purpose |
|---|---|---|---|---|
assignment_history | LEFT | users (as from_user) | assignment_history.from_user_id = from_user.user_id | Resolve display name of previous assignee |
assignment_history | LEFT | users (as to_user) | assignment_history.to_user_id = to_user.user_id | Resolve display name of new assignee |
assignment_history | LEFT | users (as action_user) | assignment_history.action_by_user_id = action_user.user_id | Resolve display name of acting user |
Filters:
assignment_history.assignment_id=:assignmentId
Computed Values:
from_user_name:from_user.first_name || ' ' || from_user.last_name— display name of the previous assigneeto_user_name:to_user.first_name || ' ' || to_user.last_name— display name of the new assigneeaction_by_user_name:action_user.first_name || ' ' || action_user.last_name— display name of the person who performed the action
Returns: Array of history entry rows for the given assignment ordered by assignment_history.action_dt descending, each including assignment_history_id, assignment_id, action_cd, from_user_id, to_user_id, from_status_cd, to_status_cd, comment_text, action_by_user_id, action_dt, and the three computed display name fields.
2.6 Gap Detection
2.6.1 Unassigned Entities by Type
Operation: getUnassignedEntitiesByType
Input Parameters:
entityTypeCd: VARCHAR (required) — which entity type to query; determines the query structuredepartmentId: Integer (optional) — restrict responsibility-type results to a specificdepartment.department_idcoverageLevel: Integer (optional) — filter on the nearest ancestor assignment level (0 = fully uncovered, 1 = department only, etc.)
Tables & Joins:
The join structure varies by entityTypeCd. All variants share a LEFT JOIN anti-pattern against assignment to identify entities with no matching active assignment.
Responsibility entity types (Level 1–4) additionally use a common CTE (open_rev_details) and a set of pre-computed assignment lookup CTEs:
| Base Table | Join | Joined Table | Condition | Purpose |
|---|---|---|---|---|
billing_item | INNER | billing_item_detail | billing_item_detail.billing_item_id = billing_item.billing_item_id AND billing_item_detail.billing_item_detail_type_cd = 'REV' | Build open REV details CTE; REV-only |
billing_item | LEFT | cash_receipt_application (subquery) | Sum of applied amounts per detail on approved worksheets | REV balance calculation |
billing_item | LEFT | cash_receipt_application_deduction (subquery) | Sum of deduction amounts per detail on approved worksheets | REV balance calculation |
cash_receipt_worksheet | — | — | worksheet_status_cd IN ('A', 'S') AND current_item_ind = true | Scope balance calc to approved/submitted worksheets |
assignment | — | — | Per entity type: entity_type_cd, entity key, assignment_type_cd = 'RESPONSIBILITY', is_active_ind = true | Assignment lookup CTEs (one per hierarchy level) |
| Entity source table | LEFT | assignment | Anti-join condition (see Filters) | Identify entities without active assignment |
Task entity types (CASH_RECEIPT, CASH_RECEIPT_SPLIT, PAYMENT) additionally join:
| Base Table | Join | Joined Table | Condition | Purpose |
|---|---|---|---|---|
cash_receipt | INNER | cash_receipt_split | cash_receipt_split.cash_receipt_id = cash_receipt.cash_receipt_id AND split_status_cd != 'V' | Receipt/split entity source |
cash_receipt_split | LEFT | cash_receipt_worksheet | cash_receipt_worksheet.cash_receipt_split_id = cash_receipt_split.cash_receipt_split_id AND current_item_ind = true | Needs-work determination |
cash_receipt_split | LEFT | cash_receipt_reference | cash_receipt_reference.cash_receipt_split_id = cash_receipt_split.cash_receipt_split_id | Reference-based coverage CTE |
payment_item | LEFT | party | party.party_id = payment_item.party_id | Payment recipient display name |
payment_item | LEFT | deal | deal.deal_id = payment_item.deal_id | Payment deal display name |
Filters:
- For responsibility types:
billing_item.current_item_ind = trueANDbilling_item.open_item_ind = true— scope to open billing items - For responsibility types:
billing_item_detail.billing_item_detail_type_cd = 'REV'— REV details only - Anti-join filter:
assignment.assignment_id IS NULL— entities with no active assignment - For task type
CASH_RECEIPT:cash_receipt.posting_status_cd != 'V' - For task types (
CASH_RECEIPT,CASH_RECEIPT_SPLIT,PAYMENT): active task filter excludes assignments withtask_status_cd IN ('COMPLETE', 'CANCELLED') - For task type
PAYMENT:payment_item.payment_execution_status_cd IN ('WAITING', 'PENDING', 'FAILED')or null - If
departmentIdprovided: restricts responsibility results to the given department - If
coverageLevelprovided: filtersnearest_assignment_level=:coverageLevel
Computed Values:
rev_balance:billing_item_detail.billing_item_detail_total_amt - SUM(deduction_amt_applied) - SUM(cash_receipt_amt_applied)on approved/submitted worksheets — REV balance per open billing item detailopen_receivable_count:COUNT(DISTINCT billing_item_id)— number of distinct open billing items for this entityopen_receivable_amount:SUM(rev_balance)— total REV balance across all open billing itemsnearest_assignment_level:CASEexpression checking ancestor assignment lookup CTEs from most specific to broadest — integer coverage level (0–3) of the nearest assigned ancestornearest_assignment_entity_type_cd: entity type of the nearest assigned ancestornearest_assigned_user_name: display name of the person assigned at the nearest ancestor level- For receipt/split:
worst_worksheet_status_rank: integer rank mapping of worst worksheet status across splits
Returns: Array of up to 200 unassigned entity rows ordered by open_receivable_amount descending (responsibility types) or by entity date descending (task types), each row including entity key and display name, department context, open receivable count and amount, nearest ancestor coverage level and user, and for task types additionally the entity amount, applied amount, processing status, and entity date.
Variant: Department (Level 1)
Operation: getUnassignedDepartments
Additional joins: department (base) INNER JOIN open_rev_details CTE on department_id. Anti-join: assignment LEFT JOIN on entity_type_cd = 'DEPARTMENT' AND entity_id = department.department_id.
Coverage always 0 (departments have no ancestors). Grouped by department.department_id, department.department_name.
All other aspects identical to 2.6.1.
Variant: Client (Level 2)
Operation: getUnassignedClients
Additional joins: open_rev_details CTE (base) INNER JOIN party on client_id; LEFT JOIN department; LEFT JOIN assigned_depts CTE on department_id. Anti-join: assignment on entity_type_cd = 'CLIENT' AND entity_id = party.party_id.
Coverage: 1 if assigned_depts match exists, else 0. Grouped by party.party_id, party.display_name.
All other aspects identical to 2.6.1.
Variant: Buyer (Level 2)
Operation: getUnassignedBuyers
Same structure as Client variant but joins on open_rev_details.buyer_id and anti-join uses entity_type_cd = 'BUYER'.
All other aspects identical to 2.6.1.
Variant: Deal (Level 3)
Operation: getUnassignedDeals
Additional joins: open_rev_details CTE (base) INNER JOIN deal on deal_id; LEFT JOIN department; LEFT JOIN assigned_clients CTE on client_id; LEFT JOIN assigned_buyers CTE on buyer_id; LEFT JOIN assigned_depts CTE on department_id. Anti-join: assignment on entity_type_cd = 'DEAL' AND entity_reference = deal.deal_reference.
Coverage: 2 if client or buyer match, 1 if department match, else 0. Grouped by deal.deal_id, deal.deal_reference, deal.deal_name.
All other aspects identical to 2.6.1.
Variant: Sales Item (Level 4)
Operation: getUnassignedSalesItems
Additional joins: open_rev_details CTE (base) INNER JOIN revenue_items on revenue_item_id AND current_item_ind = true; LEFT JOIN department; LEFT JOIN deal; LEFT JOIN assigned_deals CTE on deal_reference; LEFT JOIN assigned_clients CTE on client_id; LEFT JOIN assigned_buyers CTE on buyer_id; LEFT JOIN assigned_depts CTE on department_id. Anti-join: assignment on entity_type_cd = 'SALES_ITEM' AND entity_reference = revenue_items.sales_item_ref.
Coverage: 3 if deal match, 2 if client/buyer match, 1 if department match, else 0. Grouped by revenue_items.revenue_item_id, revenue_items.sales_item_ref, revenue_items.revenue_item_name.
All other aspects identical to 2.6.1.
Variant: Payment Term (Level 4)
Operation: getUnassignedPaymentTerms
Same structure as Sales Item variant but uses billing_item.payment_term_ref instead of revenue_items.sales_item_ref, and anti-join uses entity_type_cd = 'PAYMENT_TERM' AND entity_reference = billing_item.payment_term_ref.
All other aspects identical to 2.6.1.
Variant: Cash Receipt (Task)
Operation: getUnassignedCashReceipts
Additional joins: cash_receipt (base, posting_status_cd != 'V') INNER JOIN cash_receipt_split; LEFT JOIN cash_receipt_worksheet; LEFT JOIN cash_receipt_application (lateral subquery for sum of applied amounts); LEFT JOIN ref_coverage CTE (reference-based coverage derived from cash_receipt_reference joined against assignment lookup CTEs). Anti-join: assignment on entity_type_cd = 'CASH_RECEIPT' AND entity_id = cash_receipt.cash_receipt_id AND assignment_type_cd = 'TASK' AND is_active_ind = true AND task_status_cd NOT IN ('COMPLETE', 'CANCELLED').
"Needs work" HAVING filter: worst worksheet status rank < 4 OR |total_applied - net_receipt_amt| > 0.005.
All other aspects identical to 2.6.1.
Variant: Cash Receipt Split (Task)
Operation: getUnassignedCashReceiptSplits
Same pattern as Cash Receipt variant at the split level, with an additional assigned_receipt_tasks CTE to inherit receipt-level task coverage. Split coverage = GREATEST(ref_coverage_level, receipt_task_inheritance_level). "Needs work" filter: worksheet status is null, or not in ('A', 'R'), or |applied - split_amt| > 0.005.
All other aspects identical to 2.6.1.
Variant: Payment (Task)
Operation: getUnassignedPayments
Additional joins: payment_item (base) LEFT JOIN party on payment_item.party_id; LEFT JOIN deal on payment_item.deal_id; LEFT JOIN department; LEFT JOIN assignment lookup CTEs on direct FK columns (deal_id, client_id, buyer_id, department_id). Anti-join: assignment on entity_type_cd = 'PAYMENT' AND entity_id = payment_item.payment_item_id AND assignment_type_cd = 'TASK' AND is_active_ind = true AND task_status_cd NOT IN ('COMPLETE', 'CANCELLED').
"Needs work" filter: payment_item.payment_execution_status_cd IN ('WAITING', 'PENDING', 'FAILED') or null.
All other aspects identical to 2.6.1.
2.6.2 Unassigned Summary (Count by Entity Type)
Operation: getUnassignedSummary
Input Parameters:
- None
Tables & Joins:
| Base Table | Join | Joined Table | Condition | Purpose |
|---|---|---|---|---|
department | LEFT | assignment | entity_type_cd = 'DEPARTMENT', entity_id, RESPONSIBILITY, is_active_ind = true | Department unassigned count |
billing_item | LEFT | assignment | entity_type_cd = 'CLIENT', entity_id, RESPONSIBILITY, is_active_ind = true | Client unassigned count |
billing_item | LEFT | assignment | entity_type_cd = 'BUYER', entity_id, RESPONSIBILITY, is_active_ind = true | Buyer unassigned count |
billing_item + deal | LEFT | assignment | entity_type_cd = 'DEAL', entity_reference, RESPONSIBILITY, is_active_ind = true | Deal unassigned count |
billing_item + revenue_items | LEFT | assignment | entity_type_cd = 'SALES_ITEM', entity_reference, RESPONSIBILITY, is_active_ind = true | Sales item unassigned count |
billing_item | LEFT | assignment | entity_type_cd = 'PAYMENT_TERM', entity_reference, RESPONSIBILITY, is_active_ind = true | Payment term unassigned count |
cash_receipt + cash_receipt_split + cash_receipt_worksheet | LEFT | assignment | entity_type_cd = 'CASH_RECEIPT', TASK, active, not complete/cancelled | Receipt unassigned count |
cash_receipt_split + cash_receipt_worksheet | LEFT | assignment | entity_type_cd = 'CASH_RECEIPT_SPLIT', TASK, active, not complete/cancelled | Split unassigned count |
payment_item | LEFT | assignment | entity_type_cd = 'PAYMENT', TASK, active, not complete/cancelled | Payment unassigned count |
Filters:
- Anti-join filter on each block:
assignment.assignment_id IS NULL - For responsibility types: open billing items (
current_item_ind = true,open_item_ind = true) - For
CASH_RECEIPT:posting_status_cd != 'V'; not all splits fully approved or balance mismatch - For
CASH_RECEIPT_SPLIT: worksheet not approved/returned or balance mismatch - For
PAYMENT:payment_execution_status_cd IN ('WAITING', 'PENDING', 'FAILED')or null
Computed Values:
count:COUNT(DISTINCT entity_id or entity_reference)— number of unassigned entities per block
Returns: Array of nine summary rows (one per entity type), each with entity_type_cd and count; entity types with no unassigned entities are backfilled with a count of 0.
3. Calculations & Formulas
3.1 REV Balance
Used by all responsibility-type unassigned entity queries to determine which billing items still have open receivable amounts.
rev_balance = billing_item_detail.billing_item_detail_total_amt
- SUM(cash_receipt_application_deduction.deduction_amt_applied) [on approved/submitted worksheets]
- SUM(cash_receipt_application.cash_receipt_amt_applied) [on approved/submitted worksheets]- Source:
billing_item_detail.billing_item_detail_total_amt,cash_receipt_application.cash_receipt_amt_applied,cash_receipt_application_deduction.deduction_amt_applied - Scope: Only REV-type billing item details (
billing_item_detail.billing_item_detail_type_cd = 'REV'). - Worksheet filter: Only applications on approved (
A) or submitted (S) worksheets wherecash_receipt_worksheet.current_item_ind = trueare counted. - Precision:
decimal(15,2) - Interpretation: A positive
rev_balancemeans the receivable is still partially or fully open.
3.2 Ancestor Coverage Level
For unassigned entities at Levels 2–4, the system computes the nearest ancestor that has an active responsibility assignment. This is expressed as an integer using a CASE expression that checks ancestor assignment lookup CTEs from most specific to broadest.
nearest_assignment_level =
CASE
WHEN assigned_deals match exists THEN 3
WHEN assigned_clients match exists
OR assigned_buyers match exists THEN 2
WHEN assigned_depts match exists THEN 1
ELSE 0
END- Source: Pre-computed assignment lookup CTEs (
assigned_deals,assigned_clients,assigned_buyers,assigned_depts) filtered onassignment_type_cd = 'RESPONSIBILITY'andis_active_ind = true - Values: 0 = no ancestor has an active responsibility (fully uncovered); 1 = department-level responsibility exists; 2 = client or buyer-level responsibility exists; 3 = deal-level responsibility exists
3.3 Receipt/Split "Needs Work" Determination
For cash receipts, "needs work" is defined as:
(worst_worksheet_status_rank < 4)
OR (ABS(total_applied_amt - net_receipt_amt) > 0.005)Where worst_worksheet_status_rank maps worksheet statuses to integers: A = 4, T = 3, P = 2, D = 1, null/other = 0.
For splits:
worksheet_status IS NULL
OR worksheet_status NOT IN ('A', 'R')
OR ABS(applied_amt - split_amt) > 0.005- Source:
cash_receipt_worksheet.worksheet_status_cd,cash_receipt_application.cash_receipt_amt_applied,cash_receipt.net_receipt_amt,cash_receipt_split.split_amt - Tolerance:
0.005— aligns with the system-wide balance comparison epsilon - Example: A receipt with one split whose worksheet is in status
P(rank 2) satisfiesworst_worksheet_status_rank < 4and therefore "needs work."
3.4 Task Status Transition Validation
The service layer enforces forward-only task status transitions using a lookup table. This is not a database constraint but a service-layer validation that runs before any status update.
OPEN → WORKING, CANCELLED
WORKING → WAITING, COMPLETE, CANCELLED
WAITING → WORKING, CANCELLED
COMPLETE → (none — terminal)
CANCELLED → (none — terminal)- Source:
assignment.task_status_cd - Enforcement: Any transition not listed above is rejected before writing to the database.
- Example: Attempting to transition
COMPLETE→OPENis rejected with an error.
4. Cross-References
| Document | Relationship |
|---|---|
| Assignments Data Model | Full schema definitions, status lifecycles, validation rules, and code master values for the assignment and assignment_history tables queried throughout this document. |
| Cash Receipts Data Model | Unassigned cash receipt and cash receipt split queries join against cash_receipt, cash_receipt_split, cash_receipt_worksheet, cash_receipt_application, and cash_receipt_reference tables defined in this document. |
| Billing Items Data Model | The open_rev_details CTE used by all responsibility-type gap-detection queries operates on billing_item and billing_item_detail tables; REV balance calculation is derived from these tables. |
| Worksheets Data Model | Worksheet status codes (D, P, T, A, R) and the current_item_ind flag are used in REV balance calculations and "needs work" determination for receipts and splits. |
| Settlements Data Model | Payment origin type (SETTLEMENT) in the unassigned payment query is derived from payment_item.payment_item_type_cd = 'S' combined with the presence of a participant_settlement_item_id. |
| Deals, Sales Items & Payment Terms Data Model | Deal entity resolution in the responsibility chain and gap-detection queries joins deal by deal_id and matches assignment records by deal_reference; revenue_items is used for sales item entity resolution. |
| Parties Data Model | Client and buyer resolution uses party.party_id and party.display_name; the CLIENT and BUYER entity types in the assignment hierarchy reference party.party_id. |