--[[
|
编码: GK-84-20
|
名称: 导入国科入库任务
|
作者:HAN
|
日期:2025-7-1
|
入口函数: Import
|
来源:
|
国科
|
|
功能说明:
|
通过导入国科入库任务创建 码盘单 和 码盘明细
|
|
变更历史:
|
|
--]]
|
wms_cntr = require( "wms_container" )
|
wms_pallet = require( "wms_palletizing" )
|
|
local function set_cell_limit_def( cell_type, cell_limit, avl_cell_set, cell_set)
|
if cell_limit > 0 then
|
table.insert( avl_cell_set, cell_type )
|
local cell_limit = {
|
cell_type = cell_type,
|
loading_limit = cell_limit
|
}
|
table.insert( cell_set.cell_def, cell_limit )
|
end
|
end
|
|
function Import(strLuaDEID)
|
local nRet, strRetInfo, strNo
|
-- 获取导入的数据, 返回 [{"attr":"xx","value":""},...]
|
|
m3.PrintLuaDEInfo( strLuaDEID )
|
|
local row_data = {}
|
nRet, row_data = m3.GetSysDataJson(strLuaDEID)
|
if (nRet ~= 0 or strRetInfo == '') then
|
lua.Stop( strLuaDEID, "无法获取导入数据!")
|
return
|
end
|
|
local factory
|
nRet, factory = wms_base.Get_sConst2( "WMS_Default_Factory" )
|
if ( nRet ~= 0 ) then
|
lua.Stop( strLuaDEID, "系统无法获取常量'WMS_Default_Factory'")
|
return
|
end
|
local wh_code
|
nRet, wh_code = wms_base.Get_sConst2( "WMS_Default_Warehouse" )
|
if ( nRet ~= 0 ) then
|
lua.Stop( strLuaDEID, "系统无法获取常量'WMS_Default_Warehouse'")
|
return
|
end
|
|
|
local row_attrs
|
local n, nCount, nRows, sku, cntr_spec, ctd_code
|
|
-- 导入是可分多页分批导入, 因此每次的起始行不一样
|
nRet, strRetInfo = mobox.getGlobalAttrValue( strLuaDEID, "start_row" )
|
if ( nRet ~= 0 ) then
|
mobox.error( strLuaDEID, "获取批量导入全局参数 start_row 失败!"..strRetInfo )
|
return
|
end
|
local nStartRow = tonumber( strRetInfo )
|
local str_err_msg
|
local task_detail, item_detail
|
local cntr = {}
|
local inbound_no_set = {}
|
|
-- 步骤1 获取从excel导入的一行数据
|
nRow = nStartRow
|
for row = 1, #row_data do
|
row_attrs = row_data[row]
|
nCount = #row_attrs
|
|
cell_limit_set = {
|
A = 0, B = 0, C = 0, D = 0, E = 0, F = 0
|
}
|
task_detail = m3.AllocObject( strLuaDEID, "GK_IN_TASK_Detail" )
|
item_detail = m3.AllocObject2( strLuaDEID, "INB_Pallet_Detail" )
|
-- 初始化 SKU 对象
|
sku = m3.AllocObject(strLuaDEID,"SKU")
|
cntr_spec = ''
|
ctd_code = ''
|
str_err_msg = ''
|
for n = 1, nCount do
|
strAttr = row_attrs[n].attr
|
strValue = row_attrs[n].value
|
if (strAttr ~= '') then
|
if (strAttr == "入库单号") then
|
if (strValue == '') then
|
str_err_msg = strAttr .. "不能为空!"
|
goto err_msg_process
|
end
|
task_detail.io_no = strValue
|
find = false
|
for _, no in ipairs( inbound_no_set ) do
|
if strValue == no then
|
find = true
|
break
|
end
|
end
|
if not find then
|
table.insert( inbound_no_set, strValue )
|
end
|
elseif (strAttr == "行号") then
|
if (strValue == '') then
|
str_err_msg = strAttr .. "不能为空!"
|
goto err_msg_process
|
end
|
task_detail.row_no = lua.Get_NumAttrValue( strValue )
|
|
elseif (strAttr == "商品编码") then
|
if (strValue == '') then
|
str_err_msg = strAttr .. "不能为空!"
|
goto err_msg_process
|
end
|
sku.item_code = strValue
|
task_detail.item_code = strValue
|
item_detail.S_ITEM_CODE = strValue
|
|
elseif (strAttr == "商品名称") then
|
if (strValue == '') then
|
str_err_msg = strAttr .. "不能为空!"
|
goto err_msg_process
|
end
|
sku.item_name = strValue
|
task_detail.item_name = strValue
|
item_detail.S_ITEM_NAME = strValue
|
|
elseif (strAttr == "重量") then
|
sku.weight = lua.StrToNumber( strValue )
|
elseif (strAttr == "体积") then
|
sku.volume = lua.StrToNumber( strValue )
|
elseif (strAttr == "适配料格") then
|
if (strValue == '') then
|
str_err_msg = strAttr .. "不能为空!"
|
goto err_msg_process
|
end
|
sku.cell_type = strValue
|
elseif (strAttr == "数量") then
|
task_detail.qty = lua.Get_NumAttrValue( strValue )
|
item_detail.F_QTY = task_detail.qty
|
|
elseif (strAttr == "A") then
|
cell_limit_set.A =lua.StrToNumber( strValue )
|
elseif (strAttr == "B") then
|
cell_limit_set.B =lua.StrToNumber( strValue )
|
elseif (strAttr == "C") then
|
cell_limit_set.C =lua.StrToNumber( strValue )
|
elseif (strAttr == "D") then
|
cell_limit_set.D =lua.StrToNumber( strValue )
|
elseif (strAttr == "E") then
|
cell_limit_set.E =lua.StrToNumber( strValue )
|
elseif (strAttr == "F") then
|
cell_limit_set.F =lua.StrToNumber( strValue )
|
|
elseif (strAttr == "产品线") then
|
sku.udf01 = strValue
|
item_detail.S_UDF01 = strValue
|
elseif (strAttr == "商品状态") then
|
sku.item_state = strValue
|
task_detail.item_state = strValue
|
item_detail.S_ITEM_STATE = strValue
|
|
elseif (strAttr == "货主") then
|
sku.storer = strValue
|
task_detail.storer = strValue
|
item_detail.S_STORER = strValue
|
|
elseif (strAttr == "批次") then
|
task_detail.batch_no = strValue
|
item_detail.S_BATCH_NO = strValue
|
|
elseif (strAttr == "容器类型") then
|
if (strValue == '') then
|
str_err_msg = strAttr .. "不能为空!"
|
goto err_msg_process
|
end
|
sku.ctd_code = strValue
|
ctd_code = strValue
|
elseif (strAttr == "有效期") then
|
strValue = string.gsub( strValue, "/","-")
|
task_detail.exp_date = strValue
|
item_detail.D_EXP_DATE = strValue
|
|
elseif (strAttr == "周转箱号") then
|
if (strValue == '') then
|
str_err_msg = strAttr .. "不能为空!"
|
goto err_msg_process
|
end
|
task_detail.cntr_code = strValue
|
item_detail.S_CNTR_CODE = strValue
|
|
elseif (strAttr == "料格类型") then
|
if (strValue == '') then
|
str_err_msg = strAttr .. "不能为空!"
|
goto err_msg_process
|
end
|
cntr_spec = strValue
|
elseif (strAttr == "料格编码") then
|
if (strValue == '') then
|
str_err_msg = strAttr .. "不能为空!"
|
goto err_msg_process
|
end
|
task_detail.cell_no = strValue
|
item_detail.S_CELL_NO = strValue
|
|
end
|
end
|
end
|
|
::err_msg_process::
|
if ( str_err_msg ~= '' ) then
|
local err_msg_row = {
|
row_no = nRow,
|
err_msg = str_err_msg
|
}
|
lua.Stop( strLuaDEID, "第"..nRow.."数据不正确 --> "..str_err_msg )
|
return
|
else
|
-- 判断导入的数据是否完整
|
if task_detail.cntr_code == '' then
|
lua.Stop( strLuaDEID, "第"..nRow.."数据不正确 --> 周转箱号不能为空!")
|
return
|
end
|
if cntr_spec == '' then
|
lua.Stop( strLuaDEID, "第"..nRow.."数据不正确 --> 料格类型不能为空!")
|
return
|
end
|
if ctd_code == '' then
|
lua.Stop( strLuaDEID, "第"..nRow.."数据不正确 --> 容器类型不能为空!")
|
return
|
end
|
if task_detail.cell_no == '' then
|
lua.Stop( strLuaDEID, "第"..nRow.."数据不正确 --> 料格编码不能为空!")
|
return
|
end
|
|
-- 判断料箱是否存在, 不存在需要创建料箱,是否是空料箱,如果不是空料箱要报错
|
nRet, cntr = wms_cntr.GetInfo( strLuaDEID, task_detail.cntr_code )
|
if nRet ~= 0 then
|
lua.Stop( strLuaDEID, "第"..nRow.."获取容器对象时发生错误 --> "..cntr)
|
return
|
end
|
if cntr == '' then
|
-- 料箱不存在,新建一个
|
cntr = m3.AllocObject( strLuaDEID, "Container" )
|
cntr.type = "Cell_Box"
|
cntr.spec = cntr_spec
|
cntr.code = task_detail.cntr_code
|
cntr.ctd_code = ctd_code
|
nRet, cntr = m3.CreateDataObj( strLuaDEID, cntr )
|
if nRet ~= 0 then
|
lua.Stop( strLuaDEID, cntr )
|
return
|
end
|
else
|
if cntr.empty_full ~= 0 then
|
lua.Stop( strLuaDEID, "料箱'"..task_detail.cntr_code.."'已经存在,并且非空" )
|
return
|
end
|
if cntr.position ~= '' then
|
lua.Stop( strLuaDEID, "料箱'"..task_detail.cntr_code.."'已经和货位'"..cntr.position.."'绑定" )
|
return
|
end
|
end
|
|
local avl_cell_set = {}
|
local cell_set = {
|
ctd_code = sku.ctd_code,
|
cell_def = {}
|
}
|
|
local cell_type = "A"
|
for n = 1, 6 do
|
cell_limit = cell_limit_set[cell_type]
|
set_cell_limit_def( cell_type, cell_limit, avl_cell_set, cell_set)
|
cell_type = lua.IncrementalChar(cell_type)
|
end
|
|
sku.available_spec = lua.table2str( avl_cell_set )
|
sku.sku_grid_parm = "["..lua.table2str( cell_set ).."]"
|
sku.count_method = "Limit"
|
nRet, strRetInfo = m3.CreateDataObj( strLuaDEID, sku, 1 )
|
if nRet ~= 0 then
|
lua.Stop( strLuaDEID, strRetInfo )
|
return
|
end
|
nRet, strRetInfo = m3.CreateDataObj( strLuaDEID, task_detail )
|
if nRet ~= 0 then
|
lua.Stop( strLuaDEID, strRetInfo )
|
return
|
end
|
|
-- 增加码盘
|
local detail_item_data = {}
|
table.insert( detail_item_data, item_detail )
|
nRet, strRetInfo = wms_pallet.Add_INB_Pallet_Detail( strLuaDEID, cntr.code, detail_item_data )
|
if nRet ~= 0 then
|
lua.Stop( strLuaDEID, strRetInfo )
|
return
|
end
|
end
|
nRow = nRow + 1
|
end
|
|
local gk_in_task
|
for _, no in ipairs( inbound_no_set ) do
|
gk_in_task = m3.AllocObject(strLuaDEID,"GK_IN_TASK")
|
gk_in_task.no = no
|
gk_in_task.factory = factory
|
gk_in_task.wh_code = wh_code
|
nRet, strRetInfo = m3.CreateDataObj( strLuaDEID, gk_in_task )
|
if nRet ~= 0 then
|
lua.Stop( strLuaDEID, strRetInfo )
|
return
|
end
|
end
|
end
|