Work Order Stock-In Reversal (Cancel)

stockin.data.process
CANCEL JSON Sync

1. Basic Information

ItemDescription
API Chinese NameWork Order Stock-In Reversal (Cancel Stock-In)
API English NameWork Order Stock-In Data Process (Cancel)
CROSS API Codestockin.data.process
ESB Service/cancelStockIn (General) or /outsourcingProcess (TRANSORDERTYPE=59)
Call DirectionMES → ERP
Trigger Timing1. When MES executes cancel check-out
2. When quality issue requires rework
Trigger ConditionTL011/TL012 is not empty
Main Business ScenarioCancel completed stock-in operation, ERP needs to restore inventory and void original stock-in document
Request FormatJSON (Content-Type: application/json)
Sync/AsyncSynchronous call
Transaction ControlRequired
NotesMust check if TL011/TL012 has value before cancel, only call ERP if has value

Cancel Type Determination

TRANSORDERTYPEESB ServiceDescription
59outsourcingProcessCancel outsourcing purchase receipt
OthercancelStockInCancel general stock-in

source_type Parameter (Outsourcing Only)

source_typeDescriptionUsage Scenario
0Shipment reversalCancel check-out (outsourcing shipment)
1Receipt reversalCancel check-in (outsourcing receipt)
2Return reversalCancel return

2. Business Flow

Cancel Check-out Check TL011/TL012 Has value? Determine TRANSORDERTYPE = 59: outsourcingProcess Other: cancelStockIn Call ERP Restore inventory Complete TL011/TL012 is empty Skip ERP call Code Location: GeneralUpdater.java:1571-1605
Code Reference
  • Cancel logic: GeneralUpdater.java:1571-1605
  • TL011/TL012 check: GeneralUpdater.java:1571
  • TRANSORDERTYPE determination: GeneralUpdater.java:1577
Related API
Cancel stock-in and create stock-in (stockin.data.create) are paired.
Cancel requires TB001/TB002 returned by ERP after successful creation (stored in TL011/TL012).

3. Request Specification

Format: JSON
Content-Type: application/json

3.1 Cancel General Stock-In (cancelStockIn)

FieldTypeRequiredDescriptionMES Source
companyIDstringYCompany codeCOMPANYID
userIdstringYOperatorCurrent user
stock_in_nostringYStock-in number (type-number)TL011 + "-" + TL012

3.2 Cancel Outsourcing Stock-In (outsourcingProcess)

FieldTypeRequiredDescriptionMES Source
companyIDstringYCompany codeCOMPANYID
userIdstringYOperatorCurrent user
outsource_nostringYOutsourcing number (type-number)TL011 + "-" + TL012
source_typestringYReversal type (0/1/2)"0" (shipment reversal)

Field Source Description

stock_in_no / outsource_no = SFT_TRANSORDER_LINE.TL011 + "-" + SFT_TRANSORDER_LINE.TL012

TL011/TL012 is written after stockin.data.create succeeds, from ERP returned TB001/TB002.

4. Response Specification

FieldTypeDescription
codeint200=Success, other=Failure
msgstringProcessing result message

Success Behavior

5. Validation Rules

#Validation ItemRuleCode Location
1TL011 not emptyMust have ERP document typeGeneralUpdater.java:1571
2TL012 not emptyMust have ERP document numberGeneralUpdater.java:1571
3ERP connectionSFTConfig.isHasERP() = trueGeneralUpdater.java:1575
4TRANSORDERTYPE check59=outsourcingProcess, other=cancelStockInGeneralUpdater.java:1582
5Original document existsDocument must exist in ERPERP side validation
6Document status allows cancelOnly unposted can be reversedERP side validation
Important: ERP will not be called if TL011/TL012 is empty
In the program logic, only when both TL011 and TL012 are not empty, the cancel API will be called.
If empty, the cancel check-out action only executes on MES side, ERP is not affected.

6. Error Codes

CodeMessageDescription
E101Stock-in document not foundstock_in_no corresponding document does not exist
E102Stock-in document already postedStock-in has been posted, cannot reverse
E103Stock-in document has referencesHas subsequent sales or transfer orders
E104Insufficient inventoryInventory will be negative after cancel
E999System errorTimeout, connection exception

7. JSON Examples

Request - Cancel General Stock-In

{
  "companyID": "COMP01",
  "userId": "EMP001",
  "stock_in_no": "5101-20260319001"
}

Request - Cancel Outsourcing Stock-In

{
  "companyID": "COMP01",
  "userId": "EMP001",
  "outsource_no": "5902-20260319001",
  "source_type": "0"   // 0=Shipment reversal
}

Response (Success)

{
  "code": 200,
  "msg": "Stock-in cancelled successfully"
}

Response (Failure)

{
  "code": 500,
  "msg": "Stock-in has been posted, cannot cancel"
}

8. Race Condition Risk Description

Known Issue: TL011/TL012 is empty when cancelling check-out

When user cancels check-out before ERP returns, TL011/TL012 has not been written back yet, cancel API will not be called.
This causes MES and ERP data inconsistency.

Timeline Example

T1 MES Check-out Send to ERP T2 Cancel Check-out TL011/TL012 is empty! T3 ERP Returns TB001/TB002 ERP document not cancelled

Root Cause

// GeneralUpdater.java:1571
if(!SftTransorderLine.getTl011().equals("") && !SftTransorderLine.getTl012().equals("")){
    // Only call cancel API when TL011/TL012 is not empty
    // If cancel before ERP returns, this if is false, skip ERP call
}

Recommended Solutions

SolutionDescriptionImpact
ImmediateManually void the stock-in in ERPRequires manual intervention
Wait mechanismWait for ERP return before allowing cancelRequires code modification
Lock mechanismDisable cancel during check-out processingRequires code modification
Periodic comparisonScheduled job to compare MES and ERP document statusRequires new feature
Reference Case
See CLAUDE.md record on 2026-03-12 "0000675600 Cancel Check-out outsourcingProcess Not Called Analysis"