lzh
2025-06-24 13c4a636539584ab977fddacfae884b3ec250aee
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
ÿþ--[[
   x: JX-65-14
    Tðy: 
   \O€ÿ
   åegÿ2025-04-14
 
   ýQpeÿ Query
   ŸRý€:
 
   ôf9e°‹U_:
 
--]]
 
json  = require ("json")
mobox = require ("OILua_JavelinExt")
m3 = require ("oi_base_mobox")
 
function Query(strLuaDEID)
    local nRet, strRetInfo
    local parameter = {}
    local attrs
 
    -- ·ƒÖSЏLˆöeÂSpe
    local runtime_parameter
    nRet, runtime_parameter = m3.GetRuntimeParam(strLuaDEID)
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "GetRuntimeParam1Y%! " .. runtime_parameter)
    end
    local strSQL = lua.Get_StrAttrValue(runtime_parameter.base_condition)
    lua.Debug( strLuaDEID, debug.getinfo(1), "runtime_parameter", runtime_parameter )
    -- ·ƒÖSågâ‹b—g̑„v“eQ^\'`
    nRet, attrs = m3.GetSysInputParameter(strLuaDEID)
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "m3.GetSysInputParameter 1Y%! " .. attrs)
    end
    parameter = m3.KeyValueAttrsToObjAttr(attrs)
    lua.Debug( strLuaDEID, debug.getinfo(1), "parameter", parameter )
    local cntr_code = lua.Get_StrAttrValue(parameter.S_CNTR_CODE)           -- ™e±{x
    local bs_no = lua.Get_StrAttrValue(parameter.S_BS_NO)                   -- egnN¡RUS÷S
    local item_code = lua.Get_StrAttrValue(parameter.S_ITEM_CODE)           -- ir™ex
    local action = lua.Get_StrAttrValue(parameter.S_ACTION)                 -- ¨R\O{|‹W Tðy
    local no = lua.Get_StrAttrValue(parameter.S_NO)                         -- eQ“^US÷S
    local createtTime = lua.Get_StrAttrValue(parameter.T_CREATE)           -- Rú^öeô•
    local endTime = lua.Get_StrAttrValue(parameter.T_END_TIME)                    -- Ó~_göeô•
 
    -- „gú^ågâ‹agöN
    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 (no ~= '') then
        if (strSQL ~= '') then strSQL = strSQL .. " AND " end
        local strCondition = "S_NO = '" .. no .. "'"
        nRet, inboubd_code = m3.GetDataObjByCondition(strLuaDEID, "Inbound_Order", strCondition)
            if (nRet ~= 0) then 
                lua.Stop(strLuaDEID, "ågâ‹eQ“^UShˆ1Y%: " .. inboubd_code) 
                return
            end
        local wave_no = inboubd_code.wave_no
        strSQL = strSQL .. "S_BS_NO = '" .. wave_no .. "'"
    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
 
    -- ubÞV¥b¶r`ågâ‹
    local sub_condition = ''
    if (action == 'eQ“^') then
        sub_condition = "S_ACTION = + "
    elseif (action == 'úQ“^') then
        sub_condition = "S_ACTION = - "
    end
    if (sub_condition ~= '') then
        if (strSQL ~= '') then strSQL = strSQL .. " AND " end
        strSQL = strSQL .. sub_condition
    end
 
    lua.Debug( strLuaDEID, debug.getinfo(1), "strSQL", strSQL )
 
    -- ¾‹någâ‹agöN
    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), "setAction1Y%! " .. strRetInfo .. ' action = ' .. strAction)
    end
end