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
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
ÿþ--[[
    x: WMS-300-22.1
     Tðy: eQ“^USáOo` Tek
    \O€: KUN
    åeg: 2025-1-29
 
    eQãSýQpeÿ InboundOrder_Sync
 
    egny˜îv:  è]fŒNg™e±{“^
 
    ŸRý€ô‹f:
        1. ¥c6eegê
N8nû|ß~ÿ‚Yè]ƒlWMS    ÿ„v JSON <h_penc ÿpencSìbegn{|‹W0eQ“^US÷S0Rú^ºN0FUÁTfÆ~I{0
        2. O(u for ª_¯sM†SFUÁTfÆ~peÄ~ ÿù[Ïk*NFUÁT„vpencۏLˆ `if` $R­e
        3. \eQ“^USpencX[¨P0ReQ“^UShˆ `Inbound_Order`0
        4. \FUÁTfÆ~pencX[¨P0ReQ“^USfÆ~hˆ `Inbound_Detail` ÿv^ÎNir™ehˆågâ‹ù[”^„vir™eáOo`0
    
    “eQpenc<h_:
    {
      "source": "è]ƒlWMS",  
      "order_no": "PK10001",  
      "creator": "XXX",  
      "items":{ 
            {
            "inco": "0100001", 
            "qty": 10 
            }
            ...
        }
    }
 
    ôf9e°‹U_:
       V2.0 HAN 20250402  ãNxĉƒ
 
 
--]]
 
wms_base = require( "wms_base" )
 
