$PBExportHeader$f_update_mtrlware_spt_in.srf global type f_update_mtrlware_spt_in from function_object end type forward prototypes global function integer f_update_mtrlware_spt_in (integer arg_billtype, integer arg_thflag, long arg_mtrlwareid, long arg_mtrlid, string arg_mtrlcode, string arg_plancode, string arg_status, decimal arg_qty, decimal arg_price, long arg_sptid, string arg_woodcode, string arg_pcode, ref string arg_msg, boolean arg_ifcommit, transaction arg_transaction) end prototypes global function integer f_update_mtrlware_spt_in (integer arg_billtype, integer arg_thflag, long arg_mtrlwareid, long arg_mtrlid, string arg_mtrlcode, string arg_plancode, string arg_status, decimal arg_qty, decimal arg_price, long arg_sptid, string arg_woodcode, string arg_pcode, ref string arg_msg, boolean arg_ifcommit, transaction arg_transaction);Int rslt = 1 Long ls_newid String or_err_part Decimal ld_cost //-------------------------------------------更新库存 UPDATE ow_wfjgware SET noallocqty = noallocqty - :arg_qty , wareamt = case when (wareamt - round(:arg_qty * :arg_price,2)) * (noallocqty - :arg_qty) < 0 then 0 - (wareamt - round(:arg_qty * :arg_price,2)) else wareamt - round(:arg_qty * :arg_price,2) end , waredate = getdate(), newprice = :arg_price, cost = case noallocqty - :arg_qty when 0 then cost else round((wareamt - round(:arg_qty * :arg_price,2))/(noallocqty - :arg_qty),5) END, indate = case when :arg_qty < 0 then getdate() else indate END, outdate = case when :arg_qty > 0 then getdate() else outdate END Where ( mtrlwareid = :arg_mtrlwareid ) USING arg_transaction ; IF arg_transaction.SQLCode = 0 THEN IF arg_transaction.SQLNRows = 0 THEN /////////////////////////// ls_newid = f_sys_scidentity(0,"ow_wfjgware","mtrlwareid",arg_msg,FALSE,arg_transaction) IF ls_newid <= 0 THEN rslt = 0 GOTO ext END IF /////////////////////////// ld_cost = arg_price INSERT INTO ow_wfjgware (mtrlwareid, mtrlid, plancode, status, noallocqty, allocqty, wareamt, sptid, woodcode, pcode, cost, indate) VALUES ( :ls_newid, :arg_mtrlid, :arg_plancode, :arg_status, :arg_qty, 0, round(:arg_price * :arg_qty,2), :arg_sptid, :arg_woodcode, :arg_pcode, :ld_cost, getdate()) USING arg_transaction ; IF arg_transaction.SQLCode <> 0 THEN rslt = 0 arg_msg = "因网络或其它原因导致物料["+arg_mtrlcode+"]库存建立操作失败"+"~n"+arg_transaction.SQLErrText GOTO ext END IF END IF ELSE rslt = 0 or_err_part = 'column insert or update conflicts with a rule imposed by a previous create rule statement' IF arg_transaction.SQLCode = 513 OR Pos(Lower(arg_transaction.SQLErrText),or_err_part) > 0 THEN arg_msg = "物料["+arg_mtrlcode+"]同仓库内同批号没有足够的库存支持冲减" ELSE arg_msg = "因网络或其它原因导致物料["+arg_mtrlcode+"]库存更新操作失败"+"~n"+arg_transaction.SQLErrText END IF GOTO ext END IF //-----------------------------------更新结存 Decimal ld_balcqty,ld_balcamt Decimal ld_outqty,ld_outamt Decimal ld_reoutqty,ld_reoutamt Decimal ld_wasteqty,ld_wasteamt decimal ld_pypkqty,ld_pypkamt ld_balcqty = arg_qty ld_balcamt = Round(arg_qty * arg_price,2) CHOOSE CASE arg_billtype CASE 4,5 IF arg_thflag = 0 THEN ld_outqty = arg_qty ld_outamt = Round(arg_qty * arg_price,2) ld_reoutqty = 0 ld_reoutamt = 0 ld_pypkqty = 0 ld_pypkamt = 0 ld_wasteqty = 0 ld_wasteamt = 0 ELSE ld_outqty = 0 ld_outamt = 0 ld_reoutqty = 0 - arg_qty ld_reoutamt = 0 - Round(arg_qty * arg_price,2) ld_pypkqty = 0 ld_pypkamt = 0 ld_wasteqty = 0 ld_wasteamt = 0 END IF CASE 9 ld_outqty = 0 ld_outamt = 0 ld_reoutqty = 0 ld_reoutamt = 0 ld_pypkqty = 0 - arg_qty ld_pypkamt = 0 - Round(arg_qty * arg_price,2) ld_wasteqty = 0 ld_wasteamt = 0 CASE 10 ld_outqty = 0 ld_outamt = 0 ld_reoutqty = 0 ld_reoutamt = 0 ld_pypkqty = 0 ld_pypkamt = 0 ld_wasteqty = arg_qty ld_wasteamt = Round(arg_qty * arg_price,2) END CHOOSE UPDATE ow_wfjgbalc SET outqty = outqty + :ld_outqty , outamt = outamt + :ld_outamt, reoutqty = reoutqty + :ld_reoutqty , reoutamt = reoutamt + :ld_reoutamt, balcqty = balcqty - :ld_balcqty, balcamt = balcamt - :ld_balcamt, wasteqty = wasteqty + :ld_wasteqty, wasteamt = wasteamt + :ld_wasteamt, pypkqty = pypkqty + :ld_pypkqty, pypkamt = pypkamt + :ld_pypkamt WHERE ( mtrlid = :arg_mtrlid ) AND ( sptid = :arg_sptid ) AND ( balcdateint = 0) AND ( status = :arg_status ) AND ( woodcode = :arg_woodcode ) AND ( pcode = :arg_pcode ) USING arg_transaction ; IF arg_transaction.SQLCode = 0 THEN IF arg_transaction.SQLNRows = 0 THEN INSERT INTO ow_wfjgbalc ( balcdateint, mtrlid, sptid, bgqty, bgamt, inqty, inamt, outqty, outamt, reoutqty, reoutamt, thqty, thamt, balcqty, balcamt, status, woodcode, pcode, wasteqty, wasteamt, pypkqty, pypkamt) VALUES ( 0, :arg_mtrlid, :arg_sptid, 0, 0, 0, 0, :ld_outqty, :ld_outamt, :ld_reoutqty, :ld_reoutamt, 0, 0, 0 - :ld_balcqty, 0 - :ld_balcamt, :arg_status, :arg_woodcode, :arg_pcode, :ld_wasteqty, :ld_wasteamt, :ld_pypkqty, :ld_pypkamt) USING arg_transaction ; IF arg_transaction.SQLCode <> 0 THEN rslt = 0 arg_msg = "因网络或其它原因导致物料["+arg_mtrlcode+"]结存建立操作失败"+"~n"+arg_transaction.SQLErrText GOTO ext END IF END IF ELSE rslt = 0 or_err_part = 'column insert or update conflicts with a rule imposed by a previous create rule statement' IF arg_transaction.SQLCode = 513 OR Pos(Lower(arg_transaction.SQLErrText),or_err_part) > 0 THEN arg_msg = "物料["+arg_mtrlcode+"]同仓库内同批号没有足够的结存支持冲减" ELSE arg_msg = "因网络或其它原因导致物料["+arg_mtrlcode+"]结存更新操作失败"+"~n"+arg_transaction.SQLErrText END IF GOTO ext END IF ext: IF rslt = 0 THEN ROLLBACK; END IF RETURN rslt end function