1
Jianw
9 天以前 70f29da38121b9a467841253e3268feb5df02902
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
--[[
    编码: JX-16-09
    名称: 盘点计划-查询面板-确定后
    作者: HAN  
    日期: 2025-1-29
 
    级别: 项目
    来源: WMS-16-09
    
    函数: ClickOK
 
    功能:
       -- 获取查面板中输入的 盘点类型,仓库,库区等信息
       -- 货位 result_grid中选择的数据对象
       -- 创建盘点计划
 
    更改记录:
        V2.0 HAN 20250212
             -- 因为增加“全选”,改进了程序结构
--]]
 
jx_base = require( "jx_base" )
wms_wh = require( "wms_wh" )
 
-- 创建货品盘点
local function create_cp_good( strLuaDEID, count_plan, obj )
    local nRet, strRetInfo
    local cp_good = m3.AllocObject(strLuaDEID,"CP_Good_List")
    cp_good.cp_no = count_plan.cp_no
    cp_good.item_code = obj.item_code
    cp_good.item_name = obj.item_name
    cp_good.qty = obj.qty
 
    -- check
    -- 判断一下查询结果 Grid 中设置的 属性 是否足够支撑创建 CP_Good_List            
    if ( obj.item_code == nil) then 
        return 2, "数据类标识 = "..result_cls_id.." 的选择结果Grid中没有定义 S_ITEM_CODE 属性" 
    end
    if ( obj.item_name == nil) then 
        return 2, "数据类标识 = "..result_cls_id.." 的选择结果Grid中没有定义 S_ITEM_NAME 属性"
    end
    if ( obj.qty == nil) then 
        return 2, "数据类标识 = "..result_cls_id.." 的选择结果Grid中没有定义 F_QTY 属性" 
    end 
    nRet, cp_good = m3.CreateDataObj( strLuaDEID, cp_good )
    if (nRet ~= 0) then return 2, cp_good end
    
    return 0
end
 
-- 创建货位盘点
local function create_cp_location( strLuaDEID, count_plan, obj )
    local nRet, strRetInfo, loc
    nRet, loc = wms_wh.GetLocInfo( obj.code)
    if ( nRet ~= 0 )  then return 2, "WMS_GetLocInfo失败! "..loc end
 
    local cp_location = m3.AllocObject(strLuaDEID,"CP_Location_List")
    cp_location.cp_no = count_plan.cp_no
    cp_location.loc_code = obj.code
    cp_location.wh_code = loc.wh_code
    cp_location.area_code = loc.area_code
    -- check
    -- 判断一下查询结果 Grid 中设置的 属性 是否足够支撑创建 CP_Good_List            
    if ( obj.code == nil) then 
        return 2, "数据类标识 = "..result_cls_id.." 的选择结果Grid中没有定义 S_CODE 属性"
    end
    nRet, cp_location = m3.CreateDataObj( strLuaDEID, cp_location )
    if (nRet ~= 0) then return 2, cp_location end  
    
    return 0
end
 
-- 创建容器盘点
local function create_cp_count_cntr( strLuaDEID, count_plan, obj )
    local nRet, strRetInfo
 
    local cp_count_cntr = m3.AllocObject( strLuaDEID, "CP_Count_Container" )
    cp_count_cntr.cp_no = count_plan.cp_no
    cp_count_cntr.cntr_code = obj.code
    nRet, cp_count_cntr = m3.CreateDataObj( strLuaDEID, cp_count_cntr )
    if (nRet ~= 0) then return 2, cp_count_cntr end  
    
    return 0
