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
ÿþ-- “^X[ågâ‹
--[
-- 10·ƒÖS÷]S'MO;`pe
-- 20·ƒÖSán'MO;`pe
-- 30ÿán'MO;`pe / ÷]S;`pe    ÿ* 100 = án'MO~vRÔk
-- 40$R­eán'MO“^X[/f&T¾0R80%,¡l¾0RRԏÞVïSeQ“^÷]S
--]
local function StockInquiry(strLuaDEID)
    -- ·ƒÖS*g»QÓ~„v÷]S
    local strCondition = "N_LOCK_STATE = 0"
    local nRet, roadway = m3.QueryDataObject(strLuaDEID, "Roadway", strCondition)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'ågâ‹÷]SáOo`1Y%' .. roadway) end
    if (roadway == nil or roadway == '') then lua.Error(strLuaDEID, debug.getinfo(1), '¡l    gïSeQ“^„v÷]S!') end
 
    -- ·ƒÖSW[xQš[IN„vûy“^Ôk‹O
    local strRetInfo
    nRet, strRetInfo = mobox.getDictItemIInfo("GT_LK_RATIO")
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "getDictItemIInfo 1Y%!" .. strRetInfo) end
    strRetInfo = json.decode(strRetInfo)
    local item_ratio = tonumber(strRetInfo[1].name) -- W[xQš[IN„v÷]S‰[hQ“^X[Ôk‹O
 
    local str = ''
    for i = 1, #roadway do
        local attrs = roadway[i].attrs
        attrs = m3.KeyValueAttrsToObjAttr(attrs)
 
        -- ·ƒÖS÷]S'MO;`pe
        strCondition = "S_AREA_CODE = 'LK' AND N_ROADWAY = " .. attrs.N_ROADWAY
        nRet, strRetInfo = mobox.getDataObjCount(strLuaDEID, "Location", strCondition)
        if (nRet ~= 0) then return 2, "getDataObjCount 1Y%!" .. strRetInfo end
        local hw_count = tonumber(strRetInfo) -- cš[÷]S„v'MO;`pe
        lua.Debug(strLuaDEID, debug.getinfo(1), "hw_count", hw_count)
 
        strCondition = "S_AREA_CODE = 'LK' AND N_CURRENT_NUM <> 0 AND N_ROADWAY = " .. attrs.N_ROADWAY
        nRet, strRetInfo = mobox.getDataObjCount(strLuaDEID, "Location", strCondition)
        if (nRet ~= 0) then return 2, "getDataObjCount 1Y%!" .. strRetInfo end
        local mhw_count = tonumber(strRetInfo)         -- cš[÷]S„ván'MO;`pe
        lua.Debug(strLuaDEID, debug.getinfo(1), "mhw_count", mhw_count)
        local mhw_ratio = (mhw_count / hw_count) * 100 -- án'MO`SÔk
        if (mhw_ratio == nil) then
            return 1, "¡‹—{1Y%!÷]S:" .. attrs.N_ROADWAY ..
                " án'MOpeϑ:" .. mhw_count .. "'MO;`pe:" .. hw_count
        end
 
        if (mhw_ratio <= item_ratio) then
            str = str .. attrs.N_ROADWAY .. ","
        end
    end
    -- »Sd–gTN*N,
    str = lua.trim_laster_char(str)
    lua.Debug(strLuaDEID, debug.getinfo(1), "str", str)
    return 0, str
end
--[[
    x: GT-100-06
     Tðy: GT-WMS
    \O€ÿLZH
    eQãSýQpeÿ CreateROM
 
 
    ŸRý€ô‹f:
        GT-WMS NÑS™eáOo`Ù~ GZ-WMSû|ß~ ÿGZ-WMSû|ß~Rú^øvsQpencÑ~š[ŒTeQ“^\ON
 
        “eQpencÿ                                                                                        
        {    
        "delivery_no": "xxx",    6e'US÷S
        "delivery_row_no": "xxx",    6e'USLˆ÷S
        "serial_no": "xxx",    Am4l÷S
        "batch_no": "xxx",    yb!k÷S
        "qty": xxx,    Í‘Ï‘
        "item_code": "xxx",    ir™ex]NMOx
        "product_date": "xxx",    u§Nåeg
        "storage_loc": "xxx",    “^MO
        "wh_code": "xxx",    ÓN“^÷S
        "is_bonded": "xxx",    /f&TÝOz
        "cntr_code": "xxx",    XbØv÷S
        "start_loc_code": "xxx",    w¹p
        "item_state": "xxx",    (Ï‘¶r`
        "req_no": "xxx",    /UNhƋ
        "inbound_policy": 3,   ö€™eeQ“^V{eu
        "wheel_type_rot": "xxx",  n‹W/æ]óSËe
        "vendor":"xxx",  ›O”^FU
        "Item_code_9": "xxx",   ir™exmQMOx
        "remark1": "",  -- Yèl ‚f*g/T(u
        "remark2": "",  -- Yèl ‚f*g/T(u
        "remark3": "",  -- Yèl ‚f*g/T(u
        "remark4": ""   -- Yèl ‚f*g/T(u
        }    
 
 
        Yt;‘
        -- step1 ã‰g¥cãS O„v datajson ÂSpe
        -- step2 !hŒšÅ_ OW[µk/f&T:Nzz ÿ:NzzR¥b•
        -- step3 ¹[hV'ÁTÑ~š[
        -- step4 Rú^™eUS
        -- step5 w¹p N:NzzR 'MO¹[hVÑ~š[ v^Rú^AGV$Nµk,dЏûN¡R ÿNµkÎNw¹p0Rw¹p“^:SÑ~š[„v¥csšMO ÿNµkÎN¥csšMO0RËz“^
                                                                    
    ØSôf°‹U_:
    V1.1 LZH 20250417  R
N›O”^FUW[µk
--]]
m3    = require("oi_base_mobox")
json  = require("json")
mobox = require("OILua_JavelinExt")
require("WMS-Equipment")
wms_cntr = require("wms_container")
wms_wh = require("wms_wh")
require("GT-Base")
function CreateROM(strLuaDEID)
    local nRet, strRetInfo, in_date
    -- step1 ·ƒÖS¥cãSpenc
    nRet, in_date = m3.GetSysDataJson(strLuaDEID)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "WCStoreCallback àeÕl·ƒÖSpencS!" .. in_date) end
    lua.Debug(strLuaDEID, debug.getinfo(1), '™eeQ“^ NÑSÂSpe:', in_date)
 
    -- step2 $R­e/f&Tý    g<Pÿ¡l<P¥b•ԏÞV
    local delivery_no = in_date.delivery_no
    if (delivery_no == nil or delivery_no == '') then lua.Error(strLuaDEID, debug.getinfo(1), "6e'US÷S Ný€:Nzz!") end
    local delivery_row_no = in_date.delivery_row_no
    if (delivery_row_no == nil) then lua.Error(strLuaDEID, debug.getinfo(1), "6e'USLˆ÷S Ný€:Nzz!") end
    local serial_no = in_date.serial_no
    if (serial_no == nil or serial_no == '') then lua.Error(strLuaDEID, debug.getinfo(1), "Am4l÷S Ný€:Nzz!") end
    local batch_no = in_date.batch_no
    if (batch_no == nil or batch_no == '') then lua.Error(strLuaDEID, debug.getinfo(1), "yb!k÷S Ný€:Nzz!") end
    local qty = tonumber(in_date.qty)
    if (qty == nil) then lua.Error(strLuaDEID, debug.getinfo(1), "XbØv͑ϑ Ný€:Nzz!") end
    local item_code = in_date.item_code
    if (item_code == nil or item_code == '') then lua.Error(strLuaDEID, debug.getinfo(1), "ir™ex Ný€:Nzz!") end
    local product_date = in_date.product_date
    if (product_date == nil or product_date == '') then lua.Error(strLuaDEID, debug.getinfo(1), "u§Nåeg Ný€:Nzz!") end
    local wh_code = in_date.wh_code
    if (wh_code == nil or wh_code == '') then lua.Error(strLuaDEID, debug.getinfo(1), "ÓN“^÷S Ný€:Nzz!") end
    local is_bonded = in_date.is_bonded
    if (is_bonded == nil or is_bonded == '') then lua.Error(strLuaDEID, debug.getinfo(1), "/f&TÝOz Ný€:Nzz!") end
    local item_state = in_date.item_state
    if (item_state == nil or item_state == '') then lua.Error(strLuaDEID, debug.getinfo(1), "(Ï‘¶r` Ný€:Nzz!") end
    local wheel_type_rot = in_date.wheel_type_rot
    local storage_loc = in_date.storage_loc
    local cntr_code = in_date.cntr_code
    local start_loc_code = in_date.start_loc_code
    local req_no = in_date.req_no
    local inbound_policy = in_date.inbound_policy
    local vendor = in_date.vendor
    local remark1 = in_date.remark1
    local remark2 = in_date.remark2
    local remark3 = in_date.remark3
    local remark4 = in_date.remark4
    local Item_code_9 = in_date.item_code_9
    if (Item_code_9 == nil or Item_code_9 == '') then lua.Error(strLuaDEID, debug.getinfo(1), "ir™ex Ný€:Nzz!") end
    local level = in_date.level
    local expire_date = in_date.expire_date
    local subpool = in_date.subpool
 
    -- ·ƒÖSir™eáOo`„vir™eÍy{|
    local item_type, material
    nRet, item_type, material = GT_Get_ItemType(strLuaDEID, item_code)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), item_type) end
    lua.Debug(strLuaDEID, debug.getinfo(1), 'ir™eáOo`', material)
 
    -- step3 ¹[hV'ÁTÑ~š[
    local cg_detail = m3.AllocObject(strLuaDEID, "CG_Detail")
    cg_detail.cntr_code = cntr_code
    cg_detail.batch_no = batch_no
    cg_detail.item_code = Item_code_9
    cg_detail.item_name = material.item_name
    cg_detail.qty = qty
    cg_detail.uom = 'kg'
    cg_detail.serial_no = serial_no
    cg_detail.is_tl = 1 -- ™ehƋ 0 ck8^ 1 ™e
    lua.Debug(strLuaDEID, debug.getinfo(1), 'cg_detail', cg_detail)
    nRet, cg_detail = m3.CreateDataObj(strLuaDEID, cg_detail)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'mobox Rú^0¹[hV'ÁTfÆ~0ù[aŒ1Y%!' .. cg_detail) end
 
    -- step4 Rú^™eUS
    -- ·ƒÖSN*NRËY„v0™eUS0pencù[aŒ
    local rom = m3.AllocObject(strLuaDEID, "GT_ROM")
    -- ub\ONx
    local strCode = ''
    local strHeader = 'TL' .. os.date("%y%m%d") .. '-'
    nRet, strCode = mobox.getSerialNumber("™e", strHeader, 5)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '3u÷‹™eUSx1Y%!' .. strCode) end
 
    rom.no = strCode
    rom.delivery_no = delivery_no
    rom.delivery_row_no = delivery_row_no
    rom.item_code_9 = item_code
    rom.product_date = product_date
    rom.batch_no = batch_no
    rom.item_state = item_state
    rom.qty = qty
    rom.serial_no = serial_no
    rom.wheel_type_rot = wheel_type_rot
    rom.wh_code = wh_code
    rom.storage_loc = storage_loc
    rom.is_bonded = is_bonded
    rom.cntr_code = cntr_code
    rom.start_loc_code = start_loc_code
    rom.req_no = req_no
    rom.inbound_policy = inbound_policy
    rom.vendor = vendor
    rom.item_code = Item_code_9
    rom.level = level
    rom.expire_date = expire_date
    rom.subpool = subpool
 
    if (start_loc_code == nil or start_loc_code == '') then
        nRet, rom = m3.CreateDataObj(strLuaDEID, rom)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), 'mobox Rú^0™eUS0ù[aŒ1Y%!' .. rom)
        end
    else
        rom.state = "gbLˆ"
        nRet, rom = m3.CreateDataObj(strLuaDEID, rom)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), 'mobox Rú^0™eUS0ù[aŒ1Y%!' .. rom)
        end
 
        local ext_table = {}
        ext_table.is_insulate = material.is_insulate
 
        -- V1.3 ·ƒÖS÷]S“^X[*g¾0R 80% „vïSeQ“^÷]S
        nRet, strRetInfo = StockInquiry(strLuaDEID)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), strRetInfo) end
        ext_table.roadway_inventory = strRetInfo -- \ONibU\pencX[eQُ*N÷]S“^X[W[&{2N ÿ̑b—/f“^X[*g…Ç80%„v÷]S
 
        -- ·ƒÖSw¹páOo`
        local loc_start
        nRet, loc_start = wms_wh.GetLocInfo(start_loc_code)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'WMS_GetLocInfo1Y%!' .. loc_start) end
 
        -- step5 Rú^\ON
        local operation = m3.AllocObject(strLuaDEID, "Operation")
        operation.start_wh_code = loc_start.wh_code
        operation.start_area_code = loc_start.area_code
        operation.start_loc_code = loc_start.code
 
        operation.op_type = wms_base.Get_nConst(strLuaDEID, "\ON{|‹W-eQ“^")
        operation.op_def_name = "™eeQ“^"
        operation.cntr_code = cntr_code
        ext_table.batch_no = batch_no -- yb!k÷S
        ext_table.item_code = Item_code_9 -- ir™ex
        ext_table.item_type = item_type -- ir™e{|‹W
        ext_table.rom_no = strCode -- ™eUS÷S
        ext_table.is_sign = "AGV,dЏ" -- ™eUS÷S
        ext_table.area_code = material.area_code -- “^:S
        ext_table.isothermal = material.isothermal -- /f&TR`)n
        operation.ext_data = lua.table2str(ext_table)
 
        nRet, operation = m3.CreateDataObj(strLuaDEID, operation)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'Rú^0\ON01Y%!' .. operation) end
        lua.Debug(strLuaDEID, debug.getinfo(1), "\ONRú^TáOo`", operation)
    end
end