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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
--[[
    编码: GT-122-01
    名称: 点击确定按钮后
    作者:LZH
    日期:2024-8-25
 
    级别:固定 (说明本段代码在项目中不太会变化)
 
    函数: AfterClickOk
 
    功能:
 
 
    更改记录:
    V1.1 LZH 20241028 出库重新统计【烘胶维护】里面的库存量
 
--]]
json     = require("json")
mobox    = require("OILua_JavelinExt")
wms_wh   = require("wms_wh")
wms_base = require("wms_base")
wms_cntr = require("wms_container")
function AfterClickOk(strLuaDEID)
    local nRet, strRetInfo
 
    nRet, strRetInfo = mobox.getCurEditDataObjAttr(strLuaDEID, "S_CNTR_CODE")
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "获取当前编辑属性失败! " .. strRetInfo) end
    lua.Debug(strLuaDEID, debug.getinfo(1), 'strRetInfo', strRetInfo)
    local obj_attrs = json.decode(strRetInfo)
    local cntr_code = obj_attrs[1].value
 
    --获取货位容器信息
    nRet, strRetInfo = m3.GetDataObjectByKey(strLuaDEID, "Loc_Container", "S_CNTR_CODE", cntr_code)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), strRetInfo) end
    lua.Debug(strLuaDEID, debug.getinfo(1), 'strRetInfo', strRetInfo)
    local loc_code = strRetInfo.loc_code
 
    -- 容器货位解绑
    nRet, strRetInfo = wms_wh.Loc_Container_Unbinding(strLuaDEID, loc_code, cntr_code, "绑定解绑方法-系统",
        "强制完成")
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '货位容器解绑失败!' .. strRetInfo) end
 
    -- 容器解锁
    local container
    nRet, container = wms_cntr.GetInfo(strLuaDEID, cntr_code)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '获取容器对象失败!' .. container) end
    nRet, strRetInfo = wms_cntr.SetLock(strLuaDEID, container, "锁类型-无", "无")
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '托盘容器解锁失败!' .. strRetInfo) end
 
    -- 获取出库单据明细信息
    local stock_out
    local strCondition = "S_CNTR_CODE = '" .. cntr_code .. "' AND S_STATE IN( '执行','等待')"
    nRet, stock_out = m3.GetDataObjByCondition(strLuaDEID, "GT_SO_Detail", strCondition)
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "m3.GetDataObjByCondition 失败!" .. stock_out)
    end
    -- 设置出库单明细状态为完成
    strCondition = "S_CNTR_CODE = '" .. cntr_code .. "' AND S_STATE IN( '执行','等待')"
    local strSetSQL_update = " S_STATE = '完成'"
    nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "GT_SO_Detail", strCondition, strSetSQL_update)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "修改出库单据状态失败!" .. strRetInfo) end
 
    strCondition = "S_DO_NO = '" .. stock_out.delivery_no .. "' AND S_STATE <> '完成'"
    nRet, strRetInfo = mobox.getDataObjCount(strLuaDEID, "GT_SO_Detail", strCondition)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), strRetInfo) end
    if (tonumber(strRetInfo) <= 0) then
        -- 设置出库单状态为完成
        strCondition = "S_DO_NO = '" .. stock_out.delivery_no .. "'"
        strSetSQL_update = " S_STATE = '完成'"
        nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "GT_Stock_Out", strCondition, strSetSQL_update)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "修改出库单据状态失败!" .. strRetInfo) end
    end
 
    -- 获取容器货品信息
    local cg_detail
    strCondition = "S_CNTR_CODE = '" .. 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
 
    -- 获取入库单据行信息
    local label_crad
    strCondition = "S_SERIAL_NO = '" .. cg_detail.serial_no .. "'"
    nRet, label_crad = m3.GetDataObjByCondition(strLuaDEID, "GT_Label_Crad", strCondition, "T_CREATE DESC")
    if (nRet == 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
    elseif (nRet > 1) then
        lua.Error(strLuaDEID, debug.getinfo(1), "获取入库单据行信息失败!" .. label_crad)
    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), "获取入库单据头信息失败!" .. incoming_Info) end
 
    -- 如果出库单是手工录入的则创建GTWMS同步记录
    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 = cg_detail.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.grade = incoming_Info.level
        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 = {
            wh_code = "wmwhse1",
            task_no = stock_out.delivery_no,
            batch_no = cg_detail.batch_no,
            sku = cg_detail.item_code,
            qty = cg_detail.qty,
            rfid = cg_detail.cntr_code,
            number_no = label_crad.serial_no,
            supplier = incoming_Info.vendor,
            grade = incoming_Info.level,
            subloc = label_crad.subpool
        }
        local source = "GTWMS出库回传"
 
        -- 调用GT-WMS的回传接口
        local url = wms_base.Get_sConst(strLuaDEID, "GTWMS-url")
        local strurl = url
        local strHeader = ""
        local strBody = {
            application = "GITI",
            code = "WCS_SO_WMS",
            data = data
        }
        nRet, strRetInfo = CreateInterfaceExc(strLuaDEID, strurl, strHeader, strBody, "GTWMS", source)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "调用WCS接口失败!" .. strRetInfo)
        end
    end
 
    -- 删除容器货品明细记录
    strCondition = "S_CNTR_CODE = '" .. cntr_code .. "'"
    nRet, strRetInfo = mobox.deleteDataObject(strLuaDEID, "CG_Detail", strCondition)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), strRetInfo) end
 
    mobox.setInfo(strLuaDEID, "出库成功!")
end