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
ÿþ--[[
   x: 
    Tðy: 
   \O€ÿ
   åegÿ2024-11-18
 
   ýQpeÿ AfterItemCodeInput
   ŸRý€:
 
   ôf9e°‹U_:
 
--]]
 
json  = require ("json")
mobox = require ("OILua_JavelinExt")
m3 = require( "oi_base_mobox" )
 
function AfterItemCodeInput( strLuaDEID )
    local nRet, strRetInfo
    -- ·ƒÖSÂSpe
    nRet, strRetInfo = mobox.getCurEditDataObjAttr(strLuaDEID,"item_code")
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖSS_MR‘^\'`1Y%! " .. strRetInfo) end
    lua.Debug(strLuaDEID, debug.getinfo(1), 'strRetInfo', strRetInfo)
    local obj_attrs = json.decode(strRetInfo)
    local item_code = obj_attrs[1].value
    
    -- ·ƒÖSir™eù[”^„vir™eÏcð¾‹nۏLub—,\å‹ir™e„vyb!k÷S¾‹nbN*NRhˆ0RLub—
    -- ·ƒÖS0¹[hV'ÁTfÆ~0áOo`
    local cg_detail
    local strCondition = "S_ITEM_CODE = '" .. item_code .. "' AND S_CNTR_CODE IN(SELECT S_CNTR_CODE FROM TN_Loc_Container)"
    nRet, cg_detail = m3.QueryDataObject(strLuaDEID, "CG_Detail", strCondition)
    if (nRet ~= 0 or cg_detail == '') then lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖS0¹[hV'ÁTfÆ~01Y%ÿ" .. cg_detail) end
    lua.Debug( strLuaDEID, debug.getinfo(1), 'cg_detail', cg_detail )
    
    local attr
    local item_name = ''
    local batch_list = {}
    local batch_no = ''
    for i = 1, #cg_detail do
        attr = m3.KeyValueAttrsToObjAttr(cg_detail[i].attrs)
        item_name = attr.S_ITEM_NAME
        batch_list[i] = attr.S_BATCH_NO
    end
 
    lua.Debug( strLuaDEID, debug.getinfo(1), 'item_name', item_name )
    lua.Debug( strLuaDEID, debug.getinfo(1), 'batch_list', batch_list)
    
    -- yb!k÷S»S͑
    local result = {}
    local unique = {}
    for _, item in ipairs(batch_list) do
        if not unique[item] then
            table.insert(result, item)
            unique[item] = true
        end
    end
    
    for _, num in ipairs(result) do
        batch_no = batch_no .. '"' .. num .. '",'
    end
    -- ÖSˆmgTN*N,÷S
    batch_no = lua.trim_laster_char(batch_no)   
    lua.Debug( strLuaDEID, debug.getinfo(1), 'batch_no', batch_no)
    
    -- ¾‹nMRïzU\:yaction
    -- ¾‹n—zãS-N„váOo`
    local setAttr = '[{"attr":"item_name","value":"' .. item_name .. '"}]'
    local action1 = {}
    action1.action_type = "set_dlg_attr"
    action1.value = json.decode(setAttr)
    local action2 = {}
    setAttr = '[{"attr":"batch_no","value":"","choice_list":['..batch_no..']}]'
    action2.action_type = "set_dlg_attr"
    action2.value = json.decode(setAttr)
 
    nRet, strRetInfo = mobox.setAction(strLuaDEID, '[' .. lua.table2str(action1) .. ',' ..lua.table2str(action2).. ']')
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "setAction1Y%! " .. strRetInfo) end
end