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
--[[
    编码: GT-03-11
    名称: 新增-点击确定按钮后
    作者:HAN
    日期:2023-05-05
 
    函数: AfterClickOk
 
    功能:
       -- 获取A、B、C、D 工位的装箱数量,如果不为0,新增一个装箱工单
 
    更改记录:
    V2.0 LZH 2024-06-06 工位设置为12个
    V2.1 LZH 2024-06-07 校验该工位是否存在同一批次号物料的启动装箱工单,存在则报错(佳通问题清单序号32)
    V2.2 LZH 2024-08-09 由于数据模型的调整,进行字段的代码优化
    V2.3 LZH 2024-08-29 由于自定义表单的调整,进行代码优化
    V2.4 LZH 2024-09-13 如果入库单的状态为新建则修改为启动
 
--]]
json  = require("json")
mobox = require("OILua_JavelinExt")
m3    = require("oi_base_mobox")
 
function AfterClickOk(strLuaDEID)
    local nRet, strRetInfo, nCount
 
    -- V2.3
    nRet, strRetInfo = mobox.getCurEditDataObjAttr(strLuaDEID, "S_ORDER_NO", "A", "B", "C", "D", "E", "F", "G", "H", "I",
        "J", "K", "L", "S_BATCH_NO", "S_ITEM_CODE", "S_ITEM_NAME", "D_PRODUCT",
        "F_ACTUAL_QTY", "A_QTY", "B_QTY", "C_QTY", "D_QTY", "E_QTY", "F_QTY", "G_QTY", "H_QTY",
        "I_QTY", "J_QTY", "K_QTY", "L_QTY", "S_PALLETIZING", "S_DISPERSOID")
    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 order_no = obj_attrs[1].value -- 来料单号
    local batch_no = obj_attrs[14].value
    local item_code = obj_attrs[15].value
    local item_name = obj_attrs[16].value
    local product_date = obj_attrs[17].value                --生产日期
    local actual_qty = lua.StrToNumber(obj_attrs[18].value) -- 批次号总重
    local palletizing = obj_attrs[31].value
    local dispersoid = obj_attrs[32].value
    local station_array = {} -- 装箱工位
 
    -- V2.0 获取启用的工位装箱数量
    local i = 1
    local switch = ''
    for n = 2, 13 do
        switch = obj_attrs[n].value
        if (switch == '启用') then
            local station = {}
            station.pos = obj_attrs[n].attr
            station.qty = obj_attrs[n + 17].value
            station_array[i] = station
            i = i + 1
        end
    end
    lua.Debug(strLuaDEID, debug.getinfo(1), 'station_array', station_array)
 
    if (station_array == nil or station_array == '' or #station_array == 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), '装箱工单未选择装箱工位!')
    end
 
    -- 创建装箱工单
    for n = 1, #station_array do
        local packing_order = m3.AllocObject(strLuaDEID, "GT_Packing_Order")
        packing_order.order_no = order_no
        packing_order.item_code = item_code
        packing_order.product_date = product_date
        packing_order.batch_no = batch_no
        packing_order.item_name = item_name
        packing_order.actual_qty = actual_qty
        packing_order.palletizing = palletizing
        packing_order.dispersoid = dispersoid
        packing_order.station = station_array[n].pos
        packing_order.pack_qty = station_array[n].qty
 
        -- V2.0 校验该工位是否存在同一批次号物料的启动装箱工单
        local strCondition = "S_STATION = '" .. packing_order.station .. "'AND S_ITEM_CODE = '" .. item_code
            .. "' AND S_BATCH_NO = '" .. batch_no .. "' AND S_STATE = '启用'"
        nRet, nCount = mobox.getDBRecordCount(strLuaDEID, "TN_GT_Packing_Order", strCondition)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), nCount) end
        if (tonumber(nCount) > 0) then
            lua.Error(strLuaDEID, debug.getinfo(1),
                packing_order.station .. "工位已存在相同批次物料启用状态的装箱工单!")
        end
 
        nRet, packing_order = m3.CreateDataObj(strLuaDEID, packing_order)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'mobox 创建【装箱工单】对象失败!' .. packing_order) end
    end
 
    -- V2.4 如果入库单的状态为新建则修改为启动
    -- 查询条件
    local strCondition = "S_ORDER_NO = '" .. order_no .. "'"
    nRet, strRetInfo = mobox.queryOneDataObjAttr(strLuaDEID, "GT_Incoming_Info", strCondition)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "queryOneDataObjAttr 失败!" .. strRetInfo) end
    strRetInfo = json.decode(strRetInfo)
 
    if (strRetInfo.state == '新建') then
        local strSetAttr = "S_STATE = '启用'"
        nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "GT_Incoming_Info", strCondition, strSetAttr)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "设置状态失败!" .. strRetInfo)
        end
 
        -- 如果启动的装箱工单是散装胶的,则调用WCS接口下发机器人规格
        if (dispersoid == 'Y') then
            -- 调用国自的任务下发接口
            local strCode = lua.guid()                 -- 生产一个GUID字符串
            local url = wms_base.Get_sConst(strLuaDEID, "WCS-url")
            local strurl = url .. "/ChangeSpecifications"
            local strHeader = ""
            local data = {
                req_no = strCode,
                palletizing = palletizing
            }
            nRet, strRetInfo = CreateInterfaceExc(strLuaDEID, strurl, strHeader, data, "WCS", "机器人规格下发")
            if (nRet ~= 0) then
                lua.Error(strLuaDEID, debug.getinfo(1), "调用接口失败!" .. strRetInfo)
            end
        end
    end
end