uf_update_warecost.srf 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. $PBExportHeader$uf_update_warecost.srf
  2. global type uf_update_warecost from function_object
  3. end type
  4. forward prototypes
  5. global function integer uf_update_warecost (long arg_storageid, boolean arg_ifcommit, ref string arg_msg)
  6. end prototypes
  7. global function integer uf_update_warecost (long arg_storageid, boolean arg_ifcommit, ref string arg_msg);Int rslt = 1
  8. Int li_balctype
  9. SELECT balctype INTO :li_balctype
  10. FROM u_storage
  11. Where storageid = :arg_storageid;
  12. IF sqlca.SQLCode <> 0 THEN
  13. arg_msg = '查询仓库结存金额计算方法失败,不能结存'
  14. rslt = 0
  15. GOTO ext
  16. END IF
  17. CHOOSE CASE li_balctype
  18. CASE 0
  19. rslt = 1
  20. GOTO ext
  21. case 1
  22. case 2
  23. update u_inwaremx
  24. set u_inwaremx.fprice = u_mtrldef.planprice,
  25. u_inwaremx.price = u_mtrldef.planprice * u_inwaremx.rebate
  26. from u_inwaremx,u_inware,u_mtrldef
  27. where u_inwaremx.scid = u_inware.scid
  28. and u_inwaremx.inwareid = u_inware.inwareid
  29. and u_inwaremx.mtrlid = u_mtrldef.mtrlid
  30. and u_inware.flag = 1
  31. and u_inware.balcdateint = 0
  32. and u_inware.storageid = :arg_storageid;
  33. if sqlca.sqlcode <> 0 then
  34. arg_msg = '更新计划价为进仓价失败,'+sqlca.sqlerrtext
  35. rslt = 0
  36. goto ext
  37. end if
  38. update u_warebalc
  39. set u_warebalc.incamt = u_incamt_balc.incamt
  40. from u_warebalc,u_incamt_balc
  41. where u_warebalc.storageid = u_incamt_balc.storageid
  42. and u_warebalc.mtrlid = u_incamt_balc.mtrlid
  43. and u_warebalc.status = u_incamt_balc.status;
  44. if sqlca.sqlcode <> 0 then
  45. arg_msg = '更新进仓金额失败,'+sqlca.sqlerrtext
  46. rslt = 0
  47. goto ext
  48. end if
  49. case 3
  50. update u_inwaremx
  51. set u_inwaremx.fprice = u_mtrldef.planprice,
  52. u_inwaremx.price = u_mtrldef.planprice * u_inwaremx.rebate
  53. from u_inwaremx,u_inware,u_mtrldef
  54. where u_inwaremx.scid = u_inware.scid
  55. and u_inwaremx.inwareid = u_inware.inwareid
  56. and u_inwaremx.mtrlid = u_mtrldef.mtrlid
  57. and u_inwaremx.fprice = 0
  58. and u_inware.flag = 1
  59. and u_inware.balcdateint = 0
  60. and u_inware.storageid = :arg_storageid;
  61. if sqlca.sqlcode <> 0 then
  62. arg_msg = '更新计划价为进仓价失败,'+sqlca.sqlerrtext
  63. rslt = 0
  64. goto ext
  65. end if
  66. update u_warebalc
  67. set u_warebalc.incamt = u_incamt_balc.incamt
  68. from u_warebalc,u_incamt_balc
  69. where u_warebalc.storageid = u_incamt_balc.storageid
  70. and u_warebalc.mtrlid = u_incamt_balc.mtrlid
  71. and u_warebalc.status = u_incamt_balc.status;
  72. if sqlca.sqlcode <> 0 then
  73. arg_msg = '更新进仓金额失败,'+sqlca.sqlerrtext
  74. rslt = 0
  75. goto ext
  76. end if
  77. END CHOOSE
  78. UPDATE u_warebalc
  79. SET u_warebalc.desamt = round(u_warebalc.desqty * uv_warebalc_newoutcost.newoutcost,2),
  80. u_warebalc.balcamt = round(u_warebalc.balcqty * uv_warebalc_newoutcost.newoutcost,2)
  81. FROM u_warebalc INNER JOIN
  82. uv_warebalc_newoutcost ON
  83. u_warebalc.Storageid = uv_warebalc_newoutcost.Storageid AND
  84. u_warebalc.mtrlid = uv_warebalc_newoutcost.mtrlid AND
  85. u_warebalc.status = uv_warebalc_newoutcost.status
  86. Where (u_warebalc.balcdateint = 0) AND u_warebalc.storageid = :arg_storageid;
  87. IF sqlca.SQLCode <> 0 THEN
  88. rslt = 0
  89. arg_msg = '更新结存出仓金额及结存金额失败!>>'+sqlca.SQLErrText
  90. GOTO ext
  91. END IF
  92. UPDATE u_mtrlware
  93. SET wareamt = round(u_mtrlware.noallocqty * uv_warebalc_newoutcost.newoutcost,2),
  94. cost = uv_warebalc_newoutcost.newoutcost
  95. FROM u_mtrlware INNER JOIN
  96. uv_warebalc_newoutcost ON u_mtrlware.mtrlid = uv_warebalc_newoutcost.mtrlid AND
  97. u_mtrlware.storageid = uv_warebalc_newoutcost.Storageid AND
  98. u_mtrlware.Status = uv_warebalc_newoutcost.status
  99. Where u_mtrlware.storageid = :arg_storageid ;
  100. IF sqlca.SQLCode <> 0 THEN
  101. rslt = 0
  102. arg_msg = '更新库存金额失败!>>'+sqlca.SQLErrText
  103. GOTO ext
  104. END IF
  105. UPDATE u_outwaremx
  106. SET costamt = round(u_outwaremx.qty * uv_warebalc_newoutcost.newoutcost,2)
  107. FROM u_outwaremx INNER JOIN
  108. u_outware ON u_outwaremx.scid = u_outware.scid AND
  109. u_outwaremx.outwareid = u_outware.outwareid INNER JOIN
  110. uv_warebalc_newoutcost ON
  111. u_outware.StorageID = uv_warebalc_newoutcost.Storageid AND
  112. u_outwaremx.mtrlid = uv_warebalc_newoutcost.mtrlid AND
  113. u_outwaremx.status = uv_warebalc_newoutcost.status
  114. Where (u_outware.billtype = 1) AND u_outware.storageid = :arg_storageid AND u_outware.flag = 1 AND u_outware.balcflag = 0;
  115. IF sqlca.SQLCode <> 0 THEN
  116. rslt = 0
  117. arg_msg = '更新销售单出仓成本失败!>>'+sqlca.SQLErrText
  118. GOTO ext
  119. END IF
  120. UPDATE u_outwaremx
  121. SET costamt = round(u_outwaremx.qty * uv_warebalc_newoutcost.newoutcost,2),
  122. u_outwaremx.fprice = uv_warebalc_newoutcost.newoutcost,
  123. u_outwaremx.price = uv_warebalc_newoutcost.newoutcost*u_outwaremx.rebate
  124. FROM u_outwaremx INNER JOIN
  125. u_outware ON u_outwaremx.scid = u_outware.scid AND
  126. u_outwaremx.outwareid = u_outware.outwareid INNER JOIN
  127. uv_warebalc_newoutcost ON
  128. u_outware.StorageID = uv_warebalc_newoutcost.Storageid AND
  129. u_outwaremx.mtrlid = uv_warebalc_newoutcost.mtrlid AND
  130. u_outwaremx.status = uv_warebalc_newoutcost.status
  131. Where (u_outware.billtype <> 1) AND u_outware.storageid = :arg_storageid AND u_outware.flag = 1 AND u_outware.balcflag = 0;
  132. IF sqlca.SQLCode <> 0 THEN
  133. rslt = 0
  134. arg_msg = '更新出仓成本失败!>>'+sqlca.SQLErrText
  135. GOTO ext
  136. END IF
  137. ext:
  138. IF rslt = 0 THEN
  139. ROLLBACK;
  140. ELSEIF rslt = 1 AND arg_ifcommit THEN
  141. COMMIT;
  142. END IF
  143. RETURN rslt
  144. end function