fy36
2025-05-14 a37aca60ff9914b0abb710f04118b22420f4f398
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
ÿþ--[[
    x: WMS-300-23.1
     Tðy: úQ“^USáOo` Tek
    \O€: KUN
    åeg: 2025-1-29
 
    eQãSýQpeÿ OutboundOrder_Sync
 
    egny˜îv:  è]fŒNg™e±{“^
 
    ŸRý€ô‹f:
        1. ¥c6eegê
N8nû|ß~„v JSON <h_penc ÿv^㉐gå‹penc0
        2. ŒšÁ‹ûy“^¡‹RUS÷S0egn0USnc{|‹WŒTFUÁTfÆ~/f&TX[(W0
        3. 9hncFUÁTxÎNir™ehˆ-Någâ‹øvsQáOo`0
        4. ª_¯sM†SFUÁTRhˆ ÿÀhågvQÅ_‰„vW[µk ÿv^gbLˆúQ“^USŒTfÆ~„vX[¨PÍd\O0
        
    “eQpenc<h_:
        {
          "source": "è]ƒlWMS",
          "order_no": "SK10001",
          "order_type": "úQ“^",
          "items":
            [
              {
                "sale_no": "1",
                "inco": "04005657",
                "qty": 10 
              },
              {
                "sale_no": "2",
                "inco": "02001449",
                "qty": 10 
              },
              {
                "sale_no": "3",
                "inco": "02001365",
                "qty": 10 
              }
            ]
        }
 
    ôf9e°‹U_:
       V2.0 HAN 20250402  ãNxĉƒ
--]]
 
wms_base = require( "wms_base" )
 
function main(strLuaDEID)
    local nRet, strRetInfo, inputData
 
 
    -- ·ƒÖS¥cãS OeQ„vpenc
    nRet, inputData = m3.GetSysDataJson(strLuaDEID)
    if (nRet ~= 0) then
        lua.Stop(strLuaDEID, "àeÕl·ƒÖSpencS datajson!")
        return
    end
 
    -- ŒšÁ‹egn{|‹W0ûy“^¡‹RUS÷SŒTUSnc{|‹W
    if (inputData.source == nil or inputData.source == '') then
        lua.Stop(strLuaDEID, "egn{|‹W Ný€:Nzz!")
        return
    end
    if (inputData.order_no == nil or inputData.order_no == '') then
        lua.Stop(strLuaDEID, "úQ“^US÷S Ný€:Nzz!")
        return
    end
    if (inputData.order_type == nil or inputData.order_type == '') then
        lua.Stop(strLuaDEID, "USnc{|‹W Ný€:Nzz!")
        return
    end
 
    -- ågâ‹/f&Tò]X[(Wøv T„vúQ“^US
    local strCondition = "S_NO = '" .. inputData.order_no .. "'"
    local nRet, strRetInfo = mobox.existThisData(strLuaDEID, "Outbound_Order", strCondition)
    if (nRet ~= 0) then
        lua.Stop(strLuaDEID, "Œ(u¹eÕl existThisData úQ•: " .. strRetInfo)
        return
    end
    if (strRetInfo == 'yes') then
        lua.Stop(strLuaDEID, "úQ“^US'" .. inputData.order_no.."' ò]Ï~X[(W!")
        return
    end
 
    -- Rú^úQ“^US°‹U_
    local outbound_order = m3.AllocObject(strLuaDEID, "Outbound_Order")
    
    outbound_order.no = inputData.order_no    -- úQ“^US÷S
    outbound_order.total_qty = 0
    outbound_order.good_type_num = 0
    outbound_order.bs_type = "úQ“^US"
    nRet, outbound_order.wh_code = wms_base.Get_sConst2(strLuaDEID, "؞¤‹ÓN“^hƋ")               --ÓN“^
    if ( nRet ~= 0 ) then
        lua.Stop( strLuaDEID, "û|ß~àeÕl·ƒÖS8^ϑ'؞¤‹ÓN“^hƋ'")
        return
    end  
    nRet, outbound_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  
 
    outbound_order.create_method = "JW-WMS"
 
    
    local item
    local outbound_detail
    local material
    local total_weight = 0
    local total_volume = 0
    -- 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, ",{ " .. n .. " *NFUÁT„vFUÁTx inco  Ný€:Nzz" )
            return
        end
        if (item.qty == nil or item.qty <= 0) then
            lua.Stop(strLuaDEID, ",{ " .. n .. " *NFUÁT„vpeϑ qty Å_{˜'YŽN 0")
            return 
        end
 
        -- Àhågir™eáOo`/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
            -- ågâ‹ir™eáOo`
            nRet, material = GetDataObjByCondition(strLuaDEID, "Material", strCondition)
            if (nRet ~= 0) then
                lua.Stop(strLuaDEID, debug.getinfo(1), "·ƒÖSir™eáOo`1Y% ÿFUÁTxÿ" .. item.inco)
                return
            end
 
            -- Rú^úQ“^USfÆ~°‹U_
            outbound_detail = m3.AllocObject(strLuaDEID, "Outbound_Detail")
            outbound_detail.oo_no = inputData.order_no         -- ¾‹núQ“^US÷S
            outbound_detail.item_code = material.item_code      -- ¾‹nir™ex
            outbound_detail.item_name = material.item_name      -- ¾‹nir™e Tðy
            outbound_detail.qty = item.qty                      -- ¾‹nir™epeϑ
            outbound_detail.volume = material.volume            -- ¾‹nSOïy
            outbound_detail.weight = material.weight            -- ¾‹n͑ϑ
 
            -- Rú^úQ“^USfÆ~°‹U_
            nRet, outbound_detail = m3.CreateDataObj(strLuaDEID, outbound_detail)
            if (nRet ~= 0) then
                lua.Stop(strLuaDEID, debug.getinfo(1), "Rú^úQ“^USfÆ~°‹U_1Y% ÿFUÁTxÿ" .. item.inco)
                return
            end
 
            -- ôf°eãb'US„vGl;`penc
            outbound_order.good_type_num = outbound_order.good_type_num + 1
            outbound_order.total_qty = outbound_order.total_qty + item.qty
            -- SOïyŒT͑ϑ„v/} R ÿ    cÏk*NFUÁT„vpeϑŒTSOïy0͑ϑۏLˆ¡‹—{
            total_weight = total_weight + (material.weight * item.qty)  -- US*NFUÁT„v͑ϑ * peϑ
            total_volume = total_volume + (material.volume * item.qty)  -- US*NFUÁT„vSOïy * peϑ
 
        else
            lua.Stop(strLuaDEID, "ir™ex NX[(W ÿFUÁTxÿ" .. item.inco)
            return
        end
    end
 
    -- \Gl;`„v;`͑ϑŒT;`SOïyûm R0Rãb'US°‹U_
    outbound_order.total_weight = total_weight  -- ¾‹n;`͑ϑ
    outbound_order.total_volume = total_volume  -- ¾‹n;`SOïy
 
    -- Rú^úQ“^US°‹U_
    nRet, outbound_order = m3.CreateDataObj(strLuaDEID, outbound_order)
    if (nRet ~= 0) then
        lua.Stop( strLuaDEID, "Rú^úQ“^US°‹U_1Y%ÿ" .. outbound_order )
        return
    end
 
    -- “úQbŸRáOo`
    mobox.setInfo(strLuaDEID, "bŸR!!")
    local result = 
    {
        err_code = 0,
        err_meg = "úQ“^bŸR"
    }
 
    mobox.returnValue(strLuaDEID, 1, table2str(result))
end