f_update_mtrlware_spt_out.srf 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. $PBExportHeader$f_update_mtrlware_spt_out.srf
  2. global type f_update_mtrlware_spt_out from function_object
  3. end type
  4. forward prototypes
  5. 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)
  6. end prototypes
  7. 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
  8. Long ls_newid
  9. Decimal ld_cost
  10. String or_err_part
  11. Decimal ld_thqty,ld_thamt
  12. Decimal ld_inqty,ld_inamt
  13. Decimal ld_balcqty,ld_balcamt
  14. Decimal ld_pypkqty,ld_pypkamt
  15. IF sys_option_wfjgware_nocost = 0 THEN //核算金额
  16. UPDATE ow_wfjgware
  17. SET noallocqty = noallocqty + :arg_qty ,
  18. wareamt = case noallocqty + :arg_qty when 0 then 0 else wareamt + :arg_costamt END ,
  19. cost = case noallocqty + :arg_qty when 0 then cost else round((wareamt + :arg_costamt)/(noallocqty + :arg_qty),:sys_option_cost_dec) END ,
  20. waredate = getdate()
  21. WHERE ( mtrlid = :arg_mtrlid ) AND
  22. (status = :arg_Status) AND
  23. woodcode = :arg_woodcode AND
  24. pcode = :arg_pcode AND
  25. plancode = :arg_plancode AND
  26. sptid = :arg_sptid AND
  27. scid = :arg_scid USING arg_transaction ;
  28. IF arg_transaction.SQLCode = 0 THEN
  29. IF arg_transaction.SQLNRows = 0 THEN
  30. ls_newid = f_sys_scidentity(0,"ow_wfjgware","mtrlwareid",arg_msg,FALSE,arg_transaction)
  31. IF ls_newid <= 0 THEN
  32. rslt = 0
  33. GOTO ext
  34. END IF
  35. ld_cost = Round(arg_costamt/arg_qty,sys_option_cost_dec)
  36. INSERT INTO ow_wfjgware
  37. (mtrlwareid,
  38. mtrlid,
  39. plancode,
  40. status,
  41. noallocqty,
  42. allocqty,
  43. wareamt,
  44. planprice,
  45. sptid,
  46. woodcode,
  47. pcode,
  48. cost,
  49. scid)
  50. VALUES (
  51. :ls_newid,
  52. :arg_mtrlid,
  53. :arg_plancode,
  54. :arg_status,
  55. :arg_qty,
  56. 0,
  57. :arg_costamt,
  58. :arg_planprice,
  59. :arg_sptid,
  60. :arg_woodcode,
  61. :arg_pcode,
  62. :ld_cost,
  63. :arg_scid) USING arg_transaction ;
  64. IF arg_transaction.SQLCode <> 0 THEN
  65. rslt = 0
  66. arg_msg = "因网络或其它原因导致物料["+arg_mtrlcode+"]库存建立操作失败"+"~n"+arg_transaction.SQLErrText
  67. GOTO ext
  68. END IF
  69. END IF
  70. ELSE
  71. rslt = 0
  72. or_err_part = 'column insert or update conflicts with a rule imposed by a previous create rule statement'
  73. IF arg_transaction.SQLCode = 513 OR Pos(Lower(arg_transaction.SQLErrText),or_err_part) > 0 THEN
  74. arg_msg = "物料["+arg_mtrlcode+"]同供应商仓库内同批号没有足够的库存支持冲减"
  75. ELSE
  76. arg_msg = "因网络或其它原因导致物料["+arg_mtrlcode+"]库存更新操作失败"+"~n"+arg_transaction.SQLErrText
  77. END IF
  78. GOTO ext
  79. END IF
  80. //--------------------更新结存
  81. ld_balcqty = arg_qty
  82. ld_balcamt = arg_costamt
  83. CHOOSE CASE arg_billtype
  84. CASE 4,5
  85. IF arg_thflag = 0 THEN
  86. ld_inqty = arg_qty
  87. ld_inamt = arg_costamt
  88. ld_thqty = 0
  89. ld_thamt = 0
  90. ld_pypkqty = 0
  91. ld_pypkamt = 0
  92. ELSE
  93. ld_inqty = 0
  94. ld_inamt = 0
  95. ld_thqty = 0 - arg_qty
  96. ld_thamt = 0 - arg_costamt
  97. ld_pypkqty = 0
  98. ld_pypkamt = 0
  99. END IF
  100. CASE 9
  101. ld_inqty = 0
  102. ld_inamt = 0
  103. ld_thqty = 0
  104. ld_thamt = 0
  105. ld_pypkqty = 0 + arg_qty
  106. ld_pypkamt = 0 + arg_costamt
  107. END CHOOSE
  108. UPDATE ow_wfjgbalc
  109. SET
  110. balcqty = balcqty + :ld_balcqty,
  111. balcamt = case balcqty + :ld_balcqty when 0 then 0 else balcamt + :ld_balcamt END ,
  112. inqty = inqty + :ld_inqty,
  113. inamt = inamt + :ld_inamt,
  114. thqty = thqty + :ld_thqty,
  115. thamt = thamt + :ld_thamt,
  116. pypkqty = pypkqty + :ld_pypkqty,
  117. pypkamt = pypkamt + :ld_pypkamt
  118. WHERE ( mtrlid = :arg_mtrlid ) AND
  119. ( balcdateint = 0 ) AND
  120. ( status = :arg_status ) AND
  121. ( woodcode = :arg_woodcode ) AND
  122. ( sptid = :arg_sptid ) AND
  123. ( pcode = :arg_pcode ) AND
  124. ( scid = :arg_scid ) USING arg_transaction ;
  125. IF arg_transaction.SQLCode = 0 THEN
  126. IF arg_transaction.SQLNRows = 0 THEN
  127. INSERT INTO ow_wfjgbalc
  128. (balcdateint,
  129. sptid,
  130. mtrlid,
  131. status,
  132. woodcode,
  133. pcode,
  134. thqty,
  135. thamt,
  136. inqty,
  137. inamt,
  138. balcqty,
  139. balcamt,
  140. pypkqty,
  141. pypkamt,
  142. scid)
  143. VALUES (0,
  144. :arg_sptid,
  145. :arg_mtrlid,
  146. :arg_status,
  147. :arg_woodcode,
  148. :arg_pcode,
  149. :ld_thqty,
  150. :ld_thamt,
  151. :ld_inqty,
  152. :ld_inamt,
  153. :ld_balcqty,
  154. :ld_balcamt,
  155. :ld_pypkqty,
  156. :ld_pypkamt,
  157. :arg_scid) USING arg_transaction;
  158. IF arg_transaction.SQLCode <> 0 THEN
  159. rslt = 0
  160. arg_msg = "因网络或其它原因导致物料["+arg_mtrlcode+"]结存建立操作失败"+"~n"+arg_transaction.SQLErrText
  161. GOTO ext
  162. END IF
  163. END IF
  164. ELSE
  165. rslt = 0
  166. or_err_part = 'column insert or update conflicts with a rule imposed by a previous create rule statement'
  167. IF arg_transaction.SQLCode = 513 OR Pos(Lower(arg_transaction.SQLErrText),or_err_part) > 0 THEN
  168. arg_msg = "物料["+arg_mtrlcode+"]同仓库内同批号没有足够的结存支持冲减"
  169. ELSE
  170. arg_msg = "因网络或其它原因导致物料["+arg_mtrlcode+"]结存更新操作失败"+"~n"+arg_transaction.SQLErrText
  171. END IF
  172. GOTO ext
  173. END IF
  174. ELSE
  175. UPDATE ow_wfjgware
  176. SET noallocqty = noallocqty + :arg_qty ,
  177. wareamt = 0 ,
  178. cost = 0 ,
  179. waredate = getdate()
  180. WHERE ( mtrlid = :arg_mtrlid ) AND
  181. (status = :arg_Status) AND
  182. woodcode = :arg_woodcode AND
  183. pcode = :arg_pcode AND
  184. plancode = :arg_plancode AND
  185. sptid = :arg_sptid AND
  186. scid = :arg_scid USING arg_transaction ;
  187. IF arg_transaction.SQLCode = 0 THEN
  188. IF arg_transaction.SQLNRows = 0 THEN
  189. ls_newid = f_sys_scidentity(0,"ow_wfjgware","mtrlwareid",arg_msg,FALSE,arg_transaction)
  190. IF ls_newid <= 0 THEN
  191. rslt = 0
  192. GOTO ext
  193. END IF
  194. INSERT INTO ow_wfjgware
  195. (mtrlwareid,
  196. mtrlid,
  197. plancode,
  198. status,
  199. noallocqty,
  200. allocqty,
  201. wareamt,
  202. planprice,
  203. sptid,
  204. woodcode,
  205. pcode,
  206. cost,
  207. scid)
  208. VALUES (
  209. :ls_newid,
  210. :arg_mtrlid,
  211. :arg_plancode,
  212. :arg_status,
  213. :arg_qty,
  214. 0,
  215. 0,
  216. 0,
  217. :arg_sptid,
  218. :arg_woodcode,
  219. :arg_pcode,
  220. 0,
  221. :arg_scid) USING arg_transaction ;
  222. IF arg_transaction.SQLCode <> 0 THEN
  223. rslt = 0
  224. arg_msg = "因网络或其它原因导致物料["+arg_mtrlcode+"]库存建立操作失败"+"~n"+arg_transaction.SQLErrText
  225. GOTO ext
  226. END IF
  227. END IF
  228. ELSE
  229. rslt = 0
  230. or_err_part = 'column insert or update conflicts with a rule imposed by a previous create rule statement'
  231. IF arg_transaction.SQLCode = 513 OR Pos(Lower(arg_transaction.SQLErrText),or_err_part) > 0 THEN
  232. arg_msg = "物料["+arg_mtrlcode+"]同供应商仓库内同批号没有足够的库存支持冲减"
  233. ELSE
  234. arg_msg = "因网络或其它原因导致物料["+arg_mtrlcode+"]库存更新操作失败"+"~n"+arg_transaction.SQLErrText
  235. END IF
  236. GOTO ext
  237. END IF
  238. //--------------------更新结存
  239. ld_balcqty = arg_qty
  240. ld_balcamt = arg_costamt
  241. CHOOSE CASE arg_billtype
  242. CASE 4,5
  243. IF arg_thflag = 0 THEN
  244. ld_inqty = arg_qty
  245. ld_inamt = 0
  246. ld_thqty = 0
  247. ld_thamt = 0
  248. ld_pypkqty = 0
  249. ld_pypkamt = 0
  250. ELSE
  251. ld_inqty = 0
  252. ld_inamt = 0
  253. ld_thqty = 0 - arg_qty
  254. ld_thamt = 0
  255. ld_pypkqty = 0
  256. ld_pypkamt = 0
  257. END IF
  258. CASE 9
  259. ld_inqty = 0
  260. ld_inamt = 0
  261. ld_thqty = 0
  262. ld_thamt = 0
  263. ld_pypkqty = 0 + arg_qty
  264. ld_pypkamt = 0
  265. END CHOOSE
  266. UPDATE ow_wfjgbalc
  267. SET
  268. balcqty = balcqty + :ld_balcqty,
  269. balcamt = 0 ,
  270. inqty = inqty + :ld_inqty,
  271. inamt = 0,
  272. thqty = thqty + :ld_thqty,
  273. thamt = 0,
  274. pypkqty = pypkqty + :ld_pypkqty,
  275. pypkamt = 0
  276. WHERE ( mtrlid = :arg_mtrlid ) AND
  277. ( balcdateint = 0 ) AND
  278. ( status = :arg_status ) AND
  279. ( woodcode = :arg_woodcode ) AND
  280. ( sptid = :arg_sptid ) AND
  281. ( pcode = :arg_pcode ) AND
  282. ( scid = :arg_scid ) USING arg_transaction ;
  283. IF arg_transaction.SQLCode = 0 THEN
  284. IF arg_transaction.SQLNRows = 0 THEN
  285. INSERT INTO ow_wfjgbalc
  286. (balcdateint,
  287. sptid,
  288. mtrlid,
  289. status,
  290. woodcode,
  291. pcode,
  292. thqty,
  293. thamt,
  294. inqty,
  295. inamt,
  296. balcqty,
  297. balcamt,
  298. pypkqty,
  299. pypkamt,
  300. scid)
  301. VALUES (0,
  302. :arg_sptid,
  303. :arg_mtrlid,
  304. :arg_status,
  305. :arg_woodcode,
  306. :arg_pcode,
  307. :ld_thqty,
  308. 0,
  309. :ld_inqty,
  310. 0,
  311. :ld_balcqty,
  312. 0,
  313. :ld_pypkqty,
  314. 0,
  315. :arg_scid) USING arg_transaction;
  316. IF arg_transaction.SQLCode <> 0 THEN
  317. rslt = 0
  318. arg_msg = "因网络或其它原因导致物料["+arg_mtrlcode+"]结存建立操作失败"+"~n"+arg_transaction.SQLErrText
  319. GOTO ext
  320. END IF
  321. END IF
  322. ELSE
  323. rslt = 0
  324. or_err_part = 'column insert or update conflicts with a rule imposed by a previous create rule statement'
  325. IF arg_transaction.SQLCode = 513 OR Pos(Lower(arg_transaction.SQLErrText),or_err_part) > 0 THEN
  326. arg_msg = "物料["+arg_mtrlcode+"]同仓库内同批号没有足够的结存支持冲减"
  327. ELSE
  328. arg_msg = "因网络或其它原因导致物料["+arg_mtrlcode+"]结存更新操作失败"+"~n"+arg_transaction.SQLErrText
  329. END IF
  330. GOTO ext
  331. END IF
  332. END IF
  333. ext:
  334. IF rslt = 0 THEN
  335. ROLLBACK USING arg_transaction;
  336. ELSEIF rslt = 1 AND arg_ifcommit THEN
  337. COMMIT USING arg_transaction;
  338. END IF
  339. RETURN rslt
  340. end function