fy36
2025-05-30 d63516d67a13061977c1c7851f069f8c5a438466
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
--[[
    编码: JX-29-14
    名称: 盘点容器货品明细-盘点任务完成
    作者:HAN  
    日期:2025-1-29
 
    级别:项目
    
    函数: SetCountTaskFinish
    功能:
        -- 创建 【盘点回库】作业    
 
    更改记录:
        V2.0 HAN 20250210
             任务完成后刷新改进
--]]
 
jx_base= require( "jx_base" )
wms_count= require( "wms_count" )
 
function SetCountTaskFinish ( strLuaDEID ) 
    local nRet, strRetInfo
 
    m3.PrintLuaDEInfo(  strLuaDEID )
    local runtime_parameter
    nRet, runtime_parameter = m3.GetRuntimeParam(strLuaDEID)
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "GetRuntimeParam失败! "..runtime_parameter ) end
    -- 获取【组盘输入】面板的参数
    local parameter
    nRet, parameter = m3.GetRuntimePanel_InputParamter( strLuaDEID, runtime_parameter.panel, "盘点输入" )
    if ( nRet == 1 ) then 
        mobox.setInfo( strLuaDEID, "没有定义'盘点输入'面板参数!")
        return 
    end
 
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), parameter ) end 
    if ( parameter == nil ) then return end
    local id = parameter.id             -- 当前点中的盘点任务标识(Count_CG_Detail)
    local cc_no = parameter.cc_no       -- 当前点中的盘点任务所属盘点容器流水号
    if ( cc_no == nil or cc_no == "") then
        mobox.setInfo( strLuaDEID, "'盘点输入'面板必须有盘点容器流水号参数!")
        return         
    end
    -- 获取 实际盘点数量
    nRet, strRetInfo = mobox.getCurEditDataObjAttr( strLuaDEID, "F_ACT_QTY" ) 
 
    if ( nRet ~= 0 )  then lua.Error( strLuaDEID, debug.getinfo(1), "获取当前编辑属性失败! "..strRetInfo ) end 
    local obj_attrs = json.decode( strRetInfo ) 
    local acc_qty = lua.Get_NumAttrValue( obj_attrs[1].value )  
    if ( acc_qty < 0 ) then
        mobox.setInfo( strLuaDEID, "盘点数量不能为负数!")
        return         
    end
  
    -- 设置【盘点容器货品明细】状态 = 2(已盘点)
    local strCondition = "S_ID = '"..id.."'"
    local strUpdateSql = "N_B_STATE = 2, F_ACT_QTY = "..acc_qty
    nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Count_CG_Detail", strCondition, strUpdateSql )
    if ( nRet ~= 0 ) then  lua.Error( strLuaDEID, debug.getinfo(1), "更新【盘点容器货品明细】信息失败!"..strRetInfo ) end  
 
 
    -- 检查一下当前料箱的盘点任务是否已经全部完成,如果完成就创建一个【盘点回库】作业
    -- N_B_STATE = 1 表示未执行的盘点任务  这里 parameter.count_no 就是盘点单号
    strCondition = "S_CNTR_CODE = '"..parameter.cntr_code.."' AND N_B_STATE = 1 AND S_COUNT_NO = '"..parameter.count_no.."'"       
    nRet, strRetInfo = mobox.getDataObjCount( strLuaDEID, "Count_CG_Detail", strCondition )
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), strRetInfo ) end 
    local nCount = lua.StrToNumber( strRetInfo )  
 
    -- V2.0
    -- 当前容器中的已经不存在未盘点的盘点任务
    local action = {
        {
            action_type = "refresh_master_panel",
            value = {
                sub_page = {"当前任务","未执行任务"}
            }
        },
        {
            action_type = "set_dlg_attr",
            value = {  
                        { attr = "UPC", value = "", enable = true, prompt = "请扫商品条码..."  },
                        { attr = "S_CNTR_CODE", value = "", enable = false },
                        { attr = "S_CELL_NO", value = "", enable = false },
                        { attr = "S_ITEM_CODE", value = "", enable = false },
                        { attr = "F_QTY", value = "", enable = false },
                        { attr = "F_ACT_QTY", value = "", enable = false },
                        { attr = "S_ITEM_NAME", value = "", enable = false }
                    }       
        },
        {
            action_type = "refresh_related_panel",
            value = {  
                        {
                            panel_name = "料格显示",
                            input_parameter = {
                                cell_no = ""
                            }
                        }  
                     }       
        }         
    }    
 
    local operation = {}    
    if ( nCount == 0 ) then
        -- 创建【料箱入库】作业. 【配盘容器】状态改为4(拣货完成), CG_Detail 减去【配盘容器明细】中的内容
        local ext_info = { cc_no = cc_no }
        nRet, operation = jx_base.Create_StorageOperation( strLuaDEID, "巨沃", parameter.station, parameter.cntr_code, "盘点回库", ext_info )
        if ( nRet ~= 0 ) then
            mobox.setInfo( strLuaDEID, operation )
            return
        end  
       
        -- 【计划盘点容器】+ 回库作业号, 状态 = 3 (已盘点)
        strUpdateSql = "S_BACK_OP_NO = '"..operation.code.."', N_B_STATE = 3"
        strCondition = "S_CC_NO = '"..cc_no.."'"
        nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "CP_Count_Container", strCondition, strUpdateSql )
        if ( nRet ~= 0 ) then  
            lua.Error( strLuaDEID, debug.getinfo(1), "更新【计划盘点容器】信息失败!"..strRetInfo ) 
        end 
        local cp_cntr  
        nRet, cp_cntr = m3.GetDataObjByCondition( strLuaDEID, "CP_Count_Container", strCondition )
        if ( nRet ~= 0 ) then  
            lua.Error( strLuaDEID, debug.getinfo(1), "获取【计划盘点容器】信息失败!"..cp_cntr ) 
        end  
 
        --盘点容器盘点完成后数据处理
        --根据 CP_Count_Container 生成 【盘点差异表】
        nRet, strRetInfo = wms_count.CountCntr_PostProcess( strLuaDEID, cp_cntr )
        if ( nRet ~= 0 ) then 
            lua.Error( strLuaDEID, debug.getinfo(1), 'wms_count.CountCntr_PostProcess 失败!'..strRetInfo ) 
        end 
 
 
        -- V2.0
        action[4] = {
            action_type = "set_master_panel_cursor",
            value = { form_name = "3055 TOP VIEW", ctrl_id = "S_CNTR_CODE", value = ""}
        }           
    end   
 
    nRet, strRetInfo = mobox.setAction( strLuaDEID, lua.table2str(action) )
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "setAction失败! "..strRetInfo..' action = '..strAction ) end 
 
    -- 【注意】如果上面的程序有产生回库作业,需要对回库作业的终点货位加入库锁
    if  ( nCount == 0 ) then
        nRet, strRetInfo = wms.wms_LockLocation(strLuaDEID, operation.end_loc_code, wms_base.Get_nConst( strLuaDEID, "锁类型-入库锁" ),
                                                "", operation.code, operation.op_def_name )
        if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "wms_LockLocation 失败!"..strRetInfo ) end     
    end   
 
end