--[[
|
编码: AMS-21-31
|
名称:
|
作者:
|
日期:2025-05-16
|
|
函数: ItemCodeChange
|
功能:
|
|
更改记录:
|
|
--]]
|
|
json = require ("json")
|
mobox = require ("OILua_JavelinExt")
|
m3 = require ("oi_base_mobox")
|
|
function ItemCodeChange( strLuaDEID )
|
local nRet,attrs
|
local strRetInfo
|
local detail_records
|
-- 获取表头界面中的输入条码
|
nRet, attrs = m3.GetSysInputParameter(strLuaDEID)
|
if (nRet ~= 0) then
|
mobox.setInfo(strLuaDEID, "获取当前输入面板里的属性失败! " .. attrs)
|
return
|
end
|
|
local input_attr = m3.KeyValueAttrsToObjAttr(attrs)
|
local io_no = input_attr.S_IO_NO --入库单号
|
local item_code = input_attr.S_ITEM_CODE --物料编码
|
|
|
local Condition = "S_ITEM_CODE = '" .. item_code .. "'"
|
nRet, strRetInfo = m3.GetDataObjByCondition(strLuaDEID, "SKU", Condition)
|
if nRet ~= 0 then
|
mobox.setInfo(strLuaDEID, "查询 SKU 表失败: " .. strRetInfo)
|
return
|
end
|
local material_name = strRetInfo.item_name -- 物料名称
|
local area = strRetInfo.udf01
|
|
local Condition = "S_NO = '" .. io_no .. "'"
|
nRet, strRetInfo = m3.GetDataObjByCondition(strLuaDEID, "Inbound_Order", Condition)
|
if nRet ~= 0 then
|
mobox.setInfo(strLuaDEID, "查询 Inbound_Order 表失败: " .. strRetInfo)
|
return
|
end
|
local inbound_area = strRetInfo.area_code
|
|
if(area ~= inbound_area) then
|
mobox.setInfo(strLuaDEID, "物料所在库区和入库单对应库区不一致!!" ..item_code)
|
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)
|
|
for i = 1, #obj do
|
local page = obj[i]
|
if (page.page_name == "物料信息") then
|
page_completed = page
|
end
|
end
|
|
local item_list_completed = page_completed.item_list
|
-- 检查已码盘中是否已有料格号与物料编码匹配
|
local current_cell_no , current_item_code
|
for n = 1, #item_list_completed do
|
local attrs_obj = m3.KeyValueAttrsToObjAttr(item_list_completed[n].attrs)
|
current_item_code = attrs_obj.S_ITEM_CODE -- 商品编码
|
if (current_item_code == item_code) then
|
mobox.setInfo(strLuaDEID, "已存在物料编码 " .. current_item_code .. ",不可操作")
|
return
|
end
|
end
|
|
local strCondition = " S_IO_NO = '" ..io_no.. "' and S_ITEM_CODE = '" .. item_code .. "'"
|
nRet, strRetInfo = mobox.existThisData( strLuaDEID, "ERP_Inbound_Detail", strCondition )
|
if ( nRet ~= 0 ) then
|
mobox.setInfo(strLuaDEID, "调用existThisData方法失败! " .. attrs)
|
return
|
end
|
if ( strRetInfo ~= "yes" ) then
|
mobox.setInfo(strLuaDEID, "该入库单没有这条数据! " .. item_code)
|
return
|
end
|
|
nRet, detail_records = m3.QueryDataObject(strLuaDEID, "ERP_Inbound_Detail", strCondition)
|
if (nRet ~= 0) then
|
mobox.setInfo(strLuaDEID, debug.getinfo(1), "查询容器失败!"..data_objs)
|
return
|
end
|
|
local total_qty = 0
|
local acc_qty = 0
|
for i = 1, #detail_records do
|
local detail_obj = m3.KeyValueAttrsToObjAttr(detail_records[i].attrs)
|
total_qty = total_qty + detail_obj.F_QTY -- 入库数量
|
acc_qty = acc_qty + detail_obj.F_ACC_I_QTY -- 累计入库数量
|
end
|
local qty = total_qty - acc_qty
|
|
if qty <= 0 then
|
mobox.setInfo(strLuaDEID, "物料["..item_code.."]当前可入库数量为0!")
|
return
|
end
|
|
local row_data = {{
|
id = lua.guid(),
|
attrs = {{
|
attr = "S_ITEM_NAME",
|
value = material_name
|
}, {
|
attr = "S_ITEM_CODE",
|
value = item_code
|
}, {
|
attr = "F_QTY",
|
value = total_qty
|
}, {
|
attr = "F_ACC_I_QTY",
|
value = acc_qty
|
}, {
|
attr = "Qty",
|
value = qty
|
}
|
|
}
|
}}
|
|
local action = {}
|
|
-- 设置正在码盘页面数据
|
action[1] = {
|
action_type = "insert_subtable_page_row",
|
value = {
|
page_name = "物料信息",
|
row = row_data
|
}
|
}
|
action[2] = {
|
action_type = "set_dlg_attr",
|
value = {
|
{attr = "S_ITEM_CODE", value = ""}
|
}
|
}
|
|
lua.Debug(strLuaDEID, debug.getinfo(1), "lua.table2str(action)", lua.table2str(action))
|
nRet, strRetInfo = mobox.setAction(strLuaDEID, lua.table2str(action))
|
if (nRet ~= 0) then
|
mobox.setInfo(strLuaDEID, "setAction失败! " .. strRetInfo)
|
return
|
end
|
|
end
|