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
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
ÿþ--[[
    x: WMS-300-20.1
     Tðy: ir™e/FUÁT/'ÁTáOo` Tek
    \O€ÿHAN
    åeg: 2025-1-29
 
    eQãSýQpeÿ Material_Sync
 
    ŸRý€ô‹f:
         Tekè]XXû|ß~-N„vir™e/FUÁT/'ÁTáOo`0R WMS -N„v SKU
        “eQ datajson
        {
            {
                "inco":"xxx",               -- S_ITEM_CODE
                "name":"yyy",
                "length":10,
                "width":10,
                "height":10,
                "volume":10,
                "weight":12.5
            }
        }
    èla:
        
Nb—„v“eQáOo`O9hncy˜îv„v„v N T € N T ÿïSL‘Å`Œte
 
    ØSôf°‹U_:
        V2.0 HAN 20250422 JX_Material_Barcode 9e:N Material_Barcode      
--]]
 
wms_base = require( "wms_base" )
 
local function value_sort( a, b ) return a < b end
 
function Material_Sync( strLuaDEID )
    local nRet, strRetInfo, n
    local nErr = 0                  -- ü[eQpenc•ï‹!kpe
    local err = {}
 
    -- step1 ·ƒÖS¥cãS-N„vData
    local item_info
    nRet, item_info = m3.GetSysDataJson( strLuaDEID )
    if ( nRet ~=0 ) then 
        lua.Stop( strLuaDEID, "àeÕl·ƒÖSpencS datajson !"..item_info )
        return
    end
 
    local materail
    local value, value_array, err_msg
    local strCondition
    local update_data_obj
    local material_barcode
 
    for n = 1, #item_info do
        err_msg = ''
        materail = m3.AllocObject(strLuaDEID,"SKU")
        materail.item_code = item_info[n].inco
        if ( materail.item_code == nil or materail.item_code == '' ) then
            err_msg = "è]ƒlWMS Tekir™eáOo`1Y%:ÂSpe-N:\incoáOo`!"
            goto continue
        end
        materail.item_name = item_info[n].name
        if ( materail.item_name == nil or materail.item_name == '' ) then
            err_msg = "è]ƒlWMS Tekir™eáOo`1Y%: inco = '"..materail.item_code.."'„vir™e:\nameáOo`!"
            goto continue
        end
        -- ·ƒÖSir™e„v•½[ؚ
        value_array = {}
 
        value_array[1] = lua.Get_NumAttrValue( item_info[n].length )
        value_array[2] = lua.Get_NumAttrValue( item_info[n].width )
        value_array[3] = lua.Get_NumAttrValue( item_info[n].height )
 
        --·ƒÖS•¹ ÿ-N¹ ÿíw¹
        table.sort( value_array, value_sort )
        materail.short = value_array[1]
        materail.middle = value_array[2]
        materail.long = value_array[3]
 
        materail.volume = materail.short * materail.middle * materail.long
        materail.weight = lua.Get_NumAttrValue( item_info[n].weight )
 
        -- $R­eir™e0FUÁT0'ÁT/f&Tò]Ï~X[(W
        strCondition = "S_ITEM_CODE = '"..materail.item_code.."'"
        nRet, id, strRetInfo = mobox.getDataObjAttrByKeyAttr( strLuaDEID, "SKU", strCondition )
 
        if ( nRet > 1 ) then
            err_msg = "è]ƒlWMS Tekir™eáOo`1Y%: (WÀhåg inco = '"..materail.item_code.."'/f&TX[(Wöe1Y%!"..strRetInfo
            goto continue
        end
        if ( nRet == 1 ) then
            --  NX[(W
            nRet, materail = m3.CreateDataObj(strLuaDEID, materail)
            if (nRet ~= 0 ) then 
                lua.Stop( strLuaDEID, "Rú^0ir™e01Y%!"..materail.."ir™e Tðy:Nÿ"..item_info[n].name )
                return
            end
            material_barcode = m3.AllocObject(strLuaDEID, "Material_Barcode")
            material_barcode.item_code = materail.item_code   -- FUÁTx
            material_barcode.barcode =  materail.item_code    -- Æ‹+Rxÿ؞¤‹'ÁTx/fN*NUPC    ÿ
                
            nRet, strRetInfo = m3.CreateDataObj(strLuaDEID, material_barcode)
            if (nRet ~= 0) then
                lua.Stop(strLuaDEID, "Œ(u¹eÕlCreateDataObjúQ•: " .. strRetInfo)
                return
            end
        else
            -- ò]Ï~X[(Wôf°epencù[aŒ
            update_data_obj = {
                {
                    id = id,
                    attrs = {
                        { attr = "S_ITEM_CODE", value = materail.item_code },
                        { attr = "S_ITEM_NAME", value = materail.item_name },
                        { attr = "F_LONG", value = materail.long },
                        { attr = "F_MIDDLE", value = materail.middle },
                        { attr = "F_SHORT", value = materail.short },
                        { attr = "F_VOLUME", value = materail.volume },
                        { attr = "F_WEIGHT", value = materail.weight }
                    }
                }
            }
            nRet, strRetInfo = mobox.updateDataObj( strLuaDEID, "SKU", table2str(update_data_obj) )
            if (nRet ~= 0 ) then 
                lua.Stop( strLuaDEID, "ôf°e0ir™e0^\'`1Y%!"..strRetInfo ) 
                return
            end
        end
        
        ::continue::
        -- ‚Yœg    g•ï‹áOo` R0Rû|ß~„v Waring ù[aŒ
        if ( err_msg ~= '') then
            wms_base.Warning( strLuaDEID, 1, 601, err_msg, "ÎNXXû|ß~ TekFUÁTáOo`" )
            nErr = nErr + 1
            err[nErr] = err_msg
        end
    end
 
    if (  nErr > 0 ) then
        local err_info = {
            from = "è]ƒlWMSir™epenc Tek",
            err_msg = err
        }
        mobox.returnValue( strLuaDEID, 1, table2str(err_info), 5 )
    end
end