NextGen APIs

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

Http Verb

PATCH

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 updates the accounted hours of a resource related to a specific intervention.

Validations

  1. Check Intervention Validation Status:
    Check if the related intervention validation status record meets one of the following condition:

    • RescoureAccountedHour.validationStatusId = AUTOMATIC_VALIDATION

    • RescoureAccountedHour.validationStatusId = MANUALLY_VALIDATED

    If yes, return error WORKORDERS_ORCHESTRATOR_013.

  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, if populated, will be ignored by the business logic. In this case, Check if the userId of the API call matches with the ResourceAccountedHours.manualLockUserId of the record is intended to delete.If not, return error WORKORDERS_ORCHESTRATOR_014.

    • Otherwise, if requestBody.lockSpentTime = true and requestBody.spentTime = null and ResourceAccountedHour.manualLockUserId = null, calculate the new spentTime by subtracting request.outcomeStartDate from request.outcomeEndDate. If request.outcomeStartDate = null and/or request.outcomeEndDate = null, the spentTime of the ResourceAccountedHour record will be not updated.

  3. Intervention Status Check:

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

  4. Check User Id:

    • Check if the userId of the API call matches with the ResourceAccountedHours.manualLockUserId of the record is intended to delete.

If not, return error WORKORDERS_ORCHESTRATOR_014.

  1. Date Validations:

    • If outcomeStartDate >= 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 with:

      • resourceId = requestParam.resourceId

      • workingHourType = requestParam.workingHourType

      • workOrderOperationId = requestParam.interventionId.workOrderOperationId

    • Get from the record to be updated of ResourceAccountedHour the field spentTime. Calculate the variationAccounting = request.spentTime - spentTime. Add the variationAccounting to the TotalSpentTime.spentTime.

  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.

Query String Parameters

Field

Note

interventionId


resourceId


workingHourTypeId


Request Body Parameters

Field

Validations

Note

takeInChargeDate



arrivalDate



outcomeStartDate



outcomeEndDate



spentTime



note



customerAbsent



lockSpentTime



Response documentation

Response payload fields


Response error codes

BASE_0012, WORKORDERS_ORCHESTRATOR_010, WORKORDERS_ORCHESTRATOR_011, WORKORDERS_ORCHESTRATOR_012, WORKORDERS_ORCHESTRATOR_013.