Cancel Outsourcing Purchase Receipt

outsourcing.process
CANCEL JSON Sync

1. Basic Information

ItemDescription
API Name (Chinese)Cancel Outsourcing Receipt (Outsourcing Purchase Receipt Reversal)
CROSS API Codeoutsourcing.process
MES taskNameoutsourcingProcess
ESB Path/outsourcingProcess
DSMS Referenceapi-2058
Call DirectionMES → ERP
Trigger ConditionTRANSORDERTYPE = "59" + TL011/TL012 not empty
Request FormatJSON (Content-Type: application/json)
Transport MethodHTTP POST via ESB
Sync/AsyncSynchronous call

source_type Parameter Reference

source_typeDescriptionUse Case
0Shipment reversalCancel checkout (outsourcing shipment)
1Receipt reversalCancel check-in (outsourcing return)
2Return reversalCancel return

2. Business Flow

Cancel Checkout Check TL011/TL012 Has value? Check TRANSORDERTYPE = "59" outsourcingProcess Call ERP Reverse stock-in Done Other: cancelStockIn != "59" Code Location: GeneralUpdater.java:1571-1605
Code Reference
  • Cancel Decision: GeneralUpdater.java:1571-1605
  • TL011/TL012 Check: GeneralUpdater.java:1571
  • TRANSORDERTYPE Decision: GeneralUpdater.java:1577
  • JSON Assembly: transOrder.put("outsource_no", stock_in_no)
Related API
Cancel Outsourcing Receipt (outsourcingProcess) is used in pair with Create Outsourcing Receipt (outsourcingPurchaseStockinCreate).
When cancelling, the TB001/TB002 returned by ERP after successful creation (stored in TL011/TL012) is required.

3. Request Specification

Transport Format: JSON
Content-Type: application/json (HttpClient.java:25)

Request Fields (Parameter)

FieldTypeRequiredDescriptionMES Source
enterprise_nostringYCompany IDCOMPANYID (sftcompany)
site_nostringYSiteCOMPANYID (sftcompany)
source_nostringYSource number (outsourcing receipt no.)outsource_no (TL011 + "-" + TL012)
source_typestringYReversal type (0/1/2)"0" (shipment reversal)
objective_doc_nostringYTarget document number (same as source_no)outsource_no

outsourcing_info_data Structure

FieldTypeRequiredDescriptionMES Source
source_nostringNSource numberEmpty string
plot_nostringNLot numberEmpty string
purchase_seqnumericNPurchase sequenceEmpty string

Field Source Description

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

TL011/TL012 is written from TB001/TB002 returned by ERP after successful outsourcingPurchaseStockinCreate.

4. Response Specification

FieldTypeDescription
codeint200=Success, others=Failure
msgstringProcessing result message

Success Behavior

5. Validation Rules

#Check ItemRuleCode Location
1TL011 not emptyMust have ERP doc typeGeneralUpdater.java:1571
2TL012 not emptyMust have ERP doc numberGeneralUpdater.java:1571
3TRANSORDERTYPE = "59"Outsourcing type checkGeneralUpdater.java:1577
4Original document existsERP document must existERP validation
5Document status allows cancelCan only reverse if not postedERP validation
Important: ERP will NOT be called when TL011/TL012 is empty
In the program logic, outsourcingProcess is only called when both TL011 and TL012 are not empty.
If empty, the cancel checkout action only executes in MES, ERP is not affected.

6. Error Codes

CodeMessageDescription
E001Required field missingoutsource_no or source_type is empty
E002Outsourcing receipt not foundDocument for outsource_no not found
E003Document already posted, cannot cancelERP document posted, cannot reverse
E004Document already cancelledDuplicate cancel
E005Invalid source_typeValue not in 0/1/2 range
E999System errorTimeout, connection exception

7. JSON Examples

Request (MES Internal JSON)

{
  "companyID": "COMP01",
  "userId": "EMP001",
  "outsource_no": "5902-20260319001",
  "source_type": "0"
}

ERP XML Format (Actual Transmission)

<!-- SendFormS.java:1727-1752 -->
<parameters>
  <parameter key="enterprise_no" type="string">COMP01</parameter>
  <parameter key="site_no" type="string">COMP01</parameter>
  <parameter key="source_no" type="string">5902-20260319001</parameter>
  <parameter key="source_type" type="numeric">0</parameter>
  <parameter key="objective_doc_no" type="string">5902-20260319001</parameter>

  <parameter key="outsourcing_info_data" type="data">
    <data name="outsourcing_info">
      <row seq="1">
        <field name="source_no" type="string"></field>
        <field name="plot_no" type="string"></field>
        <field name="purchase_seq" type="numeric"></field>
      </row>
    </data>
  </parameter>
</parameters>

Response (Success)

{
  "code": 200,
  "msg": "Outsourcing receipt reversed successfully"
}

Response (Failure)

{
  "code": 500,
  "msg": "Document already posted, cannot cancel 5902-20260319001"
}

8. Race Condition Risk Description

Known Issue: TL011/TL012 is empty when cancelling checkout

When the user cancels checkout before ERP responds, since TL011/TL012 has not been written back yet, outsourcingProcess will not be called.
This leads to data inconsistency between MES and ERP.

Timeline Example

16:29:46 MES Checkout Send to ERP 16:31:08 Cancel Checkout TL011/TL012 empty! 16:31:49 ERP Response 5902-20260310069 ERP document not cancelled

Root Cause

// GeneralUpdater.java:1571
if(!SftTransorderLine.getTl011().equals("") && !SftTransorderLine.getTl012().equals("")){
    // outsourcingProcess is only called when TL011/TL012 are not empty
    // If cancelled before ERP response, this if is false, ERP call is skipped
}

Recommended Solutions

SolutionDescriptionImpact
Immediate ActionManually void the outsourcing receipt in ERPManual intervention required
Wait MechanismWait for ERP response before allowing cancel checkoutCode modification required
Lock MechanismDisable cancel operation during checkout in progressCode modification required
Periodic ComparisonScheduled job to compare MES and ERP document statusNew feature required