--[[
|
编码: AMS-21-26
|
名称:
|
作者:
|
日期:2025-04-27
|
|
函数: AfterQtyChange
|
功能:
|
|
更改记录:
|
|
--]]
|
|
json = require ("json")
|
mobox = require ("OILua_JavelinExt")
|
m3 = require ("oi_base_mobox")
|
|
function AfterQtyChange( 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, "查询 Material 表失败: " .. 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, "查询 Material 表失败: " .. strRetInfo)
|
return
|
end
|
local inbound_area = strRetInfo.area_code
|
|
if(area ~= inbound_area) then
|
mobox.setInfo(strLuaDEID, "物料所在库区和入库单对应库区不一致!!" ..item_code)
|
return
|
end
|
|
local nRet,whcode
|
nRet,whcode = wms_base.Get_sConst2("人工库存储区" )
|
if ( nRet ~= 0 ) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "获取系统常量:人工库存储区失败!" )
|
end
|
-- 获取物料对应的货位
|
local loc_data
|
local Condition = " S_ITEM_CODE = '" .. item_code .. "' AND S_AREA_CODE = '"..whcode.."'"
|
nRet, loc_data = m3.QueryDataObject(strLuaDEID, "INV_Detail", Condition)
|
if (nRet ~= 0) then
|
mobox.setInfo(strLuaDEID, "查询物料对应的货位失败" ..item_code)
|
return
|
end
|
|
local locations = {}
|
local loc_record
|
local unique_locations = {} -- 用于检查重复值的哈希表
|
|
-- 如果查询结果为空,则返回"(无数据)"
|
if #loc_data == 0 then
|
table.insert(locations, " ")
|
else
|
for n = 1, #loc_data do
|
loc_record = m3.KeyValueAttrsToObjAttr(loc_data[n].attrs)
|
if loc_record.S_LOC_CODE and loc_record.S_LOC_CODE ~= "" then
|
-- 检查是否已存在该位置代码
|
if not unique_locations[loc_record.S_LOC_CODE] then
|
table.insert(locations, loc_record.S_LOC_CODE)
|
unique_locations[loc_record.S_LOC_CODE] = true
|
end
|
end
|
end
|
|
-- 如果最终没有有效数据,也返回"(无数据)"
|
if #locations == 0 then
|
table.insert(locations, "")
|
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, "该入库单没有这条数据! " .. attrs)
|
return
|
end
|
|
nRet, detail_records = m3.QueryDataObject(strLuaDEID, "ERP_Inbound_Detail", strCondition)
|
if (nRet ~= 0) then
|
mobox.setInfo(strLuaDEID, debug.getinfo(1), "查询入库单明细失败!"..detail_records)
|
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_EXT_ATTR1", value = locations },
|
{ attr = "S_ITEM_CODE", value = item_code }--, enable = false
|
|
}
|
}
|
action[3] = {
|
action_type = "set_dlg_current_edit_attr",
|
value = "S_EXT_ATTR2"
|
}
|
|
nRet, strRetInfo = mobox.setAction(strLuaDEID, lua.table2str(action))
|
if (nRet ~= 0) then
|
mobox.setInfo(strLuaDEID, "setAction失败! " .. strRetInfo)
|
return
|
end
|
|
end
|