1
Jianw
10 天以前 88e26a2a960dbbc148332772448b79b9877102d8
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
--[[
   编码: AMS-101-13
   名称:
   作者:
   日期:2025-05-15
 
   函数: AfterSure
   功能:
 
   更改记录:
 
--]]
 
json  = require("json")
mobox = require("OILua_JavelinExt")
m3    = require("oi_base_mobox")
wms_wh = require("wms_wh")
function AfterSure(strLuaDEID)
    local nRet, strRetInfo, page_info
 
    -- 先获取表头扫描数据
    nRet, strRetInfo = m3.GetSysInputParameter(strLuaDEID)
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "获取扫描数据失败!" .. strRetInfo)
    end
    local cntr_code = m3.KeyValueAttrsToObjAttr(strRetInfo).S_CNTR_CODE -- 容器编码
    local loc_code = m3.KeyValueAttrsToObjAttr(strRetInfo).S_LOC_CODE   -- 码盘货位
 
    -- 判断料箱编码是否输入
    if (cntr_code == nil or cntr_code == "") then
        mobox.setInfo(strLuaDEID, "请输入料箱编码!")
        return
    end
 
    -- 判断货位编码是否输入
    if (loc_code == nil or loc_code == "") then
        mobox.setInfo(strLuaDEID, "请输入货位编码!")
        return
    end
 
    -- 判断货位是否存在
    local loc_info
    local strCondition = "S_CODE = '"..loc_code.."'"
    nRet, loc_info = m3.GetDataObjByCondition(strLuaDEID, "Location", strCondition)
    if(nRet == 1)then mobox.setInfo(strLuaDEID,"货位编码不存在!") return
    elseif(nRet > 1)then lua.Error(strLuaDEID, debug.getinfo(1),loc_info)
    end
 
    -- 判断容器是否存在安全库存
    -- 存在判断货位是否相同,不同则更新货位/不存在则新建货位容器绑定
    -- 相关更新表【货位容器绑定】
    strCondition = "S_CNTR_CODE = '" .. cntr_code .. "'"
    local loc_Container
    nRet, loc_Container = m3.GetDataObjByCondition(strLuaDEID, "Loc_Container", strCondition)
    if (nRet == 0) then
        -- 容器货位解绑
        nRet, strRetInfo = wms_wh.Loc_Container_Unbinding(strLuaDEID, loc_Container.loc_code, cntr_code, "绑定解绑方法-系统",
            "系统解绑")
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '货位容器解绑失败!' .. strRetInfo) end
        -- 货位容器绑定
        nRet, strRetInfo = wms_wh.Loc_Container_Binding(strLuaDEID, loc_code, cntr_code, "绑定解绑方法-系统", "系统绑定")
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '货位容器绑定失败!' .. strRetInfo) end
        -- 更新【安全库存量表】料箱对应的货位
        strCondition = "S_CNTR_CODE = '" .. cntr_code .. "'"
        local set_sql = "S_LOC_CODE = '"..loc_code.."'"
        nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "SAF_Inventory", strCondition,set_sql)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "修改【POU安全库存量表】信息失败!" .. strRetInfo) end
    elseif (nRet == 1) then
        -- 不存在则货位容器绑定
        nRet, strRetInfo = wms_wh.Loc_Container_Binding(strLuaDEID, loc_code, cntr_code, "绑定解绑方法-系统", "系统绑定")
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '货位容器绑定失败!' .. strRetInfo) end
    elseif (nRet > 1) then
        lua.Error(strLuaDEID, debug.getinfo(1), loc_Container)
    end
 
    -- 获取正在码盘页的数据
    nRet, page_info = m3.GetSysDataJson(strLuaDEID)
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), page_info)
    end
    local item_list_now = page_info[1].item_list
    for i = 1, #item_list_now do
        local item_code = m3.KeyValueAttrsToObjAttr(item_list_now[i].attrs).S_ITEM_CODE
        local item_name = m3.KeyValueAttrsToObjAttr(item_list_now[i].attrs).S_ITEM_NAME
        local safety_qty = tonumber(m3.KeyValueAttrsToObjAttr(item_list_now[i].attrs).F_SAFETY_QTY)
 
        -- 根据 容器+物料号 更新【容器货品明细】表,更新条数为0则创建容器货品明细
        strCondition = "S_CNTR_CODE = '" .. cntr_code .. "' AND S_ITEM_CODE = '"..item_code.."'"
        local set_sql = "S_ITEM_CODE = '"..item_code.."',S_ITEM_NAME = '"..item_name.."'"
        nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "CG_Detail", strCondition,set_sql)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "修改【容器货品明细】信息失败!" .. strRetInfo) end
        lua.Debug(strLuaDEID, debug.getinfo(1), '修改条数:', strRetInfo)
        if (tonumber(strRetInfo) == 0) then
            -- 创建【容器货品明细】
            local cg_detail = m3.AllocObject(strLuaDEID, "CG_Detail")
            cg_detail.cntr_code = cntr_code
            cg_detail.item_code = item_code
            cg_detail.item_name = item_name
            cg_detail.qty = 1
            cg_detail.wh_code = loc_info.wh_code
            cg_detail.area_code = loc_info.area_code
            cg_detail.loc_code = loc_info.code
            nRet, cg_detail = m3.CreateDataObj(strLuaDEID, cg_detail)
            lua.Debug(strLuaDEID, debug.getinfo(1), 'cg_detail', cg_detail)
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'mobox 创建【容器货品明细】对象失败!' .. cg_detail) end
        end
 
        -- 根据 容器+物料号 更新【安全库存量表】表,更新条数为0则创建
        strCondition = "S_CNTR_CODE = '" .. cntr_code .. "' AND S_ITEM_CODE = '"..item_code.."'"
        set_sql = "S_ITEM_CODE = '"..item_code.."',S_ITEM_NAME = '"..item_name.."',F_SAFETY_QTY =".. safety_qty
        nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "SAF_Inventory", strCondition,set_sql)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "修改【安全库存量表】信息失败!" .. strRetInfo) end
        lua.Debug(strLuaDEID, debug.getinfo(1), '修改条数:', strRetInfo)
        if (tonumber(strRetInfo) == 0) then
            -- 创建【安全库存量表】
            local saf_inventory = m3.AllocObject(strLuaDEID, "SAF_Inventory")
            saf_inventory.cntr_code = cntr_code
            saf_inventory.item_code = item_code
            saf_inventory.item_name = item_name
            saf_inventory.safety_qty = safety_qty
            saf_inventory.loc_code = loc_code
            nRet, saf_inventory = m3.CreateDataObj(strLuaDEID, saf_inventory)
            lua.Debug(strLuaDEID, debug.getinfo(1), 'saf_inventory', saf_inventory)
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'mobox 创建【安全库存量表】对象失败!' .. saf_inventory) end
        end
    end
 
        -- 组织界面数据
    local action_array = {}
 
    action_array[1] = {
        action_type = "set_dlg_attr",
        value = {
            { attr = "S_CNTR_CODE", value = "" },
            { attr = "S_LOC_CODE", value = "" }
        }
    }
 
    action_array[2] = {
        action_type = "clear_subpage_rows",
        value = {
            page_name = "正在码盘"
        }
    }
 
    action_array[3] = {
        action_type = "clear_subpage_rows",
        value = {
            page_name = "已码盘"
        }
    }
 
    nRet, strRetInfo = mobox.setAction(strLuaDEID, lua.table2str(action_array))
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "setAction失败! " .. strRetInfo)
    end
 
    mobox.setInfo(strLuaDEID, "初始化成功!")
end