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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
--[[
    编码:  WMS-56-28
    名称:  组盘明细-超重处理-保存
    作者: HAN  
    日期: 2025-3-9
 
    级别: 项目
    
    函数: Overweight_Save
    功能:
        -- 在做巨沃的入库任务时,料箱超重退回后,在超重组盘输入界面中拣出一定数量货品后,点保存按钮
        -- 点保存按钮后,系统需要处理
        --   重新计算 CG_Detail 中货品数量,如果=0 删除
        --   从新计算 Pre_Alloc_CNTR_Detail 中 F_ACT_QTY(实际装箱数量)  
        --   新增【站台货品明细】记录
 
    更改记录:
--]]
wms_wh = require( "wms_wh" )
wms_cntr= require( "wms_container" )
jx_base= require( "jx_base" )
 
function Overweight_Save ( 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       -- 当前点中的入库任务所属组盘号
    local station = parameter.station
 
    if ( pac_no == nil or pac_no == "") then
        mobox.setInfo( strLuaDEID, "'组盘输入'面板必须有orgc_no参数!")
        return         
    end
    if ( station == nil or station == "") then
        mobox.setInfo( strLuaDEID, "'组盘输入'面板必须有station参数!")
        return         
    end
 
    -- 获取当前计划入库任务装箱数量
    nRet, strRetInfo = mobox.getCurEditDataObjAttr( strLuaDEID, "F_QTY", "F_ACT_QTY" ) 
    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 cancel_qty = qty-act_qty
 
    if ( qty == 0 ) then return end
    -- V2.0
    if ( act_qty > qty ) then
        mobox.setInfo( strLuaDEID, "入库数量不能大于计划数量!")
        return         
    end
 
    -- 获取原来组盘明细中的实际入库数量
    local org_cntr_detail
    nRet, org_cntr_detail = m3.GetDataObjectByKey(strLuaDEID, "Pre_Alloc_CNTR_Detail", "S_ID", id)
    if (nRet ~= 0 ) then 
        mobox.stopProgram( strLuaDEID, "获取'Pre_Alloc_CNTR_Detail'信息失败! " .. org_cntr_detail ) 
        return
    end    
    if ( org_cntr_detail.act_qty == act_qty ) then 
        -- 和以前数据对比并没有拣出货品
        return 
    end
    if ( act_qty > org_cntr_detail.act_qty ) then
        -- 和以前数据对比实际入库数量增加,报错
        mobox.setInfo( strLuaDEID, "入库货品数量大于原入库数量,不符号超重拣出逻辑!")
        return          
    end
 
    -- 计算出超重拣出货品数量 qty
    local qty = org_cntr_detail.act_qty - act_qty
 
    -- 设置【组盘明细】中的实际入库数量
    local strCondition = "S_ID = '"..id.."'"
    local strUpdateSql = "F_ACT_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  
 
    -- 设置CG_Detail中货品数量
    strCondition = "S_ITEM_CODE = '"..org_cntr_detail.item_code.."' AND S_BATCH_NO = '"..org_cntr_detail.batch_no.."'"..
                   "AND S_CNTR_CODE = '"..org_cntr_detail.cntr_code.."' AND S_CELL_NO = '"..org_cntr_detail.cell_no.."'"
    local strOrder = ""           
    nRet, strRetInfo = wms_cntr.Reduce_CG_Detail_Qty( strLuaDEID, org_cntr_detail.cntr_code, strCondition, strOrder, qty )
    if ( nRet ~= 0 ) then
        mobox.stopProgram( strLuaDEID, strRetInfo ) 
        return        
    end
    local container
    nRet, container = wms_cntr.GetInfo( strLuaDEID, org_cntr_detail.cntr_code )
    if ( nRet ~= 0  ) then lua.Error( strLuaDEID, debug.getinfo(1), "wms_cntr.GetInfo 失败!"..container ) end  
    if ( container == '' ) then
        mobox.stopProgram( strLuaDEID, "料箱号='"..org_cntr_detail.cntr_code.."'的料箱不存在!" ) 
        return     
    end
    nRet, strRetInfo = wms_cntr.Reset( strLuaDEID, container )
    if ( nRet ~= 0 ) then
        mobox.stopProgram( strLuaDEID, strRetInfo ) 
        return        
    end
 
    -- 新增【站台货品明细】
    local sg_detail
    sg_detail = m3.AllocObject(strLuaDEID,"Station_Goods_Detail")
 
    sg_detail.station_no = station
    sg_detail.from_op = "Overweight-Pick-Out"           -- 数据来源超重拣出
 
    sg_detail.serial_no = org_cntr_detail.serial_no
    sg_detail.item_code = org_cntr_detail.item_code
    sg_detail.item_name = org_cntr_detail.item_name
    sg_detail.batch_no = org_cntr_detail.batch_no
    sg_detail.item_spec = org_cntr_detail.item_spec
    sg_detail.item_state = org_cntr_detail.item_state
    sg_detail.end_user = org_cntr_detail.end_user
    sg_detail.owner = org_cntr_detail.owner      
    sg_detail.supplier = org_cntr_detail.supplier
    sg_detail.erp_wh_code = org_cntr_detail.erp_wh_code
 
    sg_detail.bs_no = org_cntr_detail.bs_no    
    sg_detail.bs_type = org_cntr_detail.bs_type    
    sg_detail.bs_row_no = org_cntr_detail.bs_row_no    
 
    sg_detail.ext_attr1 = org_cntr_detail.ext_attr1
    sg_detail.ext_attr2 = org_cntr_detail.ext_attr2
    sg_detail.ext_attr3 = org_cntr_detail.ext_attr3
    sg_detail.ext_attr4 = org_cntr_detail.ext_attr4
    sg_detail.ext_attr5 = org_cntr_detail.ext_attr5
                
    sg_detail.qty = qty                               
    sg_detail.uom = org_cntr_detail.uom 
 
    nRet, sg_detail = m3.CreateDataObj( strLuaDEID, sg_detail )   
    if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "创建【Station_Goods_Detail】失败!"..sg_detail) end 
    
    local action = {
        {
            action_type = "refresh_master_panel",
            value = {
                sub_page = {"站台超重货品明细"}
            }
        }
    }
    nRet, strRetInfo = mobox.setAction( strLuaDEID, lua.table2str(action) )
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "setAction失败! "..strRetInfo..' action = '..strAction ) end 
 
end