---
# System prepended metadata

title: Instructions

---

# Instructions
- NonConformance/GetResolutionById Endpoint
  - Get Data to fill the form of NCR being edited
  - Receives a NonConformanceId
- NonConformance/GetAllOpenByJobRouterDetailId
  - Get Data to fill the NCR list at the tablet, where the operator can see NC Summary and choose to edit/delete
  - Receives the JobRouterDetailId
- NonConformance/CreateOrUpdateNonConformance
  - Receives the newly created or edited NonConformance and persists form data into DB.
  - Receives the form data
    - If it's new NonConformance, NonConformanceId should be undefined
    - Parts is a list of PartDetailToJobRouterDetailId of the parts being added to that NonConformance.
      - Parts that were already there, before edition, should be kept on the list.
      - Parts to be added to the NonConformance should be added to the list.
      - Parts to be remove of the NonConformance should be out of the list (procedure will know who they are)
- NonConformance/DeleteNonConformance
  - Hard Deletes a NonConformance
  - Call this when the user click onDelete in the list of NonConformances
  - Receives a NonConformanceId
- OperationStep/StartOperation
  - Creates SignOffRoundId and associate parts set as NonConformant or Ready by the user in that selection to the SignOffRoundId
  - Call this endpoint when user is done with selecting parts and "Start Ready Parts" or "Proceed to Sign-off" (Select Parts Screen Only)
- Part/SetOrUnsetPartsAsReady
  - Call this when from Remaining Tab, the user clicks "Set as Ready" or, when in "Ready to Process" tab the user clicks "Remove"
  - Parts is a list of PartDetailToJobRouterDetailId of the parts being added to Ready.
    - Parts that were already there, before edition, should be kept on the list.
    - Parts to become Ready should be added to the list.
    - Parts to be set as Not Started should be out of the list (procedure will know who they are)
## Notes:
- Cascade Update of statuses are now made through triggers.
  - NCPDTJRD (Insert/Delete) -> PDTJRD
  - PDTJRD (Update) -> PD
  - PD (Update) -> JR
# Tasks
## Back
### Tables
- [x] Update PartDetailToJobRouterDetailStatus (PDTJRDS) Table:
  - [x] Drop Selected, Impediment and Rejected
  - [x] Add NonConformant
---
- [x] Update PartDetailToJobRouterDetail (PDTJRD) Table:
  - [x] Drop RejectionReasonId FK
  - [x] Drop RejectionReasonId
  - [x] Drop RejectionDate
---
- [x] Drop RejectionReason (RR) Table
---
- [x] Update NonConformance (NC) Table:
  - [x] Drop UK NCR Number/SignOffRoundId
  - [x] Drop SignOffRoundId
  - [x] Add UK NCR Number
---
- [x] Update NonConformanceDetail (NCD) Table:
  - [x] Add WorkCenter field VARCHAR(200) NOT NULL
### Triggers
- [x] Use trigger to update status of partdetailtojobrouterdetail upon insert/deletion of nonConformanceToPartDetailToJobRouterDetail
  - [x] "Not Started" if there's no SignOffRoundId or "Ready", if it does.
- [x] Use trigger to update status of partDetail upon status update of partdetailtojobrouterdetail
- [x] Use trigger to update status of jobrouter upon status update of partdetail
- [x] See where PDTJRD/PD/JR statuses are being updated as consequence of prior status update and delete them.
  - [x] Part/FinishProcess
  - [x] NonConformance/CreateOrUpdateNCR
  - [x] sp_UpdatePartsAndAssociations
  - [x] sp_SignAndHandleSignature
### Endpoints
- [x] Update NonConformance/GetByStep Endpoint:
  - [x] if step = {NonConformanceStepEnum.CREATED_NC}: Make available in the Web only the NCRs that, upon join with NCPDTJRD, the PDTJRD isFinished = 1
---
- [x] Create NonConformance/GetAllOpen Endpoint:
---
- [x] Update NonConformance/GetResolutionById Endpoint -> Rename to GetDetailsById:
  - [x] Get WorkCenter from NC Detail, instead of OrganizationAddress
  - [x] This will be the endpoint to get ncr on tablet, upon editing existing.
  - [x] Join with NCPDTJRD and the PDTJRD isFinished = 0
  - [x] Pass JobRouterDetailId to get Pre-filled data, when there's NonConformanceId.  (Done by Marissa)
---

**Assigned to:** Alex
- [x] Update OperationStep/GetProcessStep Endpoint:
  - [x] Remove "PartsCheckUp" From OperationStepProcess Enum.
  - [x] ProcessStep = some PDTJRD Status != Not Started ? DataSheet : Selecting Parts
  - [x] Validate:
    - [x] More than one Part is sent
    - [x] All parts are associated with that user, are either Ready or NonConformant and have no SignOffRoundId
