1
Jianw
10 天以前 f6f5e6b632d6649386a380558d84003f3de7ec6c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
--[[
   编码: 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