1
Jianw
9 天以前 70f29da38121b9a467841253e3268feb5df02902
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
160
161
--[[
   编码: AMS-21-31
   名称: 
   作者:
   日期:2025-05-16
 
   函数: ItemCodeChange
   功能:
 
   更改记录:
 
--]]
 
json  = require ("json")
mobox = require ("OILua_JavelinExt")
m3 = require ("oi_base_mobox")
 
function ItemCodeChange( strLuaDEID )
        local nRet,attrs
    local strRetInfo
    local detail_records
    -- 获取表头界面中的输入条码
    nRet, attrs = m3.GetSysInputParameter(strLuaDEID)
    if (nRet ~= 0) then
        mobox.setInfo(strLuaDEID,  "获取当前输入面板里的属性失败! " .. attrs)
        return
    end
    
    local input_attr = m3.KeyValueAttrsToObjAttr(attrs)
    local io_no = input_attr.S_IO_NO            --入库单号
    local item_code = input_attr.S_ITEM_CODE    --物料编码
    
    
    local Condition = "S_ITEM_CODE = '" .. item_code .. "'"
    nRet, strRetInfo = m3.GetDataObjByCondition(strLuaDEID, "SKU", Condition)
    if nRet ~= 0 then
        mobox.setInfo(strLuaDEID,  "查询 SKU 表失败: " .. strRetInfo)
        return
    end
    local material_name = strRetInfo.item_name              -- 物料名称
    local area = strRetInfo.udf01 
    
    local Condition = "S_NO = '" .. io_no .. "'"
    nRet, strRetInfo = m3.GetDataObjByCondition(strLuaDEID, "Inbound_Order", Condition)
    if nRet ~= 0 then
        mobox.setInfo(strLuaDEID,  "查询 Inbound_Order 表失败: " .. strRetInfo)
        return
    end
    local inbound_area = strRetInfo.area_code 
    
    if(area ~= inbound_area) then
        mobox.setInfo(strLuaDEID, "物料所在库区和入库单对应库区不一致!!" ..item_code)
        return
    end
 
       -- 正在码盘和已码盘页面
    local obj
    nRet, obj = m3.GetSysDataJson(strLuaDEID) 
    if (nRet ~= 0) then
        mobox.setInfo(strLuaDEID, "无法获取数据包! " .. obj)
        return
    end
    lua.Debug(strLuaDEID, debug.getinfo(1), "obj", obj)
    
    for i = 1, #obj do
        local page = obj[i]
        if (page.page_name == "物料信息") then
            page_completed = page
        end
    end
    
    local item_list_completed = page_completed.item_list
    -- 检查已码盘中是否已有料格号与物料编码匹配
    local current_cell_no , current_item_code
    for n = 1, #item_list_completed do
        local attrs_obj = m3.KeyValueAttrsToObjAttr(item_list_completed[n].attrs)
        current_item_code = attrs_obj.S_ITEM_CODE   -- 商品编码
            if (current_item_code == item_code) then
                mobox.setInfo(strLuaDEID, "已存在物料编码 " .. current_item_code .. ",不可操作")
                return
            end
    end
    
    local strCondition = " S_IO_NO = '" ..io_no.. "' and S_ITEM_CODE = '" .. item_code .. "'"
    nRet, strRetInfo = mobox.existThisData( strLuaDEID, "ERP_Inbound_Detail", strCondition )
    if ( nRet ~= 0 ) then 
        mobox.setInfo(strLuaDEID,  "调用existThisData方法失败! " .. attrs)
        return
    end
    if ( strRetInfo ~= "yes" ) then 
        mobox.setInfo(strLuaDEID,  "该入库单没有这条数据! " .. item_code)
        return
    end  
    
    nRet, detail_records = m3.QueryDataObject(strLuaDEID, "ERP_Inbound_Detail", strCondition)
    if (nRet ~= 0) then
        mobox.setInfo(strLuaDEID, debug.getinfo(1), "查询容器失败!"..data_objs)
        return
    end
    
    local total_qty = 0
    local acc_qty = 0
    for i = 1, #detail_records do
        local detail_obj = m3.KeyValueAttrsToObjAttr(detail_records[i].attrs)
        total_qty = total_qty + detail_obj.F_QTY    -- 入库数量
        acc_qty = acc_qty + detail_obj.F_ACC_I_QTY  -- 累计入库数量
    end
    local qty = total_qty - acc_qty
    
    if qty <= 0 then
        mobox.setInfo(strLuaDEID, "物料["..item_code.."]当前可入库数量为0!")
        return
    end
    
    local row_data = {{
    id = lua.guid(),
    attrs = {{
        attr = "S_ITEM_NAME",
        value = material_name
    }, {
        attr = "S_ITEM_CODE",
        value = item_code
    }, {
        attr = "F_QTY",
        value = total_qty
    }, {
        attr = "F_ACC_I_QTY",
        value = acc_qty
    }, {
        attr = "Qty",
        value = qty
    }
        
    }
    }}
    
    local action = {}
    
    -- 设置正在码盘页面数据
    action[1] = {
        action_type = "insert_subtable_page_row",
        value = {
            page_name = "物料信息",
            row = row_data
        }
    }
    action[2] = {
            action_type = "set_dlg_attr",
            value = {
                    {attr = "S_ITEM_CODE", value = ""}
                    }
            }
    
    lua.Debug(strLuaDEID, debug.getinfo(1), "lua.table2str(action)", lua.table2str(action))
    nRet, strRetInfo = mobox.setAction(strLuaDEID, lua.table2str(action))
    if (nRet ~= 0) then
        mobox.setInfo(strLuaDEID, "setAction失败! " .. strRetInfo)
        return
    end
 
end