| | |
| | | xml = require("oi_base_xml") |
| | | mobox = require("OILua_JavelinExt") |
| | | m3 = require("oi_base_mobox") |
| | | function Create_result(flag, code, msg) |
| | | return { |
| | | flag = flag or "success", |
| | | code = code or "0", |
| | | message = msg or "" |
| | | } |
| | | end |
| | | function Receipt_Sync(strLuaDEID) |
| | | -- 初始化最终结果 |
| | | local FinalRes = Create_result() |
| | | |
| | | -- 1. 获取 xml 数据包 |
| | | local nRet, soap_xml = mobox.getCurEditDataPacket(strLuaDEID) |
| | | if nRet ~= 0 then |
| | |
| | | -- 2. 解析 xml |
| | | local nRet, parsed_data = xml.parse(soap_xml) |
| | | if nRet ~= 0 then |
| | | FinalRes = Create_result("failure", "202", "xml 格式非法") |
| | | FinalRes = Create_result("failure", "202", "xml 格式非法" .. parsed_data) |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "xml格式非法", parsed_data) |
| | |
| | | end |
| | | |
| | | -- 5. 获取系统常量 |
| | | local RetWH_COE, CONST_WH = wms_base.Get_sConst2(strLuaDEID, "GK_Default_Warehouse") |
| | | local RetFAC_COE, CONST_FACTORY = wms_base.Get_sConst2(strLuaDEID, "GK_Default_Factory") |
| | | if (RetWH_COE ~= 0 or RetFAC_COE ~= 0) then |
| | | FinalRes = Create_result("failure", "204", "获取仓库/工厂常量失败") |
| | | local RetWH_COE, CONST_WH = wms_base.Get_sConst2("GK_Default_Warehouse") |
| | | local RetFAC_COE, CONST_FACTORY = wms_base.Get_sConst2("GK_Default_Factory") |
| | | |
| | | -- 仓库常量异常捕获 |
| | | if (RetWH_COE ~= 0) then |
| | | FinalRes = Create_result("failure", "204", "获取仓库常量失败" .. CONST_WH) |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "获取系统常量失败", xml_result) |
| | | lua.Stop(strLuaDEID, "获取系统常量:GK_Default_Warehouse 失败", xml_result) |
| | | return |
| | | end |
| | | |
| | | -- 工厂常量异常捕获 |
| | | if (RetFAC_COE ~= 0) then |
| | | FinalRes = Create_result("failure", "204", "获取工厂常量失败" .. CONST_FACTORY) |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "获取系统常量:GK_Default_Factory失败", xml_result) |
| | | return |
| | | end |
| | | -- 6. 遍历所有收货单 |
| | | for i = 1, #receipt_headers do |
| | | local header = receipt_headers[i] |
| | |
| | | if nRet == 0 then |
| | | -- 查询成功且找到记录,说明收货单已存在 |
| | | lua.DebugEx(strLuaDEID, "查询成功,收货单已存在", retReceipt) |
| | | FinalRes = Create_result("failure", "1", "收货单已存在", |
| | | "收货单[" .. header.orderNo .. "]已存在") |
| | | FinalRes = Create_result("failure", "1", "收货单[" .. header.orderNo .. "]已存在") |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "收货单已存在", retReceipt) |
| | |
| | | elseif nRet ~= 1 then |
| | | -- 查询出错 |
| | | lua.DebugEx(strLuaDEID, "查询出错", retReceipt) |
| | | FinalRes = Create_result("failure", "206", "检查收货单是否存在时出错", |
| | | FinalRes = Create_result("failure", "206", |
| | | "检查收货单[" .. header.orderNo .. "]时出错: " .. retReceipt) |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | |
| | | -- 再次检查是否真的存在 |
| | | local nRetCheck, retReceiptCheck = m3.GetDataObjByCondition(strLuaDEID, "Receipt_Order", strCondition) |
| | | if nRetCheck == 0 then |
| | | FinalRes = Create_result("failure", "205", "收货单已存在", |
| | | "收货单[" .. header.orderNo .. "]已存在") |
| | | FinalRes = Create_result("failure", "205", "收货单[" .. header.orderNo .. "]已存在") |
| | | else |
| | | FinalRes = Create_result("failure", "207", "创建收货单主表失败", |
| | | FinalRes = Create_result("failure", "207", |
| | | "收货单[" .. header.orderNo .. "]创建失败: " .. ret_info) |
| | | end |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | |
| | | -- 检查明细数据是否存在 |
| | | if header.SmallPiece_TB_ITEM == nil then |
| | | lua.DebugEx(strLuaDEID, "警告:收货单 " .. header.orderNo .. " 无明细数据") |
| | | FinalRes = Create_result("failure", "208", "收货单无明细数据", |
| | | "收货单[" .. header.orderNo .. "]无明细数据") |
| | | FinalRes = Create_result("failure", "208", "收货单[" .. header.orderNo .. "]无明细数据") |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "收货单无明细数据", xml_result) |
| | |
| | | if (nRet ~= 0) then |
| | | lua.DebugEx(strLuaDEID, "SKU查询出错", |
| | | "ITEM_CODE: " .. item.skuId .. ", 错误信息: " .. receiptInfo) |
| | | FinalRes = Create_result("failure", "207", "检查 SKU 是否存在时出错", |
| | | "SKU ID: " .. item.skuId .. ", 错误: " .. receiptInfo) |
| | | FinalRes = Create_result("failure", "207", |
| | | "检查 SKU 是否存在时出错:SKU ID为 " .. item.skuId .. ", 错误: " .. receiptInfo) |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "查询失败", xml_result) |
| | | return |
| | | elseif (receiptInfo == "") then |
| | | lua.DebugEx(strLuaDEID, "查询为空", "ITEM_CODE:" .. item.skuId) |
| | | FinalRes = Create_result("failure", "208", "查询数据为空", "ITEM_CODE : " .. item.skuId) |
| | | FinalRes = Create_result("failure", "208", "查询数据为空:ITEM_CODE : " .. item.skuId) |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.Stop(strLuaDEID, "物料数据不存在", xml_result) |
| | |
| | | lua.DebugEx(strLuaDEID, "创建明细数据:", receipt_detail) |
| | | local nRet, ret_info = m3.CreateDataObj(strLuaDEID, receipt_detail) |
| | | if nRet ~= 0 then |
| | | FinalRes = Create_result("failure", "208", "创建收货明细失败", "创建失败: " .. ret_info) |
| | | FinalRes = Create_result("failure", "208", "创建收货明细失败: " .. ret_info) |
| | | local xml_result = xml.json_to_xml(FinalRes, "response") |
| | | mobox.returnValue(strLuaDEID, 0, xml_result, 0) |
| | | lua.DebugEx(strLuaDEID, "创建收货明细失败", xml_result) |