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
ÿþ--[[
    ŸRý€ÿ¡‹—{'Y{|(W708÷]S„v“^X[Ôk‹O
    big_type 'Y{|
    qty —‰ûy“^„v“^X[ÿ^—Å_kX    ÿ
--]]
local function GT_InventoryRatio(strLuaDEID, big_type, qty)
    -- ·ƒÖS708÷]S;`“^X[͑ϑ
    local strCondition = " S_CNTR_CODE IN (SELECT S_CNTR_CODE FROM TN_Loc_Container "
    strCondition = strCondition .. "WHERE S_LOC_CODE IN (SELECT S_CODE FROM TN_Location WHERE N_ROADWAY IN (7,8)))"
    local nRet, sumQty = mobox.getDataObjAttrSum(strLuaDEID, "CG_Detail", strCondition, "F_QTY")
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "" .. sumQty)
    end
    sumQty = json.decode(sumQty)
    local allQty = tonumber(sumQty[1]) -- 708÷]S;`͑ϑ
 
    -- ·ƒÖSØpö€ô~¤b Nå‹'Y{|ô~¤b„v@b    gir™ex(W708÷]SÌ‘b—„v;`͑ϑ
    strCondition = "S_BIG_TYPE = '" .. big_type .. "'"
    local glue_dryings
    nRet, glue_dryings = m3.QueryDataObject(strLuaDEID, "GT_Glue_Drying", strCondition)
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "QueryDataObject1Y%!" .. glue_dryings)
    end
 
    local big_qty = 0 -- (ueg/}¡‹'Y{| N@b    gir™ex„v;`͑ϑ
    for j = 1, #glue_dryings do
        local glue_drying
        nRet, glue_drying = m3.ObjAttrStrToLuaObj("GT_Glue_Drying", lua.table2str(glue_dryings[j].attrs))
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), glue_drying) end
        local item_code = glue_drying.item_code -- ir™ex
 
        -- ·ƒÖSå‹ir™ex(W708÷]S„v;`͑ϑ
        strCondition = "S_ITEM_CODE = '" ..
            item_code .. "' AND S_CNTR_CODE IN (SELECT S_CNTR_CODE FROM TN_Loc_Container "
        strCondition = strCondition .. "WHERE S_LOC_CODE IN (SELECT S_CODE FROM TN_Location WHERE N_ROADWAY IN (7,8)))"
        nRet, sumQty = mobox.getDataObjAttrSum(strLuaDEID, "CG_Detail", strCondition, "F_QTY")
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "" .. sumQty)
        end
        sumQty = json.decode(sumQty)
        big_qty = big_qty + tonumber(sumQty[1]) -- å‹'Y{| Nir™ex(W708÷]S;`͑ϑ
    end
    -- ‚Yœgûy“^͑ϑ N:NzzR¡‹—{ۏ;`peϑ-N
    if (tonumber(qty) ~= nil and tonumber(qty) ~= 0) then
        big_qty = big_qty + tonumber(qty)
    end
    local num = big_qty / allQty * 100 -- 'Y{|;`͑ϑ(W708÷]S;`“^X[-N„v`SÔk
    return 0, num
end
--[[
    ŸRý€ÿ·ƒÖS'Y{| N„vir™ex,Çir™ex·ƒÖS1~6÷]S„v“^X[,NXbNXbàS R͑ϑv^¡‹—{/f&Tán³
          Ôk‹Ov^\¹[hV÷Sûm R0R4NöepeÄ~,ôv0R>=ô~¤b„vÔk‹OR_ËYûy“^,YñmMOOHQ·ƒÖS0
--]]
local function GT_GetCntrCodeList(strLuaDEID, big_type, ratio)
    local cntr_codes = {} -- (uegX[¨P¹[hV÷S
    local num = 0         -- (ueg°‹U_4Nöe¹[hV„v;`͑ϑ,¡‹—{Ôk‹Oöe—‰(u0R,ÇÙ*Neg$R­e—‰Y\XbMbý€án³Øpö€ô~¤b„vÔk‹O
    -- ·ƒÖSØpö€ô~¤b Nå‹'Y{|ô~¤b„v@b    gir™ex
    local strCondition = "S_BIG_TYPE = '" .. big_type .. "'"
    local nRet, glue_dryings = m3.QueryDataObject(strLuaDEID, "GT_Glue_Drying", strCondition)
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "QueryDataObject1Y%!" .. glue_dryings)
    end
 
    for i = 1, #glue_dryings do
        local glue_drying
        nRet, glue_drying = m3.ObjAttrStrToLuaObj("GT_Glue_Drying", lua.table2str(glue_dryings[i].attrs))
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), glue_drying) end
        local item_code = glue_drying.item_code -- ir™ex
 
        -- 9hncir™exåg~b“^X[ ÿNXbNXbàS R͑ϑ ÿôv0R¾0R“^X[ô~¤b„vÔk‹O ÿv^\XbØvX[¨P0R 4NöeRhˆcntr_codes-N
        -- ·ƒÖS1~6÷]Så‹ir™e(WËz“^-NYñmMO„v¹[hV÷SŒT͑ϑ
        local condition = "S_ITEM_CODE = '" .. item_code .. "' and S_CNTR_CODE IN "
        condition = condition .. "(SELECT S_CNTR_CODE FROM TN_Loc_Container WHERE S_LOC_CODE IN ("
        condition = condition .. "SELECT S_CODE FROM TN_Location WHERE N_ROADWAY IN(1,2,3,4,5,6) AND N_POS = 1))"
        local cg_detail
        nRet, cg_detail = m3.QueryDataObject(strLuaDEID, "CG_Detail", condition)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "QueryDataObject1Y%!" .. cg_detail) end
        if (cg_detail == '') then goto coroutine end
 
        for j = 1, #cg_detail do
            local cg_detail_body
            nRet, cg_detail_body = m3.ObjAttrStrToLuaObj("CG_Detail", lua.table2str(cg_detail[j].attrs))
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), cg_detail_body) end
            local cntr_code = cg_detail_body.cntr_code -- ¹[hV÷S
            local qty = cg_detail_body.qty             -- Í‘Ï‘
            local index = tonumber(#cntr_codes) + 1
            cntr_codes[index] = cntr_code
            num = num + qty
 
            local data
            nRet, data = GT_InventoryRatio(strLuaDEID, big_type, num)
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), data) end
            lua.Debug(strLuaDEID, debug.getinfo(1), ''Y{|(W;`“^X[-N„vÔk‹O:', data)
            if (tonumber(data) >= ratio) then
                return 0, cntr_codes
            end
        end
        ::coroutine::
 
        -- ·ƒÖS1~6÷]Så‹ir™e(WËz“^-N…QñmMO„v¹[hV÷SŒT͑ϑ
        condition = "S_ITEM_CODE = '" .. item_code .. "' and S_CNTR_CODE IN "
        condition = condition .. "(SELECT S_CNTR_CODE FROM TN_Loc_Container WHERE S_LOC_CODE IN ("
        condition = condition .. "SELECT S_CODE FROM TN_Location WHERE N_ROADWAY IN(1,2,3,4,5,6) AND N_POS = 2))"
        nRet,cg_detail = m3.QueryDataObject(strLuaDEID, "CG_Detail", condition)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "QueryDataObject1Y%!" .. cg_detail) end
        lua.Debug(strLuaDEID, debug.getinfo(1), 'cg_detail:', cg_detail)
        if (cg_detail == '') then goto a end
 
        for j = 1, #cg_detail do
            local cg_detail_body
            nRet, cg_detail_body = m3.ObjAttrStrToLuaObj("CG_Detail", lua.table2str(cg_detail[j].attrs))
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), cg_detail_body) end
            local cntr_code = cg_detail_body.cntr_code -- ¹[hV÷S
            local qty = cg_detail_body.qty             -- Í‘Ï‘
            local index = tonumber(#cntr_codes) + 1
            cntr_codes[index] = cntr_code
            num = num + qty
 
            local data
            nRet, data = GT_InventoryRatio(strLuaDEID, big_type, num)
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), data) end
            lua.Debug(strLuaDEID, debug.getinfo(1), ''Y{|(W;`“^X[-N„vÔk‹O:', data)
            if (tonumber(data) >= ratio) then
                return 0, cntr_codes
            end
        end
        ::a::
    end
end
--[[
   x: GT-23-17
    Tðy: $R­e/f&Tûy“^
   \O€ÿLZH
   åegÿ2024-10-29
 
   ýQpeÿ IsMoveLocation
   ŸRý€:  ·ƒÖS708÷]S;`“^X[͑ϑ ÿR+R·ƒÖS'Y{| N@b    gir™e„v;`͑ϑ ÿ'Y{|;`͑ϑ/“^X[;`͑ϑ * 100 ÿ‚YœgNOŽNô~¤b„v'Y{|Ôk‹ORۏLˆûy“^
 
 
   ôf9e°‹U_:
 
--]]
 
json  = require("json")
mobox = require("OILua_JavelinExt")
m3 = require( "oi_base_mobox" )
wms_cntr = require( "wms_container" )
wms_wh = require( "wms_wh" )
require("GT_InAndOutboundPolicies")
function IsMoveLocation(strLuaDEID)
    -- ·ƒÖS@b    g'Y{|åNÊS;`͑ϑ
    local strCondition = "S_BIG_TYPE = S_BIG_TYPE"
    local nRet, glue_configs = m3.QueryDataObject(strLuaDEID, "GT_Glue_Config", strCondition)
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "QueryDataObject1Y%!" .. glue_configs)
    end
 
    for i = 1, #glue_configs do
        local glue_config
        nRet, glue_config = m3.ObjAttrStrToLuaObj("GT_Glue_Config", lua.table2str(glue_configs[i].attrs))
        local big_type = glue_config.big_type     -- 'Y{|
        local ratio = tonumber(glue_config.ratio) -- 'Y{|Ôk‹O
 
        local data
        nRet, data = GT_InventoryRatio(strLuaDEID, big_type)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), data) end
        lua.Debug(strLuaDEID, debug.getinfo(1), ''Y{|(W;`“^X[-N„vÔk‹O:', data)
 
        local cntr_codes = {} -- (uegX[>eûy“^„v¹[hV÷S
        -- ‚Yœg'Y{|(W;`“^X[-N„vÔk‹O < Øpö€M‘n„vÔk‹O Ræ‰ÑSûy“^
        if (tonumber(data) < ratio) then
            nRet, cntr_codes = GT_GetCntrCodeList(strLuaDEID, big_type, ratio)
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), data) end
            lua.Debug(strLuaDEID, debug.getinfo(1), 'ûy“^xƖT:', cntr_codes)
 
            for j = 1, #cntr_codes do
                local cntr_code = cntr_codes[j] -- ûy“^„v¹[hV
                -- ·ƒÖSÈ~¹p„vÂSpeüb¥c
                local cg_detail_list, cg_detail
                nRet, cg_detail_list = wms_cntr.Get_Container_Goods(strLuaDEID, cntr_code)
                nRet, cg_detail = m3.ObjAttrStrToLuaObj("CG_Detail", lua.table2str(cg_detail_list[1].attrs))
                if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), cg_detail) end
                -- local batch_no = cg_detail.batch_no
                -- local roadway = "7,8"
                -- local parameter = {
                --     batch_no = batch_no,
                --     roadway = roadway
                -- }
                -- ·ƒÖS¹[hV„vMOn\O:Nw¹p
                local start_loc_code = wms_wh.GetLocCodeByCNTR(strLuaDEID, cntr_code)
                local start_loc
                nRet, start_loc = wms_wh.Location_GetInfo(strLuaDEID, start_loc_code)
                if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), start_loc) end
 
                -- Rú^ûy“^US
                local st_detail         = m3.AllocObject(strLuaDEID, "ST_Detail")
                -- w¹páOo`
                st_detail.wh_code       = start_loc.wh_code
                st_detail.area_code     = start_loc.area_code
                st_detail.end_wh_code   = start_loc.wh_code
                st_detail.end_area_code = start_loc.area_code
                st_detail.loc_code      = start_loc.code
                st_detail.roadway       = "7,8"
 
                st_detail.item_code     = cg_detail.item_code
                st_detail.item_name     = cg_detail.item_name
                st_detail.cntr_code     = cntr_code
                -- ûy“^US÷S
                local strCode           = ''
                local strHeader         = 'ST' .. os.date("%y%m%d") .. '-'
                nRet, strCode           = mobox.getSerialNumber("ûy“^", strHeader, 5)
                st_detail.st_no         = strCode
                nRet, st_detail         = m3.CreateDataObj(strLuaDEID, st_detail)
                lua.Debug(strLuaDEID, debug.getinfo(1), "Rú^ûy“^USMRÂSpe", st_detail)
                if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), st_detail) end
            end
        end
    end
end