end
 
 
function ClickOK( strLuaDEID ) 
    local nRet, strRetInfo
    local area_code
 
    -- 获取 库区编码,盘点类型
    nRet, strRetInfo = mobox.getCurEditDataObjAttr( strLuaDEID, "S_AREA_CODE", "N_TYPE", "S_WH_CODE", "SelectAll" ) 
    if ( nRet ~= 0 )  then lua.Error( strLuaDEID, debug.getinfo(1), "获取当前编辑属性失败! "..strRetInfo ) end 
    local obj_attrs = json.decode( strRetInfo ) 
    local area_code = lua.Get_StrAttrValue( obj_attrs[1].value )
    local count_type = lua.Get_NumAttrValue( obj_attrs[2].value )  
    local wh_code = lua.Get_StrAttrValue( obj_attrs[3].value )
 
    -- 根据 盘点类型 来创建盘点计划的主表和 盘点货品/盘点容器
    local count_plan = m3.AllocObject(strLuaDEID,"Count_Plan")
    count_plan.type = count_type
    count_plan.wh_code = wh_code
    count_plan.area_code = area_code
    nRet, count_plan = m3.CreateDataObj( strLuaDEID, count_plan )
    if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), count_plan ) end   
    local obj
    local result_cls_id = ""
 
    -- V2.0
    local select_all = lua.Get_StrAttrValue( obj_attrs[4].value )
    -- 如果是全选需要根据查询条件来获取选择结果,而不是通过面板中的选择结果面板
    if ( select_all == "全选" ) then
        local strCondition, ret_condition_type
 
        nRet, ret_condition_type, strCondition = jx_base.Get_CountPlan_QueryPanel_Condition( strLuaDEID, false )
        if ( nRet == 1 ) then 
            mobox.setInfo( strLuaDEID, strCondition ) 
            return
        end
        if ( nRet > 1 ) then
            mobox.stopProgram( strLuaDEID, strCondition )
            return
        end
        -- 根据盘点类型及返回的strCondition查询数据对象
        if ( count_type == wms_base.Get_nConst(strLuaDEID, "盘点类型-货品盘点")) then
            if  ( area_code == '' ) then
                result_cls_id = "WH_Inventory"
            else
                result_cls_id = "AZ_Inventory"
            end            
        elseif ( count_type == wms_base.Get_nConst(strLuaDEID, "盘点类型-货位盘点")) then
            result_cls_id = "Location"
        else
            result_cls_id = "Container"
        end
 
        -- 查询(要支持分页查询)
        nRet, strRetInfo = mobox.queryDataObjAttr2( strLuaDEID, result_cls_id, strCondition, "", 100 )
        if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "查询'"..result_cls_id.."'数据失败!"..strRetInfo) end
        if ( strRetInfo ~= '' ) then
            local queryInfo = json.decode(strRetInfo)
            local queryID = queryInfo.queryID
            local nPageCount = queryInfo.pageCount
            local nPage = 1
            local dataSet = queryInfo.dataSet
 
            while (nPage <= nPageCount) do
                strChgItem = ''
                for n = 1, #dataSet do
                    nRet, obj = m3.ObjAttrStrToLuaObj( result_cls_id, lua.table2str(dataSet[n].attrs) )
                    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "m3.ObjAttrStrToLuaObj 失败! "..obj ) end
                    if ( count_type == wms_base.Get_nConst(strLuaDEID, "盘点类型-货品盘点")) then
                        nRet, strRetInfo = create_cp_good( strLuaDEID, count_plan, obj )
                        if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "create_cp_good 失败! "..strRetInfo ) end                        
                    elseif ( count_type == wms_base.Get_nConst(strLuaDEID, "盘点类型-货位盘点")) then
                        nRet, strRetInfo = create_cp_location( strLuaDEID, count_plan, obj )
                        if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "create_cp_location 失败! "..strRetInfo ) end                        
                    else
                        nRet, strRetInfo = create_cp_count_cntr( strLuaDEID, count_plan, obj )
                        if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "create_cp_count_cntr 失败! "..strRetInfo ) end                        
                    end 
                end
 
                nPage = nPage + 1
                if ( nPage <= nPageCount ) then
                    -- 取下一页
                    nRet, strRetInfo = mobox.queryDataObjAttr2( queryID, nPage)
                    if ( nRet ~= 0 ) then
                        lua.Error( strLuaDEID, debug.getinfo(1), "查询【库区量表】失败! nPage="..nPage.."  "..strRetInfo )
                    end 
                    queryInfo = json.decode(strRetInfo) 
                    dataSet = queryInfo.dataSet              
                end
            end
        else
            mobox.stopProgram( strLuaDEID, "在创建盘点计划前,必须选中要盘点的对象!") 
            return            
        end        
        
    else
        -- 获取选择结果
        local result_obj
        nRet, result_obj = m3.GetSysDataJson( strLuaDEID )
        if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), result_obj ) end   
        local n, nCount 
 
        nCount = #result_obj
        if ( nCount == 0 ) then 
            mobox.stopProgram( strLuaDEID, "在创建盘点计划前,必须选中要盘点的对象!") 
            return
        end
 
        if ( count_type == wms_base.Get_nConst(strLuaDEID,"盘点类型-货品盘点")) then
            -- 创建【计划盘点货品】
            if  ( area_code == '' ) then
                result_cls_id = "WH_Inventory"
            else
                result_cls_id = "AZ_Inventory"
            end
            for n = 1, nCount do
                nRet, obj = m3.ObjAttrStrToLuaObj( result_cls_id, lua.table2str(result_obj[n].attrs) )
                if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "m3.ObjAttrStrToLuaObj 失败! "..obj ) end
                nRet, strRetInfo = create_cp_good( strLuaDEID, count_plan, obj )
                if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "create_cp_good 失败! "..strRetInfo ) end
            end
        elseif ( count_type == wms_base.Get_nConst(strLuaDEID,"盘点类型-货位盘点")) then
            -- 创建【计划盘点货位】
            result_cls_id = "Location"
            for n = 1, nCount do
                nRet, obj = m3.ObjAttrStrToLuaObj( result_cls_id, lua.table2str(result_obj[n].attrs) )
                if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "m3.ObjAttrStrToLuaObj 失败! "..obj ) end
                nRet, strRetInfo = create_cp_location( strLuaDEID, count_plan, obj )
                if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "create_cp_location 失败! "..strRetInfo ) end
            end  
        else
            -- V2.0   容器盘点  
             -- 创建【计划盘点容器】
            result_cls_id = "Container" 
            for n = 1, nCount do
                nRet, obj = m3.ObjAttrStrToLuaObj( result_cls_id, lua.table2str(result_obj[n].attrs) )
                if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "m3.ObjAttrStrToLuaObj 失败! "..obj ) end
                nRet, strRetInfo = create_cp_count_cntr( strLuaDEID, count_plan, obj )
                if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "create_cp_count_cntr 失败! "..strRetInfo ) end
            end            
        end
    end
 
    local action = {
        {
            action_type = "refresh",
            value = ""
        }
    }
    nRet, strRetInfo = mobox.setAction( strLuaDEID, lua.table2str(action) )
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "setAction错误: "..strRetInfo) end       
end