Jianw
2025-05-14 29f8b36ebb718d2051bf0e7e701973ec4419ee80
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
ÿþ--[[
    x: WMS-300-21
     Tðy: FUÁTagxáOo` Tek
    \O€: KUN   
    åeg: 2025-1-29
 
    eQãSýQpeÿ Barcode_Sync
              
    ŸRý€ô‹f:
         TekXXû|ß~-N„vFUÁTagx0R WMS „v `Material_Barcode`0
        
        “eQ: FUÁTƋ+Rx Barcode/UPC 
        {
            {
                "idcode":"xxx", --Ƌ+Rx (UPC)
                "inco":"yyy"    --FUÁTx (S_ITEM_CODE)
            }
        }
    èla:
        
Nb—„v“eQáOo`O9hncy˜îv„v„v N T € N T ÿïSL‘Å`Œte
 
    ØSôf°‹U_:
       V2.0 HAN 20250401 tetĉƒ
       V3.0 HAN 20250422 JX_Material_Barcode 9e:N Material_Barcode         
--]]
 
json = require("json")
mobox = require("OILua_JavelinExt")
m3 = require( "oi_base_mobox" )
 
-- eQãSýQpe
function Barcode_Sync(strLuaDEID)
    local nRet, strRetInfo, input_data
    local inco, idcode
 
    -- ·ƒÖS OeQ„vpenc
    nRet, input_data = m3.GetSysDataJson(strLuaDEID)
    if (nRet ~= 0) then 
        lua.Stop( strLuaDEID, "àeÕl·ƒÖSpencS: " .. input_data)
        return
    end
 
    local strCondition
    local barcode
 
    -- YtÏkagpenc
    for i = 1, #input_data do
        inco = input_data[i].inco       -- FUÁTx
        idcode = input_data[i].idcode   -- Æ‹+Rx
        
        if (inco == nil or inco == '') then 
            lua.Stop(strLuaDEID, "FUÁTx Ný€:Nzz!")
            return
        end
        if (idcode == nil or idcode == '') then 
            lua.Stop(strLuaDEID, "Ƌ+Rx Ný€:Nzz!")
            return
        end
        
        -- ÀhågƋ+Rx/f&Tò]Ï~ù[”^†NvQÖNFUÁTx
        strCondition = "S_BARCODE = '" .. idcode .. "'"
        nRet, strRetInfo = mobox.existThisData(strLuaDEID, "Material_Barcode", strCondition)
        if (nRet ~= 0) then
            lua.Stop(strLuaDEID, "Œ(u¹eÕlexistThisDataúQ•: " .. strRetInfo)
            return
        end
        
        if (strRetInfo ~= 'yes') then
            -- Æ‹+Rx*g«ˆO(u ÿ°ežXFUÁTxŒTƋ+Rx„vÄ~T
            barcode = m3.AllocObject(strLuaDEID, "Material_Barcode")
            barcode.item_code = inco   -- FUÁTx
            barcode.barcode = idcode   -- Æ‹+Rx
            nRet, strRetInfo = m3.CreateDataObj(strLuaDEID, barcode)
            if (nRet ~= 0) then
                lua.Stop(strLuaDEID, "Œ(u¹eÕlCreateDataObjúQ•: " .. strRetInfo)
                return
            end
        end
    end
    
    -- ÔÞVbŸRáOo`
    mobox.setInfo(strLuaDEID, "FUÁTagxYtbŸR!")
    local result = {
        err_code = 0,
        err_meg = "bŸR"
    }
    mobox.returnValue(strLuaDEID, 1, table2str(result))
end