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
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
ÿþ--ß~¡‹;`“^X[
local function QueryAllQty(strLuaDEID, item_code)
    local strFromTabInfo = "TN_Loc_Container a LEFT JOIN TN_CG_Detail b ON a.S_CNTR_CODE = b.S_CNTR_CODE"
    -- ågâ‹&{TagöN„v͑ϑ;`ŒT
    local strAttrInfo = " SUM(b.F_QTY) "
    -- ågâ‹agöN ir™exøv T
    local Condition = "b.S_ITEM_CODE = '" .. item_code .. "'"
    local strOrderBy = "a.T_CREATE DESC"
    local nRet, inside_info = mobox.queryMultiTable(strLuaDEID, strAttrInfo, strFromTabInfo, 1, Condition, strOrderBy)
    if (nRet ~= 0) then return 1, "queryMultiTable 1Y%!" .. inside_info end
    inside_info = json.decode(inside_info)
    local all_qty
    if (inside_info[1][1] ~= nil and inside_info[1][1] ~= '') then
        all_qty = tonumber(inside_info[1][1])
    else
        all_qty = tonumber(0)
    end
    -- lua.Debug(strLuaDEID, debug.getinfo(1), 'all_qty', all_qty)
    return 0, all_qty
end
 
--ß~¡‹d–†Nö€™e0¢”NKNY„vïS(u“^X[
local function QueryUsablQty(strLuaDEID, item_code)
    local strFromTabInfo = "TN_Loc_Container a LEFT JOIN TN_CG_Detail b ON a.S_CNTR_CODE = b.S_CNTR_CODE"
    strFromTabInfo = strFromTabInfo .. " LEFT JOIN TN_Location c ON a.S_LOC_CODE = c.S_CODE"
    strFromTabInfo = strFromTabInfo .. " LEFT JOIN TN_Container d ON a.S_CNTR_CODE = d.S_CODE"
    -- ågâ‹&{TagöN„v͑ϑ;`ŒT
    local strAttrInfo = " SUM(b.F_QTY) "
    -- ågâ‹agöN ir™exøv T,'MO•ŒT¹[hV•:N0
    local Condition = "b.S_ITEM_CODE = '" .. item_code .. "' AND c.N_LOCK_STATE = 0 AND d.N_LOCK_STATE = 0 "
    local strOrderBy = "a.T_CREATE DESC"
    local nRet, inside_info = mobox.queryMultiTable(strLuaDEID, strAttrInfo, strFromTabInfo, 1, Condition, strOrderBy)
    if (nRet ~= 0) then return 1, "queryMultiTable 1Y%!" .. inside_info end
    inside_info = json.decode(inside_info)
    local all_qty
    if (inside_info[1][1] ~= nil and inside_info[1][1] ~= '') then
        all_qty = tonumber(inside_info[1][1])
    else
        all_qty = tonumber(0)
    end
    -- lua.Debug(strLuaDEID, debug.getinfo(1), 'all_qty', all_qty)
    return 0, all_qty
end
 
--ß~¡‹708÷]S„vïS(u“^X[
local function QueryBwUsablQty(strLuaDEID, item_code)
    -- ·ƒÖSù[”^“^:S ir™e„v;`͑ϑ
    local strFromTabInfo = "TN_Loc_Container a LEFT JOIN TN_CG_Detail b ON a.S_CNTR_CODE = b.S_CNTR_CODE"
    strFromTabInfo = strFromTabInfo .. " LEFT JOIN TN_Location c ON a.S_LOC_CODE = c.S_CODE"
    strFromTabInfo = strFromTabInfo .. " LEFT JOIN TN_Container d ON a.S_CNTR_CODE = d.S_CODE"
    -- ågâ‹&{TagöN„v͑ϑ;`ŒT
    local strAttrInfo = " SUM(b.F_QTY) "
    -- ågâ‹agöN ir™exøv T,'MO•ŒT¹[hV•:N0,÷]S:N708,ÝO)nöeô•‰>72\öe
    local Condition = "b.S_ITEM_CODE = '" ..
    item_code .. "' AND c.N_LOCK_STATE = 0 AND d.N_LOCK_STATE = 0 AND (SYSDATE - a.T_CREATE)*24 > 72"
    Condition = Condition .. " AND c.N_ROADWAY IN (7,8)"
    local strOrderBy = "a.T_CREATE DESC"
    local nRet, inside_info = mobox.queryMultiTable(strLuaDEID, strAttrInfo, strFromTabInfo, 1, Condition, strOrderBy)
    if (nRet ~= 0) then return 1, "queryMultiTable 1Y%!" .. inside_info end
    inside_info = json.decode(inside_info)
    local all_qty
    if (inside_info[1][1] ~= nil and inside_info[1][1] ~= '') then
        all_qty = tonumber(inside_info[1][1])
    else
        all_qty = tonumber(0)
    end
    -- lua.Debug(strLuaDEID, debug.getinfo(1), 'all_qty', all_qty)
    return 0, all_qty
end
 
--ß~¡‹1~6÷]S„vïS(u“^X[
local function QueryFbwUsablQty(strLuaDEID, item_code)
    -- ·ƒÖSù[”^“^:S ir™e„v;`͑ϑ
    local strFromTabInfo = "TN_Loc_Container a LEFT JOIN TN_CG_Detail b ON a.S_CNTR_CODE = b.S_CNTR_CODE"
    strFromTabInfo = strFromTabInfo .. " LEFT JOIN TN_Location c ON a.S_LOC_CODE = c.S_CODE"
    strFromTabInfo = strFromTabInfo .. " LEFT JOIN TN_Container d ON a.S_CNTR_CODE = d.S_CODE"
    -- ågâ‹&{TagöN„v͑ϑ;`ŒT
    local strAttrInfo = " SUM(b.F_QTY) "
    -- ågâ‹agöN ir™exøv T,'MO•ŒT¹[hV•:N0,÷]S:N708,ÝO)nöeô•‰>72\öe
    local Condition = "b.S_ITEM_CODE = '" .. item_code .. "' AND c.N_LOCK_STATE = 0 AND d.N_LOCK_STATE = 0"
    Condition = Condition .. " AND c.N_ROADWAY IN (1,2,3,4,5,6)"
    local strOrderBy = "a.T_CREATE DESC"
    local nRet, inside_info = mobox.queryMultiTable(strLuaDEID, strAttrInfo, strFromTabInfo, 1, Condition, strOrderBy)
    if (nRet ~= 0) then return 1, "queryMultiTable 1Y%!" .. inside_info end
    inside_info = json.decode(inside_info)
    local all_qty
    if (inside_info[1][1] ~= nil and inside_info[1][1] ~= '') then
        all_qty = tonumber(inside_info[1][1])
    else
        all_qty = tonumber(0)
    end
    -- lua.Debug(strLuaDEID, debug.getinfo(1), 'all_qty', all_qty)
    return 0, all_qty
end
 
--ß~¡‹iRYO'MO
local function QueryLocQty(strLuaDEID, item_type)
    local area = ''
    local str = ''
    if (item_type == '³xў') then
        area = 'TH'
    elseif (item_type == '…Pg') then
        area = 'FC'
    elseif (item_type == '^P[^') then
        area = 'LZB'
    elseif (item_type == '¢”N') then
        area = 'LK'
        str = ' AND N_LAYER IN (5,6,7,8) AND N_ROADWAY IN (1,2,3,4,5,6)'
    end
    if (item_type == '³xў' and item_type == '…Pg' and item_type == '^P[^' and item_type == '¢”N') then
        -- ·ƒÖSù[”^“^:S ir™e„v;`peϑ
        local strCondition = "N_CURRENT_NUM = 0 AND S_AREA_CODE = '" .. area .. "'"
        if(str ~= '') then strCondition = strCondition..str end
        local nRet, inside_info = mobox.getDataObjCount(strLuaDEID, "Location", strCondition)
        if (nRet ~= 0) then return 1, inside_info end
 
        local all_qty
        if (inside_info ~= nil and inside_info ~= '') then
            all_qty = tonumber(inside_info)
        else
            all_qty = tonumber(0)
        end
        -- lua.Debug(strLuaDEID, debug.getinfo(1), 'all_qty', all_qty)
        return 0, all_qty
    else
        -- ·ƒÖSù[”^“^:S ir™e„v;`peϑ
        local strCondition = "N_CURRENT_NUM = 0 AND S_AREA_CODE = 'LK' AND N_ROADWAY IN (1,2,3,4,5,6) AND N_LAYER NOT IN (5,6,7,8)"
        local nRet, inside_info = mobox.getDataObjCount(strLuaDEID, "Location", strCondition)
        if (nRet ~= 0) then return 1, inside_info end
 
        local all_qty
        all_qty = inside_info
        strCondition = "N_CURRENT_NUM = 0 AND S_AREA_CODE = 'LK' AND N_ROADWAY IN (7,8)"
        nRet, inside_info = mobox.getDataObjCount(strLuaDEID, "Location", strCondition)
        if (nRet ~= 0) then return 1, inside_info end
 
        all_qty = tonumber(all_qty) + tonumber(inside_info)
        if (all_qty ~= nil and all_qty ~= '') then
            all_qty = tonumber(inside_info)
        else
            all_qty = tonumber(0)
        end
        -- lua.Debug(strLuaDEID, debug.getinfo(1), 'all_qty', all_qty)
        return 0, all_qty
    end
end
 
 
--[[
    x: GT-17-13
     Tðy: >f:yMR
    \O€ÿLZH
    eQãSýQpeÿBeforeGridShow
 
    ŸRý€ô‹f:
        ß~¡‹ù[”^x„v;`“^X[0ïS(u“^X[0•š[“^X[
    ôf9e°‹U_:
 
--]]
json  = require("json")
mobox = require("OILua_JavelinExt")
m3 = require( "oi_base_mobox" )
 
function BeforeGridShow(strLuaDEID)
    local nRet, strRetInfo
    local arobjs, strAttrs
    local nCount
 
    nRet, arobjs = m3.GetSysDataJson(strLuaDEID)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), arobjs) end
    nCount = #arobjs
    if (nCount == 0) then return end
    lua.Debug(strLuaDEID, debug.getinfo(1), '@b    g“^X[¥bhˆ„váOo`', arobjs)
    
    -- (uŽNX[¨Pò]Ï~úQ°sǏ„vb.S_ITEM_CODE<P
    local uniqueCodes = {}
    local newArr = {}
    -- M†SŸSËYpeÄ~
    for _, item in ipairs(arobjs) do
        local found = false
        for _, attr in ipairs(item.attrs) do
            if attr.attr == "b.S_ITEM_CODE" then
                local code = attr.value
                if not uniqueCodes[code] then
                    uniqueCodes[code] = true
                    table.insert(newArr, item)
                    found = true
                    break
                end
            end
        end
        if not found then
            table.insert(newArr, item)
        end
    end
    lua.Debug(strLuaDEID, debug.getinfo(1), 'newArr', newArr)
    lua.Debug(strLuaDEID, debug.getinfo(1), '#newArr', #newArr)
    nCount = #newArr
    
    
 
    local obj, attrs, id, strDataJson
    local strRowCtrl = ''
 
    strDataJson = '['
    for n = 1, nCount do
        obj = newArr[n]
        attrs = obj.attrs
        id = obj.id
 
        strAttrs = ''
        local item_code = ''
        local item_type = ''
        local strItem
        -- ·ƒÖS ir™ex ŒT “^:Sx
        for nIndex = 1, #attrs do
            local strAttr = attrs[nIndex].attr
            local strValue = attrs[nIndex].value
            if (strAttr == 'b.S_TYPE') then
                strItem = '{"attr":"' .. strAttr .. '","value":"' .. strValue .. '"},'
                item_type = strValue
                strAttrs = strAttrs .. strItem
            elseif (strAttr == 'a.S_ITEM_CODE') then
                item_code = strValue
                strItem = '{"attr":"' .. strAttr .. '","value":"' .. strValue .. '"},'
                strAttrs = strAttrs .. strItem
            elseif (strAttr == 'a.S_ITEM_NAME') then
                strItem = '{"attr":"' .. strAttr .. '","value":"' .. strValue .. '"},'
                strAttrs = strAttrs .. strItem
            elseif (strAttr == 'a.S_SUB_TYPE') then
                strItem = '{"attr":"' .. strAttr .. '","value":"' .. strValue .. '"},'
                strAttrs = strAttrs .. strItem
            elseif (strAttr == 'a.S_MINOR_TYPE') then
                strItem = '{"attr":"' .. strAttr .. '","value":"' .. strValue .. '"},'
                strAttrs = strAttrs .. strItem
            end
        end
        -- ß~¡‹;`“^X[
        local all_qty
        nRet, all_qty = QueryAllQty(strLuaDEID, item_code)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), all_qty) end
        strItem = '{"attr":"CUSTOM_ALL","value":"' .. all_qty .. '"},'
        strAttrs = strAttrs .. strItem
 
        -- ß~¡‹ïS(u“^X[
        local usable_qty
        if (tonumber(all_qty) == 0) then
            strItem = '{"attr":"CUSTOM_USABLE","value":"0"},'
        else
            if (item_type == ')Y6qö€' or item_type == 'ceňö€' or item_type == 'ö€™e') then
                --ö€™e‰HQß~¡‹708÷]S„vïS(u“^X[(Wß~¡‹1~6÷]S„vïS(u“^X[
                local bw_usable_qty
                nRet, bw_usable_qty = QueryBwUsablQty(strLuaDEID, item_code)
                if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), bw_usable_qty) end
 
                local fbw_usable_qty
                nRet, fbw_usable_qty = QueryFbwUsablQty(strLuaDEID, item_code)
                if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), fbw_usable_qty) end
                -- ÝO)n+^—ÝO)n„vïS(upeϑ
                usable_qty = tonumber(bw_usable_qty) + tonumber(fbw_usable_qty)
            elseif (item_type == '¢”N') then
                -- ß~¡‹1~6÷]S„vïS(u“^X[
                nRet, usable_qty = QueryFbwUsablQty(strLuaDEID, item_code)
                if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), usable_qty) end
            else
                nRet, usable_qty = QueryUsablQty(strLuaDEID, item_code)
                if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), usable_qty) end
            end
            strItem = '{"attr":"CUSTOM_USABLE","value":"' .. usable_qty .. '"},'
        end
        strAttrs = strAttrs .. strItem
 
        -- ß~¡‹
N•“^X[
        local lock_qty
        if (tonumber(all_qty) == 0) then
            strItem = '{"attr":"CUSTOM_LOCK","value":"0"},'
        else
            lock_qty = tonumber(all_qty) - tonumber(usable_qty)
            strItem = '{"attr":"CUSTOM_LOCK","value":"' .. lock_qty .. '"},'
        end
        strAttrs = strAttrs .. strItem
 
        -- ß~¡‹iRYO'ir
        local loc_qty
        nRet, loc_qty = QueryLocQty(strLuaDEID, item_type)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), loc_qty) end
        strItem = '{"attr":"CUSTOM_LOC","value":"' .. loc_qty .. '"},'
        strAttrs = strAttrs .. strItem
 
        strAttrs = lua.trim_laster_char(strAttrs)
        local strRow = '{"id":"' .. id .. '"' .. strRowCtrl .. ',"attrs":[' .. strAttrs .. ']},'
        strDataJson = strDataJson .. strRow
    end
    -- ÖSˆmgTN*N,÷S
    strDataJson = lua.trim_laster_char(strDataJson)
    strDataJson = strDataJson .. ']'
    lua.Debug(strLuaDEID, debug.getinfo(1), 'strDataJson', strDataJson)
 
    local strAction = '[{"action_type":"reset_data_attr","value":' .. strDataJson .. '}]'
    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