NextGen APIs

POST /work-orders/execution/r1/interventions/resources-accounted-hours

Http Verb

POST

Url

/work-orders/execution/r1/interventions/resources-accounted-hours

Permissions required

Work Order Accounting Edit: fsm.core.workorder.accounting.edit

Personally Identifiable Information (PII)

No

Sensitive Information

No

Last Modified Version

r1

Released since

2024 W3 (FSM 18.0)

Deprecated since


Removed since


Tech Tags

PAGINATION ORDERING-SERVER-SIDE

Business Logic

This API saves the accounted hours of a resource related to a specific intervention.

Validations

  1. Duplicate Record Check:
    Check if a ResourceAccountedHours record exists with:

    • resourceId = requestBody.resourceId

    • interventionId = requestBody.interventionId

    • workingHourType = requestBody.workingHourType

    If such a record exists, return error WORKORDERS_ORCHESTRATOR_010.

  2. Spent Time Validation:

    • If requestBody.lockSpentTime = true and requestBody.spentTime = null, return error WORKORDERS_ORCHESTRATOR_011.

    • If requestBody.lockSpentTime = true and requestBody.spentTime != null, the fields requestBody.outcomeStartDate and requestBody.outcomeEndDate will be ignored by the business logic. In this case, the ResourceAccountedHours.manualLockUserId will be assigned to the user making the API request.

    • Otherwise, calculate a new spentTime by subtracting requestBody.outcomeStartDate from requestBody.outcomeEndDate.

  3. Intervention Status Check:

    • If ResourceAccountedHours.interventionId.workOrderOperationId.workOrderId.status is ALIGNED, CLOSED, or CANCELLED, return error WORKORDERS_ORCHESTRATOR_012..

  4. Date Validations:

    • If requestBody.outcomeStartDate is null, return error BASE_0003.

    • If requestBody.outcomeEndDate is null, return error BASE_0003.

    • If requestBody.outcomeStartDate >= requestBody.outcomeEndDate, return error BASE_0012.

    • If requestBody.arrivalOnSiteDate is null or requestBody.arrivalOnSiteDate > requestBody.outcomeStartDate, return error BASE_0012.

    • If requestBody.takeInChargeDate is null or requestBody.takeInChargeDate > requestBody.arrivalOnSiteDate, return error BASE_0012.

    • If requestBody.takeInChargeDate < systemSettings.outcomeMinDate, return error BASE_0012.

    • If requestBody.outcomeEndDate is later than today, return error BASE_0012.

Business Logic

  1. Total Spent Time Calculation:

    • Retrieve the TotalAccountedHour record (if it exists) with:

      • resourceId = requestBody.resourceId

      • workingHourType = requestBody.workingHourType

      • workOrderOperationId = requestBody.interventionId.workOrderOperationId

    • Add the spentTime (from the request payload or calculated) to the TotalSpentTime.spentTime.

    • If no record exists, create a new one with the fields resourceId, workOrderOperationId, workingHourType, and spentTime populated.

  2. Work Shift Check:

    • Search for a WorkShift record with:

      • WorkShift.resourceId = requestBody.resourceId

      • requestBody.takeInChargeDate < WorkShift.startDate < requestBody.takeInChargeDate + 1

    • If a record is found, set ResourceAccountedHours.workShiftId = retrievedWorkShiftId.

Header Parameters

Default.

Request Body Parameters

Field

Validations

Note

resourceId



interventionId



takeInChargeDate



arrivalDate



workingHourType



outcomeStartDate



outcomeEndDate



spentTime



note



customerAbsent



lockSpentTime



Response documentation

Response payload fields


Field

Note

id


Response error codes

BASE_0001, BASE_0003, BASE_0012, WORKORDERS_ORCHESTRATOR_010, WORKORDERS_ORCHESTRATOR_011, WORKORDERS_ORCHESTRATOR_012,