f_inware_update_mtrlware.srf 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. $PBExportHeader$f_inware_update_mtrlware.srf
  2. global type f_inware_update_mtrlware from function_object
  3. end type
  4. forward prototypes
  5. 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)
  6. end prototypes
  7. 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
  8. long ls_newid
  9. string or_err_part
  10. Decimal ld_cost
  11. //-------------------------------------------更新库存
  12. update u_mtrlware
  13. set noallocqty = noallocqty + :arg_qty ,
  14. noallocaddqty = noallocaddqty + :arg_addqty ,
  15. wareamt = wareamt + round(:arg_qty * :arg_price,2),
  16. waredate = getdate(),
  17. newprice = :arg_price,
  18. cost = case noallocqty + :arg_qty when 0 then cost else round((wareamt + round(:arg_qty * :arg_price,2)) / ( noallocqty + :arg_qty ),5) END
  19. where ( mtrlid = :arg_mtrlid ) and
  20. ( plancode = :arg_plancode ) and
  21. ( storageid = :arg_storageid ) and
  22. ( scid = :arg_scid ) and
  23. ( status = :arg_status ) and
  24. ( sptid = :arg_rel_cusid_sptid) and
  25. ( dxflag = :arg_dxflag ) and
  26. ( woodcode = :arg_woodcode ) and
  27. ( pcode = :arg_pcode ) using arg_transaction ;
  28. if arg_transaction.sqlcode = 0 then
  29. if arg_transaction.sqlnrows = 0 then
  30. ///////////////////////////
  31. ls_newid = f_sys_scidentity(arg_scid,"u_mtrlware","mtrlwareid",arg_msg,false,arg_transaction)
  32. if ls_newid <= 0 then
  33. rslt = 0
  34. goto ext
  35. end if
  36. ///////////////////////////
  37. insert into u_mtrlware
  38. ( scid,
  39. mtrlwareid,
  40. mtrlid,
  41. storageid,
  42. plancode,
  43. status,
  44. noallocqty,
  45. noallocaddqty,
  46. allocqty,
  47. wareamt,
  48. planprice,
  49. sptid,
  50. dxflag,
  51. woodcode,
  52. pcode,
  53. cost,
  54. newprice)
  55. values (
  56. :arg_scid,
  57. :ls_newid,
  58. :arg_mtrlid,
  59. :arg_storageid,
  60. :arg_plancode,
  61. :arg_status,
  62. :arg_qty,
  63. :arg_addqty,
  64. 0,
  65. round(:arg_price * :arg_qty,2),
  66. :arg_planprice,
  67. :arg_rel_cusid_sptid,
  68. :arg_dxflag,
  69. :arg_woodcode,
  70. :arg_pcode,
  71. :ld_cost,
  72. :arg_price
  73. ) using arg_transaction ;
  74. if arg_transaction.sqlcode <> 0 then
  75. rslt = 0
  76. arg_msg = "因网络或其它原因导致物料["+arg_mtrlcode+"]库存建立操作失败"+"~n"+arg_transaction.sqlerrtext
  77. goto ext
  78. end if
  79. end if
  80. else
  81. rslt = 0
  82. or_err_part = 'column insert or update conflicts with a rule imposed by a previous create rule statement'
  83. if arg_transaction.sqlcode = 513 or pos(lower(arg_transaction.sqlerrtext),or_err_part) > 0 then
  84. arg_msg = "物料["+arg_mtrlcode+"]同仓库内同批号没有足够的库存支持冲减"
  85. else
  86. arg_msg = "因网络或其它原因导致物料["+arg_mtrlcode+"]库存更新操作失败"+"~n"+arg_transaction.sqlerrtext
  87. end if
  88. goto ext
  89. end if
  90. ext:
  91. if rslt = 0 then
  92. rollback using arg_transaction;
  93. end if
  94. return rslt
  95. end function