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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
--[[
   编码: WMS-24-27
   名称: 
   作者:
   日期:2025-07-07
 
   函数: ClickReceiveButton
   功能:
 
   更改记录:
 
--]]
 
 
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_out = require("wms_outbound")
wms_base = require("wms_base")
wms_cntr = require("wms_container")
wms_station = require("wms_station")
 
-- 用于汇总出库单明细数据
function Sum_outbound_detail(strLuaDEID, out_no, storer, sum_outbound_detail)
 
    local nRet, data_objs
 
    local outbound_detail_info = {
        total_qty = 0, total_weight = 0, total_volume = 0
    }
 
    -- 获取所有出库单明细
    nRet, data_objs = m3.QueryDataObject(strLuaDEID, "Outbound_Detail", "S_OO_NO = '" .. out_no .. "'", "N_ROW_NO")
    if (nRet ~= 0) then
        return 2, "QueryDataObject失败!" .. data_objs
    end
    if (data_objs == "") then
        return 0, outbound_detail_info
    end
 
    local bFind
    for n = 1, #data_objs do
        local detail_attrs = m3.KeyValueAttrsToObjAttr(data_objs[n].attrs)
        local item_code = lua.Get_StrAttrValue(detail_attrs.S_ITEM_CODE)
        local item_state = lua.Get_StrAttrValue(detail_attrs.S_ITEM_STATE)
        local owner = lua.Get_StrAttrValue(detail_attrs.S_OWNER)
        local qty = lua.StrToNumber(detail_attrs.F_QTY)
        local weight = lua.StrToNumber(detail_attrs.F_WEIGHT)
        local volume = lua.StrToNumber(detail_attrs.F_VOLUME)
 
        if (item_code ~= "" and qty > 0) then
 
            outbound_detail_info.total_qty = outbound_detail_info.total_qty + qty
            outbound_detail_info.total_weight = outbound_detail_info.total_weight + qty * weight
            outbound_detail_info.total_volume = outbound_detail_info.total_volume + qty * volume
 
            bFind = false
            for m = 1, #sum_outbound_detail do
                if (sum_outbound_detail[m].item_code == item_code and sum_outbound_detail[m].item_state == item_state and sum_outbound_detail[m].storer == storer) then
                    sum_outbound_detail[m].qty = sum_outbound_detail[m].qty + qty
                    bFind = true
                    break
                end
            end
            if (bFind == false) then
                table.insert(sum_outbound_detail, {
                    item_code = item_code,
                    item_name = lua.Get_StrAttrValue(detail_attrs.S_ITEM_NAME),
                    item_state = item_state,
                    owner = owner,
                    storer = storer,
                    qty = qty,
                    alloc_qty = 0,
                    weight = weight,
                    volume = volume,
                    cell_type = lua.Get_StrAttrValue(detail_attrs.S_CELL_TYPE)
                })
            end
        end
    end
    return 0, outbound_detail_info
end
 
