f_update_mtrlware_spt_in.srf 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. $PBExportHeader$f_update_mtrlware_spt_in.srf
  2. global type f_update_mtrlware_spt_in from function_object
  3. end type
  4. forward prototypes
  5. global function integer f_update_mtrlware_spt_in (integer arg_billtype, integer arg_thflag, 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)
  6. end prototypes
  7. global function integer f_update_mtrlware_spt_in (integer arg_billtype, integer arg_thflag, 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
  8. Long ls_newid
  9. String or_err_part
  10. Decimal ld_cost
  11. //-------------------------------------------更新库存
  12. UPDATE ow_wfjgware
  13. SET noallocqty = noallocqty - :arg_qty ,
  14. wareamt = case when (wareamt - round(:arg_qty * :arg_price,2)) * (noallocqty - :arg_qty) < 0 then 0 - (wareamt - round(:arg_qty * :arg_price,2)) else wareamt - round(:arg_qty * :arg_price,2) end ,
  15. waredate = getdate(),
  16. newprice = :arg_price,
  17. cost = case noallocqty - :arg_qty when 0 then cost else round((wareamt - round(:arg_qty * :arg_price,2))/(noallocqty - :arg_qty),5) END,
  18. indate = case when :arg_qty < 0 then getdate() else indate END,
  19. outdate = case when :arg_qty > 0 then getdate() else outdate END
  20. Where ( mtrlwareid = :arg_mtrlwareid )
  21. USING arg_transaction ;
  22. IF arg_transaction.SQLCode = 0 THEN
  23. IF arg_transaction.SQLNRows = 0 THEN
  24. ///////////////////////////
  25. ls_newid = f_sys_scidentity(0,"ow_wfjgware","mtrlwareid",arg_msg,FALSE,arg_transaction)
  26. IF ls_newid <= 0 THEN
  27. rslt = 0
  28. GOTO ext
  29. END IF
  30. ///////////////////////////
  31. ld_cost = arg_price
  32. INSERT INTO ow_wfjgware
  33. (mtrlwareid,
  34. mtrlid,
  35. plancode,
  36. status,
  37. noallocqty,
  38. allocqty,
  39. wareamt,
  40. sptid,
  41. woodcode,
  42. pcode,
  43. cost,
  44. indate)
  45. VALUES (
  46. :ls_newid,
  47. :arg_mtrlid,
  48. :arg_plancode,
  49. :arg_status,
  50. :arg_qty,
  51. 0,
  52. round(:arg_price * :arg_qty,2),
  53. :arg_sptid,
  54. :arg_woodcode,
  55. :arg_pcode,
  56. :ld_cost,
  57. getdate()) USING arg_transaction ;
  58. IF arg_transaction.SQLCode <> 0 THEN
  59. rslt = 0
  60. arg_msg = "因网络或其它原因导致物料["+arg_mtrlcode+"]库存建立操作失败"+"~n"+arg_transaction.SQLErrText
  61. GOTO ext
  62. END IF
  63. END IF
  64. ELSE
  65. rslt = 0
  66. or_err_part = 'column insert or update conflicts with a rule imposed by a previous create rule statement'
  67. IF arg_transaction.SQLCode = 513 OR Pos(Lower(arg_transaction.SQLErrText),or_err_part) > 0 THEN
  68. arg_msg = "物料["+arg_mtrlcode+"]同仓库内同批号没有足够的库存支持冲减"
  69. ELSE
  70. arg_msg = "因网络或其它原因导致物料["+arg_mtrlcode+"]库存更新操作失败"+"~n"+arg_transaction.SQLErrText
  71. END IF
  72. GOTO ext
  73. END IF
  74. //-----------------------------------更新结存
  75. Decimal ld_balcqty,ld_balcamt
  76. Decimal ld_outqty,ld_outamt
  77. Decimal ld_reoutqty,ld_reoutamt
  78. Decimal ld_wasteqty,ld_wasteamt
  79. decimal ld_pypkqty,ld_pypkamt
  80. ld_balcqty = arg_qty
  81. ld_balcamt = Round(arg_qty * arg_price,2)
  82. CHOOSE CASE arg_billtype
  83. CASE 4,5
  84. IF arg_thflag = 0 THEN
  85. ld_outqty = arg_qty
  86. ld_outamt = Round(arg_qty * arg_price,2)
  87. ld_reoutqty = 0
  88. ld_reoutamt = 0
  89. ld_pypkqty = 0
  90. ld_pypkamt = 0
  91. ld_wasteqty = 0
  92. ld_wasteamt = 0
  93. ELSE
  94. ld_outqty = 0
  95. ld_outamt = 0
  96. ld_reoutqty = 0 - arg_qty
  97. ld_reoutamt = 0 - Round(arg_qty * arg_price,2)
  98. ld_pypkqty = 0
  99. ld_pypkamt = 0
  100. ld_wasteqty = 0
  101. ld_wasteamt = 0
  102. END IF
  103. CASE 9
  104. ld_outqty = 0
  105. ld_outamt = 0
  106. ld_reoutqty = 0
  107. ld_reoutamt = 0
  108. ld_pypkqty = 0 - arg_qty
  109. ld_pypkamt = 0 - Round(arg_qty * arg_price,2)
  110. ld_wasteqty = 0
  111. ld_wasteamt = 0
  112. CASE 10
  113. ld_outqty = 0
  114. ld_outamt = 0
  115. ld_reoutqty = 0
  116. ld_reoutamt = 0
  117. ld_pypkqty = 0
  118. ld_pypkamt = 0
  119. ld_wasteqty = arg_qty
  120. ld_wasteamt = Round(arg_qty * arg_price,2)
  121. END CHOOSE
  122. UPDATE ow_wfjgbalc
  123. SET
  124. outqty = outqty + :ld_outqty ,
  125. outamt = outamt + :ld_outamt,
  126. reoutqty = reoutqty + :ld_reoutqty ,
  127. reoutamt = reoutamt + :ld_reoutamt,
  128. balcqty = balcqty - :ld_balcqty,
  129. balcamt = balcamt - :ld_balcamt,
  130. wasteqty = wasteqty + :ld_wasteqty,
  131. wasteamt = wasteamt + :ld_wasteamt,
  132. pypkqty = pypkqty + :ld_pypkqty,
  133. pypkamt = pypkamt + :ld_pypkamt
  134. WHERE ( mtrlid = :arg_mtrlid ) AND
  135. ( sptid = :arg_sptid ) AND
  136. ( balcdateint = 0) AND
  137. ( status = :arg_status ) AND
  138. ( woodcode = :arg_woodcode ) AND
  139. ( pcode = :arg_pcode ) USING arg_transaction ;
  140. IF arg_transaction.SQLCode = 0 THEN
  141. IF arg_transaction.SQLNRows = 0 THEN
  142. INSERT INTO ow_wfjgbalc
  143. ( balcdateint,
  144. mtrlid,
  145. sptid,
  146. bgqty,
  147. bgamt,
  148. inqty,
  149. inamt,
  150. outqty,
  151. outamt,
  152. reoutqty,
  153. reoutamt,
  154. thqty,
  155. thamt,
  156. balcqty,
  157. balcamt,
  158. status,
  159. woodcode,
  160. pcode,
  161. wasteqty,
  162. wasteamt,
  163. pypkqty,
  164. pypkamt)
  165. VALUES (
  166. 0,
  167. :arg_mtrlid,
  168. :arg_sptid,
  169. 0,
  170. 0,
  171. 0,
  172. 0,
  173. :ld_outqty,
  174. :ld_outamt,
  175. :ld_reoutqty,
  176. :ld_reoutamt,
  177. 0,
  178. 0,
  179. 0 - :ld_balcqty,
  180. 0 - :ld_balcamt,
  181. :arg_status,
  182. :arg_woodcode,
  183. :arg_pcode,
  184. :ld_wasteqty,
  185. :ld_wasteamt,
  186. :ld_pypkqty,
  187. :ld_pypkamt) USING arg_transaction ;
  188. IF arg_transaction.SQLCode <> 0 THEN
  189. rslt = 0
  190. arg_msg = "因网络或其它原因导致物料["+arg_mtrlcode+"]结存建立操作失败"+"~n"+arg_transaction.SQLErrText
  191. GOTO ext
  192. END IF
  193. END IF
  194. ELSE
  195. rslt = 0
  196. or_err_part = 'column insert or update conflicts with a rule imposed by a previous create rule statement'
  197. IF arg_transaction.SQLCode = 513 OR Pos(Lower(arg_transaction.SQLErrText),or_err_part) > 0 THEN
  198. arg_msg = "物料["+arg_mtrlcode+"]同仓库内同批号没有足够的结存支持冲减"
  199. ELSE
  200. arg_msg = "因网络或其它原因导致物料["+arg_mtrlcode+"]结存更新操作失败"+"~n"+arg_transaction.SQLErrText
  201. END IF
  202. GOTO ext
  203. END IF
  204. ext:
  205. IF rslt = 0 THEN
  206. ROLLBACK;
  207. END IF
  208. RETURN rslt
  209. end function