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
--[[
   编码: JX-65-13
   名称: 
   作者:
   日期:2025-04-14
 
   函数: Query
   功能:
 
   更改记录:
 
--]]
 
json  = require ("json")
mobox = require ("OILua_JavelinExt")
m3 = require ("oi_base_mobox")
 
 
function Query(strLuaDEID)
    local nRet, strRetInfo
    local parameter = {}
    local attrs
    local no_codes = {} 
 
    -- 获取运行时参数
    local runtime_parameter
    nRet, runtime_parameter = m3.GetRuntimeParam(strLuaDEID)
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "GetRuntimeParam失败! " .. runtime_parameter)
    end
    local strSQL = lua.Get_StrAttrValue(runtime_parameter.base_condition)
    lua.Debug( strLuaDEID, debug.getinfo(1), "runtime_parameter", runtime_parameter )
    -- 获取查询面板里的输入属性
    nRet, attrs = m3.GetSysInputParameter(strLuaDEID)
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "m3.GetSysInputParameter 失败! " .. attrs)
    end
    parameter = m3.KeyValueAttrsToObjAttr(attrs)
    lua.Debug( strLuaDEID, debug.getinfo(1), "parameter", parameter )
    local cntr_code = lua.Get_StrAttrValue(parameter.S_CNTR_CODE)           -- 料箱编码
    local bs_no = lua.Get_StrAttrValue(parameter.S_BS_NO)                   -- 来源业务单号
    local item_code = lua.Get_StrAttrValue(parameter.S_ITEM_CODE)           -- 物料编码
    local wave_no = lua.Get_StrAttrValue(parameter.S_WAVE_NO)                    -- 出库波次号
    local createtTime = lua.Get_StrAttrValue(parameter.T_CREATE)           -- 创建时间
    local endTime = lua.Get_StrAttrValue(parameter.T_END_TIME)                    -- 结束时间
 
 
    -- 构建查询条件
    if (bs_no ~= '') then
        if (strSQL ~= '') then strSQL = strSQL .. " AND " end
        strSQL = strSQL .. "S_BS_NO = '" .. bs_no .. "'"
    end
    if (cntr_code ~= '') then
        if (strSQL ~= '') then strSQL = strSQL .. " AND " end
        strSQL = strSQL .. "S_CNTR_CODE = '" .. cntr_code .. "'"
    end
    if (item_code ~= '') then
        if (strSQL ~= '') then strSQL = strSQL .. " AND " end
        strSQL = strSQL .. "S_ITEM_CODE = '" .. item_code .. "'"
    end
 
    
    if (wave_no ~= '') then
        if (strSQL ~= '') then strSQL = strSQL .. " AND " end
        local strCondition = "S_WAVE_NO = '" .. wave_no .. "'"
        nRet, inboubd_code = m3.QueryDataObject(strLuaDEID, "Outbound_Order", strCondition)
            if (nRet ~= 0) then 
                lua.Stop(strLuaDEID, "查询入库单表失败: " .. inboubd_code) 
                return
            end
                local no_code = {} 
                for n = 1, #inboubd_code do
                    local inbound_detail = inboubd_code[n]
                    local inbound_attrs = m3.KeyValueAttrsToObjAttr(inbound_detail.attrs)
            
                    -- 获取物料编码
                    local no_obj = inbound_attrs.S_NO
                    if (no_obj == nil or no_obj == '') then
                        lua.Error(strLuaDEID, debug.getinfo(1), "物料编码为空!")
                    end
                    table.insert(no_codes, no_obj)
                    
                end
            
        strSQL = strSQL .. "S_BS_NO IN ("
        for i, code in ipairs(no_codes) do
            if i > 1 then
                strSQL = strSQL .. ", "
            end
            strSQL = strSQL .. "'" .. code .. "'"
        end
        strSQL = strSQL .. ")"
    end
    
    
 
    if (createtTime ~= '') then
        if (strSQL ~= '') then
            strSQL = strSQL .. " AND "
        end
        strSQL = strSQL .. "T_CREATE >= '" .. createtTime .. "'" 
    end
    
    if (endTime ~= '') then
        if (strSQL ~= '') then
            strSQL = strSQL .. " AND "
        end
        strSQL = strSQL .. "T_CREATE < '" .. endTime .. "'" 
    end
    
 
    -- 设置查询条件
    local action = {}
    action[1] = {
        action_type = "set_query_condition",
        value = {
            condition = strSQL,
            order = "a.T_CREATE DESC"
        }
    }
    nRet, strRetInfo = mobox.setAction(strLuaDEID, lua.table2str(action))
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "setAction失败! " .. strRetInfo .. ' action = ' .. strAction)
    end
end