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
ÿþlocal function CreateOp(strLuaDEID, loc_info, cntr_code, end_loc_info, ext_data)
    local nRet, strRetInfo
    local str_ext_data = {}
    --step5  Rú^\ON
    local operation = m3.AllocObject(strLuaDEID, "Operation")
    operation.start_wh_code = loc_info.wh_code
    operation.start_area_code = loc_info.area_code
    operation.start_loc_code = loc_info.code
    operation.op_type = wms_base.Get_nConst(strLuaDEID, "\ON{|‹W-úQ“^")
    operation.op_def_name = "|TëSzzXb"
    operation.cntr_code = cntr_code
    str_ext_data.roadway = loc_info.roadway
    operation.ext_data = lua.table2str(str_ext_data)
    operation.cntr_code = cntr_code
    operation.end_wh_code = end_loc_info.wh_code
    operation.end_area_code = end_loc_info.area_code
    operation.end_loc_code = end_loc_info.code
 
    nRet, operation = m3.CreateDataObj(strLuaDEID, operation)
    if (nRet ~= 0) then return 2, 'Rú^0\ON01Y%!' .. operation end
    lua.Debug(strLuaDEID, debug.getinfo(1), "\ONRú^TáOo`", operation)
 
    -- ¹[hV'ÁTã‰Ñ~
    local strCondition = "S_ITEM_CODE = 'KGZ'"
    nRet, strRetInfo = wms_cntr.Delete_CG_Detail(strLuaDEID, cntr_code, strCondition)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), ' Rd–0¹[hV'ÁTfÆ~01Y%!' .. strRetInfo) end
    return 0, ""
