f_update_mtrlware_spt_in.srf 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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_scid, 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_scid, 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. Decimal ld_balcqty,ld_balcamt
  12. Decimal ld_outqty,ld_outamt
  13. Decimal ld_reoutqty,ld_reoutamt
  14. Decimal ld_pypkqty,ld_pypkamt
  15. Decimal ld_wasteqty,ld_wasteamt
  16. //-------------------------------------------更新库存
  17. IF sys_option_wfjgware_nocost = 0 THEN
  18. UPDATE ow_wfjgware
  19. SET noallocqty = noallocqty - :arg_qty ,
  20. wareamt = case noallocqty - :arg_qty when 0 then 0 else wareamt - round(:arg_qty * :arg_price,2) END ,
  21. waredate = getdate(),
  22. newprice = :arg_price,
  23. cost = case noallocqty - :arg_qty when 0 then cost else round( (wareamt - round(:arg_qty * :arg_price,2)) /(noallocqty - :arg_qty),:sys_option_cost_dec) END
  24. Where ( mtrlwareid = :arg_mtrlwareid ) USING arg_transaction ;
  25. IF arg_transaction.SQLCode = 0 THEN
  26. IF arg_transaction.SQLNRows = 0 THEN
  27. ///////////////////////// //
  28. ls_newid = f_sys_scidentity(0,"ow_wfjgware","mtrlwareid",arg_msg,TRUE,id_sqlca)
  29. IF ls_newid <= 0 THEN
  30. rslt = 0
  31. GOTO ext
  32. END IF
  33. ///////////////////////// //
  34. ld_cost = Round(arg_price,sys_option_cost_dec)
  35. INSERT INTO ow_wfjgware
  36. (mtrlwareid,
  37. mtrlid,
  38. plancode,
  39. status,
  40. noallocqty,
  41. allocqty,
  42. wareamt,
  43. sptid,
  44. woodcode,
  45. pcode,
  46. cost,
  47. scid)
  48. VALUES (
  49. :ls_newid,
  50. :arg_mtrlid,
  51. :arg_plancode,
  52. :arg_status,
  53. :arg_qty,
  54. 0,
  55. round(:arg_price * :arg_qty,2),
  56. :arg_sptid,
  57. :arg_woodcode,
  58. :arg_pcode,
  59. :ld_cost,
  60. :arg_scid) USING arg_transaction ;
  61. IF arg_transaction.SQLCode <> 0 THEN
  62. rslt = 0
  63. arg_msg = "外协商库存,物料["+arg_mtrlcode+"]库存建立操作失败"+"~n"+arg_transaction.SQLErrText
  64. GOTO ext
  65. END IF
  66. END IF
  67. ELSE
  68. rslt = 0
  69. or_err_part = 'column insert or update conflicts with a rule imposed by a previous create rule statement'
  70. IF arg_transaction.SQLCode = 513 OR Pos(Lower(arg_transaction.SQLErrText),or_err_part) > 0 OR Pos(Lower(arg_transaction.SQLErrText),'noallocqty') > 0 THEN
  71. arg_msg = "外协商库存,物料["+arg_mtrlcode+"]没有足够的库存支持冲减"
  72. ELSEIF Pos(Lower(arg_transaction.SQLErrText),'cost') > 0 or Pos(Lower(arg_transaction.SQLErrText),'wareamt') > 0 THEN
  73. arg_msg = "外协商库存,物料["+arg_mtrlcode+"]没有足够的库存金额支持冲减"
  74. ELSE
  75. arg_msg = "外协商库存,物料["+arg_mtrlcode+"]库存更新操作失败"+"~n"+arg_transaction.SQLErrText
  76. END IF
  77. GOTO ext
  78. END IF
  79. //-----------------------------------更新结存
  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 = case balcqty - :ld_balcqty when 0 then 0 else balcamt - :ld_balcamt END ,
  130. pypkqty = pypkqty + :ld_pypkqty,
  131. pypkamt = pypkamt + :ld_pypkamt,
  132. wasteqty = wasteqty + :ld_wasteqty,
  133. wasteamt = wasteamt + :ld_wasteamt
  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 ) AND
  140. ( scid = :arg_scid ) USING arg_transaction ;
  141. IF arg_transaction.SQLCode = 0 THEN
  142. IF arg_transaction.SQLNRows = 0 THEN
  143. INSERT INTO ow_wfjgbalc
  144. ( balcdateint,
  145. mtrlid,
  146. sptid,
  147. bgqty,
  148. bgamt,
  149. inqty,
  150. inamt,
  151. outqty,
  152. outamt,
  153. reoutqty,
  154. reoutamt,
  155. thqty,
  156. thamt,
  157. balcqty,
  158. balcamt,
  159. status,
  160. woodcode,
  161. pcode,
  162. pypkqty,
  163. pypkamt,
  164. wasteqty,
  165. wasteamt,
  166. scid)
  167. VALUES (
  168. 0,
  169. :arg_mtrlid,
  170. :arg_sptid,
  171. 0,
  172. 0,
  173. 0,
  174. 0,
  175. :ld_outqty,
  176. :ld_outamt,
  177. :ld_reoutqty,
  178. :ld_reoutamt,
  179. 0,
  180. 0,
  181. 0 - :ld_balcqty,
  182. 0 - :ld_balcamt,
  183. :arg_status,
  184. :arg_woodcode,
  185. :arg_pcode,
  186. :ld_pypkqty,
  187. :ld_pypkamt,
  188. :ld_wasteqty,
  189. :ld_wasteamt,
  190. :arg_scid) USING arg_transaction ;
  191. IF arg_transaction.SQLCode <> 0 THEN
  192. rslt = 0
  193. arg_msg = "外协商库存物料["+arg_mtrlcode+"]结存建立操作失败"+"~n"+arg_transaction.SQLErrText
  194. GOTO ext
  195. END IF
  196. END IF
  197. ELSE
  198. rslt = 0
  199. or_err_part = 'column insert or update conflicts with a rule imposed by a previous create rule statement'
  200. IF arg_transaction.SQLCode = 513 OR Pos(Lower(arg_transaction.SQLErrText),or_err_part) > 0 THEN
  201. arg_msg = "外协商库存物料["+arg_mtrlcode+"]没有足够的结存支持冲减"
  202. ELSE
  203. arg_msg = "外协商库存物料["+arg_mtrlcode+"]结存更新操作失败"+"~n"+arg_transaction.SQLErrText
  204. END IF
  205. GOTO ext
  206. END IF
  207. ELSE
  208. UPDATE ow_wfjgware
  209. SET noallocqty = noallocqty - :arg_qty ,
  210. wareamt = 0 ,
  211. waredate = getdate(),
  212. newprice = 0,
  213. cost = 0
  214. Where ( mtrlwareid = :arg_mtrlwareid ) USING arg_transaction ;
  215. IF arg_transaction.SQLCode = 0 THEN
  216. IF arg_transaction.SQLNRows = 0 THEN
  217. ///////////////////////// //
  218. ls_newid = f_sys_scidentity(0,"ow_wfjgware","mtrlwareid",arg_msg,TRUE,id_sqlca)
  219. IF ls_newid <= 0 THEN
  220. rslt = 0
  221. GOTO ext
  222. END IF
  223. ///////////////////////// //
  224. ld_cost = Round(arg_price,sys_option_cost_dec)
  225. INSERT INTO ow_wfjgware
  226. (mtrlwareid,
  227. mtrlid,
  228. plancode,
  229. status,
  230. noallocqty,
  231. allocqty,
  232. wareamt,
  233. sptid,
  234. woodcode,
  235. pcode,
  236. cost,
  237. scid)
  238. VALUES (
  239. :ls_newid,
  240. :arg_mtrlid,
  241. :arg_plancode,
  242. :arg_status,
  243. :arg_qty,
  244. 0,
  245. 0,
  246. :arg_sptid,
  247. :arg_woodcode,
  248. :arg_pcode,
  249. 0,
  250. :arg_scid) USING arg_transaction ;
  251. IF arg_transaction.SQLCode <> 0 THEN
  252. rslt = 0
  253. arg_msg = "外协商库存物料["+arg_mtrlcode+"]库存建立操作失败"+"~n"+arg_transaction.SQLErrText
  254. GOTO ext
  255. END IF
  256. END IF
  257. ELSE
  258. rslt = 0
  259. or_err_part = 'column insert or update conflicts with a rule imposed by a previous create rule statement'
  260. IF arg_transaction.SQLCode = 513 OR Pos(Lower(arg_transaction.SQLErrText),or_err_part) > 0 OR Pos(Lower(arg_transaction.SQLErrText),'noallocqty') > 0 THEN
  261. arg_msg = "外协商库存,物料["+arg_mtrlcode+"]没有足够的库存支持冲减"
  262. ELSEIF Pos(Lower(arg_transaction.SQLErrText),'cost') > 0 or Pos(Lower(arg_transaction.SQLErrText),'wareamt') > 0 THEN
  263. arg_msg = "外协商库存,物料["+arg_mtrlcode+"]没有足够的库存金额支持冲减"
  264. ELSE
  265. arg_msg = "外协商库存物料["+arg_mtrlcode+"]库存更新操作失败"+"~n"+arg_transaction.SQLErrText
  266. END IF
  267. GOTO ext
  268. END IF
  269. //-----------------------------------更新结存
  270. ld_balcqty = arg_qty
  271. ld_balcamt = 0
  272. CHOOSE CASE arg_billtype
  273. CASE 4,5
  274. IF arg_thflag = 0 THEN
  275. ld_outqty = arg_qty
  276. ld_outamt = 0
  277. ld_reoutqty = 0
  278. ld_reoutamt = 0
  279. ld_pypkqty = 0
  280. ld_pypkamt = 0
  281. ld_wasteqty = 0
  282. ld_wasteamt = 0
  283. ELSE
  284. ld_outqty = 0
  285. ld_outamt = 0
  286. ld_reoutqty = 0 - arg_qty
  287. ld_reoutamt = 0
  288. ld_pypkqty = 0
  289. ld_pypkamt = 0
  290. ld_wasteqty = 0
  291. ld_wasteamt = 0
  292. END IF
  293. CASE 9
  294. ld_outqty = 0
  295. ld_outamt = 0
  296. ld_reoutqty = 0
  297. ld_reoutamt = 0
  298. ld_pypkqty = 0 - arg_qty
  299. ld_pypkamt = 0
  300. ld_wasteqty = 0
  301. ld_wasteamt = 0
  302. CASE 10
  303. ld_outqty = 0
  304. ld_outamt = 0
  305. ld_reoutqty = 0
  306. ld_reoutamt = 0
  307. ld_pypkqty = 0
  308. ld_pypkamt = 0
  309. ld_wasteqty = arg_qty
  310. ld_wasteamt = 0
  311. END CHOOSE
  312. UPDATE ow_wfjgbalc
  313. SET
  314. outqty = outqty + :ld_outqty ,
  315. outamt = 0,
  316. reoutqty = reoutqty + :ld_reoutqty ,
  317. reoutamt = 0,
  318. balcqty = balcqty - :ld_balcqty,
  319. balcamt = 0,
  320. pypkqty = pypkqty + :ld_pypkqty,
  321. pypkamt = 0,
  322. wasteqty = wasteqty + :ld_wasteqty,
  323. wasteamt = 0
  324. WHERE ( mtrlid = :arg_mtrlid ) AND
  325. ( sptid = :arg_sptid ) AND
  326. ( balcdateint = 0) AND
  327. ( status = :arg_status ) AND
  328. ( woodcode = :arg_woodcode ) AND
  329. ( pcode = :arg_pcode ) AND
  330. ( scid = :arg_scid ) USING arg_transaction ;
  331. IF arg_transaction.SQLCode = 0 THEN
  332. IF arg_transaction.SQLNRows = 0 THEN
  333. INSERT INTO ow_wfjgbalc
  334. ( balcdateint,
  335. mtrlid,
  336. sptid,
  337. bgqty,
  338. bgamt,
  339. inqty,
  340. inamt,
  341. outqty,
  342. outamt,
  343. reoutqty,
  344. reoutamt,
  345. thqty,
  346. thamt,
  347. balcqty,
  348. balcamt,
  349. status,
  350. woodcode,
  351. pcode,
  352. pypkqty,
  353. pypkamt,
  354. wasteqty,
  355. wasteamt,
  356. scid)
  357. VALUES (
  358. 0,
  359. :arg_mtrlid,
  360. :arg_sptid,
  361. 0,
  362. 0,
  363. 0,
  364. 0,
  365. :ld_outqty,
  366. 0,
  367. :ld_reoutqty,
  368. 0,
  369. 0,
  370. 0,
  371. 0 - :ld_balcqty,
  372. 0,
  373. :arg_status,
  374. :arg_woodcode,
  375. :arg_pcode,
  376. :ld_pypkqty,
  377. 0,
  378. :ld_wasteqty,
  379. 0,
  380. :arg_scid) USING arg_transaction ;
  381. IF arg_transaction.SQLCode <> 0 THEN
  382. rslt = 0
  383. arg_msg = "外协商库存物料["+arg_mtrlcode+"]结存建立操作失败"+"~n"+arg_transaction.SQLErrText
  384. GOTO ext
  385. END IF
  386. END IF
  387. ELSE
  388. rslt = 0
  389. or_err_part = 'column insert or update conflicts with a rule imposed by a previous create rule statement'
  390. IF arg_transaction.SQLCode = 513 OR Pos(Lower(arg_transaction.SQLErrText),or_err_part) > 0 THEN
  391. arg_msg = "外协商库存物料["+arg_mtrlcode+"]同仓库内同批号没有足够的结存支持冲减"
  392. ELSE
  393. arg_msg = "外协商库存物料["+arg_mtrlcode+"]结存更新操作失败"+"~n"+arg_transaction.SQLErrText
  394. END IF
  395. GOTO ext
  396. END IF
  397. END IF
  398. ext:
  399. IF rslt = 0 THEN
  400. ROLLBACK USING arg_transaction;
  401. ELSEIF rslt = 1 AND arg_ifcommit THEN
  402. COMMIT USING arg_transaction;
  403. END IF
  404. RETURN rslt
  405. end function