Jianw
2025-05-13 3b39fe3810c3ee2ec9ec97236c1769c5c85e062c
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
ÿþ--[[
    x: JX-API-05
     Tðy: Rú^ãb'USÊSfÆ~
    \O€: 
    åeg: 2025-1-29
    eQãSýQpeÿ main
    ŸRý€ô‹f:
        1. ¥c6eegê
N8nû|ß~„v JSON <h_penc ÿv^㉐gå‹penc0
        2. ŒšÁ‹egn0ãb'US÷S0USnc{|‹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ˆãb'USŒTfÆ~„vX[¨PÍd\O0
        
            “eQpenc<h_:
            {
              "source": "è]ƒlWMS",
              "wave_no": "SK10001",
              "order_type": "Rãb",
              "items":
                [
                  {
                    "sale_no": "XXXX",
                    "inco": "01001993",
                    "qty": 10 
                  },
                    {
                    "sale_no": "XXXX",
                    "inco": "04005452",
                    "qty": 10 
                  }
                ]
                ]
            }
                    
--]]
 
json = require("json")
mobox = require("OILua_JavelinExt")
wms_base = require( "wms_base" )
 
function main(strLuaDEID)
    local nRet, inputData
    local total_qty = 0  
    local good_type_num = 0
    local total_weight = 0  -- °ežXÿ;`͑ϑ
    local total_volume = 0  -- °ežXÿ;`SOïy
 
    -- ·ƒÖ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
 
    -- ŒšÁ‹egn0ãb'US÷SŒTUSnc{|‹W
    if (inputData.source == nil or inputData.source == '') then
        lua.Error(strLuaDEID, debug.getinfo(1), "egn Ný€:Nzz!")
    end
    if (inputData.wave_no == nil or inputData.wave_no == '') then
        lua.Error(strLuaDEID, debug.getinfo(1), "ãb'US÷S Ný€:Nzz!")
    end
    if (inputData.order_type == nil or inputData.order_type == '') then
        lua.Error(strLuaDEID, debug.getinfo(1), "USnc{|‹W Ný€:Nzz!")
    end
 
    -- O(uãb'US÷S\O:Någâ‹agöN ÿÀhåg/f&Tò]X[(Wøv T„vúQ“^US
    local strCondition = "S_NO = '" .. inputData.wave_no .. "'"
    local nRetl, strRetInfo = mobox.existThisData(strLuaDEID, "Outbound_Order", strCondition)
    
    if (nRetl ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "Œ(u¹eÕl existThisData úQ•: " .. strRetInfo)
    end
 
    if (strRetInfo == 'yes') then
        lua.Error(strLuaDEID, debug.getinfo(1), "úQ“^USò]X[(W ÿãb'US÷Sÿ" .. inputData.wave_no)  
    end
 
    -- Rú^ãb'US°‹U_
    local picking_order = m3.AllocObject(strLuaDEID, "Outbound_Order")
    
    picking_order.no = inputData.wave_no        -- O(uãb'US÷S
    picking_order.good_type_num = tonumber(picking_order.good_type_num)
    picking_order.total_qty = tonumber(picking_order.total_qty) 
    picking_order.create_method = "JW-WMS"
    picking_order.bs_type = "RãbUS"
    picking_order.wh_code = wms_base.Get_sConst(strLuaDEID, "؞¤‹ÓN“^hƋ")
    picking_order.area_code = wms_base.Get_sConst( strLuaDEID, "™e±{“^X[¨P:S" )
 
    lua.Debug(strLuaDEID, debug.getinfo(1), "picking_order", picking_order)
 
    local item, nRetl, strRetInfop
    local strCondition
    local material
    local picking_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.Error(strLuaDEID, debug.getinfo(1), ",{ " .. n .. " *NFUÁT„vFUÁTx inco  Ný€:Nzz")
        end
        if (item.qty == nil or item.qty <= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), ",{ " .. n .. " *NFUÁT„vpeϑ qty Å_{˜'YŽN 0")
        end
 
        -- Àhågir™eáOo`/f&TX[(W
        strCondition = "S_ITEM_CODE = '" .. item.inco .. "'"
        nRetl, strRetInfop = mobox.existThisData(strLuaDEID, "Material", strCondition)
        if (nRetl ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "Œ(u¹eÕl existThisData úQ•: " .. strRetInfop)
        end
 
        if (strRetInfop == 'yes') then
            -- ågâ‹ir™eáOo`
            
            nRet, material = GetDataObjByCondition(strLuaDEID, "Material", strCondition)
 
            if (nRet ~= 0) then
                lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖSir™eáOo`1Y% ÿFUÁTxÿ" .. item.inco)
            end
 
            -- Rú^ãb'USfÆ~°‹U_
            picking_detail = m3.AllocObject(strLuaDEID, "Outbound_Detail")
            picking_detail.oo_no = inputData.wave_no      -- ¾‹nãb'US÷S
            picking_detail.row_no = n                      -- ¾‹nLˆ÷S
            picking_detail.item_code = material.item_code  -- ¾‹nir™ex
            picking_detail.item_name = material.item_name  -- ¾‹nir™e Tðy
            picking_detail.qty = item.qty                  -- ¾‹nir™epeϑ
            picking_detail.volume = material.volume        -- ¾‹nSOïy
            picking_detail.weight = material.weight        -- ¾‹n͑ϑ
 
            lua.Debug(strLuaDEID, debug.getinfo(1), "picking_detail", picking_detail)
 
            -- Rú^ãb'USfÆ~°‹U_
            nRet, strRetInfo = m3.CreateDataObj(strLuaDEID, picking_detail)
            if (nRet ~= 0) then
                lua.Error(strLuaDEID, debug.getinfo(1), "Rú^ãb'USfÆ~°‹U_1Y% ÿFUÁTxÿ" .. item.inco)
            end
 
            -- ôf°eãb'US„vGl;`penc
            picking_order.good_type_num = picking_order.good_type_num + 1
            picking_order.total_qty = picking_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.Error(strLuaDEID, debug.getinfo(1), "ir™ex NX[(W ÿFUÁTxÿ" .. item.inco)
        end
    end
 
    -- \Gl;`„v;`͑ϑŒT;`SOïyûm R0Rãb'US°‹U_
    picking_order.total_weight = total_weight  -- ¾‹n;`͑ϑ
    picking_order.total_volume = total_volume  -- ¾‹n;`SOïy
 
    -- Rú^ãb'US°‹U_
    nRet, strRetInfo = m3.CreateDataObj(strLuaDEID, picking_order)
    
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "Rú^ãb'US°‹U_1Y%ÿ" .. strRetInfo)
    end
 
    -- “úQbŸRáOo`
    mobox.setInfo(strLuaDEID, "bŸR!!")
    
    local result = {
        err_code = 0,
        err_msg = "ãb'bŸR"
    }
 
    mobox.returnValue(strLuaDEID, 1, table2str(result))
end