--[[
|
编码: JX-API-06
|
名称: DeleteOutboundOrder
|
作者: kun
|
入口函数:main
|
功能说明:
|
- 判断出库单状态是否为“新建”
|
- 若为新建,删除出库单及其明细
|
- 否则提示不可删除
|
输入数据格式:
|
{
|
"Name": "DeleteOutboundOrder",
|
"Source": "ERP",
|
"Data":
|
{
|
"S_NO": "CKD001",
|
"SourceKey": ""
|
}
|
}
|
--]]
|
|
-- 引入基础模块
|
json = require("json")
|
mobox = require("OILua_JavelinExt")
|
m3 = require("oi_base_mobox")
|
wms_base = require("wms_base")
|
|
function DeleteOutboundOrder(strLuaDEID)
|
|
m3.PrintLuaDEInfo( strLuaDEID )
|
|
-- 初始化变量
|
local nRet, inputData
|
local item
|
local inbound_data
|
local s_no
|
local outbound_date
|
local Condition
|
|
local nRetl, strRetInfop,item
|
local inboundOrder
|
local strCondition
|
local sqlstrCondition
|
local container_data, nRet
|
local strRetInfo
|
|
local err_code = 0
|
local err_msg
|
local err = {}
|
|
-- 获取接口传入的数据
|
nRet, inputData = m3.GetSysDataJson(strLuaDEID)
|
if (nRet ~= 0) then
|
table.insert(err, "无法获取数据包:" .. inputData)
|
goto continue
|
end
|
|
--inbound_data = inputData.Data
|
|
if (inputData == nil or inputData == "")then
|
table.insert(err, "Data 不合法!:" .. inbound_data)
|
goto continue
|
end
|
|
if (inputData.S_NO == nil or inputData.S_NO == "") then
|
table.insert(err, "来源单号不能为空!:" .. inbound_data)
|
goto continue
|
end
|
|
s_no = inputData.S_NO -- 来源单号
|
|
-- 用于校验出库单的状态值,料箱库的入库单看N_B_STATE,人工库的看累计出库数量是否有值
|
strCondition = "S_BS_NO = '"..s_no.."' AND N_B_STATE <> 0 AND S_AREA_CODE = '料箱库' "
|
nRet, outbound_date = m3.QueryDataObject(strLuaDEID, "Outbound_Order", strCondition)
|
if (nRet ~= 0) then
|
table.insert(err, "查询对应的出库单失败!:" .. s_no)
|
goto continue
|
end
|
if (outbound_date ~= "") then
|
table.insert(err, "该来源单号对应的出库单有非新建状态,不可删除!:" .. s_no)
|
goto continue
|
end
|
|
|
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
|
table.insert(err, "查询对应的出库单失败!:" .. s_no)
|
goto continue
|
end
|
|
if (container_data ~= "") then
|
table.insert(err, "该来源单号对应的出库单明细有已出库的数据,不可删除!:" .. s_no)
|
goto continue
|
end
|
|
-- 用来源单号查询入库单信息是否存在
|
sqlstrCondition = "S_BS_NO = '" .. s_no .. "'"
|
nRetl, strRetInfop = mobox.existThisData(strLuaDEID, "Outbound_Order", sqlstrCondition)
|
if (nRetl ~= 0) then
|
table.insert(err, "调用方法existThisData出错" .. strRetInfop)
|
goto continue
|
end
|
if (strRetInfop == 'yes') then
|
local nRet, inbound_order = m3.QueryDataObject(strLuaDEID, "Outbound_Order", sqlstrCondition)
|
if (nRet ~= 0 or not inbound_order) then
|
lua.Stop(strLuaDEID, "查询失败: ".. s_no )
|
return
|
end
|
|
-- 查询入库单信息
|
nRet, strRetInfo= mobox.dbdeleteData(strLuaDEID, "Outbound_Order", sqlstrCondition)
|
if (nRet ~= 0) then
|
lua.Stop(strLuaDEID, "删除出库单失败:"..no)
|
return
|
end
|
|
for i = 1, #inbound_order do
|
local record = m3.KeyValueAttrsToObjAttr(inbound_order[i].attrs)
|
local no = record.S_NO
|
local sqlCondition = "S_OO_NO = '" .. no .. "'"
|
nRet, strRetInfo = mobox.dbdeleteData(strLuaDEID, "Outbound_Detail", sqlCondition)
|
if (nRet ~= 0) then
|
lua.Stop(strLuaDEID, "删除出库单明细失败:" ..no)
|
return
|
end
|
end
|
else
|
table.insert(err, "查询出库单失败")
|
end
|
|
-- 返回参数
|
::continue::
|
|
if (#err > 0) then
|
err_code = 1
|
err_msg = "出库单删除失败!" .. table.concat(err, ",")
|
else
|
err_code = 0
|
err_msg = "出库单删除成功!"
|
end
|
|
local result =
|
{
|
SourceKey = inputData.SourceKey,
|
err_code = err_code,
|
err_msg = err_msg,
|
result = {
|
S_NO = s_no
|
}
|
}
|
mobox.returnValue(strLuaDEID, 1, lua.table2str(result))
|
|
end
|