--[[
|
编码:
|
名称: DeleteOutboundOrderDetail
|
作者:
|
入口函数:DeleteOutboundDetail
|
功能说明:
|
变更历史:
|
功能:
|
- 校验出库单是否为新建状态;
|
- 根据多字段删除对应明细(S_IO_NO、S_BS_NO、N_BS_ROW_NO、S_ITEM_CODE)
|
参数格式:
|
{
|
"Name": "DeleteOutboundDetail",
|
"Source": "ERP",
|
"Data": {
|
"S_NO": "CKD001",
|
"SourceKey": "",
|
"ITEMS":
|
[
|
{
|
"N_BS_ROW_NO": 10,
|
"S_BS_NO": "10",
|
"S_ITEM_CODE": "1"
|
},
|
{
|
"N_BS_ROW_NO": 2,
|
"S_BS_NO": "6",
|
"S_ITEM_CODE": "999"
|
}
|
]
|
}
|
}
|
--]]
|
function DeleteOutboundDetail(strLuaDEID)
|
local err = {}
|
local nRet, inputData = m3.GetSysDataJson(strLuaDEID)
|
if nRet ~= 0 then
|
local result = {
|
SourceKey = "",
|
err_code = 1,
|
err_msg = "无法获取数据包!" .. inputData,
|
result = nil
|
}
|
mobox.returnValue(strLuaDEID, 1, lua.table2str(result))
|
return
|
end
|
|
--local data = inputData.Data
|
local items = inputData.ITEMS
|
local s_no = inputData.S_NO --来源单号
|
|
|
if not s_no or s_no == "" or #items == 0 then
|
local result = {
|
SourceKey = "",
|
err_code = 1,
|
err_msg = "出库单号为空或无明细!" .. s_no,
|
result = nil
|
}
|
mobox.returnValue(strLuaDEID, 1, lua.table2str(result))
|
return
|
end
|
|
-- 查询入库单信息是否存在
|
local nRetl , strRetInfop
|
local OrderstrCondition = "S_BS_NO = '" .. s_no .. "'"
|
nRetl, strRetInfop = mobox.existThisData(strLuaDEID, "Outbound_Order", OrderstrCondition)
|
if (nRetl ~= 0) then
|
local result = {
|
SourceKey = "",
|
err_code = 1,
|
err_msg = "调用existThisData方法失败" .. s_no,
|
result = nil
|
}
|
mobox.returnValue(strLuaDEID, 1, lua.table2str(result))
|
return
|
end
|
if (strRetInfop ~= 'yes') then
|
local result = {
|
SourceKey = "",
|
err_code = 1,
|
err_msg = "查询对应的出库单失败" .. s_no,
|
result = nil
|
}
|
mobox.returnValue(strLuaDEID, 1, lua.table2str(result))
|
return
|
end
|
|
-- 下面两个判断,1、判断料箱库的出库单是否有非新建状态的单子,2、判断非料箱库的出库单,明细中是否有已出库数量的明细(代表非新增状态)
|
local inbound_date
|
local strCondition = "S_BS_NO = '"..s_no.."' AND N_B_STATE <> 0 AND S_AREA_CODE = '料箱库' "
|
nRet, inbound_date = m3.QueryDataObject(strLuaDEID, "Outbound_Order", strCondition)
|
if (nRet ~= 0) then
|
local result = {
|
SourceKey = "",
|
err_code = 1,
|
err_msg = "查询对应的出库单失败" .. s_no,
|
result = nil
|
}
|
mobox.returnValue(strLuaDEID, 1, lua.table2str(result))
|
return
|
end
|
if (inbound_date ~= "") then
|
local result = {
|
SourceKey = "",
|
err_code = 1,
|
err_msg = "该来源单号对应的出库单有非新建状态,不可删除" .. s_no,
|
result = nil
|
}
|
mobox.returnValue(strLuaDEID, 1, lua.table2str(result))
|
return
|
end
|
local container_data, nRet
|
local Condition = "S_OO_NO IN (SELECT S_NO FROM TN_Outbound_Order WHERE S_BS_NO = '"..s_no.."') AND F_ACC_O_QTY <> 0 "
|
nRet, container_data = m3.QueryDataObject(strLuaDEID, "Outbound_Detail", Condition)
|
if (nRet ~= 0) then
|
local result = {
|
SourceKey = "",
|
err_code = 1,
|
err_msg = "查询对应的出库单失败" .. s_no,
|
result = nil
|
}
|
mobox.returnValue(strLuaDEID, 1, lua.table2str(result))
|
return
|
end
|
if (container_data ~= "") then
|
local result = {
|
SourceKey = "",
|
err_code = 1,
|
err_msg = "该来源单号对应的出库单明细有已出库的数据,不可删除" .. s_no,
|
result = nil
|
}
|
mobox.returnValue(strLuaDEID, 1, lua.table2str(result))
|
return
|
end
|
|
|
-- 查询入库单明细是否有对应的值
|
local bs_no ,bs_row, item_code
|
local nRet , strRetInfo
|
for _, item in ipairs(items) do
|
bs_no = item.S_BS_NO
|
bs_row = item.N_BS_ROW_NO
|
item_code = item.S_ITEM_CODE
|
|
if(bs_no == nil or bs_no == "") then
|
table.insert(err, "来源单号不能为空" ..item_code)
|
end
|
if(item_code == nil or item_code == "") then
|
table.insert(err, "商品编码不能为空" ..item_code)
|
end
|
if(bs_row == nil or bs_row == "") then
|
table.insert(err, "来源单行号不能为空" ..item_code)
|
end
|
if(type(item.N_BS_ROW_NO) ~= "number") then
|
table.insert(err, "来源单行号非数字型" ..item_code)
|
end
|
|
local Condition = " S_OO_NO IN (SELECT S_NO FROM TN_Outbound_Order WHERE S_BS_NO = '"..s_no.."') AND S_BS_NO = '" .. bs_no .. "' AND N_BS_ROW_MO = " .. bs_row .. " AND S_ITEM_CODE = '" .. item_code .. "'"
|
nRet, strRetInfo = mobox.existThisData( strLuaDEID, "Outbound_Detail", Condition )
|
if ( nRet ~= 0 ) then
|
table.insert(err, "调用existThisData方法失败"..item_code)
|
end
|
if ( strRetInfo ~= "yes" ) then
|
table.insert(err, "该出库单没有这条数据"..item_code)
|
end
|
|
end
|
|
if (#err > 0) then
|
local result = {
|
SourceKey = "",
|
err_code = 1,
|
err_msg = "明细校验失败:" .. table.concat(err, ","),
|
result = nil
|
}
|
mobox.returnValue(strLuaDEID, 1, lua.table2str(result))
|
return
|
end
|
|
-- 遍历删除每一项明细
|
for _, item in ipairs(items) do
|
local bs_no = item.S_BS_NO
|
local bs_row = item.N_BS_ROW_NO
|
local item_code = item.S_ITEM_CODE
|
|
local deleteCondition = " S_OO_NO IN (SELECT S_NO FROM TN_Outbound_Order WHERE S_BS_NO = '"..s_no.."') AND S_BS_NO = '" .. bs_no .. "' AND N_BS_ROW_MO = " .. bs_row .. " AND S_ITEM_CODE = '" .. item_code .. "'"
|
lua.Debug(strLuaDEID, debug.getinfo(1), 'deleteCondition', deleteCondition)
|
nRet, strRetInfo = mobox.dbdeleteData(strLuaDEID, "Outbound_Detail", deleteCondition)
|
if nRet ~= 0 then
|
lua.Stop(strLuaDEID, "删除失败:" .. strRetInfo)
|
return
|
end
|
end
|
|
-- 查询所有主表记录(可能多条)
|
local queryOrderSql = "S_BS_NO = '"..s_no.."'"
|
local nRet, orderData = m3.QueryDataObject(strLuaDEID, "Outbound_Order", queryOrderSql)
|
if nRet ~= 0 then
|
local result = {
|
SourceKey = inputData.SourceKey or "",
|
err_code = 1,
|
err_msg = "查询出库单主表失败:" .. (orderData or ""),
|
result = nil
|
}
|
mobox.returnValue(strLuaDEID, 1, lua.table2str(result))
|
return
|
end
|
|
-- orderData 是一条或多条,逐条处理
|
if orderData ~= "" then
|
for n = 1, #orderData do
|
local order = m3.KeyValueAttrsToObjAttr(orderData[n].attrs)
|
local s_no = order.S_NO -- 出库单号
|
-- 查询当前主单下面还有没有明细
|
local detailCondition = "S_OO_NO = '" .. s_no .. "'"
|
local nRet, detailData = m3.QueryDataObject(strLuaDEID, "Outbound_Detail", detailCondition)
|
if nRet ~= 0 then
|
local result = {
|
SourceKey = inputData.SourceKey or "",
|
err_code = 1,
|
err_msg = "查询出库明细失败:" .. (detailData or ""),
|
result = nil
|
}
|
mobox.returnValue(strLuaDEID, 1, lua.table2str(result))
|
return
|
end
|
|
-- 如果没有明细了,删除这张主单
|
if detailData == "" then
|
local deleteOrderCondition = "S_NO = '" .. s_no .. "'"
|
local nRet, strRetInfo = mobox.dbdeleteData(strLuaDEID, "Outbound_Order", deleteOrderCondition)
|
if nRet ~= 0 then
|
lua.Stop(strLuaDEID, "删除失败:" .. strRetInfo)
|
return
|
end
|
end
|
end
|
end
|
|
|
-- 成功返回
|
local result = {
|
SourceKey = inputData.SourceKey or "",
|
err_code = 0,
|
err_msg = "删除出库单明细成功",
|
result = ""
|
}
|
mobox.returnValue(strLuaDEID, 1, lua.table2str(result))
|
end
|