$PBExportHeader$uo_changed_planprice.sru forward global type uo_changed_planprice from nonvisualobject end type end forward global type uo_changed_planprice from nonvisualobject end type global uo_changed_planprice uo_changed_planprice type variables Boolean it_newbegin = FALSE //新建标志 Boolean it_updatebegin = FALSE //修改标志 Long it_mxbt = 0 long billid string billcode string billrep string dscrp long flag string opemp,modemp string auditemp datetime billdate,opdate,auditdate,moddate Transaction commit_transaction //数据commit事务 s_planprice_changed s_changed[] Boolean if_getid_ture = TRUE end variables forward prototypes public function integer newbegin (ref string arg_msg) public function integer p_reset () public function integer p_clearmx () public function integer updatebegin (long arg_billid, ref string arg_msg) public function integer p_getinfo (long arg_billid, ref string arg_msg) public function integer save (boolean arg_ifcommit, ref string arg_msg) public function integer del (long arg_billid, boolean arg_ifcommit, ref string arg_msg) public function integer getinfo (long arg_billid, ref string arg_msg) public function integer auditing (boolean arg_ifcommit, ref string arg_msg) public function integer add_dscrp (long arg_billid, string arg_newdescppart, ref string arg_msg) public function integer acceptmx (long arg_mtrlid, decimal arg_lastprice, decimal arg_planprice, string arg_reason, string arg_mxdscrp, ref string arg_msg, string arg_status, string arg_woodcode, string arg_pcode, long arg_printid) end prototypes public function integer newbegin (ref string arg_msg);//==================================================================== // Function: newbegin(long arg_scid,int arg_billtype,ref string arg_msg) //-------------------------------------------------------------------- // Description: 从置对象,设定业务类型,准备建立新进仓单 //-------------------------------------------------------------------- // Arguments: // value long arg_scid // value integer arg_billtype // reference string arg_msg //-------------------------------------------------------------------- // Returns: integer //-------------------------------------------------------------------- // Author: yyx Date: 2003.11.12 //-------------------------------------------------------------------- // Modify History: // //==================================================================== int rslt=1 p_reset() it_newbegin=true it_updatebegin=false if rslt=0 then p_reset() return rslt end function public function integer p_reset ();//int p_reset() //清除对象及其明细 billid = 0 billcode = '' dscrp = '' billrep = '' flag = 0 opemp = '' auditemp = '' modemp = '' it_newbegin = FALSE it_updatebegin = FALSE //清除明细 p_clearmx() RETURN 1 end function public function integer p_clearmx ();//int p_clearmx() //清除明细 it_mxbt=0 return 1 end function public function integer updatebegin (long arg_billid, ref string arg_msg);//==================================================================== // Function: updatebegin(arg_scid,arg_inwareid,arg_billtype,arg_msg) //-------------------------------------------------------------------- // Description: 从置对象,设定业务类型与关联ID,准备更新进仓单 //-------------------------------------------------------------------- // Arguments: // value long arg_scid // value long arg_inwareid // value integer arg_billtype // reference string arg_msg //-------------------------------------------------------------------- // Returns: integer //-------------------------------------------------------------------- // Author: yyx Date: 2003.11.12 //-------------------------------------------------------------------- // Modify History: // //==================================================================== long rslt=1 if arg_billid<=0 then rslt=0 goto ext end if rslt=p_getinfo(arg_billid,arg_msg) if rslt=0 then goto ext if flag = 1 then rslt = 0 arg_msg = '单据已经审核,不能修改' goto ext end if billid=arg_billid it_newbegin=false it_updatebegin=true p_clearmx() //清除明细 ext: if rslt=0 then p_reset() return rslt end function public function integer p_getinfo (long arg_billid, ref string arg_msg);//p_getinfo(arg_scid,arg_outwareid,arg_msg) //0 失败 1成功 INT rslt=1 IF arg_billid<=0 THEN rslt=0 arG_MSG="非法出仓单唯一码" goto ext end if select u_planprice_changed.billcode, u_planprice_changed.billdate, u_planprice_changed.billrep, u_planprice_changed.dscrp, u_planprice_changed.opemp, u_planprice_changed.opdate, u_planprice_changed.flag, u_planprice_changed.auditemp, u_planprice_changed.auditdate, u_planprice_changed.modemp, u_planprice_changed.moddate into :billcode, :billdate, :billrep, :dscrp, :opemp, :opdate, :flag, :auditemp, :auditdate, :modemp, :moddate from u_planprice_changed where u_planprice_changed.billid = :arg_billid using commit_transaction; if commit_transaction.sqlcode<>0 then rslt=0 arG_MSG="查询操作失败(错误出仓单唯一码),出仓单"+commit_transaction.sqlerrtext goto ext end if billid = arg_billid ext: IF rslt=0 THEN p_reset() return rslt end function public function integer save (boolean arg_ifcommit, ref string arg_msg);Integer rslt = 1,cnt = 0,i DateTime server_dt Long ls_newid String ls_sccode IF IsNull(billrep) THEN billrep = '' IF IsNull(dscrp) THEN dscrp = '' IF it_newbegin = FALSE AND it_updatebegin = FALSE THEN rslt = 0 arg_msg = "非编辑状态不可以提交" GOTO ext END IF SELECT Top 1 getdate() INTO :server_dt FROM u_user USING commit_transaction ; //取得系统时间,借用操作员表 IF commit_transaction.SQLCode <> 0 THEN rslt = 0 arg_msg = "查询操作失败,日期 " GOTO ext END IF IF it_mxbt = 0 THEN //如果输入物料资料错则已经清空 rslt = 0 arg_msg = "没有正确单据明细内容" GOTO ext END IF IF Year(Date(billdate)) < 2000 OR IsNull(billdate) THEN rslt = 0 arg_msg = "缺少单据发生时间或不合理" GOTO ext END IF ////////////////////////////////////////////////开始区分:新建/更新 处理 IF billid = 0 THEN //新建 ls_newid = f_sys_scidentity(0,"u_planprice_changed","billid",arg_msg,if_getid_ture,commit_transaction) IF ls_newid <= 0 THEN rslt = 0 GOTO ext END IF billcode = getid(0,ls_sccode + 'pc',Date(server_dt),if_getid_ture,commit_transaction) IF billcode = "err" THEN billcode = '' rslt = 0 arg_msg = "无法获取单据编号"+"~n"+commit_transaction.SQLErrText GOTO ext END IF INSERT INTO u_planprice_changed ( billid, billcode, billdate, billrep, dscrp, opdate, opemp) values ( :ls_newid, :billcode, :billdate, :billrep, :dscrp, :server_dt, :publ_operator) USING commit_transaction ; IF commit_transaction.SQLCode <> 0 THEN rslt = 0 IF Pos(Lower(commit_transaction.SQLErrText),'PK_u_planprice_changed') > 0 THEN arg_msg = '插入操作失败,关键字单据ID重复' ELSE arg_msg = "因网络或其它原因导致插入操作失败"+"~n"+commit_transaction.SQLErrText END IF GOTO ext END IF //读取新billid billid = ls_newid FOR i = 1 TO it_mxbt INSERT INTO u_planprice_changedmx ( billid, mtrlid, lastprice, planprice, reason, mxdscrp, printid, status, woodcode, pcode) values ( :billid, :s_changed[i].mtrlid, :s_changed[i].lastprice, :s_changed[i].planprice, :s_changed[i].reason, :s_changed[i].mxdscrp, :s_changed[i].printid, :s_changed[i].status, :s_changed[i].woodcode, :s_changed[i].pcode ) USING commit_transaction ; IF commit_transaction.SQLCode <> 0 THEN billid = 0 //还原billid rslt = 0 arg_msg = "因网络或其它原因导致插入明细操作失败"+"~n"+commit_transaction.SQLErrText GOTO ext END IF NEXT ELSE //////////////////////////////////////////////////更新 update u_planprice_changed set billdate = :billdate, billrep = :billrep, dscrp = :dscrp, modemp = :publ_operator, moddate = :server_dt where billid = :billid and flag = 0 USING commit_transaction; IF commit_transaction.SQLCode <> 0 OR commit_transaction.SQLNRows <= 0 THEN rslt = 0 arg_msg = "因网络或其它原因导致更新单据操作失败(1)"+"~n"+commit_transaction.SQLErrText GOTO ext END IF //删除原有明细 DELETE FROM u_planprice_changedmx WHERE u_planprice_changedmx.billid = :billid USING commit_transaction; IF commit_transaction.SQLCode <> 0 THEN rslt = 0 arg_msg = "删除旧有明细操作失败"+"~n"+commit_transaction.SQLErrText GOTO ext END IF FOR i = 1 TO it_mxbt INSERT INTO u_planprice_changedmx ( billid, mtrlid, lastprice, planprice, reason, mxdscrp, printid, status, woodcode, pcode ) values ( :billid, :s_changed[i].mtrlid, :s_changed[i].lastprice, :s_changed[i].planprice, :s_changed[i].reason, :s_changed[i].mxdscrp, :s_changed[i].printid, :s_changed[i].status, :s_changed[i].woodcode, :s_changed[i].pcode ) USING commit_transaction ; IF commit_transaction.SQLCode <> 0 THEN billid = 0 //还原billid rslt = 0 arg_msg = "因网络或其它原因导致插入明细操作失败"+"~n"+commit_transaction.SQLErrText GOTO ext END IF NEXT end if it_newbegin = FALSE it_updatebegin = FALSE ext: IF rslt = 0 THEN ROLLBACK USING commit_transaction; p_clearmx() ELSEIF rslt = 1 AND arg_ifcommit THEN COMMIT USING commit_transaction; END IF RETURN rslt end function public function integer del (long arg_billid, boolean arg_ifcommit, ref string arg_msg);//如果单据还没有审核删除单据极其明细 //0 FAIL, 1 SUCCESS Int rslt = 1 IF arg_billid <= 0 THEN rslt = 0 arG_MSG = "没有删除对象,操作取消" GOTO ext END IF IF p_getinfo(arg_billid,arG_MSG) = 0 THEN rslt = 0 GOTO ext END IF IF flag = 1 THEN rslt = 0 arG_MSG = "单据已经审核,不可以删除" GOTO ext END IF DELETE FROM u_planprice_changed WHERE u_planprice_changed.billid = :arg_billid USING commit_transaction; IF commit_transaction.SQLCode <> 0 THEN rslt = 0 arG_MSG = "删除计划价调整单操作失败"+"~n"+commit_transaction.SQLErrText GOTO ext END IF DELETE FROM u_planprice_changedmx WHERE u_planprice_changedmx.billid = :arg_billid USING commit_transaction; IF commit_transaction.SQLCode <> 0 THEN rslt = 0 arG_MSG = "删除计划价调整单明细操作失败"+"~n"+commit_transaction.SQLErrText GOTO ext END IF it_newbegin = FALSE it_updatebegin = FALSE ext: IF rslt = 0 THEN ROLLBACK USING commit_transaction; p_reset() ELSEIF rslt = 1 AND arg_ifcommit THEN COMMIT USING commit_transaction; END IF RETURN (rslt) end function public function integer getinfo (long arg_billid, ref string arg_msg);//getinfo(arg_scid,arg_outwareid,arg_msg) //0 失败 1成功 Int rslt = 1,i = 1,no_mxcheck = 0 IF arg_billid <= 0 THEN rslt = 0 arg_msg = "非法出仓单唯一码" GOTO ext END IF rslt = p_getinfo(arg_billid,arg_msg) IF rslt = 0 THEN GOTO ext //用游标读取明细 DECLARE cur_inwaermx CURSOR FOR select u_planprice_changedmx.mtrlid, u_planprice_changedmx.lastprice, u_planprice_changedmx.planprice, u_planprice_changedmx.reason, u_planprice_changedmx.mxdscrp, u_mtrldef.mtrlcode, u_planprice_changedmx.pcode, u_planprice_changedmx.woodcode, u_planprice_changedmx.status from u_planprice_changedmx,u_mtrldef where u_planprice_changedmx.mtrlid = u_mtrldef.mtrlid and u_planprice_changedmx.billid = :arg_billid USING commit_transaction; OPEN cur_inwaermx; FETCH cur_inwaermx INTO :s_changed[i].mtrlid,:s_changed[i].lastprice, :s_changed[i].planprice,:s_changed[i].reason,:s_changed[i].mxdscrp, :s_changed[i].mtrlcode,:s_changed[i].pcode,:s_changed[i].woodcode,:s_changed[i].status; DO WHILE commit_transaction.SQLCode = 0 i++ FETCH cur_inwaermx INTO :s_changed[i].mtrlid,:s_changed[i].lastprice, :s_changed[i].planprice,:s_changed[i].reason,:s_changed[i].mxdscrp, :s_changed[i].mtrlcode,:s_changed[i].pcode,:s_changed[i].woodcode,:s_changed[i].status; LOOP CLOSE cur_inwaermx; //检验明细是否读入完整 SELECT count(*) INTO :no_mxcheck FROM u_planprice_changedmx WHERE u_planprice_changedmx.billid = :arg_billid USING commit_transaction; IF commit_transaction.SQLCode <> 0 THEN rslt = 0 arg_msg = "查询操作失败,出仓单明细数量" GOTO ext END IF IF i <> (no_mxcheck+1) THEN rslt = 0 arg_msg = "查询操作失败,出仓单明细" GOTO ext END IF billid = arg_billid it_mxbt = i - 1 it_newbegin = FALSE it_updatebegin = FALSE ext: IF rslt = 0 THEN p_reset() RETURN rslt end function public function integer auditing (boolean arg_ifcommit, ref string arg_msg);Long rslt = 1,cnt = 0,i Dec new_noallocqty = 0 Long ls_newid IF billid = 0 THEN rslt = 0 arg_msg = "没有审核对象" GOTO ext END IF IF it_newbegin OR it_updatebegin THEN rslt = 0 arg_msg = "编辑状态下不可以执行审核" GOTO ext END IF IF flag = 1 THEN rslt = 0 arg_msg = "单据已经审核" GOTO ext END IF UPDATE u_planprice_changed SET Auditemp = :publ_operator, Auditdate = getdate(), flag = 1 WHERE u_planprice_changed.billid = :billid AND flag = 0 USING commit_transaction; IF commit_transaction.SQLCode <> 0 THEN rslt = 0 arg_msg = "因网络或其它原因导致审核单据操作失败"+"~n"+commit_transaction.SQLErrText GOTO ext ELSEIF commit_transaction.SQLNRows = 0 THEN rslt = 0 arg_msg = "单据正在审核,请稍后查询。"+"~n"+commit_transaction.SQLErrText GOTO ext END IF FOR i = 1 TO it_mxbt IF sys_option_planprice_configure = 0 THEN UPDATE u_mtrldef SET planprice = :s_changed[i].planprice Where mtrlid = :s_changed[i].mtrlid USING commit_transaction; IF commit_transaction.SQLCode <> 0 THEN rslt = 0 arg_msg = '第'+String(i)+'行,更新产品计划价失败!'+"~n"+commit_transaction.SQLErrText GOTO ext END IF ELSE UPDATE u_mtrl_planprice SET planprice = :s_changed[i].planprice WHERE mtrlid = :s_changed[i].mtrlid AND status = :s_changed[i].status AND woodcode = :s_changed[i].woodcode AND pcode = :s_changed[i].pcode USING commit_transaction; IF commit_transaction.SQLCode = -1 THEN rslt = 0 arg_msg = '第'+String(i)+'行,更新产品计划价失败!'+"~n"+commit_transaction.SQLErrText GOTO ext ELSEIF commit_transaction.SQLCode = 0 THEN IF commit_transaction.SQLNRows = 0 THEN INSERT INTO u_mtrl_planprice ( mtrlid, pcode, woodcode, status, planprice, dscrp ) VALUES ( :s_changed[i].mtrlid, :s_changed[i].pcode, :s_changed[i].woodcode, :s_changed[i].status, :s_changed[i].planprice, '' ) USING commit_transaction; IF commit_transaction.SQLCode <> 0 THEN rslt = 0 arg_msg = '第'+String(i)+'行,插入产品计划价失败!'+"~n"+commit_transaction.SQLErrText GOTO ext END IF END IF END IF END IF INSERT INTO u_planprice_his ( billid, mtrlid, lastprice, planprice, relcode, reason, changedtime, changedemp, printid, status, woodcode, pcode) VALUES( :billid, :s_changed[i].mtrlid, :s_changed[i].lastprice, :s_changed[i].planprice, :billcode, :s_changed[i].reason, :billdate, :billrep, :s_changed[i].printid, :s_changed[i].status, :s_changed[i].woodcode, :s_changed[i].pcode) USING commit_transaction ; IF commit_transaction.SQLCode <> 0 THEN rslt = 0 arg_msg = "因网络或其它原因导致插入操作失败"+"~n"+commit_transaction.SQLErrText GOTO ext END IF NEXT flag = 1 ext: IF rslt = 0 THEN ROLLBACK USING commit_transaction; ELSEIF rslt = 1 AND arg_ifcommit THEN COMMIT USING commit_transaction; END IF RETURN rslt end function public function integer add_dscrp (long arg_billid, string arg_newdescppart, ref string arg_msg);//add_dscrp(string arg_newdescppart) //0 fail 1 success int rslt=1 arg_newdescppart=trim(arg_newdescppart) if it_updatebegin or it_newbegin then rslt=0 arg_msg="编辑状态下不可用" goto ext end if if arg_newdescppart='' then rslt=0 arg_msg="要添加内容为空,操作取消" goto ext end if rslt=p_getinfo(arg_billid,arg_msg) if rslt=0 then goto ext if flag=0 then rslt=0 arg_msg="非审核状态下不可用" goto ext end if update u_planprice_changed set dscrp = dscrp+' '+:arg_newdescppart where u_planprice_changed.billid = :billid using commit_transaction; if commit_transaction.sqlcode<>0 then rollback ; rslt=0 arg_msg="因网络或其它原因导致添加单据备注操作失败"+"~n"+commit_transaction.sqlerrtext goto ext end if commit using commit_transaction; dscrp = dscrp+' '+arg_newdescppart ext: return (rslt) end function public function integer acceptmx (long arg_mtrlid, decimal arg_lastprice, decimal arg_planprice, string arg_reason, string arg_mxdscrp, ref string arg_msg, string arg_status, string arg_woodcode, string arg_pcode, long arg_printid);Long rslt = 1,i IF it_newbegin = FALSE AND it_updatebegin = FALSE THEN rslt = 0 arg_msg = "非编辑状态不可以使用,操作取消" GOTO ext END IF IF IsNull(arg_mtrlid) THEN arg_mtrlid = 0 IF IsNull(arg_lastprice) THEN arg_lastprice = 0 IF IsNull(arg_planprice) THEN arg_planprice = 0 IF IsNull(arg_reason) THEN arg_reason = '' IF IsNull(arg_mxdscrp) THEN arg_mxdscrp = '' IF IsNull(arg_status) THEN arg_status = '' IF IsNull(arg_woodcode) THEN arg_woodcode = '' IF IsNull(arg_pcode) THEN arg_pcode = '' IF arg_mtrlid = 0 THEN rslt = 1 GOTO ext END IF IF arg_planprice = 0 THEN rslt = 0 arg_msg = '第'+String(it_mxbt + 1)+'行,计划价为0' GOTO ext END IF Decimal ld_lastprice ld_lastprice = 0 SELECT top 1 planprice INTO :ld_lastprice FROM u_planprice_his WHERE mtrlid = :arg_mtrlid AND status = :arg_status AND woodcode = :arg_woodcode AND pcode = :arg_pcode Order By changedtime Desc USING commit_transaction; IF commit_transaction.SQLCode = -1 THEN rslt = 0 arg_msg = '查询第' + String(it_mxbt + 1) + '行,历史计划价失败!' GOTO ext END IF arg_lastprice = ld_lastprice FOR i = 1 TO it_mxbt IF s_changed[i].mtrlid = arg_mtrlid AND & s_changed[i].status = arg_status AND & s_changed[i].woodcode = arg_woodcode AND & s_changed[i].pcode = arg_pcode THEN rslt = 1 GOTO ext END IF NEXT //写入内容 it_mxbt++ s_changed[it_mxbt].mtrlid = arg_mtrlid s_changed[it_mxbt].lastprice = arg_lastprice s_changed[it_mxbt].planprice = arg_planprice s_changed[it_mxbt].reason = arg_reason s_changed[it_mxbt].mxdscrp = arg_mxdscrp s_changed[it_mxbt].status = arg_status s_changed[it_mxbt].woodcode = arg_woodcode s_changed[it_mxbt].pcode = arg_pcode s_changed[it_mxbt].printid = arg_printid ext: IF rslt = 0 THEN p_clearmx() RETURN rslt end function on uo_changed_planprice.create call super::create TriggerEvent( this, "constructor" ) end on on uo_changed_planprice.destroy TriggerEvent( this, "destructor" ) call super::destroy end on