--[[
|
编码: AMS-101-13
|
名称:
|
作者:
|
日期:2025-05-15
|
|
函数: AfterSure
|
功能:
|
|
更改记录:
|
|
--]]
|
|
json = require("json")
|
mobox = require("OILua_JavelinExt")
|
m3 = require("oi_base_mobox")
|
wms_wh = require("wms_wh")
|
function AfterSure(strLuaDEID)
|
local nRet, strRetInfo, page_info
|
|
-- 先获取表头扫描数据
|
nRet, strRetInfo = m3.GetSysInputParameter(strLuaDEID)
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "获取扫描数据失败!" .. strRetInfo)
|
end
|
local cntr_code = m3.KeyValueAttrsToObjAttr(strRetInfo).S_CNTR_CODE -- 容器编码
|
local loc_code = m3.KeyValueAttrsToObjAttr(strRetInfo).S_LOC_CODE -- 码盘货位
|
|
-- 判断料箱编码是否输入
|
if (cntr_code == nil or cntr_code == "") then
|
mobox.setInfo(strLuaDEID, "请输入料箱编码!")
|
return
|
end
|
|
-- 判断货位编码是否输入
|
if (loc_code == nil or loc_code == "") then
|
mobox.setInfo(strLuaDEID, "请输入货位编码!")
|
return
|
end
|
|
-- 判断货位是否存在
|
local loc_info
|
local strCondition = "S_CODE = '"..loc_code.."'"
|
nRet, loc_info = m3.GetDataObjByCondition(strLuaDEID, "Location", strCondition)
|
if(nRet == 1)then mobox.setInfo(strLuaDEID,"货位编码不存在!") return
|
elseif(nRet > 1)then lua.Error(strLuaDEID, debug.getinfo(1),loc_info)
|
end
|
|
-- 判断容器是否存在安全库存
|
-- 存在判断货位是否相同,不同则更新货位/不存在则新建货位容器绑定
|
-- 相关更新表【货位容器绑定】
|
strCondition = "S_CNTR_CODE = '" .. cntr_code .. "'"
|
local loc_Container
|
nRet, loc_Container = m3.GetDataObjByCondition(strLuaDEID, "Loc_Container", strCondition)
|
if (nRet == 0) then
|
-- 容器货位解绑
|
nRet, strRetInfo = wms_wh.Loc_Container_Unbinding(strLuaDEID, loc_Container.loc_code, cntr_code, "绑定解绑方法-系统",
|
"系统解绑")
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '货位容器解绑失败!' .. strRetInfo) end
|
-- 货位容器绑定
|
nRet, strRetInfo = wms_wh.Loc_Container_Binding(strLuaDEID, loc_code, cntr_code, "绑定解绑方法-系统", "系统绑定")
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '货位容器绑定失败!' .. strRetInfo) end
|
-- 更新【安全库存量表】料箱对应的货位
|
strCondition = "S_CNTR_CODE = '" .. cntr_code .. "'"
|
local set_sql = "S_LOC_CODE = '"..loc_code.."'"
|
nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "SAF_Inventory", strCondition,set_sql)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "修改【POU安全库存量表】信息失败!" .. strRetInfo) end
|
elseif (nRet == 1) then
|
-- 不存在则货位容器绑定
|
nRet, strRetInfo = wms_wh.Loc_Container_Binding(strLuaDEID, loc_code, cntr_code, "绑定解绑方法-系统", "系统绑定")
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '货位容器绑定失败!' .. strRetInfo) end
|
elseif (nRet > 1) then
|
lua.Error(strLuaDEID, debug.getinfo(1), loc_Container)
|
end
|
|
-- 获取正在码盘页的数据
|
nRet, page_info = m3.GetSysDataJson(strLuaDEID)
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), page_info)
|
end
|
local item_list_now = page_info[1].item_list
|
for i = 1, #item_list_now do
|
local item_code = m3.KeyValueAttrsToObjAttr(item_list_now[i].attrs).S_ITEM_CODE
|
local item_name = m3.KeyValueAttrsToObjAttr(item_list_now[i].attrs).S_ITEM_NAME
|
local safety_qty = tonumber(m3.KeyValueAttrsToObjAttr(item_list_now[i].attrs).F_SAFETY_QTY)
|
|
-- 根据 容器+物料号 更新【容器货品明细】表,更新条数为0则创建容器货品明细
|
strCondition = "S_CNTR_CODE = '" .. cntr_code .. "' AND S_ITEM_CODE = '"..item_code.."'"
|
local set_sql = "S_ITEM_CODE = '"..item_code.."',S_ITEM_NAME = '"..item_name.."'"
|
nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "CG_Detail", strCondition,set_sql)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "修改【容器货品明细】信息失败!" .. strRetInfo) end
|
lua.Debug(strLuaDEID, debug.getinfo(1), '修改条数:', strRetInfo)
|
if (tonumber(strRetInfo) == 0) then
|
-- 创建【容器货品明细】
|
local cg_detail = m3.AllocObject(strLuaDEID, "CG_Detail")
|
cg_detail.cntr_code = cntr_code
|
cg_detail.item_code = item_code
|
cg_detail.item_name = item_name
|
cg_detail.qty = 1
|
cg_detail.wh_code = loc_info.wh_code
|
cg_detail.area_code = loc_info.area_code
|
cg_detail.loc_code = loc_info.code
|
nRet, cg_detail = m3.CreateDataObj(strLuaDEID, cg_detail)
|
lua.Debug(strLuaDEID, debug.getinfo(1), 'cg_detail', cg_detail)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'mobox 创建【容器货品明细】对象失败!' .. cg_detail) end
|
end
|
|
-- 根据 容器+物料号 更新【安全库存量表】表,更新条数为0则创建
|
strCondition = "S_CNTR_CODE = '" .. cntr_code .. "' AND S_ITEM_CODE = '"..item_code.."'"
|
set_sql = "S_ITEM_CODE = '"..item_code.."',S_ITEM_NAME = '"..item_name.."',F_SAFETY_QTY =".. safety_qty
|
nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "SAF_Inventory", strCondition,set_sql)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "修改【安全库存量表】信息失败!" .. strRetInfo) end
|
lua.Debug(strLuaDEID, debug.getinfo(1), '修改条数:', strRetInfo)
|
if (tonumber(strRetInfo) == 0) then
|
-- 创建【安全库存量表】
|
local saf_inventory = m3.AllocObject(strLuaDEID, "SAF_Inventory")
|
saf_inventory.cntr_code = cntr_code
|
saf_inventory.item_code = item_code
|
saf_inventory.item_name = item_name
|
saf_inventory.safety_qty = safety_qty
|
saf_inventory.loc_code = loc_code
|
nRet, saf_inventory = m3.CreateDataObj(strLuaDEID, saf_inventory)
|
lua.Debug(strLuaDEID, debug.getinfo(1), 'saf_inventory', saf_inventory)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'mobox 创建【安全库存量表】对象失败!' .. saf_inventory) end
|
end
|
end
|
|
-- 组织界面数据
|
local action_array = {}
|
|
action_array[1] = {
|
action_type = "set_dlg_attr",
|
value = {
|
{ attr = "S_CNTR_CODE", value = "" },
|
{ attr = "S_LOC_CODE", value = "" }
|
}
|
}
|
|
action_array[2] = {
|
action_type = "clear_subpage_rows",
|
value = {
|
page_name = "正在码盘"
|
}
|
}
|
|
action_array[3] = {
|
action_type = "clear_subpage_rows",
|
value = {
|
page_name = "已码盘"
|
}
|
}
|
|
nRet, strRetInfo = mobox.setAction(strLuaDEID, lua.table2str(action_array))
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "setAction失败! " .. strRetInfo)
|
end
|
|
mobox.setInfo(strLuaDEID, "初始化成功!")
|
end
|