--[[
|
编码: JX-19-12
|
名称:
|
作者:
|
日期:2025-02-15
|
|
函数: AftercodeChange
|
功能:
|
|
更改记录:
|
|
--]]
|
|
m3 = require("oi_base_mobox")
|
wms_base = require( "wms_base" )
|
wms_wh = require( "wms_wh" )
|
|
function AftercodeChange(strLuaDEID)
|
local nRet, strRetInfo
|
local attrs
|
|
-- 获取表头界面中的输入条码
|
nRet, attrs = m3.GetSysInputParameter(strLuaDEID)
|
if (nRet ~= 0) then
|
mobox.setInfo(strLuaDEID, "获取当前输入面板里的属性失败! " .. attrs)
|
return
|
end
|
|
local input_attr = m3.KeyValueAttrsToObjAttr(attrs)
|
local item_code = input_attr.S_ITEM_CODE --商品编码
|
local cell_no = input_attr.S_CELL_NO --料格号
|
local cntr_code = input_attr.S_CNTR_CODE -- 容器号
|
|
local container_data, nRet
|
local strCondition = "S_TO_NO IN (SELECT S_NO FROM TN_JX_Transfer_Order WHERE S_CNTR_CODE = '" .. cntr_code .. "' AND N_B_STATE = 1)"
|
nRet, container_data = m3.QueryDataObject(strLuaDEID, "JX_TO_Detail", strCondition)
|
|
-- 如果没有查询到数据,直接跳过,不做报错
|
if nRet ~= 0 or not container_data or #container_data == 0 then
|
--跳过
|
else
|
-- 如果查询到了数据,则进行后续处理和比对
|
for i = 1, #container_data do
|
local detail_attrs = m3.KeyValueAttrsToObjAttr(container_data[i].attrs)
|
local current_cell_no = detail_attrs.S_CELL_NO -- 料格号
|
local current_item_code = detail_attrs.S_ITEM_CODE -- 商品编码
|
|
if current_cell_no == cell_no then
|
if current_item_code ~= item_code then
|
mobox.setInfo(strLuaDEID, "已审核的料箱的料格号 " .. cell_no .. " 已存在物料编码 " .. current_item_code .. ",不能更新为物料编码 " .. item_code)
|
return
|
end
|
end
|
end
|
end
|
|
|
-- 查询巨沃移库量表
|
local f_qty,f_acc_m_qty,f_acc_p_qty
|
local strCondition = "S_ITEM_CODE = '" .. item_code .. "'"
|
nRet, strRetInfo = m3.GetDataObjByCondition(strLuaDEID, "JX_Inventory_Transfer", strCondition)
|
if (nRet ~= 0) then
|
mobox.setInfo(strLuaDEID, "查询 JX_Inventory_Transfer 表失败: " .. strRetInfo)
|
return
|
end
|
|
f_qty = lua.Get_NumAttrValue(strRetInfo.qty)
|
f_acc_m_qty = lua.Get_NumAttrValue(strRetInfo.acc_m_qty)
|
if(f_qty == f_acc_m_qty) then
|
mobox.setInfo(strLuaDEID, "编码 = '" .. item_code .. "'的物料已分配完!")
|
return
|
end
|
|
-- 取实际数量和分配数量,做差异值
|
f_acc_p_qty = f_qty - f_acc_m_qty
|
|
local page_sorting = nil
|
local page_completed = nil
|
|
-- 正在码盘和已码盘页面
|
local obj
|
nRet, obj = m3.GetSysDataJson(strLuaDEID)
|
if (nRet ~= 0) then
|
mobox.setInfo(strLuaDEID, "无法获取数据包! " .. obj)
|
return
|
end
|
|
for i = 1, #obj do
|
local page = obj[i]
|
if (page.page_name == "码盘中") then
|
page_sorting = page
|
elseif (page.page_name == "已码盘") then
|
page_completed = page
|
end
|
end
|
|
local item_list_sorting = page_sorting.item_list
|
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_cell_no = attrs_obj.S_CELL_NO -- 料格号
|
current_item_code = attrs_obj.S_ITEM_CODE -- 商品编码
|
|
if (current_cell_no == cell_no) then
|
if (current_item_code == item_code) then
|
mobox.setInfo(strLuaDEID, "料格号 " .. cell_no .. " 已存在物料编码 " .. current_item_code .. ",请到已码盘相关料格修改数量")
|
return
|
else
|
mobox.setInfo(strLuaDEID, "料格号 " .. cell_no .. " 已存在物料编码 " .. current_item_code .. ",不能更新为物料编码 " .. item_code)
|
return
|
end
|
end
|
end
|
|
|
|
|
-- 检查正在码盘中是否已有料格号与物料编码匹配
|
local item_found = false
|
local action = {}
|
|
if (item_list_sorting ~= nil and item_list_sorting ~= '') then
|
local current_cell_no
|
local current_item_code
|
local current_qty
|
|
for n = 1, #item_list_sorting do
|
local attrs_obj = m3.KeyValueAttrsToObjAttr(item_list_sorting[n].attrs)
|
|
current_cell_no = attrs_obj.S_CELL_NO -- 料格号
|
current_item_code = attrs_obj.S_ITEM_CODE -- 商品编码
|
current_qty = tonumber(attrs_obj.F_QTY) -- 获取当前数量
|
|
if (current_cell_no == cell_no) then
|
if (current_item_code ~= item_code) then
|
mobox.setInfo(strLuaDEID, "料格号 " .. cell_no .. " 已存在物料编码 " .. current_item_code .. ",不能更新为物料编码 " .. item_code)
|
return
|
else
|
item_found = true
|
|
-- 更新正在码盘页面的数量
|
local update_action = {
|
action_type = "set_subtable_page_row",
|
value = {
|
page_name = "码盘中",
|
row = {
|
{
|
condition = {
|
{
|
attr = "S_ITEM_CODE",
|
value = current_item_code
|
},
|
{
|
attr = "S_CELL_NO",
|
value = current_cell_no
|
}
|
},
|
attrs = {
|
{
|
attr = "F_QTY",
|
operation = "+",
|
value = "1"
|
}
|
}
|
}
|
}
|
}
|
}
|
|
table.insert(action, update_action)
|
end
|
end
|
end
|
end
|
|
-- 如果没有找到料格号匹配的记录,则插入新行
|
if not item_found then
|
-- 查询条码表,获取物料编码,因为输入的是条码和编码
|
-- local strCondition = "S_BARCODE = '" .. item_code .. "'"
|
-- nRet, strRetInfo = m3.GetDataObjByCondition(strLuaDEID, "JX_Material_Barcode", strCondition)
|
-- if nRet ~= 0 then
|
-- mobox.setInfo(strLuaDEID, "查询 Material 表失败: " .. strRetInfo)
|
-- return
|
-- end
|
-- local material_code = strRetInfo.item_code -- 物料编码
|
--,再用物料编码查询物料表
|
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
|
local material_name = strRetInfo.item_name -- 物料名称
|
|
-- 准备插入数据
|
local attr_array = {}
|
local insert_row = {}
|
|
attr_array[1] = lua.KeyValueObj("S_ITEM_NAME", material_name) -- 物料名称
|
attr_array[2] = lua.KeyValueObj("S_ITEM_CODE", item_code) -- 物料编码
|
attr_array[3] = lua.KeyValueObj("S_CELL_NO", cell_no) -- 料格号
|
attr_array[4] = lua.KeyValueObj("F_QTY", "1") -- 数量
|
attr_array[5] = lua.KeyValueObj("F_ALLOC_QTY", f_acc_p_qty) -- 可码盘数量
|
|
insert_row.attrs = attr_array
|
|
local test_row = {}
|
test_row[1] = insert_row
|
|
|
-- 插入新行
|
local insert_action = {
|
action_type = "insert_subtable_page_row",
|
value = {
|
page_name = "码盘中",
|
row = test_row
|
}
|
}
|
|
table.insert(action, insert_action)
|
|
|
end
|
|
-- 设置主页面物料编码输入框为空
|
local set_dlg_action = {
|
action_type = "set_dlg_attr",
|
value = {
|
lua.KeyValueObj("S_ITEM_CODE", "")
|
}
|
}
|
|
table.insert(action, set_dlg_action)
|
|
-- 执行动作
|
nRet, strRetInfo = mobox.setAction(strLuaDEID, lua.table2str(action))
|
if (nRet ~= 0) then
|
mobox.setInfo(strLuaDEID, "setAction失败! " .. strRetInfo .. ' action = ' .. lua.table2str(action))
|
return
|
end
|
|
|
|
end
|