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
ÿþ--[[
   x: GT-119-19
    Tðy: Rú^\ON
   \O€ÿLZH
   åegÿ2024/8/13
 
   ýQpeÿ CreateOperation
   ŸRý€:
   step1 $R­eúQ“^USnc/f&T/f/T¨R¶r`
   step2 /T¨R¶r`RÇúQ“^V{eu·ƒÖS\ONw¹p
   step3 Rú^\ON
 
    ØSôf°‹U_:
    V1.1 LZH 20241122 úQ“^USîO9e:N;NP[hˆ ÿãNxŒte
    V1.2 LZH 20250326 °ežXǑ-'Am z ÿ‚YœgGTWMS NÑS„vÈ~¹p:gðS:NúVš[„v
    V1.3 LZH 20250526 eQ“^USir™exý/f9MOx ÿåg⋐Ǐ
N8n NÑS„v6MOx!jÊ|ågâ‹6qTÇyb!k÷Sš[MO
 
--]]
 
json     = require("json")
mobox    = require("OILua_JavelinExt")
m3       = require("oi_base_mobox")
wms_base = require("wms_base")
require("GT-Base")
require("GT_InAndOutboundPolicies")
wms_wh = require("wms_wh")
function CreateOperation(strLuaDEID)
    local nRet, strRetInfo
 
    local stock_out
    nRet, stock_out = m3.GetSysCurEditDataObj(strLuaDEID, "GT_Stock_Out")
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), stock_out) end
    lua.Debug(strLuaDEID, debug.getinfo(1), 'stock_out', stock_out)
 
    local ret_loc
    if (stock_out.state == '/T(u') then
        -- ·ƒÖSå‹ir™e„vir™e{|‹W
        local item_type, material
        nRet, item_type, material = GT_Get_ItemType(strLuaDEID, stock_out.item_code)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), item_type) end
 
        -- ·ƒÖS ir™e+yb÷S @b(W“^:S
        -- V1.3
        local strCondition = "S_CNTR_CODE IN (SELECT S_CNTR_CODE FROM TN_CG_Detail WHERE S_ITEM_CODE LIKE '%" ..
            stock_out.item_code .. "%' AND S_BATCH_NO = '" .. stock_out.batch_no .. "')"
        local loc_container
        nRet, loc_container = m3.GetDataObjByCondition(strLuaDEID, "Loc_Container", strCondition)
        if (nRet == 1) then
            lua.Error(strLuaDEID, debug.getinfo(1), " NX[(Wyb!k÷S:N" .. stock_out.batch_no .. "„vir™e!")
        elseif (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "m3.GetDataObjByCondition 1Y%!" .. loc_container)
        end
        -- ·ƒÖS'MOáOo`
        local loc_info
        nRet, loc_info = wms_wh.Location_GetInfo(strLuaDEID, loc_container.loc_code)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "WMS_Location_GetInfo1Y%!" .. loc_info) end
 
        local op_def_name = ''
 
 
 
        local end_loc_code, loc_baseinfo
        if (stock_out.ms_code == 'ABC') then
            op_def_name = "Ǒ-'"
            -- ·ƒÖS:gðS Nô~¤b„vúQ“^“^:S
            local area_link
            strCondition = "S_MS_CODE = 'ABC'"
            nRet, area_link = m3.QueryDataObject(strLuaDEID, "MS_Area_Link", strCondition)
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '·ƒÖSǑ-':gðSáOo`1Y%!' .. area_link) end
            if (area_link == nil or area_link == '') then lua.Error(strLuaDEID, debug.getinfo(1), '÷‹ô~¤bǑ-'úQ“^“^:SbMOn!') end
            lua.Debug(strLuaDEID, debug.getinfo(1), 'area_link', area_link)
 
            -- ·ƒÖS–:gpe,–:gcš[úQ“^“^:SMOn
            local randomInt = math.random(1, #area_link)
            local attr
            nRet, attr = m3.ObjAttrStrToLuaObj("MS_Area_Link", lua.table2str(area_link[randomInt].attrs))
            if (nRet ~= 0) then
                lua.Error(strLuaDEID, debug.getinfo(1),
                    "m3.ObjAttrStrToLuaObj(GT_Label_Crad) 1Y%! " .. attr)
            end
            lua.Debug(strLuaDEID, debug.getinfo(1), 'attr', attr)
 
            if (tonumber(attr.la_type) == 0) then
                end_loc_code = attr.la_code .. "-QY"
            elseif (tonumber(attr.la_type) == 1) then
                end_loc_code = attr.la_code
            end
        else
            if (loc_info.area_code == 'PFL' or loc_info.area_code == 'TFL' or loc_info.area_code == 'HWPFL' or loc_info.area_code == 'HWTFL') then
                nRet, ret_loc = FL_StockOut(strLuaDEID, stock_out)
                if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), ret_loc) end
                lua.Debug(strLuaDEID, debug.getinfo(1), '111', 111)
                op_def_name = "‰|™eúQ“^"
                end_loc_code = stock_out.ms_code
            elseif (loc_info.area_code == 'LK') then
                nRet, ret_loc = LK_StockOut(strLuaDEID, stock_out)
                if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), ret_loc) end
                lua.Debug(strLuaDEID, debug.getinfo(1), 'ret_loc', lua.table2str(ret_loc))
                op_def_name = "Ëz“^úQ“^"
                nRet, end_loc_code = wms_base.GetAreaAvaliableLoc(strLuaDEID, stock_out.ms_code, "")
                if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "WMS_GetAreaAvaliableLoc1Y%ÿ" .. end_loc_code) end
                end_loc_code = end_loc_code.loc_code
            end
 
            if (ret_loc == nil or ret_loc == '') then
                lua.Error(strLuaDEID, debug.getinfo(1), "¡l    gïSúQ“^„v'ÁT!")
            end
            lua.Debug(strLuaDEID, debug.getinfo(1), 'ret_loc', ret_loc)
            nRet, loc_baseinfo = wms.wms_GetLocBaseInfo(ret_loc.start_loc_code)
            if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖS'MOúW,gáOo`1Y%!" .. loc_baseinfo) end
            lua.Debug(strLuaDEID, debug.getinfo(1), 'w¹p'MOáOo`', loc_baseinfo)
            loc_baseinfo = json.decode(loc_baseinfo)
        end
 
        lua.Debug(strLuaDEID, debug.getinfo(1), 'end_loc_code', end_loc_code)
        local end_loc
        nRet, end_loc = wms.wms_GetLocBaseInfo(end_loc_code)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖS'MOúW,gáOo`1Y%!" .. end_loc) end
        lua.Debug(strLuaDEID, debug.getinfo(1), 'È~¹p'MOáOo`', end_loc)
        end_loc                   = json.decode(end_loc)
 
        -- step4: Rú^,dЏ\ON
        local operation           = m3.AllocObject(strLuaDEID, "Operation")
        operation.start_wh_code   = loc_baseinfo.wh_code
        operation.start_area_code = loc_baseinfo.area_code
        operation.start_loc_code  = loc_baseinfo.code
 
        -- È~¹p/fsOWMS OǏeg„v
        operation.end_wh_code     = end_loc.wh_code
        operation.end_area_code   = end_loc.area_code
        operation.end_loc_code    = end_loc.code
 
        operation.bs_no           = stock_out.delivery_no -- N¡RUS÷S:NúQ“^ûN¡R÷S
 
        operation.cntr_code       = ret_loc.cntr_code
        operation.op_def_name     = op_def_name
        operation.op_type         = wms_base.Get_nConst(strLuaDEID, "\ON{|‹W-úQ“^")
 
        local strCode
        local strHeader           = 'TA' .. os.date("%y%m%d") .. '-'
        nRet, strCode             = mobox.getSerialNumber("ûN¡R", strHeader, 5)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '3u÷‹0ûN¡R0x1Y%!' .. strCode) end
 
        -- ¾‹nibU\ÂSpe&^eQ\ON/T¨R ÿûN¡RŒ[b
        local ext_table       = {}
        ext_table.batch_no    = stock_out.batch_no
        ext_table.item_type   = item_type
        ext_table.delivery_no = stock_out.delivery_no
        ext_table.task_no     = strCode
        ext_table.mes_task_no     = stock_out.mes_task_no
        ext_table.wms_task_no     = stock_out.wms_task_no
        ext_table.wmsLot     = stock_out.wms_lot
        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), 'operation', operation)
 
        -- \ON„vw¹p R•
        nRet, strRetInfo = wms.wms_LockLocation(strLuaDEID, operation.start_loc_code,
        wms_base.Get_nConst(strLuaDEID, "•{|‹W-úQ“^•"), strCode, operation.code, operation.op_def_name)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "wms_LockLocation 1Y%!" .. strRetInfo) end
 
        -- ¹[hV R•
        local container
        nRet, container = wms_cntr.GetInfo(strLuaDEID, operation.cntr_code)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1),'·ƒÖS¹[hVù[aŒ1Y%!' .. container) end
        nRet, strRetInfo = wms_cntr.SetLock(strLuaDEID, container, "•{|‹W-úQ“^•", operation.code)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'XbØv¹[hVûm RúQ“^•1Y%!' .. strRetInfo) end
 
        lua.Debug(strLuaDEID, debug.getinfo(1), '111', 111)
        -- °ežXúQ“^USfÆ~
        local so_detail           = m3.AllocObject(strLuaDEID, "GT_SO_Detail")
        -- w¹páOo`
        so_detail.delivery_no     = stock_out.delivery_no
        so_detail.op_code         = operation.code
        so_detail.cntr_code       = ret_loc.cntr_code
        so_detail.start_area_code = loc_baseinfo.area_code
        so_detail.start_loc_code  = loc_baseinfo.code
        so_detail.end_area_code   = end_loc.area_code
        so_detail.end_loc_code    = end_loc.code
        nRet, so_detail           = m3.CreateDataObj(strLuaDEID, so_detail)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'Rú^0úQ“^USfÆ~01Y%!' .. so_detail) end
    end
end