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
ÿþ--[[
    x: GT-122-01
     Tðy: ¹pûQnxš[    c®”T
    \O€ÿLZH
    åegÿ2024-8-25
 
    §~+RÿúVš[ (ô‹f,gµkãNx(Wy˜îv-N N*YOØSS)
 
    ýQpeÿ AfterClickOk
 
    ŸRý€:
 
 
    ôf9e°‹U_:
    V1.1 LZH 20241028 úQ“^͑°eß~¡‹0Øpö€ô~¤b0̑b—„v“^X[ϑ
 
--]]
json     = require("json")
mobox    = require("OILua_JavelinExt")
wms_wh   = require("wms_wh")
wms_base = require("wms_base")
wms_cntr = require("wms_container")
function AfterClickOk(strLuaDEID)
    local nRet, strRetInfo
 
    nRet, strRetInfo = mobox.getCurEditDataObjAttr(strLuaDEID, "S_CNTR_CODE")
    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 cntr_code = obj_attrs[1].value
 
    --·ƒÖS'MO¹[hVáOo`
    nRet, strRetInfo = m3.GetDataObjectByKey(strLuaDEID, "Loc_Container", "S_CNTR_CODE", cntr_code)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), strRetInfo) end
    lua.Debug(strLuaDEID, debug.getinfo(1), 'strRetInfo', strRetInfo)
    local loc_code = strRetInfo.loc_code
 
    -- ¹[hV'MOã‰Ñ~
    nRet, strRetInfo = wms_wh.Loc_Container_Unbinding(strLuaDEID, loc_code, cntr_code, "Ñ~š[ã‰Ñ~¹eÕl-û|ß~",
        ":_6RŒ[b")
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), ''MO¹[hVã‰Ñ~1Y%!' .. strRetInfo) end
 
    -- ¹[hV㉕
    local container
    nRet, container = wms_cntr.GetInfo(strLuaDEID, 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-àe", "àe")
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'XbØv¹[hV㉕1Y%!' .. strRetInfo) end
 
    -- ·ƒÖSúQ“^USncfÆ~áOo`
    local stock_out
    local strCondition = "S_CNTR_CODE = '" .. cntr_code .. "' AND S_STATE IN( 'gbLˆ','I{…_')"
    nRet, stock_out = m3.GetDataObjByCondition(strLuaDEID, "GT_SO_Detail", strCondition)
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "m3.GetDataObjByCondition 1Y%!" .. stock_out)
    end
    -- ¾‹núQ“^USfÆ~¶r`:NŒ[b
    strCondition = "S_CNTR_CODE = '" .. cntr_code .. "' AND S_STATE IN( 'gbLˆ','I{…_')"
    local strSetSQL_update = " S_STATE = 'Œ[b'"
    nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "GT_SO_Detail", strCondition, strSetSQL_update)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "îO9eúQ“^USnc¶r`1Y%ÿ" .. strRetInfo) end
 
    strCondition = "S_DO_NO = '" .. stock_out.delivery_no .. "' AND S_STATE <> 'Œ[b'"
    nRet, strRetInfo = mobox.getDataObjCount(strLuaDEID, "GT_SO_Detail", strCondition)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), strRetInfo) end
    if (tonumber(strRetInfo) <= 0) then
        -- ¾‹núQ“^US¶r`:NŒ[b
        strCondition = "S_DO_NO = '" .. stock_out.delivery_no .. "'"
        strSetSQL_update = " S_STATE = 'Œ[b'"
        nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "GT_Stock_Out", strCondition, strSetSQL_update)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "îO9eúQ“^USnc¶r`1Y%ÿ" .. strRetInfo) end
    end
 
    -- ·ƒÖS¹[hV'ÁTáOo`
    local cg_detail
    strCondition = "S_CNTR_CODE = '" .. cntr_code .. "'"
    nRet, cg_detail = m3.GetDataObjByCondition(strLuaDEID, "CG_Detail", strCondition)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "m3.GetDataObjByCondition 1Y%!" .. cg_detail) end
 
    -- ·ƒÖSeQ“^USncLˆáOo`
    local label_crad
    strCondition = "S_SERIAL_NO = '" .. cg_detail.serial_no .. "'"
    nRet, label_crad = m3.GetDataObjByCondition(strLuaDEID, "GT_Label_Crad", strCondition, "T_CREATE DESC")
    if (nRet == 1) then
        nRet, label_crad = m3.GetDataObjByCondition(strLuaDEID, "GT_ROM", strCondition, "T_CREATE DESC")
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖSAm4l÷SáOo`1Y%!" .. label_crad) end
    elseif (nRet > 1) then
        lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖSeQ“^USncLˆáOo`1Y%!" .. label_crad)
    end
 
    -- ·ƒÖSeQ“^USnc4YáOo`
    local incoming_Info
    strCondition = "S_DELIVERY_NO = '" ..label_crad.delivery_no.. "' AND N_DELIVERY_ROW_NO = '" .. label_crad.delivery_row_no .. "'"
    nRet, incoming_Info = m3.GetDataObjByCondition(strLuaDEID, "GT_Incoming_Info", strCondition, "T_CREATE DESC")
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖSeQ“^USnc4YáOo`1Y%!" .. incoming_Info) end
 
    -- ‚YœgúQ“^US/fKbå]U_eQ„vRRú^GTWMS Tek°‹U_
    if (incoming_Info.type == 'ºNå]U_eQ') then
        -- Rú^0GTWMS Tek°‹U_0
        local sys_record = m3.AllocObject(strLuaDEID, "GTWMS_SYNC_RECORD")
        sys_record.delivery_no = incoming_Info.delivery_no
        sys_record.delivery_row_no = incoming_Info.delivery_row_no
        sys_record.lpn = cg_detail.serial_no
        sys_record.rfid = cg_detail.cntr_code
        sys_record.lpnweight = cg_detail.qty
        sys_record.sku = cg_detail.item_code
        sys_record.batch_no = cg_detail.batch_no
        sys_record.remark3 = cg_detail.serial_no
        sys_record.grade = incoming_Info.level
        sys_record.type = "úQ“^ÞV O"
        lua.Debug(strLuaDEID, debug.getinfo(1), 'sys_record', sys_record)
        nRet, sys_record = m3.CreateDataObj(strLuaDEID, sys_record)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'mobox Rú^0GTWMS Tek°‹U_0ù[aŒ1Y%!' .. sys_record) end
    else
        -- úQ“^Ó~œgÞV O
        local data = {
            wh_code = "wmwhse1",
            task_no = stock_out.delivery_no,
            batch_no = cg_detail.batch_no,
            sku = cg_detail.item_code,
            qty = cg_detail.qty,
            rfid = cg_detail.cntr_code,
            number_no = label_crad.serial_no,
            supplier = incoming_Info.vendor,
            grade = incoming_Info.level,
            subloc = label_crad.subpool
        }
        local source = "GTWMSúQ“^ÞV O"
 
        -- Œ(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_SO_WMS",
            data = data
        }
        nRet, strRetInfo = CreateInterfaceExc(strLuaDEID, strurl, strHeader, strBody, "GTWMS", source)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "Œ(uWCS¥cãS1Y%!" .. strRetInfo)
        end
    end
 
    --  Rd–¹[hV'ÁTfÆ~°‹U_
    strCondition = "S_CNTR_CODE = '" .. cntr_code .. "'"
    nRet, strRetInfo = mobox.deleteDataObject(strLuaDEID, "CG_Detail", strCondition)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), strRetInfo) end
 
    mobox.setInfo(strLuaDEID, "úQ“^bŸRÿ")
end