123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- $PBExportHeader$f_inware_update_mtrlware.srf
- global type f_inware_update_mtrlware from function_object
- end type
- forward prototypes
- global function integer f_inware_update_mtrlware (long arg_scid, long arg_mtrlid, string arg_mtrlcode, long arg_storageid, string arg_plancode, string arg_status, decimal arg_qty, decimal arg_addqty, decimal arg_price, decimal arg_planprice, long arg_rel_cusid_sptid, integer arg_dxflag, string arg_woodcode, string arg_pcode, ref string arg_msg, transaction arg_transaction)
- end prototypes
- global function integer f_inware_update_mtrlware (long arg_scid, long arg_mtrlid, string arg_mtrlcode, long arg_storageid, string arg_plancode, string arg_status, decimal arg_qty, decimal arg_addqty, decimal arg_price, decimal arg_planprice, long arg_rel_cusid_sptid, integer arg_dxflag, string arg_woodcode, string arg_pcode, ref string arg_msg, transaction arg_transaction);int rslt = 1
- long ls_newid
- string or_err_part
- Decimal ld_cost
- //-------------------------------------------更新库存
- update u_mtrlware
- set noallocqty = noallocqty + :arg_qty ,
- noallocaddqty = noallocaddqty + :arg_addqty ,
- wareamt = wareamt + round(:arg_qty * :arg_price,2),
- 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
- where ( mtrlid = :arg_mtrlid ) and
- ( plancode = :arg_plancode ) and
- ( storageid = :arg_storageid ) and
- ( scid = :arg_scid ) and
- ( status = :arg_status ) and
- ( sptid = :arg_rel_cusid_sptid) and
- ( dxflag = :arg_dxflag ) and
- ( woodcode = :arg_woodcode ) and
- ( pcode = :arg_pcode ) using arg_transaction ;
- if arg_transaction.sqlcode = 0 then
- if arg_transaction.sqlnrows = 0 then
- ///////////////////////////
- ls_newid = f_sys_scidentity(arg_scid,"u_mtrlware","mtrlwareid",arg_msg,false,arg_transaction)
- if ls_newid <= 0 then
- rslt = 0
- goto ext
- end if
- ///////////////////////////
- insert into u_mtrlware
- ( scid,
- mtrlwareid,
- mtrlid,
- storageid,
- plancode,
- status,
- noallocqty,
- noallocaddqty,
- allocqty,
- wareamt,
- planprice,
- sptid,
- dxflag,
- woodcode,
- pcode,
- cost,
- newprice)
- values (
- :arg_scid,
- :ls_newid,
- :arg_mtrlid,
- :arg_storageid,
- :arg_plancode,
- :arg_status,
- :arg_qty,
- :arg_addqty,
- 0,
- round(:arg_price * :arg_qty,2),
- :arg_planprice,
- :arg_rel_cusid_sptid,
- :arg_dxflag,
- :arg_woodcode,
- :arg_pcode,
- :ld_cost,
- :arg_price
- ) 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 using arg_transaction;
- end if
- return rslt
- end function
|