--[[
|
编码: 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
|