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
ÿþ--[[ 
    x: WMS-300-24.1
     Tðy: Øv¹p¡‹R Tek
    \O€: KUN
    åeg: 2025-1-29
 
    eQãSýQpeÿ CountingPlan_Sync
    egny˜îv:  è]fŒNg™e±{“^
 
    ŸRý€ô‹f:
        1. ¥c6eegê
N8nû|ß~„v JSON <h_penc ÿv^㉐gå‹penc0
        2. ŒšÁ‹Øv¹p¡‹R÷SŒTFUÁTfÆ~/f&TX[(W0(N,‚ý/f'ÁTØv¹p)
        3. 9hncFUÁTxÎNir™ehˆ-Någâ‹øvsQáOo`0
        4. Rú^Øv¹p¡‹RÊSØv¹pUS°‹U_ ÿv^ûm RÅ_‰„vW[µk0
        
        {
          "plan_no": "SK10001",
          "items":
            [
              {
                "inco": "900000016"
              },
               {
                "inco": "900000015"
              }
            ]
        }
 
    ô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
 
    -- ÀhågØv¹p¡‹R÷S
    if (inputData.plan_no == nil or inputData.plan_no == "") then
        lua.Stop(strLuaDEID, "Øv¹p¡‹R÷S Ný€:Nzz")
        return
    end
    if (inputData.items == nil or #inputData.items == 0) then
        lua.Stop(strLuaDEID, "Øv¹pfÆ~Rhˆ Ný€:Nzz")
        return
    end
 
    local cp_no = inputData.plan_no                     --Øv¹p¡‹R÷S
    
    -- ŒšÁ‹Øv¹p¡‹R/f&Tò]X[(W
    local strCondition = "S_CP_NO = '" .. cp_no .. "'"
    local nRet, exists = mobox.existThisData(strLuaDEID, "JX_Count_Plan", strCondition)
    if (nRet ~= 0) then
        lua.Stop(strLuaDEID, "Œ(uexistThisDataöeúQ•")
        return
    end
 
    if (exists == 'yes') then
        lua.Stop(strLuaDEID, "Øv¹p¡‹Rò]X[(W: " .. inputData.plan_no)
        return
    end
 
    -- Rú^Øv¹p¡‹R°‹U_
    local count_plan = m3.AllocObject(strLuaDEID, "Count_Plan")
    count_plan.cp_no = inputData.plan_no        -- Øv¹p¡‹R÷S
    count_plan.plan_total = #inputData.items    -- ¡‹RØv¹p„vFUÁTpeϑ
    count_plan.s_type = "'ÁTØv¹p"
    count_plan.type = 1                         -- 1 'ÁTØv¹p
    nRet, count_plan.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, count_plan = m3.CreateDataObj(strLuaDEID, count_plan)
    if (nRet ~= 0) then
        lua.Stop(strLuaDEID, "Rú^Øv¹pUS°‹U_1Y%! "..count_plan)
        return 
    end
    
    local item_code
    local cntr_list
    local wh_code,f_qty,item_name
    local count_order
 
    for i = 1, #inputData.items do
        item_code = inputData.items[i].inco
 
        strCondition = "S_ITEM_CODE = '" .. item_code .. "' "
        nRet, cntr_list = m3.QueryDataObject(strLuaDEID, "WH_Inventory", strCondition)--    cgqir™ex»Såg~bÓN“^ϑhˆ ÖSúQ“^X[peϑ
    
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖSáOo`1Y%!" .. cntr_list)
        end
 
        wh_code = m3.KeyValueAttrsToObjAttr(cntr_list[1].attrs)
        f_qty = wh_code.F_QTY           --“^X[peϑ
        item_name = wh_code.S_ITEM_NAME --ir™e Tðy
        lua.Debug(strLuaDEID, debug.getinfo(1), "wh_code:", wh_code)
 
        -- Rú^¡‹RØv¹p'ÁT
        count_order = m3.AllocObject(strLuaDEID, "CP_Good_List")
        count_order.cp_no = inputData.plan_no   -- Øv¹p¡‹R÷S
        count_order.qty = f_qty                 -- “^X[peϑ
        count_order.item_code = item_code       -- ir™ex
        count_order.item_name = item_name       -- ir™e Tðy
 
        nRet, strRetInfop = m3.CreateDataObj(strLuaDEID, count_order)
        if (nRet ~= 0) then
            lua.Error(strLuaDEID, debug.getinfo(1), "Rú^Øv¹pUS°‹U_1Y%")
        end
        
    end
 
    -- ÔÞVbŸRˆmo`
    mobox.setInfo(strLuaDEID, "Øv¹p¡‹RŒTØv¹pUSRú^bŸR")
 
    -- “úQbŸRáOo`
    mobox.setInfo(strLuaDEID, "bŸR!!")
    local result = 
    {
        err_code = 0,
        err_meg = "Øv¹pbŸR!"
    }
 
    mobox.returnValue(strLuaDEID, 1, table2str(result))
end