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
ÿþ--[[
 x: GT-10-11
  Tðy: ­pўeQ“^'MO¹[hVÑ~š[
 \O€: LZH
 eQãSýQpeÿLocContainerBinding
 ŸRý€ô‹f:
    10Çkbx·ƒÖSAm4l÷S
    20ÇAm4l÷S·ƒÖS¹[hV'ÁTfÆ~°‹U_ ÿ NX[(W¥b•ÿ¹[hV'ÁT*gÑ~š[    ÿ
    30X[(WR¡‹—{N*NïSeQ“^„v ­pўirt'MOv^ûm R'MO¹[hVÑ~š[°‹U_
 ØSôf†SòS:
 V2.0 LZH 20240626 ÎN‘-N·ƒÖSXbØvx
 V2.1 LZH 20240704 ŸRý€9eØS ÿkbx·ƒÖSAm4l÷SåNÊS¹[hV÷SåNÊS!hŒš'MO÷S,v^Rú^¹[hV'ÁTfÆ~°‹U_
 v2.2 LZH 20240723 ³xў“^¡l    g¹[hV ÿ(WW[xQš[INGT_TH_CRTN̑b—/f­pў„vMR ÿ–:gubXbØv÷S ÿ(W³xў“^úQ“^öe ÿ Rd–ُ*Nub„v¹[hV
 --]]
json     = require("json")
mobox    = require("OILua_JavelinExt")
wms_wh   = require("wms_wh")
wms_base = require("wms_base")
require("GT-Base")
wms_cntr = require("wms_container")
function LocContainerBinding(strLuaDEID)
    local nRet, strRetInfo
    -- ·ƒÖS‘-N„vagxáOo`
    nRet, strRetInfo = mobox.getCurEditDataObjAttr(strLuaDEID, "S_SERIAL_NO", "S_LOC_CODE", "VERIFY_LOC_CODE",
        "S_CNTR_CODE")
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖSS_MR‘^\'`1Y%! " .. strRetInfo) end
    local obj_attrs = json.decode(strRetInfo)
    lua.Debug(strLuaDEID, debug.getinfo(1), 'obj_attrs', obj_attrs)
    -- (u,g0WÂSpe¥c6e
    local serial_no = obj_attrs[1].value
    if (serial_no == nil or serial_no == '') then lua.Error(strLuaDEID, debug.getinfo(1), "îvƉaSAm4l÷S Ný€:Nzz!") end
    local loc_code = obj_attrs[2].value
 
    -- V2.1 !hŒš'MO/f&TŒTÐc:y„v'MONô ÿ2–bk>e•
    local verify_loc_code = obj_attrs[3].value
    if (verify_loc_code == nil or verify_loc_code == '') then lua.Error(strLuaDEID, debug.getinfo(1), "'MO Ný€:Nzz!") end
    if (loc_code ~= verify_loc_code) then
        lua.Error(strLuaDEID, debug.getinfo(1), "kbx'MOŒTÐc:y'MO NNô!")
    end
    local cntr_code = obj_attrs[4].value
 
    -- V2.1 ·ƒÖSîvƉaS-N„váOo` ÿ(uُ*NaS-N„váOo`Rú^ CG_Detail
    local strCondition = "S_SERIAL_NO = '" .. serial_no .. "'"
    local label_card
    nRet, label_card = m3.GetDataObjByCondition(strLuaDEID, "GT_Label_Crad", strCondition)
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "m3.GetDataObjByCondition 1Y%!" .. label_card)
    end
 
    -- 0eg™eáOo`0-N /}¡‹Åˆ±{peϑ +  ‚Yœg…úQ ž[E–peϑ û|ß~¥b•
    local obj
    strCondition = "S_ORDER_NO = '" .. label_card.order_no .. "'"
    nRet, obj = mobox.incDataObjAccQty(strLuaDEID, "GT_Incoming_Info", strCondition, "N_CNTR_QTY",
        "N_ACC_PACK_QTY", 1)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "incDataObjAccQty 1Y%! " .. obj) end
    if (obj ~= '') then
        -- ô‹f/} Rpeϑ…úQ F_ACTUAL_QTY û|ß~¥b•
        lua.Error(strLuaDEID, debug.getinfo(1), "eQ“^US÷S: " .. label_card.order_no .. " -NeQ“^US„v/}¡‹eQ“^peϑ/}ïyT…ÇXbØvpeϑ!")
    end
 
    -- ‚YœgeQ“^USnc4Y„vXbØvpeϑŒT/}¡‹eQ“^peϑNôRîO9e¶r`:NŒ[b
    local incoming_info
    nRet, incoming_info = m3.GetDataObjectByKey(strLuaDEID, "GT_Incoming_Info", "S_ORDER_NO", label_card.order_no)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), incoming_info) end
    lua.Debug(strLuaDEID, debug.getinfo(1), 'strRetInfo', incoming_info)
    if (tonumber(strRetInfo.cntr_qty) == tonumber(strRetInfo.acc_pack_qty)) then
        -- îO9eeQ“^USnc4Y¶r`
        local strSetSQL_update
        strCondition = "S_ORDER_NO = '" .. label_card.order_no .. "'"
        strSetSQL_update = "S_STATE = 'Œ[b'"
        nRet, obj = mobox.updateDataAttrByCondition(strLuaDEID, "GT_Incoming_Info", strCondition, strSetSQL_update)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "îO9eeQ“^USnc4Y¶r`1Y%ÿ" .. obj) end
    end
 
    -- ·ƒÖSir™e{|‹WŒTir™eù[aŒ
    local item_type, material
    nRet, item_type, material = GT_Get_ItemType(strLuaDEID, label_card.item_code)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖS0ir™e^\'`{|‹W0áOo`1Y%! " .. item_type) end
 
    local area = ''  -- “^:Sx,9hncir™e{|‹Weg$R­eir™ex
    local loc = ''   -- ÞV OGTWMS„v“^MOáOo`
    if (item_type == '³xў') then
        loc = "LK002"
        -- v2.2 ågâ‹W[xQ–:gub¹[hV÷Sv^Rú^¹[hV
        nRet, strRetInfo = mobox.getDictItemIInfo("GT_TH_CRTN")
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "getDictItemIInfo1Y%!" .. strRetInfo) end
        lua.Debug(strLuaDEID, debug.getinfo(1), ')Y6qö€W[xQáOo`!', strRetInfo)
        local dictItems = json.decode(strRetInfo)
        cntr_code = dictItems[1].name
        cntr_code = cntr_code .. os.date("%m%d")
        nRet, cntr_code = mobox.getSerialNumber("¹[hV", cntr_code, 5)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '3u÷‹0¹[hV0x1Y%!' .. cntr_code) end
        local container = m3.AllocObject(strLuaDEID, "Container")
        container.code = cntr_code
        nRet, strRetInfo = m3.CreateDataObj(strLuaDEID, container)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'Rú^0¹[hV0ù[aŒ1Y%!' .. strRetInfo) end
 
        area = 'TH'
    elseif (item_type == '^P[^') then
        -- $R­e¹[hV'ÁTfÆ~/f&TX[(W,ò]X[(WR NAQ¸‹eQ“^
        local cg_detail
        nRet, cg_detail = wms_cntr.Get_Container_Goods(strLuaDEID, cntr_code)
        if (cg_detail ~= nil and cg_detail ~= '') then
            lua.Error(strLuaDEID, debug.getinfo(1), "å‹Am4l÷Sò]eQ“^!")
        end
        loc = "LK003"
        if (wms_cntr.Exist(strLuaDEID, cntr_code)) then
            area = 'LZB'
        else
            lua.Error(strLuaDEID, debug.getinfo(1), "¹[hV NX[(W!")
        end
    elseif (item_type == '…Pg') then
        loc = "LK004"
        if (wms_cntr.Exist(strLuaDEID, cntr_code)) then
            area = 'FC'
        else
            lua.Error(strLuaDEID, debug.getinfo(1), "¹[hV NX[(W!")
        end
    end
 
 
    -- V2.1 Rú^¹[hV'ÁTfÆ~°‹U_
    local cg_detail = m3.AllocObject(strLuaDEID, "CG_Detail")
    cg_detail.cntr_code = cntr_code
    cg_detail.item_merge = 'N'  --  NTv^ir™eub Container_Good
    cg_detail.batch_no = label_card.batch_no
    cg_detail.item_code = label_card.item_code
    cg_detail.item_name = label_card.item_name
    cg_detail.qty = label_card.qty
    cg_detail.uom = 'kg'
    cg_detail.serial_no = label_card.serial_no
    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
 
 
    -- ¹[hVŒT'MOÑ~š[
    wms_wh.Loc_Container_Binding(strLuaDEID, loc_code, cntr_code, "Ñ~š[ã‰Ñ~¹eÕl-ºNå]", "")
    -- 9hnc¹[hV'ÁTfÆ~ R“^X[ϑ
    wms_base.Add_WHAreaQty_ByCGDetail(strLuaDEID, "AHYLK", area, cntr_code)
 
    -- ã‰•
    nRet, strRetInfo = wms.wms_UnlockByTask(strLuaDEID, loc_code)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "wms_UnlockByTask 1Y%! " .. strRetInfo) end
 
    -- eQ“^Ó~œgÞV O
    local data = {
        wh_code = "wmwhse1",
        delivery_no = label_card.delivery_no,
        delivery_row_no = label_card.delivery_row_no,
        lpn = label_card.serial_no,
        rfid = cg_detail.cntr_code,
        lpnweight = label_card.qty,
        sku = label_card.item_code,
        batch_no = label_card.batch_no,
        remark3 = label_card.req_no,
        loc = loc
    }
    -- Œ(uGT-WMS„vÞV O¥cãS
    local url = wms_base.Get_sConst(strLuaDEID, "GTWMS-url")
    local strurl = url
    local strHeader = ""
    local strBody = {
        application = "GITI",
        code = "WCS_ASN_WMS",
        data = data
    }
 
    nRet, strRetInfo = mobox.sendHttpRequest(strurl, strHeader, lua.table2str(strBody))
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "Œ(uGTWMSÞV O¥cãS1Y%!" .. strRetInfo)
    end
    if (strRetInfo == '' or strRetInfo == nil) then
        lua.Error(strLuaDEID, debug.getinfo(1), "Œ(uGTWMSÞV O¥cãSԏÞV:Nzz!")
    else
        local success, resJson = pcall(json.decode, strRetInfo)
        if (success == false) then lua.Error(strLuaDEID, debug.getinfo(1), "^—Õl„vJSON<h_!" .. resJson) end
 
        local success = resJson.success
        local message = resJson.message
        lua.Debug(strLuaDEID, debug.getinfo(1), 'success', success)
        lua.Debug(strLuaDEID, debug.getinfo(1), 'message', message)
 
        local exc = m3.AllocObject(strLuaDEID, "GT_Interface_Exc")
        exc.source = "GTWMS"
        exc.interface_name = "GTWMSeQ“^ÞV O"
        exc.url = strurl
        exc.body = lua.table2str(strBody)
        if (success == false) then
            exc.state = "1Y%"
            exc.err = message
        end
        nRet, exc = m3.CreateDataObj(strLuaDEID, exc)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'Rú^0¥cãS_8^°‹U_01Y%!' .. exc) end
    end
 
    mobox.setInfo(strLuaDEID, "Íd\ObŸR!")
end