--[[
|
编码: WMS-31-12
|
名称: 盘点差异-复盘
|
作者:HAN
|
日期:2025-1-29
|
|
级别:固定 (说明本段代码在项目中不太会变化)
|
|
函数: RepeatCount
|
|
功能:
|
根据选中的盘点差异生成新的盘点单,盘点货品数量有差异的货品
|
|
更改记录:
|
|
--]]
|
wms_cntr= require( "wms_container" )
|
wms_wh = require( "wms_wh" )
|
|
function RepeatCount( strLuaDEID )
|
local nRet, strRetInfo
|
|
-- step1 获取当前点中的任务
|
nRet, objs = m3.GetSysDataJson( strLuaDEID )
|
if ( nRet ~=0 ) then lua.Error( strLuaDEID, debug.getinfo(1), objs ) end
|
-- [{"id":"","attrs":[{"attr":"","value":""},..]},..]
|
local nCount = #objs
|
if (nCount == 0) then return end
|
|
-- 获取功能点输入面板中的站台信息
|
local runtime_parameter
|
nRet, runtime_parameter = m3.GetRuntimeParam(strLuaDEID)
|
if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "GetRuntimeParam失败! "..runtime_parameter ) end
|
local input_panel = runtime_parameter.inputPanelDataObj
|
if ( nil == input_panel ) then
|
mobox.stopProgram( strLuaDEID, "功能点定义里缺少输入面板!")
|
return
|
end
|
local station = lua.Get_StrAttrValue( input_panel.Station )
|
if ( "" == station ) then
|
mobox.stopProgram( strLuaDEID, "站台不能为空!")
|
return
|
end
|
|
local count_diff
|
local count_cntr_list = {} -- 需要盘点的容器
|
local find, id
|
for n = 1, nCount do
|
-- 获取盘点差异对象属性
|
id = lua.trim_guid_str(objs[n].id)
|
nRet, count_diff = m3.GetDataObject( strLuaDEID, "Count_Diff", id )
|
if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), '获取【盘点差异】对象失败!'..count_diff ) end
|
-- 盘点是否允许复盘 , 状态不能是在盘点中...
|
if ( count_diff.recount == 'Y' and count_diff.b_state == 1 and count_diff.diff_move == 'N') then
|
find = false
|
local count_item = {
|
id = id,
|
item_code = count_diff.item_code,
|
item_name = count_diff.item_name,
|
qty = count_diff.qty,
|
cell_no = count_diff.cell_no,
|
item_state = count_diff.item_state,
|
batch_no = count_diff.batch_no,
|
serial_no = count_diff.serial_no,
|
erp_wh_code = count_diff.erp_wh_code,
|
end_user = count_diff.end_user,
|
supplier = count_diff.supplier,
|
ext_attr1 = count_diff.ext_attr1,
|
ext_attr2 = count_diff.ext_attr2,
|
ext_attr3 = count_diff.ext_attr3,
|
ext_attr4 = count_diff.ext_attr4,
|
ext_attr5 = count_diff.ext_attr5,
|
cg_detail_id = count_diff.cg_detail_id,
|
item_spec = count_diff.item_spec,
|
uom = count_diff.uom
|
}
|
|
for m = 1, #count_cntr_list do
|
if ( count_cntr_list[m].cntr_code == count_diff.cntr_code ) then
|
table.insert( count_cntr_list[m].count_item_list, count_item )
|
find = true
|
break
|
end
|
end
|
if ( find == false ) then
|
local count_cntr = {
|
cntr_code = count_diff.cntr_code,
|
first_cc_no = count_diff.cc_no,
|
count_item_list = {}
|
}
|
table.insert( count_cntr.count_item_list, count_item )
|
table.insert( count_cntr_list, count_cntr )
|
end
|
end
|
end
|
local strUpdateSql, strCondition
|
nCount = #count_cntr_list
|
if ( nCount == 0 ) then return end
|
|
-- 创建盘点单
|
local count_order = m3.AllocObject(strLuaDEID,"Count_Order")
|
count_order.method = 2 -- 2 自动出库到站点
|
count_order.num = nCount
|
count_order.station = station
|
count_order.count_type = 3 -- 3 复盘
|
count_order.diff_hand_method = 1 -- 1 不自动差异转移
|
nRet, count_order = m3.CreateDataObj( strLuaDEID, count_order )
|
if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "创建【盘点单】失败!"..count_order ) end
|
|
-- 创建【计划盘点容器】
|
local count_cg_detail, count_item
|
local cp_count_container_list = {}
|
local loc, loc_code
|
|
for n = 1, nCount do
|
-- 获取容器所在货位
|
nRet, loc_code = wms_cntr.Get_Container_Loc( strLuaDEID, count_cntr_list[n].cntr_code )
|
if ( nRet ~= 0 ) then
|
mobox.stopProgram( strLuaDEID, loc_code)
|
return
|
end
|
if ( loc_code == '' ) then
|
mobox.stopProgram( strLuaDEID, "容器'"..count_cntr_list[n].cntr_code.."'不在货位上")
|
return
|
end
|
nRet, loc = wms_wh.GetLocInfo( loc_code )
|
if ( nRet ~= 0 ) then return 1, '获取货位信息失败! '..loc_code end
|
|
|
local cp_count_container = m3.AllocObject(strLuaDEID,"CP_Count_Container")
|
cp_count_container.method = 2
|
cp_count_container.station = station
|
cp_count_container.loc_code = loc_code
|
cp_count_container.wh_code = loc.wh_code
|
cp_count_container.area_code = loc.area_code
|
|
cp_count_container.count_no = count_order.count_no
|
cp_count_container.cntr_code = count_cntr_list[n].cntr_code
|
cp_count_container.first_cc_no = count_cntr_list[n].first_cc_no
|
nRet, cp_count_container = m3.CreateDataObj( strLuaDEID, cp_count_container )
|
if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), cp_count_container ) end
|
table.insert( cp_count_container_list, cp_count_container )
|
|
-- 创建【盘点容器货品明细】Count_CG_Detail
|
for m = 1, #count_cntr_list[n].count_item_list do
|
count_cg_detail = m3.AllocObject(strLuaDEID,"Count_CG_Detail")
|
count_item = count_cntr_list[n].count_item_list[m]
|
|
count_cg_detail.cg_detail_id = count_item.cg_detail_id
|
count_cg_detail.cc_no = cp_count_container.cc_no
|
count_cg_detail.count_no = count_order.count_no
|
count_cg_detail.station = station
|
count_cg_detail.cntr_code = cp_count_container.cntr_code
|
count_cg_detail.cell_no = count_item.cell_no
|
count_cg_detail.serial_no = count_item.serial_no
|
count_cg_detail.item_code = count_item.item_code
|
count_cg_detail.item_name = count_item.item_name
|
count_cg_detail.batch_no = count_item.batch_no
|
count_cg_detail.item_spec = count_item.item_spec
|
count_cg_detail.item_state = count_item.item_state
|
count_cg_detail.end_user = count_item.end_user
|
count_cg_detail.owner = count_item.owner
|
count_cg_detail.supplier = count_item.supplier
|
|
count_cg_detail.erp_wh_code = count_item.erp_wh_code
|
count_cg_detail.ext_attr1 = count_item.ext_attr1
|
count_cg_detail.ext_attr2 = count_item.ext_attr2
|
count_cg_detail.ext_attr3 = count_item.ext_attr3
|
count_cg_detail.ext_attr4 = count_item.ext_attr4
|
count_cg_detail.ext_attr5 = count_item.ext_attr5
|
|
count_cg_detail.qty = count_item.qty
|
count_cg_detail.uom = count_item.uom
|
|
nRet, count_cg_detail = m3.CreateDataObj( strLuaDEID, count_cg_detail )
|
if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "创建【Count_CG_Detail】失败!"..count_cg_detail) end
|
|
-- 设置【盘点差异】表记录的状态=2/复盘
|
local strUpdateSql = "N_B_STATE = 2"
|
strCondition = "S_ID = '"..count_item.id.."'"
|
nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Count_Diff", strCondition, strUpdateSql )
|
if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "更新【盘点差异表】信息失败!"..strRetInfo ) end
|
end
|
end
|
|
-- 盘点容器生成作业
|
local add_wfp
|
for n = 1, #cp_count_container_list do
|
-- 增加一个后台进程进行入库单完工回报
|
add_wfp = {
|
wfp_type = 1, -- 触发数据对象事件(指定数据对象标识)
|
cls = "CP_Count_Container",
|
obj_id = cp_count_container_list[n].id,
|
obj_name = "Container No '"..cp_count_container_list[n].cntr_code.."'-->Create stocktaking outbound operation",
|
trigger_event = "CreateStocktakingOutOperation"
|
}
|
|
nRet, strRetInfo = m3.AddSysWFP( strLuaDEID, add_wfp )
|
if ( nRet ~= 0 ) then
|
wms.wms_AbortCntrLockTrans( count_order.count_no )
|
lua.Error( strLuaDEID, debug.getinfo(1), "AddSysWFP失败!"..strRetInfo )
|
end
|
-- step6: 给容器加盘点锁 4 -- 盘点锁
|
nRet, strRetInfo = wms.wms_LockCntr( cp_count_container_list[n].cntr_code, 4, count_order.count_no )
|
if ( nRet ~= 0 ) then
|
wms.wms_AbortCntrLockTrans( count_order.count_no )
|
lua.Error( strLuaDEID, debug.getinfo(1), "给容器'"..cp_count_container_list[n].cntr_code.."'加盘点锁失败!")
|
end
|
end
|
wms.wms_CommitCntrLockTrans( count_order.count_no )
|
|
|
local action
|
if ( nCount == 1 ) then
|
action = {
|
{
|
action_type = "refresh_cur_row",
|
value = ""
|
}
|
}
|
else
|
action = {
|
{
|
action_type = "refresh",
|
value = ""
|
}
|
}
|
end
|
nRet, strRetInfo = mobox.setAction(strLuaDEID, lua.table2str(action))
|
if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "setAction错误: "..strRetInfo) end
|
|
end
|