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
--[[
    编码: WMS-31-12
    名称: 盘点差异-复盘
    作者:HAN  
    日期:2025-1-29
 
    级别:固定 (说明本段代码在项目中不太会变化)
    
    函数: RepeatCount
 
    功能:
        根据选中的盘点差异生成新的盘点单,盘点货品数量有差异的货品
 
    更改记录:
 
--]]
wms_cntr= require( "wms_container" )
wms_wh = require( "wms_wh" )
 
function RepeatCount( strLuaDEID ) 
    local   nRet, strRetInfo
 
    -- step1  获取当前点中的任务
    nRet, objs = m3.GetSysDataJson( strLuaDEID )
    if ( nRet ~=0 ) then lua.Error( strLuaDEID, debug.getinfo(1), objs ) end  
    -- [{"id":"","attrs":[{"attr":"","value":""},..]},..]
    local nCount = #objs
    if (nCount == 0) then  return end
 
    -- 获取功能点输入面板中的站台信息
    local runtime_parameter
    nRet, runtime_parameter = m3.GetRuntimeParam(strLuaDEID)
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "GetRuntimeParam失败! "..runtime_parameter ) end
    local input_panel =  runtime_parameter.inputPanelDataObj
    if  ( nil == input_panel ) then
        mobox.stopProgram( strLuaDEID, "功能点定义里缺少输入面板!")
        return 
    end
    local station = lua.Get_StrAttrValue( input_panel.Station )
    if ( "" == station ) then
        mobox.stopProgram( strLuaDEID, "站台不能为空!")
        return         
    end
 
    local count_diff    
    local count_cntr_list = {}   -- 需要盘点的容器
    local find, id
    for n = 1, nCount do
        -- 获取盘点差异对象属性
        id = lua.trim_guid_str(objs[n].id)
        nRet, count_diff = m3.GetDataObject( strLuaDEID, "Count_Diff", id )
        if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), '获取【盘点差异】对象失败!'..count_diff ) end  
        -- 盘点是否允许复盘 , 状态不能是在盘点中...
        if ( count_diff.recount == 'Y' and count_diff.b_state == 1 and count_diff.diff_move == 'N') then
            find = false
            local count_item = {
                id = id,
                item_code = count_diff.item_code,
                item_name = count_diff.item_name,
                qty = count_diff.qty,
                cell_no = count_diff.cell_no,
                item_state = count_diff.item_state,
                batch_no = count_diff.batch_no,
                serial_no = count_diff.serial_no,
                erp_wh_code = count_diff.erp_wh_code,
                end_user = count_diff.end_user,
                supplier = count_diff.supplier,
                ext_attr1 = count_diff.ext_attr1,
                ext_attr2 = count_diff.ext_attr2,
                ext_attr3 = count_diff.ext_attr3,
                ext_attr4 = count_diff.ext_attr4,
                ext_attr5 = count_diff.ext_attr5,
                cg_detail_id = count_diff.cg_detail_id,
                item_spec = count_diff.item_spec,
                uom = count_diff.uom
            }
 
            for m = 1, #count_cntr_list do
                if ( count_cntr_list[m].cntr_code == count_diff.cntr_code ) then
                    table.insert( count_cntr_list[m].count_item_list, count_item )
                    find = true
                    break
                end
            end
            if ( find == false ) then
                local count_cntr = {
                    cntr_code = count_diff.cntr_code,
                    first_cc_no = count_diff.cc_no,
                    count_item_list = {}
                }
                table.insert( count_cntr.count_item_list, count_item )
                table.insert( count_cntr_list, count_cntr )
            end
        end
    end
    local strUpdateSql, strCondition
    nCount = #count_cntr_list
    if ( nCount == 0 ) then return end
 
    -- 创建盘点单
    local count_order = m3.AllocObject(strLuaDEID,"Count_Order")
    count_order.method = 2                  -- 2 自动出库到站点
    count_order.num = nCount
    count_order.station = station
    count_order.count_type = 3              -- 3 复盘
    count_order.diff_hand_method = 1        -- 1 不自动差异转移
    nRet, count_order = m3.CreateDataObj( strLuaDEID, count_order )   
    if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "创建【盘点单】失败!"..count_order ) end  
    
    -- 创建【计划盘点容器】
    local count_cg_detail, count_item
    local cp_count_container_list = {}
    local loc, loc_code
 
    for n = 1, nCount do
        --  获取容器所在货位
        nRet, loc_code = wms_cntr.Get_Container_Loc( strLuaDEID, count_cntr_list[n].cntr_code )
        if ( nRet ~= 0 ) then
            mobox.stopProgram( strLuaDEID, loc_code)
            return  
        end    
        if ( loc_code == '' ) then
            mobox.stopProgram( strLuaDEID, "容器'"..count_cntr_list[n].cntr_code.."'不在货位上")
            return              
        end
        nRet, loc = wms_wh.GetLocInfo( loc_code )
        if ( nRet ~= 0 ) then return 1, '获取货位信息失败! '..loc_code end   
    
 
        local cp_count_container = m3.AllocObject(strLuaDEID,"CP_Count_Container")
        cp_count_container.method = 2
        cp_count_container.station = station
        cp_count_container.loc_code = loc_code
        cp_count_container.wh_code = loc.wh_code
        cp_count_container.area_code = loc.area_code
 
        cp_count_container.count_no = count_order.count_no
        cp_count_container.cntr_code = count_cntr_list[n].cntr_code
        cp_count_container.first_cc_no = count_cntr_list[n].first_cc_no
        nRet, cp_count_container = m3.CreateDataObj( strLuaDEID, cp_count_container )
        if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), cp_count_container ) end  
        table.insert( cp_count_container_list, cp_count_container )
 
        -- 创建【盘点容器货品明细】Count_CG_Detail
        for m = 1, #count_cntr_list[n].count_item_list do
            count_cg_detail = m3.AllocObject(strLuaDEID,"Count_CG_Detail")
            count_item = count_cntr_list[n].count_item_list[m]
 
            count_cg_detail.cg_detail_id = count_item.cg_detail_id
            count_cg_detail.cc_no = cp_count_container.cc_no
            count_cg_detail.count_no = count_order.count_no
            count_cg_detail.station = station  
            count_cg_detail.cntr_code = cp_count_container.cntr_code
            count_cg_detail.cell_no = count_item.cell_no
            count_cg_detail.serial_no = count_item.serial_no
            count_cg_detail.item_code = count_item.item_code
            count_cg_detail.item_name = count_item.item_name
            count_cg_detail.batch_no = count_item.batch_no
            count_cg_detail.item_spec = count_item.item_spec
            count_cg_detail.item_state = count_item.item_state
            count_cg_detail.end_user = count_item.end_user
            count_cg_detail.owner = count_item.owner      
            count_cg_detail.supplier = count_item.supplier
 
            count_cg_detail.erp_wh_code = count_item.erp_wh_code
            count_cg_detail.ext_attr1 = count_item.ext_attr1
            count_cg_detail.ext_attr2 = count_item.ext_attr2
            count_cg_detail.ext_attr3 = count_item.ext_attr3
            count_cg_detail.ext_attr4 = count_item.ext_attr4
            count_cg_detail.ext_attr5 = count_item.ext_attr5
                        
            count_cg_detail.qty = count_item.qty                               
            count_cg_detail.uom = count_item.uom 
 
            nRet, count_cg_detail = m3.CreateDataObj( strLuaDEID, count_cg_detail )   
            if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "创建【Count_CG_Detail】失败!"..count_cg_detail) end 
            
            -- 设置【盘点差异】表记录的状态=2/复盘
            local strUpdateSql = "N_B_STATE = 2"
            strCondition = "S_ID = '"..count_item.id.."'"
            nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Count_Diff", strCondition, strUpdateSql )
            if ( nRet ~= 0 ) then  lua.Error( strLuaDEID, debug.getinfo(1), "更新【盘点差异表】信息失败!"..strRetInfo ) end                 
        end
    end
   
    -- 盘点容器生成作业
    local add_wfp
    for n = 1, #cp_count_container_list do
        -- 增加一个后台进程进行入库单完工回报
        add_wfp = {
            wfp_type = 1,                  -- 触发数据对象事件(指定数据对象标识)
            cls = "CP_Count_Container",
            obj_id = cp_count_container_list[n].id,
            obj_name = "Container No '"..cp_count_container_list[n].cntr_code.."'-->Create stocktaking outbound operation",
            trigger_event = "CreateStocktakingOutOperation"
        }
 
        nRet, strRetInfo = m3.AddSysWFP( strLuaDEID, add_wfp )
        if ( nRet ~= 0 ) then 
            wms.wms_AbortCntrLockTrans( count_order.count_no ) 
            lua.Error( strLuaDEID, debug.getinfo(1), "AddSysWFP失败!"..strRetInfo )  
        end         
        -- step6: 给容器加盘点锁 4 -- 盘点锁
        nRet, strRetInfo = wms.wms_LockCntr( cp_count_container_list[n].cntr_code, 4, count_order.count_no )
        if ( nRet ~= 0 ) then
            wms.wms_AbortCntrLockTrans( count_order.count_no ) 
            lua.Error( strLuaDEID, debug.getinfo(1), "给容器'"..cp_count_container_list[n].cntr_code.."'加盘点锁失败!")   
        end  
    end
    wms.wms_CommitCntrLockTrans( count_order.count_no )    
 
 
    local action
    if ( nCount  == 1 ) then
        action = {
            {
                action_type = "refresh_cur_row",
                value = ""
            }
        }
    else
        action = {
            {
                action_type = "refresh",
                value = ""
            }
        }        
    end
    nRet, strRetInfo = mobox.setAction(strLuaDEID, lua.table2str(action))
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "setAction错误: "..strRetInfo) end      
 
end