--[[
|
编码: JX-19-04
|
名称: 码盘中-确定
|
作者:
|
日期:
|
|
级别:
|
|
函数: ClickOK
|
|
功能:
|
--]]
|
|
wms_base = require( "wms_base" )
|
wms_wh = require( "wms_wh" )
|
|
|
-- 主函数
|
function ClickOK(strLuaDEID)
|
local nRet, strRetInfo
|
local attrs
|
|
local now = os.date("%Y%m%d%H%M%S")
|
local randomNum = math.random(1, 99999)
|
local strHeader = 'HHWMS'..os.date("%y%m")..'-'
|
local strCode
|
|
-- 获取码盘单号
|
nRet, strCode = mobox.getSerialNumber( "巨沃移库单", strHeader, 5 )
|
if (nRet ~= 0) then
|
mobox.setInfo(strLuaDEID, '申请码盘单编码失败!'..strCode)
|
return
|
end
|
|
-- 获取输入参数
|
nRet, attrs = m3.GetSysInputParameter(strLuaDEID)
|
if (nRet ~= 0) then
|
mobox.setInfo(strLuaDEID, "获取当前输入面板里的属性失败! " .. attrs)
|
return
|
end
|
lua.Debug(strLuaDEID, debug.getinfo(1), "attrs", attrs)
|
|
local input_attr = m3.KeyValueAttrsToObjAttr(attrs)
|
|
local cntr_code = input_attr.S_CNTR_CODE
|
local no = input_attr.S_EXT_ATTR1
|
|
if (cntr_code == nil or cntr_code == '') then
|
mobox.setInfo(strLuaDEID, "容器编码不能为空!")
|
return
|
end
|
|
-- 获取"正在码盘"数据
|
local obj
|
nRet, obj = m3.GetSysDataJson(strLuaDEID)
|
if (nRet ~= 0) then
|
mobox.setInfo(strLuaDEID, "无法获取数据包!" .. obj)
|
return
|
end
|
|
lua.Debug(strLuaDEID, debug.getinfo(1), "obj", obj)
|
|
local item_list = obj[1].item_list
|
local action = {}
|
|
-- 如果码盘单号为空的话,那么就是没有新建状态的码盘单,则需要新建一个码盘单数据
|
if (no == '') then
|
|
local cell_no, item_code, qty
|
local f_qty, f_acc_m_qty, f_acc_p_qty
|
-- 创建码盘单对象
|
local transfer_order = m3.AllocObject(strLuaDEID, "JX_Transfer_Order")
|
transfer_order.no = strCode
|
transfer_order.cntr_code = cntr_code
|
|
for i = 1, #item_list do
|
local item = item_list[i]
|
local attrs_obj = m3.KeyValueAttrsToObjAttr(item.attrs)
|
cell_no = attrs_obj.S_CELL_NO
|
item_code = attrs_obj.S_ITEM_CODE
|
qty = lua.Get_NumAttrValue(attrs_obj.F_QTY)
|
|
-- 查询巨沃移库量表,校验库存数量
|
local strCondition = "S_ITEM_CODE = '" .. item_code .. "'"
|
nRet, strRetInfo = m3.GetDataObjByCondition(strLuaDEID, "JX_Inventory_Transfer", strCondition)
|
if (nRet ~= 0) then
|
mobox.setInfo(strLuaDEID, "查询 Material 表失败: " .. strRetInfo)
|
return
|
end
|
|
f_qty = lua.Get_NumAttrValue(strRetInfo.qty)
|
f_acc_m_qty = lua.Get_NumAttrValue(strRetInfo.acc_m_qty)
|
f_acc_p_qty = f_qty - f_acc_m_qty
|
if (qty > f_acc_p_qty) then
|
mobox.setInfo(strLuaDEID, "物料编码 " .. item_code .. " 的数量超出库存量!")
|
return
|
end
|
|
-- 查询物料信息
|
local strCondition = "S_ITEM_CODE = '" .. item_code .. "'"
|
nRet, strRetInfo = m3.GetDataObjByCondition(strLuaDEID, "Material", strCondition)
|
if (nRet ~= 0) then
|
mobox.setInfo(strLuaDEID, "查询 Material 表失败: " .. strRetInfo)
|
return
|
end
|
|
-- 创建JX_TO_Detail对象并插入数据
|
local to_detail = m3.AllocObject(strLuaDEID, "JX_TO_Detail")
|
to_detail.to_no = strCode
|
to_detail.cntr_code = cntr_code
|
to_detail.item_code = item_code
|
to_detail.item_name = strRetInfo.item_name
|
to_detail.qty = qty
|
to_detail.cell_no = cell_no
|
to_detail.f_alloc_qty = f_acc_p_qty
|
to_detail.volume = strRetInfo.volume
|
to_detail.weight = strRetInfo.weight
|
|
nRet, to_detail = m3.CreateDataObj(strLuaDEID, to_detail)
|
if (nRet ~= 0) then
|
mobox.setInfo(strLuaDEID, '创建码盘明细对象失败!' .. to_detail)
|
return
|
end
|
end
|
|
nRet, transfer_order = m3.CreateDataObj(strLuaDEID, transfer_order)
|
if (nRet ~= 0) then
|
mobox.setInfo(strLuaDEID, '创建码盘对象失败!' .. transfer_order)
|
return
|
end
|
|
-- 查询明细数据
|
local detail_strCondition = "S_TO_NO = '" .. strCode .. "'"
|
local detail_data_objs
|
nRet, detail_data_objs = m3.QueryDataObject(strLuaDEID, "JX_TO_Detail", detail_strCondition)
|
if (nRet ~= 0) then
|
mobox.setInfo(strLuaDEID,"查询明细数据失败! " .. detail_data_objs)
|
return
|
end
|
lua.Debug(strLuaDEID, debug.getinfo(1), "detail_data_objs", detail_data_objs)
|
|
action[1] =
|
{
|
action_type = "set_dlg_attr",
|
value = {
|
{ attr = "S_EXT_ATTR1", value = strCode }
|
}
|
}
|
-- 将所有行数据批量插入到页面
|
action[2] = {
|
action_type = "set_subtable_page_content",
|
value = {
|
page_name = "已码盘",
|
content = detail_data_objs,
|
clear = true,
|
clear_confirm = false,
|
checkbox = false
|
}
|
}
|
|
action[3] = {
|
action_type = "clear_subpage_rows",
|
value = {
|
page_name = "码盘中"
|
}
|
}
|
|
-- 执行所有操作
|
nRet, strRetInfo = mobox.setAction(strLuaDEID, lua.table2str(action))
|
if (nRet ~= 0) then
|
mobox.setInfo(strLuaDEID,"执行操作失败! " .. strRetInfo)
|
return
|
end
|
|
else
|
local page_info = {}
|
local cell_no, item_code, qty
|
local f_qty, f_acc_m_qty, f_acc_p_qty
|
|
for i = 1, #item_list do
|
local item = item_list[i]
|
local attrs_obj = m3.KeyValueAttrsToObjAttr(item.attrs)
|
cell_no = attrs_obj.S_CELL_NO
|
item_code = attrs_obj.S_ITEM_CODE
|
qty = lua.Get_NumAttrValue(attrs_obj.F_QTY)
|
|
-- 查询巨沃移库量表,校验库存数量
|
local strCondition = "S_ITEM_CODE = '" .. item_code .. "'"
|
nRet, strRetInfo = m3.GetDataObjByCondition(strLuaDEID, "JX_Inventory_Transfer", strCondition)
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "查询 Material 表失败: " .. strRetInfo)
|
end
|
|
f_qty = lua.Get_NumAttrValue(strRetInfo.qty)
|
f_acc_m_qty = lua.Get_NumAttrValue(strRetInfo.acc_m_qty)
|
f_acc_p_qty = f_qty - f_acc_m_qty
|
if (qty > f_acc_p_qty) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "物料编码 " .. item_code .. " 的数量超出库存量!")
|
end
|
|
-- 查询物料信息
|
local strCondition = "S_ITEM_CODE = '" .. item_code .. "'"
|
nRet, strRetInfo = m3.GetDataObjByCondition(strLuaDEID, "Material", strCondition)
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "查询 Material 表失败: " .. strRetInfo)
|
end
|
|
-- 创建JX_TO_Detail对象并插入数据
|
local to_detail = m3.AllocObject(strLuaDEID, "JX_TO_Detail")
|
to_detail.to_no = no
|
to_detail.cntr_code = cntr_code
|
to_detail.item_code = item_code
|
to_detail.item_name = strRetInfo.item_name
|
to_detail.qty = qty
|
to_detail.cell_no = cell_no
|
to_detail.f_alloc_qty = f_acc_p_qty
|
to_detail.volume = strRetInfo.volume
|
to_detail.weight = strRetInfo.weight
|
|
nRet, to_detail = m3.CreateDataObj(strLuaDEID, to_detail)
|
if (nRet ~= 0) then
|
mobox.setInf(strLuaDEID, '创建码盘明细对象失败!' .. to_detail)
|
return
|
end
|
|
end
|
|
-- 查询明细数据
|
local detail_strCondition = "S_TO_NO = '" .. no .. "'"
|
local detail_data_objs
|
nRet, detail_data_objs = m3.QueryDataObject(strLuaDEID, "JX_TO_Detail", detail_strCondition)
|
if (nRet ~= 0) then
|
mobox.setInfo(strLuaDEID, "查询明细数据失败! " .. detail_data_objs)
|
return
|
end
|
lua.Debug(strLuaDEID, debug.getinfo(1), "detail_data_objs", detail_data_objs)
|
-- 将所有行数据批量插入到页面
|
action[1] = {
|
action_type = "set_subtable_page_content",
|
value = {
|
page_name = "已码盘",
|
content = detail_data_objs,
|
clear = true,
|
clear_confirm = false,
|
checkbox = false
|
}
|
}
|
|
action[2] = {
|
action_type = "clear_subpage_rows",
|
value = {
|
page_name = "码盘中"
|
}
|
}
|
|
|
-- 执行所有操作
|
nRet, strRetInfo = mobox.setAction(strLuaDEID, lua.table2str(action))
|
if (nRet ~= 0) then
|
mobox.setInfo(strLuaDEID,"执行操作失败! " .. strRetInfo)
|
return
|
end
|
end
|
|
|
|
end
|