--[[
|
编码: AMS-102-03
|
名称:
|
作者:
|
日期:2025-05-29
|
|
函数: ClickOutbound
|
功能:
|
|
更改记录:
|
|
--]]
|
|
json = require ("json")
|
mobox = require ("OILua_JavelinExt")
|
m3 = require ("oi_base_mobox")
|
|
function ClickOutbound( strLuaDEID )
|
local nRet,strRetInfo
|
local data_json
|
nRet,data_json = m3.GetSysDataJson(strLuaDEID)
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), data_json)
|
end
|
lua.Debug(strLuaDEID, debug.getinfo(1), 'data_json',data_json)
|
|
local function contains(table, value)
|
for _, v in ipairs(table) do
|
if v == value then
|
return true
|
end
|
end
|
return false
|
end
|
|
local uniqueCntrCodes = {} -- 存储唯一的料箱编号
|
|
--检查插入料箱代码到uniqueCntrCodes中
|
local Data_attrs = {}
|
for _, v in ipairs(data_json) do
|
local attrs = v.attrs
|
local Data_attrs1 = m3.KeyValueAttrsToObjAttr(attrs)
|
lua.Debug(strLuaDEID,debug.getinfo(1),'Data_attrs1',Data_attrs1)
|
|
-- 值存在不插入
|
if( not contains(uniqueCntrCodes,Data_attrs1.S_CNTR_CODE)) then
|
table.insert(uniqueCntrCodes,Data_attrs1.S_CNTR_CODE)
|
end
|
|
table.insert(Data_attrs, Data_attrs1)
|
end
|
lua.Debug(strLuaDEID,debug.getinfo(1),'Data_attrs',Data_attrs)
|
|
-- 收集 所有不同的 S_CNTR_CODE
|
lua.Debug(strLuaDEID, debug.getinfo(1), 'uniqueCntrCodes',uniqueCntrCodes)
|
|
-- 统计数量
|
local nCount = #uniqueCntrCodes
|
lua.Debug(strLuaDEID,debug.getinfo(1),'nCount',nCount)
|
if(nCount == 0)then
|
return
|
elseif(nCount > 5)then
|
mobox.setInfo(strLuaDEID,"禁止选择超过五种料箱")
|
return
|
end
|
|
local area_groups = {}
|
for i,item in ipairs(Data_attrs) do
|
--获取库区编码
|
local area = item.S_AREA_CODE
|
if not area_groups[area] then
|
area_groups[area] = {} -- 确保 area_groups[area] 是表
|
end
|
table.insert(area_groups[area],item)
|
end
|
lua.Debug(strLuaDEID,debug.getinfo(1),'area_groups',area_groups)
|
|
|
--创建出库单(按area_code拆分)
|
for area_code,items in pairs(area_groups) do
|
|
--生成出库单号
|
local header = 'CK'..os.date("%y%m%d")..'-'
|
local nRet,order_no = mobox.getSerialNumber("出库单",header,4)
|
if(nRet ~= 0)then
|
mobox.setInfo(strLuaDEID,"申请出库单单号失败:"..order_no)
|
return
|
end
|
lua.Debug(strLuaDEID,debug.getinfo(1),'order_no',order_no)
|
|
for i,item in ipairs(Data_attrs) do
|
-- local cntr_code = item.S_CNTR_CODE
|
-- local item_code = item.S_ITEM_CODE
|
-- local strCondition = "S_CNTR_CODE = '" .. cntr_code .. "' AND S_ITEM_CODE = '" .. item_code .. "'"
|
local oo_no = item.S_OO_NO
|
local strCondition = "S_OO_NO = '"..oo_no.."'"
|
local strSetAttr = "S_NO = '" .. order_no .. "', N_B_STATE = '1' "
|
|
lua.Debug(strLuaDEID,debug.getinfo(1),'strCondition',strCondition)
|
lua.Debug(strLuaDEID,debug.getinfo(1),'strSetAttr',strSetAttr)
|
|
|
if( item.S_NO and item.S_NO ~= "") or item.N_B_STATE == "1" then
|
mobox.setInfo(strLuaDEID,"请勿重复创建出库单号!")
|
return
|
elseif( item.S_NO and item.S_NO == "") or item.N_B_STATE == "0" then
|
nRet,strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "Outbound_Request", strCondition, strSetAttr)
|
if(nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "更新数据失败: "..strRetInfo)
|
end
|
-- if(nRet == 0) then
|
-- mobox.setInfo(strLuaDEID,"出库单号创建成功!")
|
-- end
|
end
|
end
|
|
|
-- --库区编码和出库方向都来自POU
|
-- local order = m3.AllocObject(strLuaDEID, "Outbound_Order")
|
-- order.state = "发布" --单据状态
|
-- order.no = order_no --出库单号
|
-- order.bs_no = order_no --来源单号
|
-- order.box_qty = nCount --发货箱数量
|
-- order.area_code = area_code
|
|
-- for _,item in ipairs(items) do
|
-- local detail = m3.AllocObject(strLuaDEID, "Outbound_Detail")
|
-- detail.oo_no = order_no
|
-- detail.item_code = item.S_ITEM_CODE
|
-- detail.item_name = item.S_ITEM_NAME
|
-- detail.qty = item.F_QTY
|
|
|
-- local ret1, msg1 = m3.CreateDataObj(strLuaDEID, detail)
|
-- if ret1 ~= 0 then
|
-- lua.Stop(strLuaDEID, "创建出库单明细失败:" .. msg1)
|
-- return
|
-- end
|
|
-- end
|
|
-- local ret, msg = m3.CreateDataObj(strLuaDEID, order)
|
-- if ret ~= 0 then
|
-- lua.Stop(strLuaDEID, "创建出库单失败:" .. msg)
|
-- return
|
-- end
|
end
|
|
local action = {
|
{
|
action_type = "refresh",
|
value = ""
|
}
|
}
|
local nRetAction, strRetInfo8 = mobox.setAction(strLuaDEID, lua.table2str(action))
|
if nRetAction ~= 0 then
|
lua.Error(strLuaDEID, debug.getinfo(1), 'setAction错误: ' .. strRetInfo8)
|
end
|
mobox.setInfo(strLuaDEID,"出库单号创建成功!")
|
end
|