function InboundOrder_Sync(strLuaDEID)
    local nRet, strRetInfo, inputData
 
    -- ·ƒÖS¥cãS OeQ„vpenc
    nRet, inputData = m3.GetSysDataJson(strLuaDEID)
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "àeÕl·ƒÖSpencS datajson")
    end
 
    -- ÀhågÅ_kXW[µk/f&TX[(WN    gHe
    if (inputData.source ~= "è]ƒlWMS" and inputData.source ~= ")Y+sýVE–") then
        lua.Stop(strLuaDEID, "egn{|‹W Nù[")
        return
    end
    if (inputData.order_no == nil or inputData.order_no == "") then
        lua.Stop(strLuaDEID, "eQ“^US÷S Ný€:Nzz")
        return
    end
    if (inputData.creator == nil or inputData.creator == "") then
        lua.Stop(strLuaDEID, "Rú^ºN Ný€:Nzz")
        return
    end
    if (inputData.items == nil or #inputData.items == 0) then
        lua.Stop(strLuaDEID, "FUÁTfÆ~Rhˆ Ný€:Nzz")
        return
    end
 
    -- Àhåg/f&Tò]X[(Wøv T„veQ“^US
    local strCondition = "S_NO = '" .. inputData.order_no .. "'"
    local nRet, strRetInfo = mobox.existThisData(strLuaDEID, "Inbound_Order", strCondition)
    if (nRet ~= 0) then
        lua.Stop(strLuaDEID, "Œ(u¹eÕl existThisData úQ•: " .. strRetInfo)
        return
    end
    if (strRetInfo == 'yes') then
        lua.Stop(strLuaDEID, "eQ“^US'" .. inputData.order_no.."' ò]Ï~X[(W!")
        return
    end
 
    -- Rú^eQ“^US°‹U_
    local inbound_order = m3.AllocObject(strLuaDEID, "Inbound_Order")
 
    inbound_order.no = inputData.order_no           -- eQ“^US÷S
    -- åN Nُ›N/fy˜îvyr¹p ÿ    g›NeQ“^US Tek„vöeP1\    g&^ÓN“^ŒT“^:Sx ÿُ›N9hncwQSOy˜îvš[
    nRet, inbound_order.wh_code = wms_base.Get_sConst2(strLuaDEID, "؞¤‹ÓN“^hƋ") 
    if ( nRet ~= 0 ) then
        lua.Stop( strLuaDEID, "û|ß~àeÕl·ƒÖS8^ϑ'؞¤‹ÓN“^hƋ'")
        return
    end
 
    nRet, inbound_order.area_code = wms_base.Get_sConst2( strLuaDEID, "™e±{“^X[¨P:S" )
    if ( nRet ~= 0 ) then
        lua.Stop( strLuaDEID, "û|ß~àeÕl·ƒÖS8^ϑ'™e±{“^X[¨P:S'")
        return
    end    
    inbound_order.wave_no = ""
    inbound_order.create_method = "JW-WMS"
    inbound_order.good_type_num = 0
    inbound_order.total_qty = 0
    
    local item
    local material
    local inbound_detail
 
    -- M†SFUÁTfÆ~peÄ~
    for n = 1, #inputData.items do
        item = inputData.items[n]
 
        -- ÀhågFUÁTxŒTpeϑ/f&TX[(WN    gHe
        if (item.inco == nil or item.inco == "") then
            lua.Stop(strLuaDEID, debug.getinfo(1), ",{ " .. n .. " *NFUÁT„vFUÁTxinco Ný€:Nzz")
            return
        end
        if (item.qty == nil or item.qty == 0) then
            lua.Stop(strLuaDEID, debug.getinfo(1), ",{ " .. n .. " *NFUÁT„vpeϑqtyÅ_{˜'YŽN 0")
            return
        end
 
        -- $R­eeQ“^fÆ~-N„vir™e/f&TX[(W
        strCondition = "S_ITEM_CODE = '" .. item.inco .. "'"
        nRet, strRetInfo = mobox.existThisData(strLuaDEID, "SKU", strCondition)
        if (nRet ~= 0) then
            lua.Stop(strLuaDEID, "Œ(u¹eÕlexistThisDataúQ•: " .. strRetInfo )
            return
        end
        if (strRetInfo == 'yes') then
            -- ir™eX[(W
            nRet, material = GetDataObjByCondition(strLuaDEID, "SKU", strCondition)
            if (nRet ~= 0) then
                lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖSir™eáOo`1Y% ÿFUÁTxÿ" .. item.inco)
            end
            -- Rú^eQ“^USfÆ~°‹U_
            inbound_detail = m3.AllocObject(strLuaDEID, "Inbound_Detail")
 
            inbound_detail.io_no = inputData.order_no           -- ¾‹neQ“^US÷S
            inbound_detail.item_code = material.item_code       -- ¾‹nir™ex
            inbound_detail.item_name = material.item_name       -- ¾‹nir™e Tðy
            inbound_detail.qty = item.qty                       -- ¾‹nir™epeϑ
            inbound_detail.volume = material.volume             -- ¾‹nSOïy
            inbound_detail.weight = material.weight             -- ¾‹n͑ϑ
            inbound_detail.cell_type = material.cell_type       -- ™e<h{|‹W
            -- Rú^eQ“^USfÆ~
            nRet, inbound_detail = m3.CreateDataObj(strLuaDEID, inbound_detail)
            if (nRet ~= 0) then
                lua.Stop(strLuaDEID, "Rú^eQ“^USfÆ~°‹U_1Y% ÿFUÁTxÿ" .. item.inco.. ",ŸSàVÿ"..strRetInfo)
                return
            end
            -- ôf°eeQ“^US„vGl;`penc
            inbound_order.good_type_num = inbound_order.good_type_num + 1
            inbound_order.total_qty = inbound_order.total_qty + item.qty
        else
            lua.Stop(strLuaDEID, "ir™ex NX[(W ÿFUÁTxÿ" .. item.inco)
            return
        end
    end
 
    -- Rú^eQ“^USpencù[aŒ
    nRet, inbound_order = m3.CreateDataObj(strLuaDEID, inbound_order)
    if (nRet ~= 0) then
        lua.Stop(strLuaDEID, "Rú^eQ“^US°‹U_1Y%ÿ" .. inbound_order)
        return
    end
 
    -- ÔÞVÂSpe
    local result = 
    {
        err_code = 0,
        err_meg = "eQ“^bŸR"
    }
    mobox.returnValue(strLuaDEID, 1, table2str(result))
 
end