1
Jianw
2025-07-09 88e26a2a960dbbc148332772448b79b9877102d8
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
--[[
    编码: 
    名称: 
    作者: HUI
    创建时间: 2025/6/10 10:53
    入口函数: 
    功能说明: 
    变更历史: 
--]]
 
m3 = require("oi_base_mobox")
wms = require("OILua_WMS")
lua = require("oi_base_func")
json = require("json")
mobox = require("OILua_JavelinExt")
wms_wh = require("wms_wh")
wms_base = require("wms_base")
wms_cntr = require("wms_container")
 
function AfterSure (strLuaDEID)
 
    local nRet, strRetInfo
    local parameter
    local out_order_array
 
    -- 获取自定义表单附加参数
    nRet, parameter = m3.GetSysInputParameter(strLuaDEID)
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), parameter)
    end
 
    local id = parameter.id
    local wave_no = parameter.wave_no
 
    -- 获取输入的拣料箱数据
    nRet, strRetInfo = mobox.getCurEditDataObjAttr(strLuaDEID, "PickingBoxCode", "PickingBoxNum")
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), strRetInfo)
    end
 
    local input_value = json.decode(strRetInfo)
    local picking_box_codes = input_value[1].value              -- 拣料箱编码
    -- if (picking_box_codes == "") then
    --     mobox.stopProgram(strLuaDEID, "必须绑定拣料箱!")
    --     return
    -- end
    local picking_box_num = tonumber(input_value[2].value)      -- 拣料箱数量
    if (picking_box_num < 0) then
        mobox.stopProgram(strLuaDEID, "拣料箱数量不合法!")
        return
    end
    if (picking_box_num ~= 0) then
        
        local pick_box_code_array = lua.split(picking_box_codes, ";")
    
        if (#pick_box_code_array ~= picking_box_num) then
            mobox.stopProgram(strLuaDEID, "绑定的拣料箱数量必须=" .. picking_box_num)
            return
        end
    
        -- 获取波次明细, 组织预分配参数
        local ipa_item_list = {}
        local sum_detail_list = parameter.o_detail_list
        for n = 1, #sum_detail_list do
            table.insert(ipa_item_list, {
                N_ROW_NO = n,
                S_ITEM_CODE = sum_detail_list[n].item_code,
                S_ITEM_NAME = sum_detail_list[n].item_name,
                F_QTY = sum_detail_list[n].qty
            })
        end
    
        -- 组织用于清空拣料箱的SetSQL数据
        local in_cntr_code = ""
        for n = 1, #pick_box_code_array do
            in_cntr_code = in_cntr_code .. "'" .. pick_box_code_array[n] .. "',"
        end
        in_cntr_code = lua.trim_laster_char(in_cntr_code)
    
        -- 清空拣料箱中的货品明细INV_Detail
        nRet, strRetInfo = mobox.dbdeleteData(strLuaDEID, "INV_Detail", "S_CNTR_CODE IN (" .. in_cntr_code .. ")")
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "删除【INV_Detail】失败!" .. strRetInfo)
        end
    
        -- 更新波次的分拣料箱编码和分拣料箱数
        nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "Outbound_Wave", "S_WAVE_NO = '" .. wave_no .. "'", "N_PICKING_BOX_NUM = " .. #pick_box_code_array .. ", S_SORT_BOX = '" .. lua.table2str(pick_box_code_array) .. "'")
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "修改出库单波次信息失败" .. strRetInfo)
        end
    
        -- 查询各个出库单需要的拣料箱数
        nRet, out_order_array = m3.QueryDataObject(strLuaDEID, "Outbound_Order", "S_WAVE_NO = '" .. wave_no .. "'", "")
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), out_order_array)
        end
    
        -- 给每个出库单设置对应数量的拣料箱编码
        for n = 1, #out_order_array do
            local out_order = m3.KeyValueAttrsToObjAttr(out_order_array[n].attrs)
            local out_no = out_order.S_NO
            local box_qty = out_order.F_BOX_QTY
            local set_box = {}
            for i = box_qty, 1, -1 do
                table.insert(set_box, pick_box_code_array[i])
                table.remove(pick_box_code_array, i)
            end
            lua.Debug(strLuaDEID, debug.getinfo(1), "出库单:" .. out_no .. "分配的拣料箱:", set_box)
            lua.Debug(strLuaDEID, debug.getinfo(1), "pick_box_code_array剩余拣料箱:", pick_box_code_array)
            nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "Outbound_Order", "S_NO = '" .. out_no .. "'", "N_PICKING_BOX_NUM = F_BOX_QTY, S_PICK_BOX_CODE = '" .. lua.table2str(set_box) .. "'")
            if (nRet ~= 0) then
                mobox.error(strLuaDEID, "修改出库单明细状态失败" .. strRetInfo)
            end
        end
    end
    -- 开始配盘
    nRet, strRetInfo = mobox.triggerClsEvent(strLuaDEID, "Outbound_Wave", id, "自动配盘")
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "执行【盘点计划启动】脚本失败!" .. strRetInfo)
    end
 
    -- 刷新界面
    local action = {
        {
            action_type = "close_dlg",
            value = ""
        },
        {
            action_type = "refresh",
            value = ""
        }
    }
 
    nRet, strRetInfo = mobox.setAction(strLuaDEID, lua.table2str(action))
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "setAction失败! " .. strRetInfo)
    end
 
    mobox.setInfo(strLuaDEID, "配盘成功!")
 
end