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
ÿþ--[[
   x: GT-19-12
    Tðy: 
   \O€ÿ
   åegÿ2025-02-28
 
   ýQpeÿ BeforeGridShow
   ŸRý€:
 
   ôf9e°‹U_:
 
--]]
 
json  = require ("json")
mobox = require ("OILua_JavelinExt")
m3 = require( "oi_base_mobox" )
 
function BeforeGridShow( strLuaDEID )
    nRet, data = m3.GetSysDataJson( strLuaDEID )
    if ( nRet ~=0 ) then lua.Error( strLuaDEID, debug.getinfo(1), arobjs ) end  
    lua.Debug(strLuaDEID, debug.getinfo(1), 'data', data)
    
    -- (uŽNX[¨PRÄ~Ó~œg„vhˆ
    local grouped = {}
 
    -- M†Spenc
    for _, item in ipairs(data) do
        local item_code
        local batch_no
        local qty
        local area_code
        -- M†S attrs peÄ~ ÿ·ƒÖS S_ITEM_CODE0S_BATCH_NO ŒT N_QTY „v<P
        for _, attr in ipairs(item.attrs) do
            if attr.attr == "a.S_ITEM_CODE" then
                item_code = attr.value
            elseif attr.attr == "a.S_BATCH_NO" then
                batch_no = attr.value
            elseif attr.attr == "a.F_QTY" then
                qty = tonumber(attr.value)
            elseif attr.attr == "c.S_AREA_CODE" then
                area_code = attr.value
            end
        end
        -- ubÄ~T.•
        local key = item_code .. "_" .. batch_no .. "_" .. area_code
        if not grouped[key] then
            -- ‚Yœgå‹Ä~T.•؏*gX[(W ÿRËYSRÄ~áOo`
            grouped[key] = {
                id = item.id,
                item_code = item_code,
                batch_no = batch_no,
                area_code = area_code,
                total_qty = qty
            }
        else
            -- ‚Yœgå‹Ä~T.•ò]X[(W ÿ/} R N_QTY „v<P
            grouped[key].total_qty = grouped[key].total_qty + qty
        end
    end
    lua.Debug(strLuaDEID, debug.getinfo(1), 'grouped', grouped)
    
    -- „gú^gÈ~Ó~œgpeÄ~
    local result = {}
    for _, group in pairs(grouped) do
        lua.Debug(strLuaDEID, debug.getinfo(1), 'group', group)
        local new_item = {
            id = group.id,
            attrs = {
                {attr = "a.S_ITEM_CODE", value = group.item_code},
                {attr = "c.S_AREA_CODE", value = group.area_code},
                {attr = "a.S_BATCH_NO", value = group.batch_no},
                {attr = "a.F_QTY", value = tostring(group.total_qty)}
            }
        }
        table.insert(result, new_item)
    end
    lua.Debug(strLuaDEID, debug.getinfo(1), 'result', result)
    
    local strAction = '[{"action_type":"reset_data_attr","value":' .. lua.table2str(result) .. '}]'
    nRet, strRetInfo = mobox.setAction(strLuaDEID, strAction)
    if ( nRet ~= 0 ) then 
        lua.Warning( strLuaDEID, debug.getinfo(1), strAction )
        lua.Error( strLuaDEID, debug.getinfo(1), "setAction•ï‹: "..strRetInfo) 
    end
    
end