---
- [ ] Create OperationStep/StartOperation Endpoint
  - [x] Receives PDTJRDs
  - [x] Creates SignOffRoundId
  - [x] Insert at SignOffRound
  - [x] Update PDTJRD with SignOffRoundId
  - [x] Update sp_CreateOrUpdateProcessDataSheetDetail
    - Bonus: simplify procedure using merge
---
**Assigned to:** Gabriel
- [x] Update GetUnavailablePartsToSelectAsync Method -> Rename to CheckUnavailableParts
  - [x] Receives a list of @PDTJRD [PartDetailToJobRouterDetail] and @UserId
  - [x] Returns the serial numbers of that @PDTJRD
        WHERE UserId IS NOT NULL AND UserId <> @UserId  
---
**Assigned to:** Alex
- [ ] Create Part/SetOrUnsetPartsAsReady Endpoint:
  - [x] Receives a list of @PDTJRD Id that should be set as ready
  - [x] Validation:
    - [x] Validate that all PDTJRD in that list have UserId IS NULL OR UserId = @UserId
      - [x] Use GetUnavailablePartsToSelectAsync
  - [x] Merges with PDTJRD table.
    - [x] When Matched -> Set PDTJRD status as Ready
    - [x] When not Matched by Source
          AND JobRouterDetailId = @JobRouterDetailId
          AND SignOffRoundId IS NULL
          AND UserId IS NOT NULL
          AND Status = Ready
          -> Set PDTJRD status as Not Started.
---
**Assigned to:** Gabriel
- [ ] Update NonConformance/CreateOrUpdateNonConformance Endpoint:
  - [ ] Validation:
    - [x] Validate that PDTJRD list has at least one Id.    PDTJRD.Any() && !Any(q => !q.Id.IsValid())
    - [x] Validate that all PDTJRD in that list have UserId IS NULL OR UserId = @UserId
      - [x] Use GetUnavailablePartsToSelectAsync
    - [x] Description Code/ Cause Code/ Inspection Step/ NCR Number/ Work Center are mandatory.
    - [x] Validate that NCR Number is a valid number, less than 7 digits long. 
	- [x] If creating a NonConformance (NonConformanceId null ou Guid.Empty) and NCR Number passed validation above,
	check in database if exists a register in NonConformance with that same NCR Number. If exists, Request Status fail
    - [x] NCR Number cannot be changed once NC is created.
---
**Assigned to:** Alex
- [x] Create NonConformance/Delete Endpoint:
  - [x] Validation:
    - [x] Ensure that the PDTJRDs of that NC are associated with the user deleting it.
    - [x] Ensure that the PDTJRDs of that NC are all isFinished = 0 AND that it has no record in Disposition Table.
    * For Continuity Approach "Accept as Is" doesn't remove parts records from NCPDTJRD and set IsFinished = 0
  - [x] Procedure:
    - [x] NCPDTJRD with NonConformanceId = @NonConformanceId
    - [x] NC Detail with NonConformanceId = @NonConformanceId
    - [x] NC with NonConformanceId = @NonConformanceId
  * Receives @NonConformanceId
  * Hard Delete
---
- [x] Update FinishProcess Endpoint:
  - [x] Remove SignOffRoundId if Part is @NotStarted
---
- [x] Drop Part/SelectPartsForProcess
- [x] Drop Part/Unblock
- [x] Drop Part/CheckUpParts
- [x] Drop Part/CreateOrUpdateImpediments
### Others
---
- [x] Update PartDetailToJobRouterDetailType
  - [x] drop rejection reason id
  - [x] drop rejection date
---
- [x] drop sp_CreateOrUpdateImpediments
- [x] drop sp_UnblockPartsAndAssociations
---
- [x] drop PartImpedimentDTO
- [x] drop PartDetailToJobRouterDetailDTO
---
- [x] Revise References to Selected/Impediment/Rejected
  - [x] Revisit code that uses JobRouterDetailOperatorStatusEnum
  * Roughly:
    - NonConformant + IsFinished 1 = Rejected
    - NonConformant + IsFinished 0 = Impediment
    - IsFinished is a flag from PDTJRD that is set to 1 at the end of FinishTheProcess and it's 0 until then.
---
**Assigned to:** Saturnino
- [ ] Review logic of GetOperationStepStatus at JobRouterDetailService
---
Bonus:
- Create jobRouterDetailController and move some endpoints to there.
## Front
- [ ] Toggle text between "Start Ready Parts" become "Proceed to Sign-off" in "Select" screen, depending if all parts are NCR or not and redirecting to "Finish the Process" if it's "Proceed to Sign-off".
- [ ] Remove "PartsCheckUp" From OperationStepProcess Enum.
- [ ] Remove References to RejectionReason.
- [ ] Update PartDetailToJobRouterDetailStatuses.
- [ ] Remove Endpoints
  - [ ] Part/SelectPartsForProcess
  - [ ] Part/Unblock
  - [ ] Part/CheckUpParts
  - [ ] Part/CreateOrUpdateImpediments
- [ ] Remove Components
  - Parts Check-up