--[[
|
编码: JX-API-OUTBOUND-01
|
名称: 创建出库单及明细
|
作者:
|
日期: 2025-1-29
|
|
入口函数: main
|
功能说明:
|
|
输入数据格式:
|
{
|
"taskId": "361de469-8f6b-42c8-8cf1-054a8024ea5b",
|
"taskType": "CGTH",
|
"orderNo": "432536433214321",
|
"customerId": "11",
|
"orderDate": "2020-12-22",
|
"priority": 0,
|
"memo": "",
|
"items": [
|
{
|
"orderItemId":"1",
|
"storerId": "HC",
|
"skuId": "2200011995005",
|
"skuName": "",
|
"qty": 20,
|
"batchNo": "44",
|
"contractNo": "",
|
"memo":""
|
}
|
]
|
}
|
|
响应示例:
|
{
|
"flag": "success",
|
"code": "0",
|
"message": "成功"
|
}
|
--]]
|
|
json = require("json")
|
mobox = require("OILua_JavelinExt")
|
m3 = require( "oi_base_mobox" )
|
wms_base = require( "wms_base" )
|
|
function CreateOrderBound(strLuaDEID)
|
local nRet, inputData
|
|
-- 获取接口传入的数据
|
nRet, inputData = m3.GetSysDataJson(strLuaDEID)
|
lua.DebugEx(strLuaDEID, "inputData-->", inputData)
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "无法获取数据包 datajson!")
|
end
|
|
-- 验证来源类型、移库计划单号和单据类型
|
if (inputData.orderNo == nil or inputData.orderNo == '') then
|
lua.Error(strLuaDEID, debug.getinfo(1), "关联单号不能为空!")
|
end
|
|
if (inputData.taskType == nil or inputData.taskType == '') then
|
lua.Error(strLuaDEID, debug.getinfo(1), "任务类型不能为空!")
|
end
|
|
if (inputData.customerId == nil or inputData.customerId == '') then
|
lua.Error(strLuaDEID, debug.getinfo(1), "供应商不能为空!")
|
end
|
|
|
-- 使用移库计划单号查询是否已存在相同的出库单
|
local strCondition = "S_NO = '" .. inputData.orderNo .. "'"
|
local nRetl, strRetInfo = mobox.existThisData(strLuaDEID, "Outbound_Order", strCondition)
|
|
if (nRetl ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "调用方法 existThisData 出错: " .. strRetInfo)
|
end
|
|
if (strRetInfo == 'yes') then
|
lua.Error(strLuaDEID, debug.getinfo(1), "出库单已存在,移库计划单号:" .. inputData.order_no)
|
end
|
|
-- 创建出库单记录
|
local outbound_order = m3.AllocObject(strLuaDEID, "Outbound_Order")
|
|
outbound_order.no = inputData.orderNo -- 出库单号
|
outbound_order.task_no = inputData.taskId
|
outbound_order.bs_type = inputData.taskType
|
outbound_order.storer = inputData.customerId
|
outbound_order.order_time = inputData.orderDate
|
outbound_order.priority = inputData.priority
|
outbound_order.memo = inputData.memo
|
outbound_order.wh_code = "HCCK"
|
outbound_order.area_code = "JBW"
|
nRet, strRetInfop = m3.CreateDataObj(strLuaDEID, outbound_order)
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "创建出库单记录失败!"..strRetInfop)
|
else
|
lua.Debug(strLuaDEID, debug.getinfo(1), "outbound_order", strRetInfop)
|
|
local nRet, strRetIinfo
|
local item
|
local strCondition
|
local outbound_detail
|
|
-- 遍历商品明细数组
|
for n = 1, #inputData.items do
|
|
item = inputData.items[n]
|
|
-- 检查商品编码和数量是否存在且有效
|
if (item.skuId == nil or item.skuId == '') then
|
lua.Error(strLuaDEID, debug.getinfo(1), "第 " .. n .. " 个商品的商品编码不能为空")
|
end
|
if (item.qty == nil or item.qty <= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "第 " .. n .. " 个商品的数量 qty 必须大于 0")
|
end
|
|
-- 检查物料信息是否存在
|
strCondition = "S_ITEM_CODE = '" .. item.skuId .. "'"
|
nRetl, strRetIinfo = mobox.existThisData(strLuaDEID, "Material", strCondition)
|
|
if (nRetl ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "调用方法existThisData出错: " .. strRetIinfo)
|
end
|
|
if (strRetIinfo == 'yes') then
|
lua.Error(strLuaDEID, debug.getinfo(1), "物料编码不存在,商品编码:" .. item.skuId)
|
else
|
|
-- 创建出库单明细记录
|
outbound_detail = m3.AllocObject(strLuaDEID, "Outbound_Detail")
|
outbound_detail.oo_no = inputData.orderNo -- 设置出库单号
|
outbound_detail.row_no = item.orderItemId
|
outbound_detail.storer = item.storerId
|
outbound_detail.item_code = item.skuId
|
outbound_detail.item_name = item.skuName
|
outbound_detail.qty = item.qty -- 设置物料数量
|
outbound_detail.batch_no = item.batchNo
|
outbound_detail.bs_no = "11"
|
-- 销售合同号
|
outbound_detail.udf01 = item.contractNo
|
-- 备注
|
outbound_detail.udf02 = item.memo
|
|
-- 创建出库单明细记录
|
nRet, strRetInfop = m3.CreateDataObj(strLuaDEID, outbound_detail)
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "创建出库单明细记录失败,商品编码:" .. strRetInfop)
|
end
|
end
|
end
|
|
local result = {
|
flag = "success",
|
code = "0",
|
message = "成功"
|
}
|
|
mobox.returnValue(strLuaDEID, 1, lua.table2str(result))
|
end
|
end
|