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
ÿþ--[[
    x: GT-03-11
     Tðy: °ežX-¹pûQnxš[    c®”T
    \O€ÿHAN
    åegÿ2023-05-05
 
    ýQpeÿ AfterClickOk
 
    ŸRý€:
       -- ·ƒÖSA0B0C0D å]MO„vň±{peϑ ÿ‚Yœg N:N0 ÿ°ežXN*Nň±{å]US
 
    ôf9e°‹U_:
    V2.0 LZH 2024-06-06 å]MO¾‹n:N12*N
    V2.1 LZH 2024-06-07 !hŒšå‹å]MO/f&TX[(W TNyb!k÷Sir™e„v/T¨Rň±{å]US ÿX[(WR¥b•ÿsOî•˜˜nUS^÷S32    ÿ
    V2.2 LZH 2024-08-09 1uŽNpenc!j‹W„vŒte ÿۏLˆW[µk„vãNxOS
    V2.3 LZH 2024-08-29 1uŽNꁚ[INhˆUS„vŒte ÿۏLˆãNxOS
    V2.4 LZH 2024-09-13 ‚YœgeQ“^US„v¶r`:N°eú^RîO9e:N/T¨R
 
--]]
json  = require("json")
mobox = require("OILua_JavelinExt")
m3    = require("oi_base_mobox")
 
function AfterClickOk(strLuaDEID)
    local nRet, strRetInfo, nCount
 
    -- V2.3
    nRet, strRetInfo = mobox.getCurEditDataObjAttr(strLuaDEID, "S_ORDER_NO", "A", "B", "C", "D", "E", "F", "G", "H", "I",
        "J", "K", "L", "S_BATCH_NO", "S_ITEM_CODE", "S_ITEM_NAME", "D_PRODUCT",
        "F_ACTUAL_QTY", "A_QTY", "B_QTY", "C_QTY", "D_QTY", "E_QTY", "F_QTY", "G_QTY", "H_QTY",
        "I_QTY", "J_QTY", "K_QTY", "L_QTY", "S_PALLETIZING", "S_DISPERSOID")
    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 order_no = obj_attrs[1].value -- eg™eUS÷S
    local batch_no = obj_attrs[14].value
    local item_code = obj_attrs[15].value
    local item_name = obj_attrs[16].value
    local product_date = obj_attrs[17].value                --u§Nåeg
    local actual_qty = lua.StrToNumber(obj_attrs[18].value) -- yb!k÷S;`͑
    local palletizing = obj_attrs[31].value
    local dispersoid = obj_attrs[32].value
    local station_array = {} -- Åˆ±{å]MO
 
    -- V2.0 ·ƒÖS/T(u„vå]MOň±{peϑ
    local i = 1
    local switch = ''
    for n = 2, 13 do
        switch = obj_attrs[n].value
        if (switch == '/T(u') then
            local station = {}
            station.pos = obj_attrs[n].attr
            station.qty = obj_attrs[n + 17].value
            station_array[i] = station
            i = i + 1
        end
    end
    lua.Debug(strLuaDEID, debug.getinfo(1), 'station_array', station_array)
 
    if (station_array == nil or station_array == '' or #station_array == 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), 'ň±{å]US*g    ébň±{å]MO!')
    end
 
    -- Rú^ň±{å]US
    for n = 1, #station_array do
        local packing_order = m3.AllocObject(strLuaDEID, "GT_Packing_Order")
        packing_order.order_no = order_no
        packing_order.item_code = item_code
        packing_order.product_date = product_date
        packing_order.batch_no = batch_no
        packing_order.item_name = item_name
        packing_order.actual_qty = actual_qty
        packing_order.palletizing = palletizing
        packing_order.dispersoid = dispersoid
        packing_order.station = station_array[n].pos
        packing_order.pack_qty = station_array[n].qty
 
        -- V2.0 !hŒšå‹å]MO/f&TX[(W TNyb!k÷Sir™e„v/T¨Rň±{å]US
        local strCondition = "S_STATION = '" .. packing_order.station .. "'AND S_ITEM_CODE = '" .. item_code
            .. "' AND S_BATCH_NO = '" .. batch_no .. "' AND S_STATE = '/T(u'"
        nRet, nCount = mobox.getDBRecordCount(strLuaDEID, "TN_GT_Packing_Order", strCondition)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), nCount) end
        if (tonumber(nCount) > 0) then
            lua.Error(strLuaDEID, debug.getinfo(1),
                packing_order.station .. "å]MOò]X[(Wøv Tyb!kir™e/T(u¶r`„vň±{å]USÿ")
        end
 
        nRet, packing_order = m3.CreateDataObj(strLuaDEID, packing_order)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'mobox Rú^0ň±{å]US0ù[aŒ1Y%!' .. packing_order) end
    end
 
    -- V2.4 ‚YœgeQ“^US„v¶r`:N°eú^RîO9e:N/T¨R
    -- ågâ‹agöN
    local strCondition = "S_ORDER_NO = '" .. order_no .. "'"
    nRet, strRetInfo = mobox.queryOneDataObjAttr(strLuaDEID, "GT_Incoming_Info", strCondition)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "queryOneDataObjAttr 1Y%!" .. strRetInfo) end
    strRetInfo = json.decode(strRetInfo)
 
    if (strRetInfo.state == '°eú^') then
        local strSetAttr = "S_STATE = '/T(u'"
        nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "GT_Incoming_Info", strCondition, strSetAttr)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "¾‹n¶r`1Y%!" .. strRetInfo)
        end
 
        -- ‚Yœg/T¨R„vň±{å]US/fceňö€„v ÿRŒ(uWCS¥cãS NÑS:ghVºNĉ<h
        if (dispersoid == 'Y') then
            -- Œ(uýVꁄvûN¡R NÑS¥cãS
            local strCode = lua.guid()                 -- u§NN*NGUIDW[&{2N
            local url = wms_base.Get_sConst(strLuaDEID, "WCS-url")
            local strurl = url .. "/ChangeSpecifications"
            local strHeader = ""
            local data = {
                req_no = strCode,
                palletizing = palletizing
            }
            nRet, strRetInfo = CreateInterfaceExc(strLuaDEID, strurl, strHeader, data, "WCS", ":ghVºNĉ<h NÑS")
            if (nRet ~= 0) then
                lua.Error(strLuaDEID, debug.getinfo(1), "Œ(u¥cãS1Y%!" .. strRetInfo)
            end
        end
    end
end