--[[ 编码: GT-02-01 名称: 创建前 作者: LZH 创建时间: 2024/7/3 入口函数: 功能说明: -- 判断目视卡数量+来料信息累计装箱数量是否超过来料信息的实际数量 变更记录: V1.1 LZH 20240718 判空校验,函数getDataObjAttrSum在没有值的情况下返回的是空字符串不是0 V1.2 LZH 20240806 从【物料】表中获取是否验证字段 V1.3 LZH 20240809 由于来料信息字段变动,获取该入库单据头下的所有入库单据行数量+1判断是否大于入库单据头的托盘数量 V1.4 LZH 20240909 散装胶类型的物料不需要校验数量 --]] json = require("json") mobox = require("OILua_JavelinExt") m3 = require("oi_base_mobox") require("GT-Base") function BeforeDataObjCreate(strLuaDEID) local nRet, strRetInfo lua.Debug(strLuaDEID, debug.getinfo(1), '1', 1) -- 获取当前创建的数据对象属性 nRet, strRetInfo = mobox.getCurEditDataObjAttr(strLuaDEID, "S_ORDER_NO", "S_ITEM_CODE", "S_DISPERSOID", "S_SERIAL_NO") if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "获取编辑信息失败 " .. strRetInfo) end local obj_attrs = json.decode(strRetInfo) local order_no = obj_attrs[1].value local item_code = obj_attrs[2].value local dispersoid = obj_attrs[3].value local serial_no = obj_attrs[4].value lua.Debug(strLuaDEID, debug.getinfo(1), '获取参数', strRetInfo) if (order_no == nil or order_no == '') then lua.Error(strLuaDEID, debug.getinfo(1), "入库单号不能为空!") end if (item_code == nil or item_code == '') then lua.Error(strLuaDEID, debug.getinfo(1), "物料编码不能为空!") end -- 获取来料信息 local incoming_info local strCondition = " S_ORDER_NO= '" .. order_no .. "'" nRet, incoming_info = m3.GetDataObjByCondition(strLuaDEID, "GT_Incoming_Info", strCondition) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "m3.GetDataObjByCondition 失败!" .. incoming_info) end local lable_crad local strCode = '' if (incoming_info.type == '人工录入') then -- 自动生成流水号(编码规则 S + 7位数字) nRet, strCode = mobox.getSerialNumber("人工录入流水号", 'A', 7) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1),"申请人工录入入库单据行编码失败!" .. strCode) end else -- 校验流水号不能为空不能重复 strCondition = "S_SERIAL_NO = '" .. serial_no .. "'" nRet, lable_crad = m3.GetDataObjByCondition(strLuaDEID, "GT_Label_Crad", strCondition) if (nRet == 0) then lua.Error(strLuaDEID, debug.getinfo(1), "流水号不能重复!") elseif (nRet == 2) then lua.Error(strLuaDEID, debug.getinfo(1), "m3.GetDataObjByCondition 失败!" .. lable_crad) end end -- V1.4 获取物料类型 local item_type, material nRet, item_type, material = GT_Get_ItemType(strLuaDEID, item_code) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), item_type) end lua.Debug(strLuaDEID, debug.getinfo(1), '物料信息', material) if (item_type ~= '散装胶') then -- V1.3 获取该送货单号下目视卡数量总和 local num nRet, num = mobox.getDataObjCount(strLuaDEID, "GT_Label_Crad", strCondition) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "getDataObjCount 失败!" .. num) end if (dispersoid ~= 'Y') then if (tonumber(num) + 1 > tonumber(incoming_info.cntr_qty)) then lua.Error(strLuaDEID, debug.getinfo(1), "入库单据行总数超过入库单据头的托盘数量!") end end end -- V1.2 设置信息 local attr_value = {} attr_value[1] = lua.KeyValueObj("C_IS_VALIDATE", material.is_validate) if(strCode ~= '')then attr_value[2] = lua.KeyValueObj("S_SERIAL_NO", strCode) attr_value[3] = lua.KeyValueObj("S_REQ_NO", strCode) end nRet, strRetInfo = mobox.setCurEditDataObjAttr(strLuaDEID, lua.table2str(attr_value)) if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "设置入库单据行信息失败! " .. strRetInfo) end end