end
--[[
    x: GT-122-19
     Tðy: ºNå]|TëSzzXb
    \O€ÿLZH
    åegÿ2025-02-19
 
    §~+RÿúVš[ (ô‹f,gµkãNx(Wy˜îv-N N*YOØSS)
 
    ýQpeÿ CallEmptyCntr
 
    ŸRý€: ºNå]kbx·ƒÖSÈ~¹pMOn,    ébzzXb{|‹W6qTRú^úQ“^\ON
    ôf9e°‹U_:
--]]
m3 = require( "oi_base_mobox" )
json     = require("json")
mobox    = require("OILua_JavelinExt")
wms_wh   = require("wms_wh")
wms_base = require("wms_base")
wms_cntr = require("wms_container")
require("GT_InAndOutboundPolicies")
function CallEmptyCntr(strLuaDEID)
    local nRet, strRetInfo,loc_code
    -- ·ƒÖSpenc
    nRet, strRetInfo = mobox.getCurEditDataObjAttr(strLuaDEID, "end_loc", "cntr_type")
    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 end_loc = obj_attrs[1].value             -- È~¹pMOn
    local cntr_type = tonumber(obj_attrs[2].value) -- zzXb{|‹W 1 zzXb 2 zzö€Fh
    -- ÂSpe!hŒš
    if (end_loc == nil or end_loc == '') then lua.Error(strLuaDEID, debug.getinfo(1), "È~¹pMOn Ný€:Nzz!") end
    if (cntr_type == nil or cntr_type == '') then lua.Error(strLuaDEID, debug.getinfo(1), "zzXb{|‹W Ný€:Nzz!") end
    -- ·ƒÖSÈ~¹p'MO„váOo`
    local end_loc_info
    nRet, end_loc_info = wms_wh.GetLocInfo(end_loc)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'GetLocInfo1Y%!' .. end_loc_info) end
 
    -- 9hnczzXb{|‹W~bËz“^-Nù[”^„vzzXb“^X[
    local cntr_str = ''
    if (cntr_type == 1) then
        cntr_str = '106EGP'
    else
        cntr_str = '106EGR' -- ö€FhMR6*NW[&{ XbØv/f106EGP
    end
 
    local strOrder = "T_CREATE"
    -- ·ƒÖSYñmMO„vzzå]ň
    local condition =
    "S_LOC_CODE IN (SELECT S_CODE FROM TN_Location WHERE S_AREA_CODE = 'LK' AND N_LOCK_STATE = 0 AND C_ENABLE = 'Y' AND N_POS = 1)"
    condition = condition ..
        " AND S_CNTR_CODE IN (SELECT S_CNTR_CODE FROM TN_CG_Detail WHERE S_ITEM_CODE = 'KGZ' AND S_CNTR_CODE LIKE '" ..
        cntr_str .. "%')"
    -- gY·ƒÖS 10 ag
    nRet, strRetInfo = mobox.queryDataObjAttr3(strLuaDEID, "Loc_Container", condition, 10, strOrder)
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖS'MO¹[hVáOo`•ï‹! " .. strRetInfo .. " SQLagöN: " .. condition)
    end
    if (strRetInfo ~= nil and strRetInfo ~= '') then goto back end
 
    -- YñmMO NX[(WR·ƒÖS…QñmMO„vzzå]ň
    condition =
    "S_LOC_CODE IN (SELECT S_CODE FROM TN_Location WHERE S_AREA_CODE = 'LK' AND N_LOCK_STATE = 0 AND C_ENABLE = 'Y' AND N_POS = 2)"
    condition = condition ..
        " AND S_CNTR_CODE IN (SELECT S_CNTR_CODE FROM TN_CG_Detail WHERE S_ITEM_CODE = 'KGZ' AND S_CNTR_CODE LIKE '" ..
        cntr_str .. "%')"
    -- gY·ƒÖS 10 ag
    nRet, strRetInfo = mobox.queryDataObjAttr3(strLuaDEID, "Loc_Container", condition, 10, strOrder)
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖS'MO¹[hVáOo`•ï‹! " .. strRetInfo .. " SQLagöN: " .. condition)
    end
    if (strRetInfo == nil or strRetInfo == '') then lua.Error(strLuaDEID, debug.getinfo(1), "Ëz“^-N NX[(Wå‹{|‹W„vzzå]ň!") end
    ::back::
    lua.Debug(strLuaDEID, debug.getinfo(1), "strRetInfo", strRetInfo)
 
    strRetInfo = json.decode(strRetInfo)
    local data -- ‚Yœg¡l    gYñmMOŒT…QñmMOù[”^YñmMO¡l    g'ÁT„v'MO RŠbgTN*N<PK<PÙ~dataù[aŒ,Rú^ûy“^\ON(WúQ“^
    -- M†S·ƒÖS0R„v'MO¹[hVáOo`
    for i = 1, #strRetInfo do
        local attrs = strRetInfo[i]
        lua.Debug(strLuaDEID, debug.getinfo(1), "attrs", attrs)
        -- <h_lbc [{"attr":"a1","value":"xxx1"},..]lbc:N{"lua_a1":"xxx1","lua_a2":"xxx2"}
        nRet, attrs = m3.ObjAttrStrToLuaObj("Loc_Container", attrs.attrs)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "ObjAttrStrToLuaObj1Y%!" .. attrs) end
 
        -- ·ƒÖSw¹p'MO„váOo`
        local start_loc_info
        nRet, start_loc_info = wms_wh.GetLocInfo(attrs.loc_code)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'GetLocInfo1Y%!' .. start_loc_info) end
 
        -- OHQ§~,YñmMOOHQvQ!k/f…QñmMOù[”^„vYñmMO¡l    g'ÁT
        if (start_loc_info.pos == 1) then
            -- Rú^\ON
            nRet, loc_code = CreateOp(strLuaDEID, start_loc_info, attrs.cntr_code, end_loc_info)
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), loc_code) end
            return -- ‚YœgRú^†N\ONRôv¥cԏÞV
        elseif (start_loc_info.pos == 2) then
            local outLocCode
            -- $R­e…QñmMOù[”^„vYñmMO/f&TX[(W'ÁT
            nRet, outLocCode = QueryOutLoc(strLuaDEID, start_loc_info.code)
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), outLocCode) end
 
            local strCondition = "N_LOCK_STATE = 0 AND N_CURRENT_NUM = 0 AND S_CODE = '" .. outLocCode .. "'"
            nRet, strRetInfo = mobox.getDataObjCount(strLuaDEID, "Location", strCondition)
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "getDataObjCount1Y%!" .. outLocCode) end
            -- ‚YœgÓ~œg > 0 RRú^\ON
            if (tonumber(strRetInfo) > 0) then
                -- Rú^\ON
                nRet, loc_code = CreateOp(strLuaDEID, start_loc_info, attrs.cntr_code, end_loc_info)
                if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), loc_code) end
                return -- ‚YœgRú^†N\ONRôv¥cԏÞV
            else
                data = attrs
                data.outLocCode = outLocCode
            end
        end
    end
    -- ‚YœgãNxgbLˆ0Ȓُ,ãNhˆËz“^-N NX[(WYñmMOŒT…QñmMOù[”^„vYñmMO NX[(W'ÁT„vzzXb'MO
    -- HQ\YñmMO„v¹[hVûy“^0RvQÖNMOn,(WRú^zzXbúQ“^\ON
    -- ·ƒÖSw¹p'MO„váOo`
    local start_loc_info
    nRet, start_loc_info = wms_wh.GetLocInfo(data.loc_code)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'GetLocInfo1Y%!' .. start_loc_info) end
    -- ·ƒÖSÈ~¹páOo`
    nRet, end_loc = GetEndLoc(strLuaDEID, start_loc_info.roadway)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), end_loc) end
    -- ·ƒÖS¹[hVáOo`
    local strCondition = "S_LOC_CODE = '" .. data.outLocCode .. "'"
    local cntr_loc
    nRet, cntr_loc = m3.GetDataObjByCondition(strLuaDEID, "Loc_Container", strCondition)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖS0'MO¹[hV0áOo`1Y%! " .. cntr_loc) end
 
 
    -- Rú^sOûN¡R
    local gt_task = m3.AllocObject(strLuaDEID, "GT_Task")
    lua.Debug(strLuaDEID, debug.getinfo(1), 'gt_task', gt_task)
    -- w¹páOo`
    gt_task.start_wh_code = start_loc_info.wh_code
    gt_task.start_area_code = start_loc_info.area_code
    gt_task.start_loc_code = start_loc_info.code
    -- È~¹páOo`
    gt_task.end_wh_code = end_loc.wh_code
    gt_task.end_area_code = end_loc.area_code
    gt_task.end_loc_code = end_loc.code
    gt_task.type = 3     -- 1 ‰|™eŒèb,dЏ 2 Øpö€,dЏ 3  T÷]Sûy“^
    gt_task.priority = 2 -- 'Y„vOHQ
    gt_task.cntr_code = cntr_loc.cntr_code
    nRet, gt_task = m3.CreateDataObj(strLuaDEID, gt_task)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'Rú^0sOûN¡R01Y%!' .. gt_task) end
 
    -- ·ƒÖSûy“^„vûN¡RáOo`
    strCondition = "S_CNTR_CODE = '" .. cntr_loc.cntr_code .. "' AND N_B_STATE IN (0,1,2)"
    local task
    nRet, task = m3.GetDataObjByCondition(strLuaDEID, "Task", strCondition)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖS0ûN¡R0áOo`1Y%! " .. task) end
 
    -- Rú^úQ“^\ON
    local ext_data = {}
    ext_data.task_no = task.code
    -- Rú^\ON
    nRet, loc_code = CreateOp(strLuaDEID, start_loc_info, data.cntr_code, end_loc_info,ext_data)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), loc_code) end
end