fy36
2025-07-01 350eb5ec9163d3ea21416b1525bb80191e958071
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
--[[
    编码: WMS-56-26
    名称: 组盘明细-组盘输入-强制置满
    作者:HAN  
    日期:2025-1-29
 
    级别:固定 (说明本段代码在项目中不太会变化)
    
    函数:SetTaskFinish
    功能:
        -- 当前入库货品无法放入当前的料格,需要完成当前的入库任务,并且把多余的物料加入后续的组盘明细中,或从新
        -- 呼出空料箱
 
    更改记录:
 
--]]
wms_wh = require( "wms_wh" )
wms_cntr = require( "wms_container" )
prj_base = require( "prj_base" )
require ("jx_reallocate_emptybox")
 
function SetTaskFinish ( strLuaDEID ) 
    local nRet, strRetInfo
    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                 -- 当前点中的入库任务标识
    local pac_no = parameter.pac_no       -- 当前点中的入库任务所属组盘号
    if ( pac_no == nil or pac_no == "") then
        mobox.setInfo( strLuaDEID, "'组盘输入'面板必须有orgc_no参数!")
        return         
    end
 
    -- 通过来源单号获取入库仓库编码,呼出空料箱需要仓库编码
    local bs_type = lua.Get_StrAttrValue( parameter.bs_type )
    local bs_no = lua.Get_StrAttrValue( parameter.bs_no )
    if ( bs_type == '' ) then
        mobox.setInfo( strLuaDEID, "'组盘输入'面板必须有 bs_type 参数!")
        return           
    end
    if ( bs_no == '' ) then
        mobox.setInfo( strLuaDEID, "'组盘输入'面板必须有 bs_no 参数!")
        return           
    end
    local strCondition
    if ( bs_type == 'Inbound_Wave') then
        local inbound_wave
        strCondition = "S_WAVE_NO = '"..bs_no.."'"
        nRet, inbound_wave = m3.GetDataObjByCondition(strLuaDEID, "Inbound_Wave", strCondition )
        if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), inbound_wave ) end 
        parameter.wh_code = inbound_wave.wh_code
    else
        mobox.setInfo( strLuaDEID, "系统目前不支持对来源类型 = "..bs_type.." 的入库任务进行强制置满操作!")
        return            
    end   
    if ( '' == parameter.wh_code ) then
        mobox.setInfo( strLuaDEID, "强制置满操作置满前无法确定料箱仓库编码!")
        return            
    end
 
    -- 获取当前计划入库任务装箱数量
    nRet, strRetInfo = mobox.getCurEditDataObjAttr( strLuaDEID, "F_QTY", "F_ACT_QTY", "S_ITEM_CODE" ) 
    if ( nRet ~= 0 )  then lua.Error( strLuaDEID, debug.getinfo(1), "获取当前编辑属性失败! "..strRetInfo ) end 
    local obj_attrs = json.decode( strRetInfo ) 
    local qty = lua.Get_NumAttrValue( obj_attrs[1].value )  
    local act_qty = lua.Get_NumAttrValue( obj_attrs[2].value )  
    local item_code = lua.Get_StrAttrValue( obj_attrs[3].value )  
    local cancel_qty = qty-act_qty
 
    if ( qty == 0 ) then return end
 
    if ( lua.equation( 0, cancel_qty ) or cancel_qty < 0 ) then
        mobox.setInfo( strLuaDEID, "装箱数量已经满足不需要用强制置满操作!")
        return          
    end
 
    -- 设置【组盘明细】状态 = 2(组盘完成)
    local strCondition = "S_ID = '"..id.."'"
    local strUpdateSql = "C_FORCED_FILL = 'Y', N_B_STATE = 2, F_ACT_QTY = "..act_qty..", F_QTY = "..act_qty
    nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Pre_Alloc_CNTR_Detail", strCondition, strUpdateSql )
    if ( nRet ~= 0 ) then  lua.Error( strLuaDEID, debug.getinfo(1), "更新【组盘明细】信息失败!"..strRetInfo ) end  
 
    -- 剩余的放不下的货品重新计算一个料格,原则如下:
    -- 1# 从本入库波次呼出的料箱格中找到同货品编码的料格,检查一下是否可以放下
    -- 2# 从本入库波次呼出的料箱格中找一下是否有空料格能放下货品
    -- 3# 如果上面1,2都无法满足,从新呼出一个空料箱
    -- 获取 item 的基础信息
    local material
    nRet, material = m3.GetDataObjectByKey(strLuaDEID, "SKU", "S_ITEM_CODE", item_code )
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "获取货品信息失败!"..material ) end
    local item = {
        item_code = item_code,
        item_name = material.item_name,
        cell_type = material.cell_type,
        weight = material.weight,
        volume = material.volume,
        qty = cancel_qty,
        alloc_qty = 0
    }  
    nRet, strRetInfo = JX_Reallocate_EmptyBox( strLuaDEID, parameter, item, parameter.cntr_code )
    if ( nRet ~= 0 ) then  
        mobox.stopProgram( strLuaDEID, "重新给货品分配料箱时出错!"..strRetInfo )
        return
    end
 
    local action
    nRet, action = prj_base.Pre_Alloc_CNTR_PostProcess( strLuaDEID, pac_no, parameter.station, parameter.cntr_code )
    if ( nRet ~= 0 ) then 
        lua.Stop( strLuaDEID,  "Pre_Alloc_CNTR_PostProcess 失败!"..action )
        return
    end
 
    nRet, strRetInfo = mobox.setAction( strLuaDEID, lua.table2str(action) )
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "setAction失败! "..strRetInfo..' action = '..strAction ) end 
 
  
end