lzh
2025-06-19 3a6436e0c88042c6ce8dca2fe8adb0109f0ad9e4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
--[[
 编码: GT-40-37
 名称: 任务完成
 作者:
 入口函数:TaskFinish
 功能说明:
    -- 判断是粉料退库还是胶料退库
    -- 胶料退库直接设置作业完成,粉料退库增加库存并修改退料单状态为完成和设置作业完成
 变更历史:
 --]]
require("WMS-BASE")
wms_op = require("wms_operation")
wms_cntr = require("wms_container")
require("GT_InAndOutboundPolicies")
function TaskFinish(strLuaDEID)
    local nRet, strRetInfo
 
    -- 获取当前作业对象
    local operation
    nRet, operation = m3.GetSysCurEditDataObj(strLuaDEID, "Operation")
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), operation) end
 
    -- 获取任务对象
    local task
    nRet, task = m3.SysInputParamToDataObj(strLuaDEID, "Task")
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), task) end
 
    if (task.end_area_code == 'HWPFL' or task.end_area_code == 'PFL' or task.end_area_code == 'HWTFL' or task.end_area_code == 'TFL') then
        -- 设置作业完成
        nRet, strRetInfo = wms_op.SetFinish(strLuaDEID, operation.code)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "设置作业编号='" .. operation.code .. "' 的作业完成失败!" .. strRetInfo)
        end
 
        -- 获取容器货品明细
        local cg_detail
        local strCondition = "S_CNTR_CODE = '" .. operation.cntr_code .. "'"
        nRet, cg_detail = m3.GetDataObjByCondition(strLuaDEID, "CG_Detail", strCondition)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "m3.GetDataObjByCondition 失败!" .. cg_detail) end
        -- 加库区/库量表 (通过CG_Detail)
        nRet = wms.wms_ResetInventory("Area", task.end_area_code)
 
        -- 获取入库单据行信息
        local label_crad
        strCondition = "S_SERIAL_NO = '" .. cg_detail.serial_no .. "'"
        if (tonumber(cg_detail.is_tl) == 1) then
            nRet, label_crad = m3.GetDataObjByCondition(strLuaDEID, "GT_ROM", strCondition, "T_CREATE DESC")
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "获取流水号信息失败!" .. label_crad) end
        else
            nRet, label_crad = m3.GetDataObjByCondition(strLuaDEID, "GT_Label_Crad", strCondition, "T_CREATE DESC")
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "获取流水号信息失败!" .. label_crad) end
        end
 
        -- 获取入库单据头信息
        local incoming_Info
        strCondition = "S_DELIVERY_NO = '" ..
            label_crad.delivery_no .. "' AND N_DELIVERY_ROW_NO = '" .. label_crad.delivery_row_no .. "'"
        nRet, incoming_Info = m3.GetDataObjByCondition(strLuaDEID, "GT_Incoming_Info", strCondition, "T_CREATE DESC")
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "获取入库单据头信息失败!") end
 
        -- 如果入库单是手工录入的则
        -- if (incoming_Info.type == '手工录入') then
        --     -- 创建【GTWMS同步记录】
        --     local sys_record = m3.AllocObject(strLuaDEID, "GTWMS_SYNC_RECORD")
        --     sys_record.delivery_no = incoming_Info.delivery_no
        --     sys_record.delivery_row_no = incoming_Info.delivery_row_no
        --     sys_record.lpn = cg_detail.serial_no
        --     sys_record.rfid = operation.cntr_code
        --     sys_record.lpnweight = cg_detail.qty
        --     sys_record.sku = cg_detail.item_code
        --     sys_record.batch_no = cg_detail.batch_no
        --     sys_record.remark3 = cg_detail.serial_no
        --     sys_record.type = "入库回传"
        --     lua.Debug(strLuaDEID, debug.getinfo(1), 'sys_record', sys_record)
        --     nRet, sys_record = m3.CreateDataObj(strLuaDEID, sys_record)
        --     if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'mobox 创建【GTWMS同步记录】对象失败!' .. sys_record) end
        -- else
        -- 入库结果回传
        local data
        local source = "GTWMS入库回传"
        nRet, data = StorageResult(strLuaDEID, operation.code, source)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "入库结果回传失败!" .. data)
        end
        data.loc = "LK001"
        lua.Debug(strLuaDEID, debug.getinfo(1), 'data', data)
 
        -- 调用GT-WMS的回传接口
        local url = wms_base.Get_sConst(strLuaDEID, "GTWMS-url")
        local strurl = url
        local strHeader = ""
        local strBody = {
            application = "GITI",
            code = "WCS_ASN_WMS",
            data = data
        }
        nRet, strRetInfo = CreateInterfaceExc(strLuaDEID, strurl, strHeader, strBody, "GTWMS", source)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "调用接口失败!" .. strRetInfo)
        end
        -- end
 
        -- 如果是退料单则修改退料单状态为完成
        if (tonumber(cg_detail.is_tl) == 1) then
            local condition = "S_CNTR_CODE = '" .. operation.cntr_code .. "'"
            local strSetAttr = "S_STATE = '完成'"
            nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "GT_ROM", condition, strSetAttr)
            if (nRet ~= 0) then
                lua.Error(strLuaDEID, debug.getinfo(1), "设置状态失败!" .. strRetInfo)
            end
        end
    else
        -- 设置作业完成
        nRet, strRetInfo = wms_op.SetFinish(strLuaDEID, operation.code)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "设置作业编号='" .. operation.code .. "' 的作业完成失败!" .. strRetInfo)
        end
    end
end