--[[
|
编码: JX-01-19
|
名称: 系统转换
|
作者:KUN
|
日期:2025-02-08
|
|
函数: Convert
|
功能:
|
|
更改记录:
|
|
--]]
|
json = require ("json")
|
mobox = require ("OILua_JavelinExt")
|
m3 = require("oi_base_mobox")
|
lua = require ("oi_base_func")
|
|
function Convert(strLuaDEID)
|
local nRet, strRetInfo
|
|
nRet, strRetInfo = mobox.getCurEditDataObjAttr(strLuaDEID, "SOURCESYS", "Number")
|
lua.Debug(strLuaDEID, debug.getinfo(1), "strRetInfo", strRetInfo)
|
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "获取当前编辑属性失败! " .. strRetInfo)
|
end
|
|
local obj_attrs = json.decode(strRetInfo)
|
local source_sys = lua.Get_StrAttrValue(obj_attrs[1].value)
|
local num = lua.Get_NumAttrValue(obj_attrs[2].value)
|
|
local strCondition
|
if (source_sys == "巨星转巨沃") then
|
strCondition = "S_SOURCE = '巨星' AND N_EMPTY_FULL = 0 AND N_LOCK_STATE = 0"
|
else
|
strCondition = "S_SOURCE = '巨沃' AND N_MAX_CELL_NUM = 1 AND N_EMPTY_FULL = 0 AND N_LOCK_STATE = 0"
|
end
|
|
nRet, strRetInfo = mobox.getDataObjCount(strLuaDEID, "Container", strCondition)
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "getDataObjCount 失败! " .. strRetInfo)
|
end
|
local nCount = tonumber(strRetInfo)
|
|
lua.Debug(strLuaDEID, debug.getinfo(1), "nCount", nCount)
|
|
if (num > nCount) then
|
mobox.setInfo(strLuaDEID, "填写数量不能大于库存数量! 库存数量为:" .. nCount)
|
return
|
end
|
|
-- 更新容器并处理料格
|
local strUpdateSql
|
local cntr_code,id,attrs
|
local updateCondition
|
local cntr_cell
|
local deleteCondition
|
|
for n = 1, num do
|
-- 获取容器号值,作为唯一标识
|
nRet, id, strRetInfo = mobox.getDataObjAttrByKeyAttr(strLuaDEID, "Container", strCondition, "S_CODE")
|
if (nRet ~= 0 or strRetInfo == "" or strRetInfo == nil) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "获取记录失败!")
|
end
|
|
attrs = json.decode(strRetInfo)
|
cntr_code = attrs[1].value
|
|
lua.Debug(strLuaDEID, debug.getinfo(1), "cntr_code", cntr_code)
|
|
updateCondition = "S_CODE = '" .. cntr_code .. "'"
|
|
if (source_sys == "巨星转巨沃") then
|
-- 更新容器信息
|
strUpdateSql = "S_SOURCE = '巨沃', N_MAX_CELL_NUM = 1, S_SPEC = 'A', N_TYPE = 3"
|
nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "Container", updateCondition, strUpdateSql)
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "更新容器表失败! " .. strRetInfo)
|
end
|
|
cntr_cell = m3.AllocObject(strLuaDEID, "Container_Cell")
|
cntr_cell.S_CNTR_CODE = cntr_code
|
cntr_cell.cell_no = "A-1"
|
cntr_cell.long = 60
|
cntr_cell.middle = 40
|
cntr_cell.short = 30
|
cntr_cell.volume = cntr_cell.long * cntr_cell.middle * cntr_cell.short
|
cntr_cell.cell_type = 'A'
|
|
nRet, cntr_cell = m3.CreateDataObj(strLuaDEID, cntr_cell)
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "创建【容器箱格】失败! " .. cntr_cell)
|
end
|
else
|
strUpdateSql = "S_SOURCE = '巨星', N_MAX_CELL_NUM = 0, S_SPEC = '', N_TYPE = 2"
|
nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "Container", updateCondition, strUpdateSql)
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "更新容器表失败! " .. strRetInfo)
|
end
|
|
deleteCondition = "S_CNTR_CODE = '" .. cntr_code .. "'"
|
nRet, strRetInfo = mobox.deleteDataObject(strLuaDEID, "Container_Cell", deleteCondition)
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "删除【容器箱格】失败! " .. strRetInfo)
|
end
|
end
|
end
|
|
mobox.setInfo(strLuaDEID, "成功更新 " .. num .. " 条记录")
|
end
|
|
|
|
|