function ClickReceiveButton (strLuaDEID)
 
    local nRet, strRetInfo
    local runtime_paramter
    local outbound_array
    local outbound_obj
    local outbound_sum_info
    local strUserLogin
    local strUserName
    local area_info
    local loc_code
    local station_info
    local xb_area_code
 
    local wh_code = ""
    local area_code = ""
    local lx_count = 0
    local outbound_list = {}
    local sum_detail_list = {}
 
    -- 获取操作人员信息
    nRet, strUserLogin, strUserName = mobox.getCurUserInfo(strLuaDEID)
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "获取当前操作人员信息失败!")
    end
 
    -- 获取系统运行参数
    nRet, runtime_paramter = m3.GetRuntimeParam(strLuaDEID)
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "GetRuntimeParam失败! " .. runtime_paramter)
    end
    local station = runtime_paramter.formQueryDataObj.S_STATION_NO
 
    if (station == nil or station == "") then
        mobox.setInfo(strLuaDEID, "请选择出库站台!")
        return
    end
    
    
    -- 获取选中的出库单
    nRet, outbound_array = m3.GetSysDataJson(strLuaDEID)
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), outbound_array)
    end
    if (#outbound_array == 0) then
        mobox.setInfo(strLuaDEID, "必须选中一个出库单!")
        return
    end
 
    -- 循环获取所有出库单对象
    for n = 1, #outbound_array do
        nRet, outbound_obj = m3.GetDataObject(strLuaDEID, "Outbound_Order", outbound_array[n].id)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), outbound_obj)
        end
 
        -- 开始进行出库单领用
        if ((outbound_obj.station ~= "" and outbound_obj.station ~= nil) or (outbound_obj.wave_no ~= "" and outbound_obj.wave_no ~= nil)) then
            mobox.setInfo(strLuaDEID, "当前出库单:" .. outbound_obj.no .. "已被领用, 无法重复领用!")
            return
        end
 
        -- 汇总拣料箱数量
        -- lx_count = lx_count + outbound_obj.box_qty
 
        -- 已有波次进行拦截
        if (outbound_obj.wave_no ~= "" or outbound_obj.b_state ~= 0) then
            mobox.setInfo(strLuaDEID, "出库单:" .. outbound_obj.no .. " 已经有出库波次!")
            return
        end
 
        -- 校验仓库库区是否一致
        if (wh_code == "") then
            wh_code = lua.Get_StrAttrValue(outbound_obj.wh_code)
        else
            if (wh_code ~= outbound_obj.wh_code) then
                mobox.setInfo(strLuaDEID, "选中的出库单仓库必须是一样的!")
                return
            end
        end
        if (area_code == "") then
            area_code = lua.Get_StrAttrValue(outbound_obj.area_code)
        else
            if (area_code ~= outbound_obj.area_code) then
                mobox.setInfo(strLuaDEID, "选中的出库单库区必须是一样的!")
                return
            end
        end
 
        -- 获取出库单下的所有明细
        nRet, outbound_sum_info = Sum_outbound_detail(strLuaDEID, outbound_obj.no, outbound_obj.storer, sum_detail_list)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "Sum_outbound_detail 失败!" .. outbound_sum_info)
        end
 
        lua.Debug(strLuaDEID, debug.getinfo(1), "sum_detail_list:", sum_detail_list)
        lua.Debug(strLuaDEID, debug.getinfo(1), "outbound_sum_info:", outbound_sum_info)
 
        -- 处理完毕后将出库单号插入list
        table.insert(outbound_list, outbound_obj.no)
    end
 
    --  开始创建出库波次
    local outbound_wave = m3.AllocObject(strLuaDEID, "Outbound_Wave")
    outbound_wave.wh_code = wh_code                                 -- 仓库编码
    outbound_wave.area_code = area_code                             -- 库区编码
    outbound_wave.station = station                                 -- 出库站台
    outbound_wave.operator = strUserLogin                           -- 操作账号
    outbound_wave.operator_name = strUserName                       -- 操作人
    outbound_wave.good_type_num = #sum_detail_list                  -- 物料种类
    outbound_wave.total_qty = outbound_sum_info.total_qty           -- 物料总量
    outbound_wave.picking_box_num = lx_count                        -- 料箱总数
    lua.Debug(strLuaDEID, debug.getinfo(1), "出库波次创建前", outbound_wave)
    nRet, outbound_wave = m3.CreateDataObj(strLuaDEID, outbound_wave)
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "创建【出库波次】对象失败!" .. outbound_wave)
    end
 
    -- 创建出库波次明细
    for n = 1, #sum_detail_list do
        local wave_detail = m3.AllocObject(strLuaDEID, "OW_Detail")
        wave_detail.wave_no = outbound_wave.wave_no
        wave_detail.row_no = n
        wave_detail.item_code = sum_detail_list[n].item_code
        wave_detail.item_name = sum_detail_list[n].item_name
        wave_detail.item_state = sum_detail_list[n].item_state
        wave_detail.storer = sum_detail_list[n].storer
        wave_detail.qty = sum_detail_list[n].qty
        wave_detail.weight = sum_detail_list[n].weight
        wave_detail.volume = sum_detail_list[n].volume
        lua.Debug(strLuaDEID, debug.getinfo(1), "出库波次明细创建前", wave_detail)
        nRet, strRetInfo = m3.CreateDataObj(strLuaDEID, wave_detail)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "创建【出库波次明细】对象失败!" .. strRetInfo)
        end
    end
 
    -- 最后将处理完成后的出库单list统一更新状态, 站台和波次号
    for n = 1, #outbound_list do
        local out_no = outbound_list[n]
        local strUpdateSql = "S_STATION_NO = '" .. station .. "', N_B_STATE = 1, S_WAVE_NO = '" .. outbound_wave.wave_no .. "'"
        local strCondition = "S_NO = '" .. out_no .. "'"
        nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "Outbound_Order", strCondition, strUpdateSql)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "更新【出库单】信息失败!" .. strRetInfo)
        end
        -- 创建出库波次组成
        local ow_compose = m3.AllocObject(strLuaDEID, "OW_Compose")
        ow_compose.oo_no = out_no
        ow_compose.wave_no = outbound_wave.wave_no
        nRet, strRetInfo = m3.CreateDataObj(strLuaDEID, ow_compose)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "创建【出库波次组成】对象失败!" .. strRetInfo)
        end
    end
 
 
    mobox.setInfo(strLuaDEID, "领用成功, 已生成波次!")
 
end