123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433 |
- $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_scid, 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_scid, 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
- Decimal ld_balcqty,ld_balcamt
- Decimal ld_outqty,ld_outamt
- Decimal ld_reoutqty,ld_reoutamt
- Decimal ld_pypkqty,ld_pypkamt
- Decimal ld_wasteqty,ld_wasteamt
- //-------------------------------------------更新库存
- IF sys_option_wfjgware_nocost = 0 THEN
- UPDATE ow_wfjgware
- SET noallocqty = noallocqty - :arg_qty ,
- wareamt = case noallocqty - :arg_qty when 0 then 0 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),:sys_option_cost_dec) 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,TRUE,id_sqlca)
- IF ls_newid <= 0 THEN
- rslt = 0
- GOTO ext
- END IF
- ///////////////////////// //
- ld_cost = Round(arg_price,sys_option_cost_dec)
- INSERT INTO ow_wfjgware
- (mtrlwareid,
- mtrlid,
- plancode,
- status,
- noallocqty,
- allocqty,
- wareamt,
- sptid,
- woodcode,
- pcode,
- cost,
- scid)
- 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,
- :arg_scid) 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 OR Pos(Lower(arg_transaction.SQLErrText),'noallocqty') > 0 THEN
- arg_msg = "外协商库存,物料["+arg_mtrlcode+"]没有足够的库存支持冲减"
- ELSEIF Pos(Lower(arg_transaction.SQLErrText),'cost') > 0 or Pos(Lower(arg_transaction.SQLErrText),'wareamt') > 0 THEN
- arg_msg = "外协商库存,物料["+arg_mtrlcode+"]没有足够的库存金额支持冲减"
- ELSE
- arg_msg = "外协商库存,物料["+arg_mtrlcode+"]库存更新操作失败"+"~n"+arg_transaction.SQLErrText
- END IF
- GOTO ext
- END IF
-
- //-----------------------------------更新结存
-
-
- 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 = case balcqty - :ld_balcqty when 0 then 0 else balcamt - :ld_balcamt END ,
- pypkqty = pypkqty + :ld_pypkqty,
- pypkamt = pypkamt + :ld_pypkamt,
- wasteqty = wasteqty + :ld_wasteqty,
- wasteamt = wasteamt + :ld_wasteamt
- WHERE ( mtrlid = :arg_mtrlid ) AND
- ( sptid = :arg_sptid ) AND
- ( balcdateint = 0) AND
- ( status = :arg_status ) AND
- ( woodcode = :arg_woodcode ) AND
- ( pcode = :arg_pcode ) AND
- ( scid = :arg_scid ) 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,
- pypkqty,
- pypkamt,
- wasteqty,
- wasteamt,
- scid)
- 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_pypkqty,
- :ld_pypkamt,
- :ld_wasteqty,
- :ld_wasteamt,
- :arg_scid) 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
- ELSE
- UPDATE ow_wfjgware
- SET noallocqty = noallocqty - :arg_qty ,
- wareamt = 0 ,
- waredate = getdate(),
- newprice = 0,
- cost = 0
- 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,TRUE,id_sqlca)
- IF ls_newid <= 0 THEN
- rslt = 0
- GOTO ext
- END IF
- ///////////////////////// //
- ld_cost = Round(arg_price,sys_option_cost_dec)
- INSERT INTO ow_wfjgware
- (mtrlwareid,
- mtrlid,
- plancode,
- status,
- noallocqty,
- allocqty,
- wareamt,
- sptid,
- woodcode,
- pcode,
- cost,
- scid)
- VALUES (
- :ls_newid,
- :arg_mtrlid,
- :arg_plancode,
- :arg_status,
- :arg_qty,
- 0,
- 0,
- :arg_sptid,
- :arg_woodcode,
- :arg_pcode,
- 0,
- :arg_scid) 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 OR Pos(Lower(arg_transaction.SQLErrText),'noallocqty') > 0 THEN
- arg_msg = "外协商库存,物料["+arg_mtrlcode+"]没有足够的库存支持冲减"
- ELSEIF Pos(Lower(arg_transaction.SQLErrText),'cost') > 0 or Pos(Lower(arg_transaction.SQLErrText),'wareamt') > 0 THEN
- arg_msg = "外协商库存,物料["+arg_mtrlcode+"]没有足够的库存金额支持冲减"
- ELSE
- arg_msg = "外协商库存物料["+arg_mtrlcode+"]库存更新操作失败"+"~n"+arg_transaction.SQLErrText
- END IF
- GOTO ext
- END IF
-
- //-----------------------------------更新结存
-
-
- ld_balcqty = arg_qty
- ld_balcamt = 0
-
- CHOOSE CASE arg_billtype
- CASE 4,5
- IF arg_thflag = 0 THEN
- ld_outqty = arg_qty
- ld_outamt = 0
- 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
- 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
- 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 = 0
- END CHOOSE
-
- UPDATE ow_wfjgbalc
- SET
- outqty = outqty + :ld_outqty ,
- outamt = 0,
- reoutqty = reoutqty + :ld_reoutqty ,
- reoutamt = 0,
- balcqty = balcqty - :ld_balcqty,
- balcamt = 0,
- pypkqty = pypkqty + :ld_pypkqty,
- pypkamt = 0,
- wasteqty = wasteqty + :ld_wasteqty,
- wasteamt = 0
- WHERE ( mtrlid = :arg_mtrlid ) AND
- ( sptid = :arg_sptid ) AND
- ( balcdateint = 0) AND
- ( status = :arg_status ) AND
- ( woodcode = :arg_woodcode ) AND
- ( pcode = :arg_pcode ) AND
- ( scid = :arg_scid ) 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,
- pypkqty,
- pypkamt,
- wasteqty,
- wasteamt,
- scid)
- VALUES (
- 0,
- :arg_mtrlid,
- :arg_sptid,
- 0,
- 0,
- 0,
- 0,
- :ld_outqty,
- 0,
- :ld_reoutqty,
- 0,
- 0,
- 0,
- 0 - :ld_balcqty,
- 0,
- :arg_status,
- :arg_woodcode,
- :arg_pcode,
- :ld_pypkqty,
- 0,
- :ld_wasteqty,
- 0,
- :arg_scid) 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
- END IF
- ext:
- IF rslt = 0 THEN
- ROLLBACK USING arg_transaction;
- ELSEIF rslt = 1 AND arg_ifcommit THEN
- COMMIT USING arg_transaction;
- END IF
- RETURN rslt
- end function
|