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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
--[[   
    编码: JX-19-11
    名称: 码盘入库
    作者: kun
    日期:2025-2-14
    函数: CntrChange
    功能: 
        -- 码盘入库,扫料箱编码
        -- 查询料箱信息
        -- 用料箱号查询对应的料格信息,并插入下拉列表以供选择
        -- 用料箱号查询移库单,查询对应移库单的状态值,开立状态取编码赋值给码盘单号,无开立状态则不赋值
        -- 光标跳转物料编码框,方便操作人员操作
        -- 判断该料箱是否有巨沃入库的开立状态的任务池,有的话则报错处理
--]]
 
wms_cntr = require("wms_container")
wms_wh = require("wms_wh")
 
function CntrChange(strLuaDEID)
 
    local nRet, strRetInfo
    local cntr_detail_array
    local jx_task
 
    nRet, attrs = m3.GetSysInputParameter(strLuaDEID)
    if (nRet ~= 0) then
        mobox.setInfo(strLuaDEID, "获取当前输入面板里的属性失败! " .. attrs)
        return
    end
    lua.Debug(strLuaDEID, debug.getinfo(1), "attrs", attrs)
    
    local input_attr = m3.KeyValueAttrsToObjAttr(attrs)
 
    local cntr_code = input_attr.S_CNTR_CODE    -- 料箱编码
    local no = input_attr.S_EXT_ATTR1           -- 码盘单号
    local cell = input_attr.S_CELL_NO           -- 料格号
 
    if (cntr_code == nil or cntr_code == '') then
        mobox.setInfo(strLuaDEID, "容器编码不能为空!")
        return
    end
    if (no ~= '') then
        mobox.setInfo(strLuaDEID, "已有码盘单号!")
        return
    end
 
    -- 获取容器信息
    local cntr_obj
    nRet, cntr_obj = wms_cntr.GetInfo(strLuaDEID, cntr_code)
    if (nRet ~= 0 or cntr_obj == '') then
        mobox.setInfo(strLuaDEID, "编码 = '" .. cntr_code .. "'的拣料箱不存在或获取失败!")
        return
    end
    if (cntr_obj.source ~= '巨沃') then
        mobox.setInfo(strLuaDEID, "编码 = '" .. cntr_code .. "'的拣料箱不是巨沃的料箱!")
        return
    end
    if (cntr_obj.empty_full ~= 0) then
        mobox.setInfo(strLuaDEID, "编码 = '" .. cntr_code .. "'的拣料箱是有货的料箱!")
        return
    end
    if (cntr_obj.position ~= '') then
        mobox.setInfo(strLuaDEID, "编码 = '" .. cntr_code .. "'的拣料箱在库里!")
        return
    end
    
    if (cntr_obj.lock_state ~= 0) then
        mobox.setInfo(strLuaDEID, "编码 = '" .. cntr_code .. "'的拣料箱有锁!")
        return
    end
    
    local strCondition = "S_CNTR_CODE = '"..cntr_code.."' AND (N_B_STATE = 0 OR N_B_STATE = 1) AND S_SOURCESYS = '巨沃入库'"
    nRet, jx_task = m3.QueryDataObject(strLuaDEID, "JX_Task", strCondition)
 
    if (nRet ~= 0) then
        mobox.setInfo(strLuaDEID, "查询失败: " .. jx_task)
        return
    end
    if (jx_task ~= "") then
        mobox.setInfo(strLuaDEID, "该料箱有空料箱入库作业不可进行码盘!!!")
        return
    end
    
    -- 查询料格明细
    nRet, cntr_detail_array = m3.QueryDataObject(strLuaDEID, "Container_Cell", "S_CNTR_CODE = '" .. cntr_code .. "'")
    if (nRet ~= 0) then
        mobox.setInfo(strLuaDEID,"获取【料格明细】信息失败!" .. cntr_detail_array)
        return
    end
    
    -- 将查询的料格打包
    local merge_table = {}
    for n = 1, #cntr_detail_array do
        local cntr_detail = m3.KeyValueAttrsToObjAttr(cntr_detail_array[n].attrs)
        
        table.insert(merge_table, cntr_detail.S_CELL_NO)
    end
    
    -- 查询 JX_Transfer_Order 获取码盘单号
    local strCondition = "S_CNTR_CODE = '" .. cntr_code .. "' AND N_B_STATE = 0"
    local data_objs
    nRet, data_objs = m3.QueryDataObject(strLuaDEID, "JX_Transfer_Order", strCondition)
    if (nRet ~= 0) then
        mobox.setInfo(strLuaDEID, "查询码盘单失败!" .. data_objs)
        return
    end
    if (#data_objs > 1) then
        mobox.setInfo(strLuaDEID, "编码 = '" .. cntr_code .. "'的料箱有多个开立状态的码盘单请清理!!!")
        return
    end
    local action_array = {}
    -- 如果有开立状态的码盘单,取码盘单号以及明细显示在已码盘
    if (data_objs ~= '') then
        local date_list = m3.KeyValueAttrsToObjAttr(data_objs[1].attrs)
        local no = date_list.S_NO           --码盘单号
 
        -- 查询明细数据
        local detail_strCondition = "S_TO_NO = '" .. no .. "'"
        local strOrder = "S_CELL_NO"                --以料格进行排序
        local detail_data_objs
        nRet, detail_data_objs = m3.QueryDataObject(strLuaDEID, "JX_TO_Detail", detail_strCondition, strOrder )
        if (nRet ~= 0) then
            mobox.setInfo(strLuaDEID,"查询明细数据失败! " .. detail_data_objs)
            return
        end
        action_array[1] = {
            action_type = "set_subtable_page_content",
            value = {
                page_name = "已码盘",
                content = detail_data_objs,
                clear = true,
                clear_confirm = false,
                checkbox = false
            }
        }
 
        -- 赋值码盘单号和料格值
        action_array[2] = {
            action_type = "set_dlg_attr",
            value = {
                {attr = "S_EXT_ATTR1", value = no },
                {attr = "S_CELL_NO", value = merge_table[1], choice_list = merge_table },
                { attr = "S_CNTR_CODE", value = cntr_code, enable = false  }
                }
        }
        -- 将光标放在物料编码框
        action_array[3] = {
        action_type = "set_dlg_current_edit_attr",
        value = "S_ITEM_CODE"
                }
        nRet, strRetInfo = mobox.setAction(strLuaDEID, lua.table2str(action_array))
        if (nRet ~= 0) then
            mobox.setInfo(strLuaDEID, "setAction失败! " .. strRetInfo)
            return
        end
    else
        -- 没有匹配码盘单,只赋值 S_CELL_NO
        action_array[1] = {
            action_type = "set_dlg_attr",
            value = {
                {attr = "S_CELL_NO", value = merge_table[1], choice_list = merge_table },
                { attr = "S_CNTR_CODE", value = cntr_code, enable = false  }
            }
        }
        -- 将光标放在物料编码框
        action_array[2] = {
                action_type = "set_dlg_current_edit_attr",
                value = "S_ITEM_CODE"
                        }
 
        nRet, strRetInfo = mobox.setAction(strLuaDEID, lua.table2str(action_array))
        if (nRet ~= 0) then
            mobox.setInfo(strLuaDEID, "setAction失败! " .. strRetInfo)
            return
        end
    end
end