123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382 |
- $PBExportHeader$f_update_mtrlware_spt_out.srf
- global type f_update_mtrlware_spt_out from function_object
- end type
- forward prototypes
- global function integer f_update_mtrlware_spt_out (integer arg_billtype, integer arg_thflag, long arg_scid, long arg_mtrlid, string arg_mtrlcode, string arg_plancode, string arg_status, decimal arg_qty, decimal arg_costamt, decimal arg_planprice, 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_out (integer arg_billtype, integer arg_thflag, long arg_scid, long arg_mtrlid, string arg_mtrlcode, string arg_plancode, string arg_status, decimal arg_qty, decimal arg_costamt, decimal arg_planprice, 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
- Decimal ld_cost
- String or_err_part
- Decimal ld_thqty,ld_thamt
- Decimal ld_inqty,ld_inamt
- Decimal ld_balcqty,ld_balcamt
- Decimal ld_pypkqty,ld_pypkamt
- 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 + :arg_costamt END ,
- cost = case noallocqty + :arg_qty when 0 then cost else round((wareamt + :arg_costamt)/(noallocqty + :arg_qty),:sys_option_cost_dec) END ,
- waredate = getdate()
- WHERE ( mtrlid = :arg_mtrlid ) AND
- (status = :arg_Status) AND
- woodcode = :arg_woodcode AND
- pcode = :arg_pcode AND
- plancode = :arg_plancode AND
- sptid = :arg_sptid AND
- scid = :arg_scid 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 = Round(arg_costamt/arg_qty,sys_option_cost_dec)
- INSERT INTO ow_wfjgware
- (mtrlwareid,
- mtrlid,
- plancode,
- status,
- noallocqty,
- allocqty,
- wareamt,
- planprice,
- sptid,
- woodcode,
- pcode,
- cost,
- scid)
- VALUES (
- :ls_newid,
- :arg_mtrlid,
- :arg_plancode,
- :arg_status,
- :arg_qty,
- 0,
- :arg_costamt,
- :arg_planprice,
- :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 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 = arg_costamt
-
- CHOOSE CASE arg_billtype
- CASE 4,5
-
- IF arg_thflag = 0 THEN
- ld_inqty = arg_qty
- ld_inamt = arg_costamt
- ld_thqty = 0
- ld_thamt = 0
- ld_pypkqty = 0
- ld_pypkamt = 0
- ELSE
- ld_inqty = 0
- ld_inamt = 0
- ld_thqty = 0 - arg_qty
- ld_thamt = 0 - arg_costamt
- ld_pypkqty = 0
- ld_pypkamt = 0
- END IF
- CASE 9
- ld_inqty = 0
- ld_inamt = 0
- ld_thqty = 0
- ld_thamt = 0
- ld_pypkqty = 0 + arg_qty
- ld_pypkamt = 0 + arg_costamt
-
- END CHOOSE
-
-
-
- UPDATE ow_wfjgbalc
- SET
- balcqty = balcqty + :ld_balcqty,
- balcamt = case balcqty + :ld_balcqty when 0 then 0 else balcamt + :ld_balcamt END ,
- inqty = inqty + :ld_inqty,
- inamt = inamt + :ld_inamt,
- thqty = thqty + :ld_thqty,
- thamt = thamt + :ld_thamt,
- pypkqty = pypkqty + :ld_pypkqty,
- pypkamt = pypkamt + :ld_pypkamt
- WHERE ( mtrlid = :arg_mtrlid ) AND
- ( balcdateint = 0 ) AND
- ( status = :arg_status ) AND
- ( woodcode = :arg_woodcode ) AND
- ( sptid = :arg_sptid ) 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,
- sptid,
- mtrlid,
- status,
- woodcode,
- pcode,
- thqty,
- thamt,
- inqty,
- inamt,
- balcqty,
- balcamt,
- pypkqty,
- pypkamt,
- scid)
- VALUES (0,
- :arg_sptid,
- :arg_mtrlid,
- :arg_status,
- :arg_woodcode,
- :arg_pcode,
- :ld_thqty,
- :ld_thamt,
- :ld_inqty,
- :ld_inamt,
- :ld_balcqty,
- :ld_balcamt,
- :ld_pypkqty,
- :ld_pypkamt,
- :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 ,
- cost = 0 ,
- waredate = getdate()
- WHERE ( mtrlid = :arg_mtrlid ) AND
- (status = :arg_Status) AND
- woodcode = :arg_woodcode AND
- pcode = :arg_pcode AND
- plancode = :arg_plancode AND
- sptid = :arg_sptid AND
- scid = :arg_scid 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
-
- INSERT INTO ow_wfjgware
- (mtrlwareid,
- mtrlid,
- plancode,
- status,
- noallocqty,
- allocqty,
- wareamt,
- planprice,
- sptid,
- woodcode,
- pcode,
- cost,
- scid)
- VALUES (
- :ls_newid,
- :arg_mtrlid,
- :arg_plancode,
- :arg_status,
- :arg_qty,
- 0,
- 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 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 = arg_costamt
-
- CHOOSE CASE arg_billtype
- CASE 4,5
-
- IF arg_thflag = 0 THEN
- ld_inqty = arg_qty
- ld_inamt = 0
- ld_thqty = 0
- ld_thamt = 0
- ld_pypkqty = 0
- ld_pypkamt = 0
- ELSE
- ld_inqty = 0
- ld_inamt = 0
- ld_thqty = 0 - arg_qty
- ld_thamt = 0
- ld_pypkqty = 0
- ld_pypkamt = 0
- END IF
- CASE 9
- ld_inqty = 0
- ld_inamt = 0
- ld_thqty = 0
- ld_thamt = 0
- ld_pypkqty = 0 + arg_qty
- ld_pypkamt = 0
-
- END CHOOSE
-
-
-
- UPDATE ow_wfjgbalc
- SET
- balcqty = balcqty + :ld_balcqty,
- balcamt = 0 ,
- inqty = inqty + :ld_inqty,
- inamt = 0,
- thqty = thqty + :ld_thqty,
- thamt = 0,
- pypkqty = pypkqty + :ld_pypkqty,
- pypkamt = 0
- WHERE ( mtrlid = :arg_mtrlid ) AND
- ( balcdateint = 0 ) AND
- ( status = :arg_status ) AND
- ( woodcode = :arg_woodcode ) AND
- ( sptid = :arg_sptid ) 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,
- sptid,
- mtrlid,
- status,
- woodcode,
- pcode,
- thqty,
- thamt,
- inqty,
- inamt,
- balcqty,
- balcamt,
- pypkqty,
- pypkamt,
- scid)
- VALUES (0,
- :arg_sptid,
- :arg_mtrlid,
- :arg_status,
- :arg_woodcode,
- :arg_pcode,
- :ld_thqty,
- 0,
- :ld_inqty,
- 0,
- :ld_balcqty,
- 0,
- :ld_pypkqty,
- 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
|