--[[
|
编码: GK-56-21
|
名称: 预分配容器明细-条码
|
作者:HAN
|
日期:2025-1-29
|
|
级别:固定 (说明本段代码在项目中不太会变化)
|
|
函数: BarCodeChange
|
|
功能:
|
-- 根据输入的周转箱号 GK_IN_TASK_Detail 表查询, 获取入库单明细中的货品编码,批次号等信息
|
|
|
更改记录:
|
|
|
--]]
|
wms_wh = require( "wms_wh" )
|
wms_cntr = require( "wms_container" )
|
gk_base = require( "gk_base" )
|
|
function BarCodeChange ( strLuaDEID )
|
local nRet, strRetInfo
|
|
m3.PrintLuaDEInfo( strLuaDEID )
|
|
-- 获取周转箱号
|
nRet, strRetInfo = mobox.getCurEditDataObjAttr( strLuaDEID, "BarCode","ScanType","Prompt","TrayCode","F_ACT_QTY","S_ITEM_CODE")
|
if ( nRet ~= 0 ) then
|
wms_base.Notice_Audio( strLuaDEID, "获取当前编辑属性失败! "..strRetInfo, "error.mp3" )
|
return
|
end
|
local obj_attrs = json.decode( strRetInfo )
|
local bar_code = lua.Get_StrAttrValue( obj_attrs[1].value )
|
local scan_type = lua.Get_StrAttrValue( obj_attrs[2].value )
|
local prompt = lua.Get_StrAttrValue( obj_attrs[3].value )
|
local cur_tray_code = lua.Get_StrAttrValue( obj_attrs[4].value )
|
local act_qty = lua.Get_NumAttrValue( obj_attrs[5].value )
|
local item_code = lua.Get_StrAttrValue( obj_attrs[6].value )
|
|
if bar_code == '' then return end
|
|
local parameter
|
nRet, parameter = m3.Get_3053_PanelParameter( strLuaDEID, "组盘输入" )
|
if nRet ~= 0 then
|
wms_base.Notice_Audio( strLuaDEID, parameter, "error.mp3" )
|
return
|
end
|
local station = parameter.station or ''
|
if ( station == "") then
|
wms_base.Notice_Audio( strLuaDEID, "'组盘输入'面板必须有 station 参数!", "error.mp3")
|
return
|
end
|
local groupID = "Station:"..station
|
|
local wms_url
|
nRet, wms_url = wms_base.Get_sConst2( "网站URL" )
|
if ( nRet ~= 0 ) then
|
wms_base.Notice_Audio( strLuaDEID, "系统无法获取常量'网站URL'", "error.mp3" )
|
return
|
end
|
|
local success
|
local action = {}
|
if prompt == "请扫周转箱号" then
|
-- 扫周转箱的处理程序
|
local tray_code = bar_code
|
local sku_list = {}
|
nRet, sku_list = gk_base.Set_CurTrayBoxDetail( strLuaDEID, station, tray_code )
|
if ( nRet ~= 0 ) then
|
wms_base.Notice_Audio( strLuaDEID, sku_list, "error.mp3" )
|
return
|
end
|
if scan_type == "SN" then
|
prompt_info = "请扫商品SN"
|
else
|
prompt_info = "请扫商品条码"
|
end
|
action =
|
{
|
{
|
action_type = "set_panel_dlg_attr",
|
value = {
|
panel_name = "组盘输入",
|
attrs = {
|
{ attr = "S_ITEM_CODE", value = "" },
|
{ attr = "S_ITEM_NAME", value = "" },
|
{ attr = "BarCode", prompt = prompt_info },
|
{ attr = "Prompt", value = prompt_info },
|
{ attr = "S_BATCH_NO", value = "" },
|
{ attr = "F_QTY", value = 0 },
|
{ attr = "ExpDate", value = "" },
|
{ attr = "TrayCode", value = tray_code },
|
{ attr = "F_ACT_QTY", value = 0, enable = false }
|
}
|
}
|
|
},
|
{
|
action_type = "set_dlg_cursor",
|
value = {
|
ctrl_id = "BarCode"
|
}
|
},
|
{
|
action_type = "play_audio",
|
value = wms_url.."/static/audio/".."success.mp3"
|
}
|
}
|
mobox.removeCacheValue( "CurInboundTask", groupID )
|
else
|
if lua.StrIsEmpty( cur_tray_code ) then
|
wms_base.Notice_Audio( strLuaDEID, "请先扫周转箱!", "error.mp3" )
|
return
|
end
|
-- 获取当前亮灯的周转箱号+入库任务信息, 局部变量 CurInboundTask
|
-- { tray_code="xx", pac_detail_id = "xxx", loc_code = "" }
|
nRet, strRetInfo = mobox.getCacheValue( "CurInboundTask", groupID )
|
local cur_in_task = {}
|
if ( nRet == 0 ) then
|
local success
|
success, cur_in_task = pcall( json.decode, strRetInfo )
|
if ( success == false ) then
|
wms_base.Notice_Audio( strLuaDEID, "获取当前入库任务缓存信息失败!", "error.mp3" )
|
return
|
end
|
end
|
|
local sku_list = {}
|
local reload_traybox_detail = false
|
|
-- 获取周转箱缓存中的货品编码去匹配输入的条码
|
nRet, strRetInfo = mobox.getCacheValue( cur_tray_code.."->Detail", groupID )
|
if nRet == 0 then
|
success, sku_list = pcall( json.decode, strRetInfo)
|
if ( success == false ) then
|
reload_traybox_detail = true
|
end
|
end
|
|
if reload_traybox_detail then
|
nRet, sku_list = gk_base.Set_CurTrayBoxDetail( strLuaDEID, station, bar_code )
|
if ( nRet ~= 0 ) then
|
wms_base.Notice_Audio( strLuaDEID, sku_list, "error.mp3" )
|
return
|
end
|
end
|
-- 扫单一的商品条码,ScanType 不能是 SN
|
local find = false
|
local find_sku = {}
|
local next_prompt_info = ''
|
local scaned_sn_set = {} -- 已经扫描过的SN号
|
|
if prompt == "请扫商品条码" then
|
for _, sku in ipairs( sku_list ) do
|
if string.find( bar_code, sku.item_code ) then
|
if #sku.item_code == #bar_code then
|
-- 说明当前扫的是完整的商品编码,还要继续扫批次号,分的两段编码
|
action =
|
{
|
{
|
action_type = "set_panel_dlg_attr",
|
value = {
|
panel_name = "组盘输入",
|
attrs = {
|
{ attr = "BarCode", prompt = "请扫商品批号" },
|
{ attr = "Prompt", value = "请扫商品批号" },
|
{ attr = "S_ITEM_CODE", value = bar_code },
|
{ attr = "S_BATCH_NO", value = "" }
|
}
|
}
|
|
},
|
{
|
action_type = "set_dlg_cursor",
|
value = {
|
ctrl_id = "BarCode"
|
}
|
},
|
{
|
action_type = "play_audio",
|
value = wms_url.."/static/audio/".."success.mp3"
|
}
|
}
|
nRet, strRetInfo = mobox.setAction( strLuaDEID, lua.table2str(action) )
|
if ( nRet ~= 0 ) then
|
lua.Stop( strLuaDEID, "setAction失败! "..strRetInfo )
|
return
|
end
|
return
|
else
|
if string.find( bar_code, sku.batch_no ) then
|
if string.find( bar_code, sku.exp_date ) then
|
find = true
|
find_sku = sku
|
break
|
end
|
end
|
end
|
end
|
end
|
next_prompt_info = "请扫商品条码"
|
elseif prompt == "请扫商品批号" then
|
-- 分两次扫码的模式,bar_code 里面包含 批次号和有效期
|
if item_code == '' then
|
wms_base.Notice_Audio( strLuaDEID, "请先扫商品编码!", "error.mp3" )
|
return
|
end
|
for _, sku in ipairs( sku_list ) do
|
if string.find( item_code, sku.item_code ) then
|
if string.find( bar_code, sku.batch_no ) then
|
if string.find( bar_code, sku.exp_date ) then
|
find = true
|
find_sku = sku
|
break
|
end
|
end
|
|
end
|
end
|
next_prompt_info = "请扫商品条码"
|
elseif prompt == "请扫商品SN" then
|
-- 从 S_SN 里进行比对
|
-- 从缓存获取周转箱已经扫描过的SN
|
nRet, strRetInfo = mobox.getCacheValue( cur_tray_code.."->SN", groupID )
|
|
if nRet == 0 then
|
success, scaned_sn_set = pcall( json.decode, strRetInfo)
|
if ( success == false ) then
|
scaned_sn_set = {}
|
end
|
end
|
-- 如果已经扫描过,报错
|
if not lua.isTableEmpty( scaned_sn_set ) then
|
for _, sn in ipairs( scaned_sn_set ) do
|
if bar_code == sn then
|
wms_base.Notice_Audio( strLuaDEID, "扫描的SN'"..bar_code.."'已经扫描过一次!", "error.mp3" )
|
return
|
end
|
end
|
end
|
-- 判断 SN 是否 在S_SN中
|
for _, sku in ipairs( sku_list ) do
|
if string.find( sku.sn, bar_code ) then
|
find = true
|
find_sku = sku
|
break
|
end
|
end
|
next_prompt_info = "请扫商品SN"
|
else
|
wms_base.Notice_Audio( strLuaDEID, "扫码提示'"..prompt.."'系统没定义!", "error.mp3" )
|
return
|
end
|
|
if find then
|
-- 通过 商品编码+批次+有效期+周转箱 匹配到
|
local strCondition
|
local pac_detail_objs
|
|
strCondition = "S_ITEM_CODE = '"..find_sku.item_code.."' AND S_STORER = '"..find_sku.storer.."' AND S_ITEM_STATE = '"..find_sku.item_state.."' AND "..
|
"S_BATCH_NO = '"..find_sku.batch_no.."' AND N_B_STATE = "..PAC_DETAIL_STATE.Palletizing.." AND "..
|
"D_EXP_DATE = '"..find_sku.exp_date_long.."' AND S_UDF20 = '"..cur_tray_code.."'"
|
|
nRet, pac_detail_objs = m3.QueryDataObject( strLuaDEID, "Pre_Alloc_CNTR_Detail", strCondition, "" )
|
if nRet ~= 0 then
|
wms_base.Notice_Audio( strLuaDEID, "查询入库任务明细(预分配)错误!", "error.mp3" )
|
return
|
end
|
if pac_detail_objs == '' then
|
wms_base.Notice_Audio( strLuaDEID, "系统无法定位到有效的任务明细! (没满足条件)请看系统日志" )
|
lua.DebugEx( strLuaDEID, "站台["..station.."]扫码无法定位入库任务 -->", strCondition )
|
return
|
end
|
if #pac_detail_objs > 1 then
|
wms_base.Notice_Audio( strLuaDEID, "系统无法定位到有效的任务明细! (超过1条)请看系统日志" )
|
lua.DebugEx( strLuaDEID, "站台["..station.."]扫码无法定位入库任务 -->", strCondition )
|
return
|
end
|
|
local obj_attrs = m3.KeyValueAttrsToObjAttr( pac_detail_objs[1].attrs )
|
local cntr_code = obj_attrs.S_CNTR_CODE or ''
|
local cell_no = obj_attrs.S_CELL_NO or ''
|
local loc_code
|
nRet, loc_code = wms_cntr.Get_Container_Loc( strLuaDEID, cntr_code )
|
if nRet ~= 0 then
|
wms_base.Notice_Audio( strLuaDEID, " Get_Container_Loc 失败!"..loc_code, "error.mp3" )
|
return
|
end
|
if loc_code == '' then
|
wms_base.Notice_Audio( strLuaDEID, "料箱'"..cntr_code.."'没有和货位进行绑定!", "error.mp3")
|
return
|
end
|
local login_info
|
nRet, login_info = wms_base.Get_CurLoginUserInfo( strLuaDEID )
|
if ( nRet ~= 0 ) then
|
wms_base.Notice_Audio( strLuaDEID, login_info, "error.mp3" )
|
return
|
end
|
|
-- 亮灯,设置站台缓存, 这个缓存要拍灯后才起取消
|
local light_action = {}
|
if lua.isTableEmpty( cur_in_task ) then
|
local in_task = {
|
tray_code = cur_tray_code,
|
pac_detail_id = pac_detail_objs[1].id,
|
loc_code = loc_code
|
}
|
nRet, strRetInfo = gk_base.Lighting( loc_code, obj_attrs.S_CELL_NO, lua.Get_NumAttrValue(obj_attrs.F_QTY),
|
PTL_COLOR.Green, 1, login_info.login, "站台入库" )
|
if nRet ~= 0 then
|
wms_base.Notice_Audio( strLuaDEID, "货位'"..loc_code.."' 亮灯失败! "..strRetInfo, "error.mp3" )
|
return
|
end
|
nRet = mobox.setCacheValue( "CurInboundTask", lua.table2str( in_task ), groupID )
|
if nRet ~= 0 then
|
wms_base.Notice_Audio( strLuaDEID, "设置站台缓存[CurInboundTask]失败!", "error.mp3")
|
return
|
end
|
|
light_action =
|
{
|
action_type = "refresh_related_panel",
|
value = {
|
{
|
panel_name = "料格显示",
|
input_parameter = {
|
cell_no = obj_attrs.S_CELL_NO,
|
loc_code = loc_code,
|
light_color = "#00FF00" -- 绿色
|
}
|
}
|
}
|
}
|
else
|
-- 已经有亮灯,判断一下是否是同一个入库任务
|
if cur_in_task.pac_detail_id ~= pac_detail_objs[1].id then
|
wms_base.Notice_Audio( strLuaDEID, "扫码的商品不在当前入库任务里!")
|
return
|
end
|
end
|
act_qty = act_qty + 1
|
action =
|
{
|
{
|
action_type = "set_panel_dlg_attr",
|
value = {
|
panel_name = "组盘输入",
|
attrs = {
|
{ attr = "BarCode", prompt = next_prompt_info },
|
{ attr = "Prompt", value = next_prompt_info },
|
{ attr = "S_ITEM_CODE", value = find_sku.item_code },
|
{ attr = "S_ITEM_NAME", value = find_sku.item_name },
|
{ attr = "S_BATCH_NO", value = find_sku.batch_no },
|
{ attr = "F_QTY", value = obj_attrs.F_QTY },
|
{ attr = "ExpDate", value = find_sku.exp_date_long },
|
{ attr = "F_ACT_QTY", value = act_qty, enable = true }
|
}
|
}
|
|
},
|
{
|
action_type = "set_dlg_cursor",
|
value = {
|
ctrl_id = "BarCode"
|
}
|
},
|
{
|
action_type = "play_audio",
|
value = wms_url.."/static/audio/".."success.mp3"
|
}
|
}
|
if not lua.isTableEmpty( light_action ) then
|
table.insert( action, light_action )
|
end
|
|
-- 如果是扫描的SN 需要把SN保存的缓存
|
if prompt == "请扫商品SN" then
|
table.insert( scaned_sn_set, bar_code )
|
nRet = mobox.setCacheValue( cur_tray_code.."->SN", lua.table2str( scaned_sn_set ), groupID )
|
if nRet ~= 0 then
|
wms_base.Notice_Audio( strLuaDEID, "设置站台缓存[SN]失败!", "error.mp3")
|
return
|
end
|
end
|
else
|
-- 没找到报错
|
action =
|
{
|
-- 设置当前光标还是在 商品编码输入框
|
{
|
action_type = "set_dlg_cursor",
|
value = {
|
ctrl_id = "BarCode"
|
}
|
},
|
{
|
action_type = "play_audio",
|
value = wms_url.."/static/audio/".."notexist.mp3"
|
}
|
}
|
end
|
end
|
|
lua.DebugEx( strLuaDEID, "item code change action", action )
|
|
nRet, strRetInfo = mobox.setAction( strLuaDEID, lua.table2str(action) )
|
if ( nRet ~= 0 ) then
|
lua.Stop( strLuaDEID, "setAction失败! "..strRetInfo )
|
return
|
end
|
|
end
|