uo_spt_price.sru 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735
  1. $PBExportHeader$uo_spt_price.sru
  2. forward
  3. global type uo_spt_price from nonvisualobject
  4. end type
  5. end forward
  6. global type uo_spt_price from nonvisualobject
  7. end type
  8. global uo_spt_price uo_spt_price
  9. type variables
  10. end variables
  11. forward prototypes
  12. public function integer uf_del_sdsptprice (long arg_mtrlid, long arg_sptid, string arg_unit, string arg_status, string arg_woodcode, string arg_pcode, datetime arg_opdate, decimal arg_price, decimal arg_zqrate, boolean arg_ifcommit, ref string arg_msg)
  13. public function integer uf_getmtrlsptprice (long arg_sptid, long arg_mtrlid, ref string arg_unit, string arg_status, string arg_woodcode, string arg_pcode, long arg_flag, ref decimal arg_price, ref decimal arg_zqrate, ref decimal arg_rate, ref string arg_msg)
  14. public function integer uf_getmtrlsptprice_ch (long arg_sptid, long arg_mtrlid, string arg_unit, string arg_status, string arg_woodcode, string arg_pcode, ref decimal arg_price, ref decimal arg_rate, ref datetime arg_lastdate, ref string arg_msg)
  15. public function integer uf_getmtrlname (long arg_sptid, long arg_mtrlid, ref string arg_sptmtrlname, ref string arg_msg)
  16. public function integer uf_update_sptmtrlname (long arg_sptid, long arg_mtrlid, string arg_unit, string arg_sptmtrlname, boolean arg_ifcommit, ref string arg_msg)
  17. public function integer uf_update_sptprice (integer arg_ifth, long arg_sptid, long arg_mtrlid, string arg_unit, string arg_status, string arg_woodcode, string arg_pcode, long arg_inwareid, long arg_moneyid, decimal arg_price, decimal arg_zqrate, decimal arg_rate, decimal arg_wareprice, datetime arg_indate, string arg_inwarecode, long arg_flag, string arg_dscrp, long arg_printid, integer arg_billtype, boolean arg_ifcommit, ref string arg_msg)
  18. public function integer uf_del_sptprice (integer arg_ifth, long arg_sptid, long arg_mtrlid, string arg_unit, string arg_status, string arg_woodcode, string arg_pcode, long arg_inwareid, long arg_printid, long arg_moneyid, boolean arg_ifcommit, ref string arg_msg)
  19. public function integer uf_update_sptprice_mx_bk (integer arg_ifth, long arg_sptid, long arg_mtrlid, string arg_unit, string arg_status, string arg_woodcode, string arg_pcode, long arg_inwareid, long arg_printid, long arg_moneyid, boolean arg_ifcommit, ref string arg_msg)
  20. public function integer uf_update_sptprice_mx (integer arg_ifth, long arg_inwareid, long arg_printid, integer arg_billtype, decimal arg_price, decimal arg_zqrate, boolean arg_ifcommit, ref string arg_msg)
  21. public function integer uof_getmtrlsptprice (long arg_sptid, long arg_mtrlid, ref string arg_unit, string arg_status, string arg_woodcode, string arg_pcode, long arg_flag, ref decimal arg_price, ref decimal arg_zqrate, ref decimal arg_rate, ref string arg_msg)
  22. public function integer uof_get_mtrl_buyprice (long arg_sptid, long arg_mtrlid, ref string arg_unit, string arg_status, string arg_woodcode, string arg_pcode, long arg_flag, ref decimal arg_price, ref decimal arg_zqrate, ref decimal arg_rate, ref string arg_msg)
  23. public function integer uof_get_buyprice_his (long arg_sptid, long arg_mtrlid, ref string arg_unit, string arg_status, string arg_woodcode, string arg_pcode, ref decimal arg_price, ref decimal arg_zqrate, ref decimal arg_rate, ref string arg_msg)
  24. public function integer uof_get_bj_price (long arg_sptid, long arg_mtrlid, ref string arg_unit, string arg_status, string arg_woodcode, string arg_pcode, ref decimal arg_price, ref decimal arg_zqrate, ref decimal arg_rate, ref string arg_msg)
  25. public function integer uof_get_lmbuyprice (long arg_mtrlid, ref decimal arg_buyprice, ref decimal arg_rebate)
  26. public function integer uf_check_price_save (integer arg_thflag, long arg_sptid, long arg_mtrlid, string arg_mtrlcode, string arg_unit, string arg_status, string arg_woodcode, string arg_pcode, decimal arg_price, ref string arg_msg)
  27. public function integer uf_check_price_audit (integer arg_thflag, long arg_sptid, long arg_mtrlid, string arg_mtrlcode, string arg_unit, string arg_status, string arg_woodcode, string arg_pcode, decimal arg_price, ref string arg_msg)
  28. private function integer uf_check_price (integer arg_thflag, long arg_sptid, long arg_mtrlid, string arg_mtrlcode, string arg_unit, string arg_status, string arg_woodcode, string arg_pcode, decimal arg_price, ref string arg_msg)
  29. end prototypes
  30. public function integer uf_del_sdsptprice (long arg_mtrlid, long arg_sptid, string arg_unit, string arg_status, string arg_woodcode, string arg_pcode, datetime arg_opdate, decimal arg_price, decimal arg_zqrate, boolean arg_ifcommit, ref string arg_msg);//uf_del_sdsptprice(arg_mtrlid,arg_sptid,arg_opdate,arg_price,arg_ifcommit,arg_msg)
  31. //删除手动添加的采购价格
  32. long rslt=1
  33. long cnt=0
  34. //检查供应商存在否
  35. select count(*)
  36. into :cnt
  37. from u_spt
  38. where u_spt.sptid=:arg_sptid;
  39. if sqlca.sqlcode<>0 then
  40. rslt=0
  41. arg_msg='因网络和其他原因查询失败'+sqlca.sqlerrtext
  42. goto ext
  43. end if
  44. if cnt=0 then
  45. rslt=0
  46. arg_msg='供应商不存在'
  47. goto ext
  48. end if
  49. //检查商品存在否
  50. select count(*)
  51. into :cnt
  52. from u_mtrldef
  53. where u_mtrldef.mtrlid=:arg_mtrlid;
  54. if sqlca.sqlcode<>0 then
  55. rslt=0
  56. arg_msg='因网络和其他原因查询失败'+sqlca.sqlerrtext
  57. goto ext
  58. end if
  59. if cnt=0 then
  60. rslt=0
  61. arg_msg='编码不存在'
  62. goto ext
  63. end if
  64. //删除手动添加价格
  65. delete
  66. from u_spt_price_mx
  67. where u_spt_price_mx.sptid=:arg_sptid and u_spt_price_mx.mtrlid=:arg_mtrlid
  68. and u_spt_price_mx.opdate=:arg_opdate
  69. and u_spt_price_mx.unit=:arg_unit and u_spt_price_mx.status=:arg_status
  70. and u_spt_price_mx.woodcode=:arg_woodcode and u_spt_price_mx.pcode=:arg_pcode;
  71. if sqlca.sqlcode<>0 then
  72. rslt=0
  73. arg_msg='查询失败'+sqlca.sqlerrtext
  74. goto ext
  75. end if
  76. //更新最新价格表
  77. update u_spt_price
  78. set u_spt_price.price=:arg_price * :arg_zqrate,
  79. u_spt_price.fprice=:arg_price,
  80. u_spt_price.zqrate=:arg_zqrate
  81. where u_spt_price.sptid=:arg_sptid
  82. and u_spt_price.mtrlid=:arg_mtrlid
  83. and u_spt_price.unit=:arg_unit and u_spt_price.status=:arg_status
  84. and u_spt_price.woodcode=:arg_woodcode and u_spt_price.pcode=:arg_pcode;
  85. if sqlca.sqlcode<>0 then
  86. rslt=0
  87. arg_msg='查询失败'+sqlca.sqlerrtext
  88. goto ext
  89. end if
  90. ext:
  91. if rslt=0 then
  92. rollback;
  93. elseif rslt=1 and arg_ifcommit then
  94. commit;
  95. end if
  96. return rslt
  97. end function
  98. public function integer uf_getmtrlsptprice (long arg_sptid, long arg_mtrlid, ref string arg_unit, string arg_status, string arg_woodcode, string arg_pcode, long arg_flag, ref decimal arg_price, ref decimal arg_zqrate, ref decimal arg_rate, ref string arg_msg);Long rslt = 1
  99. Decimal rtn_price,rtn_zqrate,rtn_rate
  100. String rtn_unit
  101. String rtn_wareunit
  102. IF arg_unit = '' THEN
  103. IF sys_option_buyprice_ifbj = 0 THEN
  104. SELECT top 1 fprice,zqrate,rate,unit
  105. INTO :rtn_price,:rtn_zqrate ,:rtn_rate ,:rtn_unit
  106. FROM u_spt_price_MX
  107. WHERE u_spt_price_MX.mtrlid = :arg_mtrlid AND
  108. u_spt_price_MX.sptid = :arg_sptid AND
  109. u_spt_price_MX.woodcode = :arg_woodcode AND
  110. u_spt_price_MX.status = :arg_status AND
  111. u_spt_price_MX.pcode = :arg_pcode
  112. Order By u_spt_price_MX.opdate Desc;
  113. ELSE
  114. SELECT top 1 fprice,zqrate,rate,unit
  115. INTO :rtn_price,:rtn_zqrate ,:rtn_rate ,:rtn_unit
  116. FROM u_spt_price_MX
  117. WHERE u_spt_price_MX.mtrlid = :arg_mtrlid AND
  118. u_spt_price_MX.sptid = :arg_sptid AND
  119. u_spt_price_MX.woodcode = :arg_woodcode AND
  120. u_spt_price_MX.status = :arg_status AND
  121. u_spt_price_MX.pcode = :arg_pcode AND
  122. u_spt_price_mx.billtype = 2
  123. Order By u_spt_price_MX.opdate Desc;
  124. END IF
  125. IF sqlca.SQLCode = -1 THEN
  126. rslt = 0
  127. arg_msg = '查询操作失败'+sqlca.SQLErrText
  128. GOTO ext
  129. ELSEIF sqlca.SQLCode = 100 OR IsNull(rtn_price) THEN
  130. SELECT unit,unit_buy,rate_buy
  131. INTO :rtn_wareunit,:rtn_unit,:rtn_rate
  132. FROM u_mtrldef
  133. Where mtrlid = :arg_mtrlid;
  134. IF sqlca.SQLCode <> 0 THEN
  135. rslt = 2
  136. rtn_price = 0.00
  137. rtn_zqrate = 1
  138. rtn_rate = 1
  139. rtn_unit = ''
  140. arg_msg = '不存在资料'+sqlca.SQLErrText
  141. GOTO ext
  142. END IF
  143. IF rtn_unit = '' OR rtn_rate = 0 THEN
  144. rtn_unit = rtn_wareunit
  145. rtn_price = 0.00
  146. rtn_rate = 1
  147. rslt = 2
  148. GOTO ext
  149. END IF
  150. END IF
  151. ELSE
  152. IF sys_option_buyprice_ifbj = 0 THEN
  153. SELECT fprice,zqrate,rate,unit
  154. INTO :rtn_price,:rtn_zqrate ,:rtn_rate ,:rtn_unit
  155. FROM u_spt_price
  156. WHERE u_spt_price.mtrlid = :arg_mtrlid AND
  157. u_spt_price.sptid = :arg_sptid AND
  158. u_spt_price.unit = :arg_unit AND
  159. u_spt_price.woodcode = :arg_woodcode AND
  160. u_spt_price.status = :arg_status AND
  161. u_spt_price.pcode = :arg_pcode;
  162. ELSE
  163. SELECT top 1 fprice,zqrate,rate,unit
  164. INTO :rtn_price,:rtn_zqrate ,:rtn_rate ,:rtn_unit
  165. FROM u_spt_price_MX
  166. WHERE u_spt_price_MX.mtrlid = :arg_mtrlid AND
  167. u_spt_price_MX.sptid = :arg_sptid AND
  168. u_spt_price_MX.unit = :arg_unit AND
  169. u_spt_price_MX.woodcode = :arg_woodcode AND
  170. u_spt_price_MX.status = :arg_status AND
  171. u_spt_price_MX.pcode = :arg_pcode AND
  172. u_spt_price_mx.billtype = 2
  173. Order By u_spt_price_MX.opdate Desc;
  174. END IF
  175. IF sqlca.SQLCode = -1 THEN
  176. rslt = 0
  177. arg_msg = '查询操作失败'+sqlca.SQLErrText
  178. GOTO ext
  179. ELSEIF sqlca.SQLCode = 100 OR IsNull(rtn_price) THEN
  180. rslt = 2
  181. rtn_price = 0.00
  182. rtn_zqrate = 1
  183. GOTO ext
  184. END IF
  185. END IF
  186. ext:
  187. arg_price = rtn_price
  188. arg_zqrate = rtn_zqrate
  189. arg_rate = rtn_rate
  190. arg_unit = rtn_unit
  191. RETURN rslt
  192. end function
  193. public function integer uf_getmtrlsptprice_ch (long arg_sptid, long arg_mtrlid, string arg_unit, string arg_status, string arg_woodcode, string arg_pcode, ref decimal arg_price, ref decimal arg_rate, ref datetime arg_lastdate, ref string arg_msg);Long rslt = 1
  194. Decimal rtn_price,rtn_rate
  195. DateTime rtn_lastdate
  196. IF arg_unit = '' THEN
  197. rtn_price = 0.00
  198. rtn_rate = 1
  199. SetNull(rtn_lastdate)
  200. rslt = 2
  201. GOTO ext
  202. ELSE
  203. IF sys_option_buyprice_ifbj = 0 THEN
  204. SELECT top 1 fprice,rate,outdate
  205. INTO :rtn_price,:rtn_rate ,:rtn_lastdate
  206. FROM u_spt_price_mx
  207. WHERE u_spt_price_mx.mtrlid = :arg_mtrlid
  208. AND u_spt_price_mx.sptid = :arg_sptid
  209. AND u_spt_price_mx.unit = :arg_unit
  210. AND u_spt_price_mx.status = :arg_status
  211. AND u_spt_price_mx.woodcode = :arg_woodcode
  212. AND u_spt_price_mx.pcode = :arg_pcode
  213. Order By Opdate Desc;
  214. ELSE
  215. SELECT top 1 fprice,rate,outdate
  216. INTO :rtn_price,:rtn_rate ,:rtn_lastdate
  217. FROM u_spt_price_mx
  218. WHERE u_spt_price_mx.mtrlid = :arg_mtrlid
  219. AND u_spt_price_mx.sptid = :arg_sptid
  220. AND u_spt_price_mx.unit = :arg_unit
  221. AND u_spt_price_mx.status = :arg_status
  222. AND u_spt_price_mx.woodcode = :arg_woodcode
  223. AND u_spt_price_mx.pcode = :arg_pcode
  224. AND u_spt_price_mx.billtype = 2
  225. Order By Opdate Desc;
  226. END IF
  227. IF sqlca.SQLCode = -1 THEN
  228. rslt = 0
  229. arg_msg = '查询操作失败'+sqlca.SQLErrText
  230. GOTO ext
  231. ELSEIF sqlca.SQLCode = 100 OR IsNull(rtn_price) THEN
  232. rslt = 2
  233. rtn_price = 0.00
  234. rtn_rate = 1
  235. SetNull(rtn_lastdate)
  236. GOTO ext
  237. END IF
  238. END IF
  239. ext:
  240. arg_price = rtn_price
  241. arg_lastdate = rtn_lastdate
  242. arg_rate = rtn_rate
  243. RETURN rslt
  244. end function
  245. public function integer uf_getmtrlname (long arg_sptid, long arg_mtrlid, ref string arg_sptmtrlname, ref string arg_msg);Long rslt = 1
  246. String rtn_sptmtrlname
  247. SELECT sptmtrlname
  248. INTO :rtn_sptmtrlname
  249. FROM u_sptmtrlname
  250. WHERE u_sptmtrlname.mtrlid = :arg_mtrlid
  251. AND u_sptmtrlname.sptid = :arg_sptid;
  252. IF sqlca.SQLCode = -1 THEN
  253. rslt = 0
  254. arg_msg = '查询操作失败'+sqlca.SQLErrText
  255. GOTO ext
  256. ELSEIF sqlca.SQLCode = 100 OR IsNull(rtn_sptmtrlname) THEN
  257. rtn_sptmtrlname = ''
  258. END IF
  259. arg_sptmtrlname = rtn_sptmtrlname
  260. ext:
  261. RETURN rslt
  262. end function
  263. public function integer uf_update_sptmtrlname (long arg_sptid, long arg_mtrlid, string arg_unit, string arg_sptmtrlname, boolean arg_ifcommit, ref string arg_msg);long rslt = 1
  264. long cnt = 0
  265. if isnull(arg_sptmtrlname) then arg_sptmtrlname = ''
  266. //检查供应商存在否
  267. select count(*)
  268. into :cnt
  269. from u_spt
  270. where u_spt.sptid = :arg_sptid;
  271. if sqlca.sqlcode <> 0 then
  272. rslt = 0
  273. arg_msg = '因网络和其他原因查询失败'+sqlca.sqlerrtext
  274. goto ext
  275. end if
  276. if cnt = 0 then
  277. rslt = 0
  278. arg_msg = '供应商不存在'
  279. goto ext
  280. end if
  281. //检查商品存在否
  282. select count(*)
  283. into :cnt
  284. from u_mtrldef
  285. where u_mtrldef.mtrlid = :arg_mtrlid;
  286. if sqlca.sqlcode <> 0 then
  287. rslt = 0
  288. arg_msg = '因网络和其他原因查询失败'+sqlca.sqlerrtext
  289. goto ext
  290. end if
  291. if cnt = 0 then
  292. rslt = 0
  293. arg_msg = '物料资料不存在'
  294. goto ext
  295. end if
  296. //1.更新供应商售价表
  297. select count(*)
  298. into :cnt
  299. from u_spt_price
  300. where u_spt_price.sptid = :arg_sptid and
  301. u_spt_price.mtrlid = :arg_mtrlid;
  302. if sqlca.sqlcode <> 0 then
  303. rslt = 0
  304. arg_msg = '因网络和其他原因查询供应商物料最新价格失败'+sqlca.sqlerrtext
  305. goto ext
  306. end if
  307. if cnt > 0 then
  308. update u_spt_price
  309. set u_spt_price.sptmtrlname = :arg_sptmtrlname
  310. where u_spt_price.sptid = :arg_sptid and
  311. u_spt_price.mtrlid = :arg_mtrlid;
  312. if sqlca.sqlcode <> 0 then
  313. rslt = 0
  314. arg_msg = '因网络和其它原因,供应商物料别名更新失败'+sqlca.sqlerrtext
  315. goto ext
  316. end if
  317. elseif cnt = 0 then
  318. insert into u_spt_price
  319. (sptid,
  320. mtrlid,
  321. price,
  322. fprice,
  323. zqrate,
  324. dscrp,
  325. sptmtrlname,
  326. unit,
  327. status)
  328. values
  329. (
  330. :arg_sptid,
  331. :arg_mtrlid,
  332. 0,
  333. 0,
  334. 1,
  335. '',
  336. :arg_sptmtrlname,
  337. :arg_unit,
  338. '' );
  339. if sqlca.sqlcode <> 0 then
  340. rslt = 0
  341. arg_msg = '因网络或其他原因,新增供应商物料别名失败'
  342. goto ext
  343. end if
  344. end if
  345. ext:
  346. if rslt = 0 then
  347. rollback;
  348. elseif arg_ifcommit and rslt = 1 then
  349. commit;
  350. end if
  351. return rslt
  352. end function
  353. public function integer uf_update_sptprice (integer arg_ifth, long arg_sptid, long arg_mtrlid, string arg_unit, string arg_status, string arg_woodcode, string arg_pcode, long arg_inwareid, long arg_moneyid, decimal arg_price, decimal arg_zqrate, decimal arg_rate, decimal arg_wareprice, datetime arg_indate, string arg_inwarecode, long arg_flag, string arg_dscrp, long arg_printid, integer arg_billtype, boolean arg_ifcommit, ref string arg_msg);//====================================================================
  354. // 事件: uo_spt_price.Script - uf_update_sptprice ( integer arg_ifth, long arg_sptid, long arg_mtrlid, string arg_unit, string arg_status, string arg_woodcode, string arg_pcode, long arg_inwareid, long arg_moneyid, decimal arg_price, decimal arg_zqrate, decimal arg_rate, decim()
  355. //--------------------------------------------------------------------
  356. // 描述:更新供应商售价表及售价变动明细表
  357. //--------------------------------------------------------------------
  358. // 参数:
  359. // value integer arg_ifth 0 正常 1 退货 2 修改供应商物料名称
  360. // value long arg_sptid
  361. // value long arg_mtrlid
  362. // value string arg_unit
  363. // value string arg_status
  364. // value string arg_woodcode
  365. // value string arg_pcode
  366. // value long arg_inwareid
  367. // value long arg_moneyid
  368. // value decimal arg_price
  369. // value decimal arg_zqrate
  370. // value decimal arg_rate
  371. // value decimal arg_wareprice
  372. // value datetime arg_indate
  373. // value string arg_inwarecode
  374. // value long arg_flag 手动添加标志
  375. // value string arg_dscrp
  376. // value long arg_printid
  377. // value integer arg_billtype
  378. // value boolean arg_ifcommit
  379. // reference string arg_msg
  380. //--------------------------------------------------------------------
  381. // 返回: (none)
  382. //--------------------------------------------------------------------
  383. // 作者: LHD 日期: 2013年12月11日
  384. //--------------------------------------------------------------------
  385. // Copyright (c) 2002-2018 RICHTA(TM), All rights reserved.
  386. //--------------------------------------------------------------------
  387. // 修改历史:
  388. //
  389. //====================================================================
  390. Long rslt = 1
  391. Long cnt = 0
  392. DateTime server_time
  393. String ls_dscrp
  394. //检查退货
  395. IF arg_ifth = 1 THEN
  396. rslt = 1
  397. GOTO ext
  398. END IF
  399. //检查参数
  400. IF IsNull(arg_sptid) THEN arg_sptid = 0
  401. IF IsNull(arg_mtrlid) THEN arg_mtrlid = 0
  402. IF IsNull(arg_status) THEN arg_status = ''
  403. IF IsNull(arg_price) THEN arg_price = 0.0
  404. IF IsNull(arg_moneyid) THEN arg_moneyid = 0
  405. IF arg_indate <= DateTime(Date('1900-01-01'),Time(0)) THEN
  406. rslt = 0
  407. arg_msg = '不合理的发生时间'
  408. GOTO ext
  409. END IF
  410. IF Trim(arg_msg) = '' THEN arg_msg = ''
  411. IF Trim(arg_inwarecode) = '' THEN arg_inwarecode = ''
  412. //获得服务器时间
  413. SELECT Top 1 getdate() Into :server_time From u_user;
  414. //检查供应商存在否
  415. SELECT count(*)
  416. INTO :cnt
  417. FROM u_spt
  418. Where u_spt.sptid = :arg_sptid;
  419. IF sqlca.SQLCode <> 0 THEN
  420. rslt = 0
  421. arg_msg = '因网络和其他原因查询失败'+sqlca.SQLErrText
  422. GOTO ext
  423. END IF
  424. IF cnt = 0 THEN
  425. rslt = 0
  426. arg_msg = '供应商不存在'
  427. GOTO ext
  428. END IF
  429. cnt = 0
  430. SELECT count(*) INTO :cnt
  431. FROM cw_currency
  432. Where moneyid = :arg_moneyid;
  433. IF sqlca.SQLCode <> 0 THEN
  434. arg_msg = '查询币种失败'
  435. rslt = 0
  436. GOTO ext
  437. END IF
  438. IF cnt = 0 THEN
  439. arg_msg = '币种资料不存在'
  440. rslt = 0
  441. GOTO ext
  442. END IF
  443. //检查商品存在否
  444. SELECT count(*)
  445. INTO :cnt
  446. FROM u_mtrldef
  447. Where u_mtrldef.mtrlid = :arg_mtrlid;
  448. IF sqlca.SQLCode <> 0 THEN
  449. rslt = 0
  450. arg_msg = '因网络和其他原因查询失败'+sqlca.SQLErrText
  451. GOTO ext
  452. END IF
  453. IF cnt = 0 THEN
  454. rslt = 0
  455. arg_msg = '资料不存在'
  456. GOTO ext
  457. END IF
  458. //1.更新供应商售价表
  459. IF arg_billtype = 0 THEN
  460. ls_dscrp = '采购收货单'
  461. ELSEIF arg_billtype = 1 THEN
  462. ls_dscrp = '手动添加'
  463. ELSEIF arg_billtype = 2 THEN
  464. ls_dscrp = '调价单'
  465. ELSEIF arg_billtype = 4 THEN
  466. ls_dscrp = '外协收货单'
  467. ELSE
  468. ls_dscrp = arg_dscrp
  469. END IF
  470. UPDATE u_spt_price
  471. SET u_spt_price.price = :arg_price * :arg_zqrate,
  472. u_spt_price.fprice = :arg_price,
  473. u_spt_price.zqrate = :arg_zqrate,
  474. u_spt_price.wareprice = :arg_wareprice,
  475. u_spt_price.rate = :arg_rate,
  476. u_spt_price.dscrp = :ls_dscrp,
  477. u_spt_price.sys_changetime = getdate()
  478. WHERE u_spt_price.sptid = :arg_sptid AND
  479. u_spt_price.mtrlid = :arg_mtrlid AND
  480. u_spt_price.unit = :arg_unit AND
  481. u_spt_price.status = :arg_status AND
  482. u_spt_price.woodcode = :arg_woodcode AND
  483. u_spt_price.pcode = :arg_pcode AND
  484. u_spt_price.moneyid = :arg_moneyid;
  485. IF sqlca.SQLCode = 0 THEN
  486. IF sqlca.SQLNRows = 0 THEN
  487. INSERT INTO u_spt_price
  488. (sptid,
  489. mtrlid,
  490. price,
  491. fprice,
  492. zqrate,
  493. dscrp,
  494. unit,
  495. wareprice,
  496. rate,
  497. status,
  498. woodcode,
  499. pcode,
  500. moneyid,
  501. sys_changetime)
  502. VALUES
  503. (
  504. :arg_sptid,
  505. :arg_mtrlid,
  506. :arg_price * :arg_zqrate,
  507. :arg_price,
  508. :arg_zqrate,
  509. :ls_dscrp,
  510. :arg_unit,
  511. :arg_wareprice,
  512. :arg_rate,
  513. :arg_status,
  514. :arg_woodcode,
  515. :arg_pcode,
  516. :arg_moneyid,
  517. getdate());
  518. IF sqlca.SQLCode <> 0 THEN
  519. rslt = 0
  520. arg_msg = '新增供应商报价失败,'+sqlca.SQLErrText
  521. GOTO ext
  522. END IF
  523. END IF
  524. ELSE
  525. rslt = 0
  526. arg_msg = '供应商报价表更新失败,'+sqlca.SQLErrText
  527. GOTO ext
  528. END IF
  529. //2.插入供应商售价变动明细表
  530. INSERT INTO u_spt_price_mx
  531. (
  532. u_spt_price_mx.sptid,
  533. u_spt_price_mx.mtrlid,
  534. u_spt_price_mx.opdate,
  535. u_spt_price_mx.opemp,
  536. u_spt_price_mx.inwareid,
  537. u_spt_price_mx.inwarecode,
  538. u_spt_price_mx.outdate,
  539. u_spt_price_mx.price,
  540. u_spt_price_mx.fprice,
  541. u_spt_price_mx.zqrate,
  542. u_spt_price_mx.dscrp,
  543. u_spt_price_mx.status,
  544. u_spt_price_mx.buildtype,
  545. u_spt_price_mx.unit,
  546. u_spt_price_mx.printid,
  547. u_spt_price_mx.wareprice,
  548. u_spt_price_mx.rate,
  549. u_spt_price_mx.woodcode,
  550. u_spt_price_mx.pcode,
  551. u_spt_price_mx.billtype,
  552. moneyid
  553. )
  554. VALUES
  555. (
  556. :arg_sptid,
  557. :arg_mtrlid,
  558. :server_time,
  559. :publ_operator,
  560. :arg_inwareid,
  561. :arg_inwarecode,
  562. :arg_indate,
  563. :arg_price * :arg_zqrate,
  564. :arg_price,
  565. :arg_zqrate,
  566. :arg_dscrp,
  567. :arg_status,
  568. :arg_flag,
  569. :arg_unit,
  570. :arg_printid,
  571. :arg_wareprice,
  572. :arg_rate,
  573. :arg_woodcode,
  574. :arg_pcode,
  575. :arg_billtype,
  576. :arg_moneyid);
  577. IF sqlca.SQLCode <> 0 THEN
  578. rslt = 0
  579. arg_msg = '登记在供应商报价表失败,'+sqlca.SQLErrText
  580. GOTO ext
  581. END IF
  582. ext:
  583. IF rslt = 0 THEN
  584. ROLLBACK;
  585. ELSEIF arg_ifcommit And rslt = 1 THEN
  586. COMMIT;
  587. END IF
  588. RETURN rslt
  589. end function
  590. public function integer uf_del_sptprice (integer arg_ifth, long arg_sptid, long arg_mtrlid, string arg_unit, string arg_status, string arg_woodcode, string arg_pcode, long arg_inwareid, long arg_printid, long arg_moneyid, boolean arg_ifcommit, ref string arg_msg);//删除自动类型的价格历史记录
  591. Int rslt = 1
  592. Long cnt = 0,ll_cnt = 0
  593. DateTime ld_opdate
  594. //检查供应商存在否
  595. SELECT count(*)
  596. INTO :cnt
  597. FROM u_spt
  598. Where u_spt.sptid = :arg_sptid;
  599. IF sqlca.SQLCode <> 0 THEN
  600. rslt = 0
  601. arg_msg = '因网络和其他原因查询失败'+sqlca.SQLErrText
  602. GOTO ext
  603. END IF
  604. IF cnt = 0 THEN
  605. rslt = 0
  606. arg_msg = '供应商不存在'
  607. GOTO ext
  608. END IF
  609. //检查商品存在否
  610. SELECT count(*)
  611. INTO :cnt
  612. FROM u_mtrldef
  613. Where u_mtrldef.mtrlid = :arg_mtrlid;
  614. IF sqlca.SQLCode <> 0 THEN
  615. rslt = 0
  616. arg_msg = '因网络和其他原因查询失败'+sqlca.SQLErrText
  617. GOTO ext
  618. END IF
  619. IF cnt = 0 THEN
  620. rslt = 0
  621. arg_msg = '物料不存在'
  622. GOTO ext
  623. END IF
  624. SELECT count(*) INTO :cnt
  625. FROM u_spt_price_mx
  626. WHERE sptid = :arg_sptid
  627. AND mtrlid = :arg_mtrlid
  628. AND unit = :arg_unit
  629. AND inwareid = :arg_inwareid
  630. AND printid = :arg_printid
  631. AND status = :arg_status
  632. AND woodcode = :arg_woodcode
  633. AND pcode = :arg_pcode
  634. AND moneyid = :arg_moneyid;
  635. IF sqlca.SQLCode <> 0 THEN
  636. rslt = 0
  637. arg_msg = '查询失败'+sqlca.SQLErrText
  638. GOTO ext
  639. END IF
  640. IF cnt = 0 THEN
  641. rslt = 1
  642. GOTO ext
  643. END IF
  644. SELECT top 1 Opdate INTO :ld_opdate
  645. FROM u_spt_price_mx
  646. WHERE sptid = :arg_sptid
  647. AND mtrlid = :arg_mtrlid
  648. AND unit = :arg_unit
  649. AND inwareid = :arg_inwareid
  650. AND printid = :arg_printid
  651. AND status = :arg_status
  652. AND woodcode = :arg_woodcode
  653. AND pcode = :arg_pcode
  654. AND moneyid = :arg_moneyid
  655. Order By Opdate Desc;
  656. IF sqlca.SQLCode <> 0 THEN
  657. rslt = 0
  658. arg_msg = '查询失败'+sqlca.SQLErrText
  659. GOTO ext
  660. END IF
  661. SELECT count(*) INTO :cnt
  662. FROM u_spt_price_mx
  663. WHERE sptid = :arg_sptid
  664. AND mtrlid = :arg_mtrlid
  665. AND unit = :arg_unit
  666. AND status = :arg_status
  667. AND woodcode = :arg_woodcode
  668. AND pcode = :arg_pcode
  669. AND Opdate > :ld_opdate
  670. AND moneyid = :arg_moneyid;
  671. IF sqlca.SQLCode <> 0 THEN
  672. rslt = 0
  673. arg_msg = '查询失败'+sqlca.SQLErrText
  674. GOTO ext
  675. END IF
  676. Decimal ld_fprice,ld_zqrate,ld_price
  677. DateTime ld_sys_changetime,ld_nulldt
  678. SetNull(ld_nulldt)
  679. IF cnt = 0 THEN //如果被删明细是最新,用次新明细更新最新价
  680. SELECT count(*) INTO :ll_cnt
  681. FROM u_spt_price_mx
  682. WHERE sptid = :arg_sptid
  683. AND mtrlid = :arg_mtrlid
  684. AND unit = :arg_unit
  685. AND status = :arg_status
  686. AND woodcode = :arg_woodcode
  687. AND pcode = :arg_pcode
  688. AND Opdate < :ld_opdate
  689. AND moneyid = :arg_moneyid;
  690. IF sqlca.SQLCode <> 0 THEN
  691. rslt = 0
  692. arg_msg = '查询失败'+sqlca.SQLErrText
  693. GOTO ext
  694. END IF
  695. IF ll_cnt = 0 THEN
  696. DELETE FROM u_spt_price
  697. WHERE sptid = :arg_sptid
  698. AND mtrlid = :arg_mtrlid
  699. AND unit = :arg_unit
  700. AND status = :arg_status
  701. AND woodcode = :arg_woodcode
  702. AND pcode = :arg_pcode
  703. AND moneyid = :arg_moneyid;
  704. IF sqlca.SQLCode <> 0 THEN
  705. rslt = 0
  706. arg_msg = '更新最新价失败'+sqlca.SQLErrText
  707. GOTO ext
  708. END IF
  709. ELSE
  710. SELECT top 1 fprice,zqrate,price,sys_changetime
  711. INTO :ld_fprice,:ld_zqrate,:ld_price,:ld_sys_changetime
  712. FROM u_spt_price_mx
  713. WHERE sptid = :arg_sptid
  714. AND mtrlid = :arg_mtrlid
  715. AND unit = :arg_unit
  716. AND status = :arg_status
  717. AND woodcode = :arg_woodcode
  718. AND pcode = :arg_pcode
  719. AND Opdate < :ld_opdate
  720. AND moneyid = :arg_moneyid
  721. Order By Opdate Desc;
  722. IF sqlca.SQLCode <> 0 THEN
  723. rslt = 0
  724. arg_msg = '查询失败'+sqlca.SQLErrText
  725. GOTO ext
  726. END IF
  727. UPDATE u_spt_price
  728. SET fprice = :ld_fprice ,
  729. zqrate = :ld_zqrate,
  730. price = :ld_price,
  731. sys_changetime = :ld_sys_changetime
  732. WHERE sptid = :arg_sptid
  733. AND mtrlid = :arg_mtrlid
  734. AND unit = :arg_unit
  735. AND status = :arg_status
  736. AND woodcode = :arg_woodcode
  737. AND pcode = :arg_pcode
  738. AND moneyid = :arg_moneyid;
  739. IF sqlca.SQLCode <> 0 THEN
  740. rslt = 0
  741. arg_msg = '更新最新价失败'+sqlca.SQLErrText
  742. GOTO ext
  743. END IF
  744. END IF
  745. END IF
  746. //删除手动添加价格
  747. DELETE
  748. FROM u_spt_price_mx
  749. Where sptid = :arg_sptid
  750. AND mtrlid = :arg_mtrlid
  751. AND unit = :arg_unit
  752. AND inwareid = :arg_inwareid
  753. AND printid = :arg_printid
  754. AND status = :arg_status
  755. AND woodcode = :arg_woodcode
  756. AND pcode = :arg_pcode
  757. AND moneyid = :arg_moneyid;
  758. IF sqlca.SQLCode <> 0 THEN
  759. rslt = 0
  760. arg_msg = '查询失败'+sqlca.SQLErrText
  761. GOTO ext
  762. END IF
  763. ext:
  764. IF rslt = 0 THEN
  765. ROLLBACK;
  766. ELSEIF rslt = 1 AND arg_ifcommit THEN
  767. COMMIT;
  768. END IF
  769. RETURN rslt
  770. end function
  771. public function integer uf_update_sptprice_mx_bk (integer arg_ifth, long arg_sptid, long arg_mtrlid, string arg_unit, string arg_status, string arg_woodcode, string arg_pcode, long arg_inwareid, long arg_printid, long arg_moneyid, boolean arg_ifcommit, ref string arg_msg);//删除自动类型的价格历史记录
  772. Int rslt = 1
  773. Long cnt = 0,ll_cnt = 0
  774. DateTime ld_opdate
  775. //检查供应商存在否
  776. SELECT count(*)
  777. INTO :cnt
  778. FROM u_spt
  779. Where u_spt.sptid = :arg_sptid;
  780. IF sqlca.SQLCode <> 0 THEN
  781. rslt = 0
  782. arg_msg = '因网络和其他原因查询失败'+sqlca.SQLErrText
  783. GOTO ext
  784. END IF
  785. IF cnt = 0 THEN
  786. rslt = 0
  787. arg_msg = '供应商不存在'
  788. GOTO ext
  789. END IF
  790. //检查商品存在否
  791. SELECT count(*)
  792. INTO :cnt
  793. FROM u_mtrldef
  794. Where u_mtrldef.mtrlid = :arg_mtrlid;
  795. IF sqlca.SQLCode <> 0 THEN
  796. rslt = 0
  797. arg_msg = '因网络和其他原因查询失败'+sqlca.SQLErrText
  798. GOTO ext
  799. END IF
  800. IF cnt = 0 THEN
  801. rslt = 0
  802. arg_msg = '物料不存在'
  803. GOTO ext
  804. END IF
  805. SELECT count(*) INTO :cnt
  806. FROM u_spt_price_mx
  807. WHERE sptid = :arg_sptid
  808. AND mtrlid = :arg_mtrlid
  809. AND unit = :arg_unit
  810. AND inwareid = :arg_inwareid
  811. AND printid = :arg_printid
  812. AND status = :arg_status
  813. AND woodcode = :arg_woodcode
  814. AND pcode = :arg_pcode
  815. AND moneyid = :arg_moneyid;
  816. IF sqlca.SQLCode <> 0 THEN
  817. rslt = 0
  818. arg_msg = '查询失败'+sqlca.SQLErrText
  819. GOTO ext
  820. END IF
  821. IF cnt = 0 THEN
  822. rslt = 1
  823. GOTO ext
  824. END IF
  825. SELECT top 1 Opdate INTO :ld_opdate
  826. FROM u_spt_price_mx
  827. WHERE sptid = :arg_sptid
  828. AND mtrlid = :arg_mtrlid
  829. AND unit = :arg_unit
  830. AND inwareid = :arg_inwareid
  831. AND printid = :arg_printid
  832. AND status = :arg_status
  833. AND woodcode = :arg_woodcode
  834. AND pcode = :arg_pcode
  835. AND moneyid = :arg_moneyid
  836. Order By Opdate Desc;
  837. IF sqlca.SQLCode <> 0 THEN
  838. rslt = 0
  839. arg_msg = '查询失败'+sqlca.SQLErrText
  840. GOTO ext
  841. END IF
  842. //查询此明细后是否有记录
  843. SELECT count(*) INTO :cnt
  844. FROM u_spt_price_mx
  845. WHERE sptid = :arg_sptid
  846. AND mtrlid = :arg_mtrlid
  847. AND unit = :arg_unit
  848. AND status = :arg_status
  849. AND woodcode = :arg_woodcode
  850. AND pcode = :arg_pcode
  851. AND Opdate > :ld_opdate
  852. AND moneyid = :arg_moneyid;
  853. IF sqlca.SQLCode <> 0 THEN
  854. rslt = 0
  855. arg_msg = '查询失败'+sqlca.SQLErrText
  856. GOTO ext
  857. END IF
  858. Decimal ld_fprice,ld_zqrate,ld_price
  859. DateTime ld_sys_changetime,ld_nulldt
  860. SetNull(ld_nulldt)
  861. IF cnt = 0 THEN //如果被删明细是最新,用新价更新最新价
  862. SELECT count(*) INTO :ll_cnt
  863. FROM u_spt_price_mx
  864. WHERE sptid = :arg_sptid
  865. AND mtrlid = :arg_mtrlid
  866. AND unit = :arg_unit
  867. AND status = :arg_status
  868. AND woodcode = :arg_woodcode
  869. AND pcode = :arg_pcode
  870. AND Opdate < :ld_opdate
  871. AND moneyid = :arg_moneyid;
  872. IF sqlca.SQLCode <> 0 THEN
  873. rslt = 0
  874. arg_msg = '查询失败'+sqlca.SQLErrText
  875. GOTO ext
  876. END IF
  877. IF ll_cnt = 0 THEN
  878. DELETE FROM u_spt_price
  879. WHERE sptid = :arg_sptid
  880. AND mtrlid = :arg_mtrlid
  881. AND unit = :arg_unit
  882. AND status = :arg_status
  883. AND woodcode = :arg_woodcode
  884. AND pcode = :arg_pcode
  885. AND moneyid = :arg_moneyid;
  886. IF sqlca.SQLCode <> 0 THEN
  887. rslt = 0
  888. arg_msg = '更新最新价失败'+sqlca.SQLErrText
  889. GOTO ext
  890. END IF
  891. ELSE
  892. SELECT top 1 fprice,zqrate,price,sys_changetime
  893. INTO :ld_fprice,:ld_zqrate,:ld_price,:ld_sys_changetime
  894. FROM u_spt_price_mx
  895. WHERE sptid = :arg_sptid
  896. AND mtrlid = :arg_mtrlid
  897. AND unit = :arg_unit
  898. AND status = :arg_status
  899. AND woodcode = :arg_woodcode
  900. AND pcode = :arg_pcode
  901. AND Opdate < :ld_opdate
  902. AND moneyid = :arg_moneyid
  903. Order By Opdate Desc;
  904. IF sqlca.SQLCode <> 0 THEN
  905. rslt = 0
  906. arg_msg = '查询失败'+sqlca.SQLErrText
  907. GOTO ext
  908. END IF
  909. UPDATE u_spt_price
  910. SET fprice = :ld_fprice ,
  911. zqrate = :ld_zqrate,
  912. price = :ld_price,
  913. sys_changetime = :ld_sys_changetime
  914. WHERE sptid = :arg_sptid
  915. AND mtrlid = :arg_mtrlid
  916. AND unit = :arg_unit
  917. AND status = :arg_status
  918. AND woodcode = :arg_woodcode
  919. AND pcode = :arg_pcode
  920. AND moneyid = :arg_moneyid;
  921. IF sqlca.SQLCode <> 0 THEN
  922. rslt = 0
  923. arg_msg = '更新最新价失败'+sqlca.SQLErrText
  924. GOTO ext
  925. END IF
  926. END IF
  927. END IF
  928. //删除手动添加价格
  929. DELETE
  930. FROM u_spt_price_mx
  931. Where sptid = :arg_sptid
  932. AND mtrlid = :arg_mtrlid
  933. AND unit = :arg_unit
  934. AND inwareid = :arg_inwareid
  935. AND printid = :arg_printid
  936. AND status = :arg_status
  937. AND woodcode = :arg_woodcode
  938. AND pcode = :arg_pcode
  939. AND moneyid = :arg_moneyid;
  940. IF sqlca.SQLCode <> 0 THEN
  941. rslt = 0
  942. arg_msg = '查询失败'+sqlca.SQLErrText
  943. GOTO ext
  944. END IF
  945. ext:
  946. IF rslt = 0 THEN
  947. ROLLBACK;
  948. ELSEIF rslt = 1 AND arg_ifcommit THEN
  949. COMMIT;
  950. END IF
  951. RETURN rslt
  952. end function
  953. public function integer uf_update_sptprice_mx (integer arg_ifth, long arg_inwareid, long arg_printid, integer arg_billtype, decimal arg_price, decimal arg_zqrate, boolean arg_ifcommit, ref string arg_msg);//更新因修改单价导致的单价不对应的价格历史记录
  954. Int rslt = 1
  955. Long cnt = 0,ll_cnt = 0
  956. DateTime ld_opdate
  957. if arg_ifth = 1 then
  958. rslt = 1
  959. goto ext
  960. end if
  961. SELECT count(*) INTO :cnt
  962. FROM u_spt_price_mx
  963. WHERE inwareid = :arg_inwareid
  964. AND printid = :arg_printid;
  965. IF sqlca.SQLCode <> 0 THEN
  966. rslt = 0
  967. arg_msg = '查询失败'+sqlca.SQLErrText
  968. GOTO ext
  969. END IF
  970. IF cnt = 0 THEN
  971. rslt = 1
  972. GOTO ext
  973. END IF
  974. string ll_sptid, ll_mtrlid, ll_moneyid
  975. string ls_unit, ls_status, ls_woodcode, ls_pcode
  976. SELECT top 1 Opdate ,sptid, mtrlid,unit ,status,woodcode,pcode,moneyid
  977. INTO :ld_opdate,:ll_sptid, :ll_mtrlid, :ls_unit, :ls_status, :ls_woodcode, :ls_pcode, :ll_moneyid
  978. FROM u_spt_price_mx
  979. WHERE inwareid = :arg_inwareid
  980. AND printid = :arg_printid
  981. Order By Opdate Desc;
  982. IF sqlca.SQLCode <> 0 THEN
  983. rslt = 0
  984. arg_msg = '查询失败'+sqlca.SQLErrText
  985. GOTO ext
  986. END IF
  987. //查询此明细后是否有记录
  988. SELECT count(*) INTO :cnt
  989. FROM u_spt_price_mx
  990. WHERE sptid = :ll_sptid
  991. AND mtrlid = :ll_mtrlid
  992. AND unit = :ls_unit
  993. AND status = :ls_status
  994. AND woodcode = :ls_woodcode
  995. AND pcode = :ls_pcode
  996. AND moneyid = :ll_moneyid
  997. AND Opdate > :ld_opdate;
  998. IF sqlca.SQLCode <> 0 THEN
  999. rslt = 0
  1000. arg_msg = '查询失败'+sqlca.SQLErrText
  1001. GOTO ext
  1002. END IF
  1003. Decimal ld_fprice,ld_zqrate,ld_price
  1004. DateTime ld_sys_changetime,ld_nulldt
  1005. SetNull(ld_nulldt)
  1006. IF cnt = 0 THEN //如果被删明细是最新,用新价更新最新价
  1007. UPDATE u_spt_price
  1008. SET u_spt_price.sptid = :ll_sptid,
  1009. u_spt_price.mtrlid = :ll_mtrlid,
  1010. u_spt_price.price = :arg_price * :arg_zqrate,
  1011. u_spt_price.fprice = :arg_price,
  1012. u_spt_price.zqrate = :arg_zqrate
  1013. WHERE u_spt_price.sptid = :ll_sptid AND
  1014. u_spt_price.mtrlid = :ll_mtrlid AND
  1015. u_spt_price.unit = :ls_unit AND
  1016. u_spt_price.status = :ls_status AND
  1017. u_spt_price.woodcode = :ls_woodcode AND
  1018. u_spt_price.pcode = :ls_pcode AND
  1019. u_spt_price.moneyid = :ll_moneyid;
  1020. IF sqlca.SQLCode <> 0 THEN
  1021. rslt = 0
  1022. arg_msg = '因网络和其它原因,供应商报价表更新失败'+sqlca.SQLErrText
  1023. GOTO ext
  1024. END IF
  1025. END IF
  1026. UPDATE u_spt_price_mx
  1027. SET price = :arg_price * :arg_zqrate,
  1028. fprice = :arg_price,
  1029. zqrate = :arg_zqrate
  1030. WHERE inwareid = :arg_inwareid
  1031. AND printid = :arg_printid
  1032. AND sptid = :ll_sptid
  1033. AND mtrlid = :ll_mtrlid
  1034. AND unit = :ls_unit
  1035. AND status = :ls_status
  1036. AND woodcode = :ls_woodcode
  1037. AND pcode = :ls_pcode
  1038. AND moneyid = :ll_moneyid;
  1039. IF sqlca.SQLCode <> 0 THEN
  1040. rslt = 0
  1041. arg_msg = '因网络或其他原因,更新在供应商报价明细表失败'
  1042. GOTO ext
  1043. END IF
  1044. ext:
  1045. IF rslt = 0 THEN
  1046. ROLLBACK;
  1047. ELSEIF rslt = 1 AND arg_ifcommit THEN
  1048. COMMIT;
  1049. END IF
  1050. RETURN rslt
  1051. end function
  1052. public function integer uof_getmtrlsptprice (long arg_sptid, long arg_mtrlid, ref string arg_unit, string arg_status, string arg_woodcode, string arg_pcode, long arg_flag, ref decimal arg_price, ref decimal arg_zqrate, ref decimal arg_rate, ref string arg_msg);Long rslt = 1
  1053. Decimal rtn_price,rtn_zqrate,rtn_rate
  1054. String rtn_unit
  1055. String rtn_wareunit
  1056. IF arg_unit = '' THEN
  1057. IF sys_option_buyprice_ifbj = 0 THEN
  1058. SELECT top 1 fprice,zqrate,rate,unit
  1059. INTO :rtn_price,:rtn_zqrate ,:rtn_rate ,:rtn_unit
  1060. FROM u_spt_price_MX
  1061. WHERE u_spt_price_MX.mtrlid = :arg_mtrlid AND
  1062. u_spt_price_MX.sptid = :arg_sptid AND
  1063. u_spt_price_MX.woodcode = :arg_woodcode AND
  1064. u_spt_price_MX.status = :arg_status AND
  1065. u_spt_price_MX.pcode = :arg_pcode
  1066. Order By u_spt_price_MX.opdate Desc;
  1067. ELSE
  1068. SELECT top 1 fprice,zqrate,rate,unit
  1069. INTO :rtn_price,:rtn_zqrate ,:rtn_rate ,:rtn_unit
  1070. FROM u_spt_price_MX
  1071. WHERE u_spt_price_MX.mtrlid = :arg_mtrlid AND
  1072. u_spt_price_MX.sptid = :arg_sptid AND
  1073. u_spt_price_MX.woodcode = :arg_woodcode AND
  1074. u_spt_price_MX.status = :arg_status AND
  1075. u_spt_price_MX.pcode = :arg_pcode AND
  1076. u_spt_price_mx.billtype = 2
  1077. Order By u_spt_price_MX.opdate Desc;
  1078. END IF
  1079. IF sqlca.SQLCode = -1 THEN
  1080. rslt = 0
  1081. arg_msg = '查询操作失败'+sqlca.SQLErrText
  1082. GOTO ext
  1083. ELSEIF sqlca.SQLCode = 100 OR IsNull(rtn_price) THEN
  1084. SELECT unit,unit_buy,rate_buy
  1085. INTO :rtn_wareunit,:rtn_unit,:rtn_rate
  1086. FROM u_mtrldef
  1087. Where mtrlid = :arg_mtrlid;
  1088. IF sqlca.SQLCode <> 0 THEN
  1089. rslt = 2
  1090. rtn_price = 0.00
  1091. rtn_zqrate = 1
  1092. rtn_rate = 1
  1093. rtn_unit = ''
  1094. arg_msg = '不存在资料'+sqlca.SQLErrText
  1095. GOTO ext
  1096. END IF
  1097. IF rtn_unit = '' OR rtn_rate = 0 THEN
  1098. rtn_unit = rtn_wareunit
  1099. rtn_price = 0.00
  1100. rtn_rate = 1
  1101. rslt = 2
  1102. GOTO ext
  1103. END IF
  1104. END IF
  1105. ELSE
  1106. IF sys_option_buyprice_ifbj = 0 THEN
  1107. SELECT fprice,zqrate,rate,unit
  1108. INTO :rtn_price,:rtn_zqrate ,:rtn_rate ,:rtn_unit
  1109. FROM u_spt_price
  1110. WHERE u_spt_price.mtrlid = :arg_mtrlid AND
  1111. u_spt_price.sptid = :arg_sptid AND
  1112. u_spt_price.unit = :arg_unit AND
  1113. u_spt_price.woodcode = :arg_woodcode AND
  1114. u_spt_price.status = :arg_status AND
  1115. u_spt_price.pcode = :arg_pcode;
  1116. ELSE
  1117. SELECT top 1 fprice,zqrate,rate,unit
  1118. INTO :rtn_price,:rtn_zqrate ,:rtn_rate ,:rtn_unit
  1119. FROM u_spt_price_MX
  1120. WHERE u_spt_price_MX.mtrlid = :arg_mtrlid AND
  1121. u_spt_price_MX.sptid = :arg_sptid AND
  1122. u_spt_price_MX.unit = :arg_unit AND
  1123. u_spt_price_MX.woodcode = :arg_woodcode AND
  1124. u_spt_price_MX.status = :arg_status AND
  1125. u_spt_price_MX.pcode = :arg_pcode AND
  1126. u_spt_price_mx.billtype = 2
  1127. Order By u_spt_price_MX.opdate Desc;
  1128. END IF
  1129. IF sqlca.SQLCode = -1 THEN
  1130. rslt = 0
  1131. arg_msg = '查询操作失败'+sqlca.SQLErrText
  1132. GOTO ext
  1133. ELSEIF sqlca.SQLCode = 100 OR IsNull(rtn_price) THEN
  1134. rslt = 2
  1135. rtn_price = 0.00
  1136. rtn_zqrate = 1
  1137. GOTO ext
  1138. END IF
  1139. END IF
  1140. ext:
  1141. arg_price = rtn_price
  1142. arg_zqrate = rtn_zqrate
  1143. arg_rate = rtn_rate
  1144. arg_unit = rtn_unit
  1145. RETURN rslt
  1146. end function
  1147. public function integer uof_get_mtrl_buyprice (long arg_sptid, long arg_mtrlid, ref string arg_unit, string arg_status, string arg_woodcode, string arg_pcode, long arg_flag, ref decimal arg_price, ref decimal arg_zqrate, ref decimal arg_rate, ref string arg_msg);Long rslt = 1
  1148. Decimal rtn_price,rtn_zqrate,rtn_rate
  1149. String rtn_unit
  1150. String rtn_wareunit
  1151. Decimal lde_buyprice, lde_rebate
  1152. //参数合法性检查
  1153. //IF arg_sptid = 0 THEN
  1154. // rslt = 0
  1155. // GOTO ext
  1156. //END IF
  1157. IF arg_mtrlid = 0 THEN
  1158. rslt = 0
  1159. GOTO ext
  1160. END IF
  1161. IF sys_option_buyprice_ifbj = 0 THEN //取采购历史
  1162. IF uof_get_buyprice_his(arg_sptid, arg_mtrlid, arg_unit , arg_status, arg_woodcode, arg_pcode, lde_buyprice, lde_rebate,arg_rate,arg_msg) = 0 THEN
  1163. lde_buyprice = 0
  1164. lde_rebate = 1
  1165. END IF
  1166. rtn_price = lde_buyprice
  1167. rtn_zqrate = lde_rebate
  1168. rtn_unit = arg_unit
  1169. rtn_rate = arg_rate
  1170. ELSEIF sys_option_buyprice_ifbj = 1 THEN //取报价
  1171. IF uof_get_bj_price(arg_sptid, arg_mtrlid, arg_unit , arg_status, arg_woodcode, arg_pcode, lde_buyprice, lde_rebate,arg_rate,arg_msg) = 0 THEN
  1172. lde_buyprice = 0
  1173. lde_rebate = 1
  1174. END IF
  1175. rtn_price = lde_buyprice
  1176. rtn_zqrate = lde_rebate
  1177. rtn_unit = arg_unit
  1178. rtn_rate = arg_rate
  1179. ELSEIF sys_option_buyprice_ifbj = 2 THEN //取设定购价
  1180. IF uof_get_lmbuyprice(arg_mtrlid, lde_buyprice, lde_rebate) = 0 THEN
  1181. lde_buyprice = 0
  1182. lde_rebate = 1
  1183. END IF
  1184. rtn_price = lde_buyprice
  1185. rtn_zqrate = lde_rebate
  1186. END IF
  1187. ext:
  1188. arg_price = rtn_price
  1189. arg_zqrate = rtn_zqrate
  1190. arg_rate = rtn_rate
  1191. arg_unit = rtn_unit
  1192. RETURN rslt
  1193. end function
  1194. public function integer uof_get_buyprice_his (long arg_sptid, long arg_mtrlid, ref string arg_unit, string arg_status, string arg_woodcode, string arg_pcode, ref decimal arg_price, ref decimal arg_zqrate, ref decimal arg_rate, ref string arg_msg);//取价格历史
  1195. Long rslt = 1
  1196. Decimal rtn_price,rtn_zqrate,rtn_rate
  1197. String rtn_unit
  1198. String rtn_wareunit
  1199. IF arg_unit = '' THEN
  1200. SELECT top 1 fprice,zqrate,rate,unit
  1201. INTO :rtn_price,:rtn_zqrate ,:rtn_rate ,:rtn_unit
  1202. FROM u_spt_price_MX
  1203. WHERE u_spt_price_MX.mtrlid = :arg_mtrlid AND
  1204. u_spt_price_MX.sptid = :arg_sptid AND
  1205. u_spt_price_MX.status = :arg_status AND
  1206. u_spt_price_MX.woodcode = :arg_woodcode AND
  1207. u_spt_price_MX.pcode = :arg_pcode
  1208. Order By u_spt_price_MX.opdate Desc;
  1209. IF sqlca.SQLCode = -1 THEN
  1210. rslt = 0
  1211. arg_msg = '查询操作失败'+sqlca.SQLErrText
  1212. GOTO ext
  1213. ELSEIF sqlca.SQLCode = 100 Or IsNull(rtn_price) THEN
  1214. SELECT unit,unit_buy,rate_buy
  1215. INTO :rtn_wareunit,:rtn_unit,:rtn_rate
  1216. FROM u_mtrldef
  1217. Where mtrlid = :arg_mtrlid;
  1218. IF sqlca.SQLCode <> 0 THEN
  1219. rslt = 2
  1220. rtn_price = 0.00
  1221. rtn_zqrate = 1
  1222. rtn_rate = 1
  1223. rtn_unit = ''
  1224. arg_msg = '不存在资料'+sqlca.SQLErrText
  1225. GOTO ext
  1226. END IF
  1227. IF rtn_unit = '' Or rtn_rate = 0 THEN
  1228. rtn_unit = rtn_wareunit
  1229. rtn_price = 0.00
  1230. rtn_rate = 1
  1231. rslt = 2
  1232. GOTO ext
  1233. END IF
  1234. END IF
  1235. ELSE
  1236. SELECT fprice,zqrate,rate,unit
  1237. INTO :rtn_price,:rtn_zqrate ,:rtn_rate ,:rtn_unit
  1238. FROM u_spt_price
  1239. WHERE u_spt_price.mtrlid = :arg_mtrlid AND
  1240. u_spt_price.sptid = :arg_sptid AND
  1241. u_spt_price.unit = :arg_unit AND
  1242. u_spt_price.woodcode = :arg_woodcode AND
  1243. u_spt_price.status = :arg_status AND
  1244. u_spt_price.pcode = :arg_pcode;
  1245. IF sqlca.SQLCode = -1 THEN
  1246. rslt = 0
  1247. arg_msg = '查询操作失败'+sqlca.SQLErrText
  1248. GOTO ext
  1249. ELSEIF sqlca.SQLCode = 100 Or IsNull(rtn_price) THEN
  1250. rslt = 2
  1251. rtn_price = 0.00
  1252. rtn_zqrate = 1
  1253. GOTO ext
  1254. END IF
  1255. END IF
  1256. ext:
  1257. arg_price = rtn_price
  1258. arg_zqrate = rtn_zqrate
  1259. arg_rate = rtn_rate
  1260. arg_unit = rtn_unit
  1261. RETURN rslt
  1262. end function
  1263. public function integer uof_get_bj_price (long arg_sptid, long arg_mtrlid, ref string arg_unit, string arg_status, string arg_woodcode, string arg_pcode, ref decimal arg_price, ref decimal arg_zqrate, ref decimal arg_rate, ref string arg_msg);Long rslt = 1
  1264. Decimal rtn_price,rtn_zqrate,rtn_rate
  1265. String rtn_unit
  1266. String rtn_wareunit
  1267. IF arg_unit = '' THEN
  1268. SELECT top 1 fprice,zqrate,rate,unit
  1269. INTO :rtn_price,:rtn_zqrate ,:rtn_rate ,:rtn_unit
  1270. FROM u_spt_price_MX
  1271. WHERE u_spt_price_MX.mtrlid = :arg_mtrlid AND
  1272. u_spt_price_MX.sptid = :arg_sptid AND
  1273. u_spt_price_MX.woodcode = :arg_woodcode AND
  1274. u_spt_price_MX.status = :arg_status AND
  1275. u_spt_price_MX.pcode = :arg_pcode AND
  1276. u_spt_price_mx.billtype = 2
  1277. Order By u_spt_price_MX.opdate Desc;
  1278. IF sqlca.SQLCode = -1 THEN
  1279. rslt = 0
  1280. arg_msg = '查询操作失败'+sqlca.SQLErrText
  1281. GOTO ext
  1282. ELSEIF sqlca.SQLCode = 100 OR IsNull(rtn_price) THEN
  1283. SELECT unit,unit_buy,rate_buy
  1284. INTO :rtn_wareunit,:rtn_unit,:rtn_rate
  1285. FROM u_mtrldef
  1286. Where mtrlid = :arg_mtrlid;
  1287. IF sqlca.SQLCode <> 0 THEN
  1288. rslt = 2
  1289. rtn_price = 0.00
  1290. rtn_zqrate = 1
  1291. rtn_rate = 1
  1292. rtn_unit = ''
  1293. arg_msg = '不存在资料'+sqlca.SQLErrText
  1294. GOTO ext
  1295. END IF
  1296. IF rtn_unit = '' OR rtn_rate = 0 THEN
  1297. rtn_unit = rtn_wareunit
  1298. rtn_price = 0.00
  1299. rtn_rate = 1
  1300. rslt = 2
  1301. GOTO ext
  1302. END IF
  1303. END IF
  1304. ELSE
  1305. SELECT top 1 fprice,zqrate,rate,unit
  1306. INTO :rtn_price,:rtn_zqrate ,:rtn_rate ,:rtn_unit
  1307. FROM u_spt_price_MX
  1308. WHERE u_spt_price_MX.mtrlid = :arg_mtrlid AND
  1309. u_spt_price_MX.sptid = :arg_sptid AND
  1310. u_spt_price_MX.unit = :arg_unit AND
  1311. u_spt_price_MX.woodcode = :arg_woodcode AND
  1312. u_spt_price_MX.status = :arg_status AND
  1313. u_spt_price_MX.pcode = :arg_pcode AND
  1314. u_spt_price_mx.billtype = 2
  1315. Order By u_spt_price_MX.opdate Desc;
  1316. IF sqlca.SQLCode = -1 THEN
  1317. rslt = 0
  1318. arg_msg = '查询操作失败'+sqlca.SQLErrText
  1319. GOTO ext
  1320. ELSEIF sqlca.SQLCode = 100 OR IsNull(rtn_price) THEN
  1321. rslt = 2
  1322. rtn_price = 0.00
  1323. rtn_zqrate = 1
  1324. GOTO ext
  1325. END IF
  1326. END IF
  1327. ext:
  1328. arg_price = rtn_price
  1329. arg_zqrate = rtn_zqrate
  1330. arg_rate = rtn_rate
  1331. arg_unit = rtn_unit
  1332. RETURN rslt
  1333. end function
  1334. public function integer uof_get_lmbuyprice (long arg_mtrlid, ref decimal arg_buyprice, ref decimal arg_rebate);Int rslt = 1
  1335. SELECT lmbuyprice
  1336. INTO :arg_buyprice
  1337. FROM u_mtrldef
  1338. Where mtrlid = :arg_mtrlid;
  1339. IF sqlca.SQLCode <> 0 THEN
  1340. arg_buyprice = 0
  1341. END IF
  1342. arg_rebate = 1
  1343. RETURN rslt
  1344. end function
  1345. public function integer uf_check_price_save (integer arg_thflag, long arg_sptid, long arg_mtrlid, string arg_mtrlcode, string arg_unit, string arg_status, string arg_woodcode, string arg_pcode, decimal arg_price, ref string arg_msg);//====================================================================
  1346. // Function: uf_check_price()
  1347. //--------------------------------------------------------------------
  1348. // Description:
  1349. //--------------------------------------------------------------------
  1350. // Arguments:
  1351. // value long arg_sptid
  1352. // value long arg_mtrlid
  1353. // value string arg_mtrlcode
  1354. // value decimal arg_price
  1355. // reference string arg_msg
  1356. //--------------------------------------------------------------------
  1357. // Returns: integer
  1358. //--------------------------------------------------------------------
  1359. // Author: yyx Date: 2004.07.21
  1360. //--------------------------------------------------------------------
  1361. // Modify History:
  1362. //
  1363. //====================================================================
  1364. Int rslt = 1
  1365. //124 保存, 1769 审核
  1366. IF Not f_power_ind(124) Or sys_power_issuper THEN
  1367. rslt = 1
  1368. GOTO ext
  1369. END IF
  1370. IF uf_check_price(arg_thflag, arg_sptid, arg_mtrlid, arg_mtrlcode, arg_unit, arg_status, arg_woodcode, arg_pcode, arg_price, arg_msg) = 0 THEN
  1371. rslt = 0
  1372. GOTO ext
  1373. END IF
  1374. ext:
  1375. RETURN rslt
  1376. end function
  1377. public function integer uf_check_price_audit (integer arg_thflag, long arg_sptid, long arg_mtrlid, string arg_mtrlcode, string arg_unit, string arg_status, string arg_woodcode, string arg_pcode, decimal arg_price, ref string arg_msg);//====================================================================
  1378. // Function: uf_check_price()
  1379. //--------------------------------------------------------------------
  1380. // Description:
  1381. //--------------------------------------------------------------------
  1382. // Arguments:
  1383. // value long arg_sptid
  1384. // value long arg_mtrlid
  1385. // value string arg_mtrlcode
  1386. // value decimal arg_price
  1387. // reference string arg_msg
  1388. //--------------------------------------------------------------------
  1389. // Returns: integer
  1390. //--------------------------------------------------------------------
  1391. // Author: yyx Date: 2004.07.21
  1392. //--------------------------------------------------------------------
  1393. // Modify History:
  1394. //
  1395. //====================================================================
  1396. Int rslt = 1
  1397. //124 保存, 1769 审核
  1398. IF Not f_power_ind(1769) Or sys_power_issuper THEN
  1399. rslt = 1
  1400. GOTO ext
  1401. END IF
  1402. IF uf_check_price(arg_thflag, arg_sptid, arg_mtrlid, arg_mtrlcode, arg_unit, arg_status, arg_woodcode, arg_pcode, arg_price, arg_msg) = 0 THEN
  1403. rslt = 0
  1404. GOTO ext
  1405. END IF
  1406. ext:
  1407. RETURN rslt
  1408. end function
  1409. private function integer uf_check_price (integer arg_thflag, long arg_sptid, long arg_mtrlid, string arg_mtrlcode, string arg_unit, string arg_status, string arg_woodcode, string arg_pcode, decimal arg_price, ref string arg_msg);//====================================================================
  1410. // Function: uf_check_price()
  1411. //--------------------------------------------------------------------
  1412. // Description:
  1413. //--------------------------------------------------------------------
  1414. // Arguments:
  1415. // value long arg_sptid
  1416. // value long arg_mtrlid
  1417. // value string arg_mtrlcode
  1418. // value decimal arg_price
  1419. // reference string arg_msg
  1420. //--------------------------------------------------------------------
  1421. // Returns: integer
  1422. //--------------------------------------------------------------------
  1423. // Author: yyx Date: 2004.07.21
  1424. //--------------------------------------------------------------------
  1425. // Modify History:
  1426. //
  1427. //====================================================================
  1428. Decimal i_lmbuyprice
  1429. String i_sptname
  1430. Int rslt = 1
  1431. Long cnt = 0
  1432. //124 保存, 1769 审核
  1433. //IF NOT f_power_ind(124) OR sys_power_issuper THEN
  1434. // rslt = 1
  1435. // GOTO ext
  1436. //END IF
  1437. IF IsNull(arg_status) THEN arg_status = ''
  1438. IF IsNull(arg_woodcode) THEN arg_woodcode = ''
  1439. IF IsNull(arg_pcode) THEN arg_pcode = ''
  1440. IF sys_option_buylimit_ifbj = 0 THEN //价格历史
  1441. SELECT price,u_spt.name INTO :i_lmbuyprice,:i_sptname
  1442. FROM u_spt_price,u_spt
  1443. WHERE u_spt_price.mtrlid = :arg_mtrlid
  1444. AND u_spt_price.sptid = :arg_sptid
  1445. AND u_spt_price.sptid = u_spt.sptid
  1446. AND u_spt_price.unit = :arg_unit
  1447. AND u_spt_price.status = :arg_status
  1448. AND u_spt_price.woodcode = :arg_woodcode
  1449. AND u_spt_price.pcode = :arg_pcode;
  1450. ELSEIF sys_option_buylimit_ifbj = 1 THEN //报价
  1451. SELECT top 1 price,u_spt.name INTO :i_lmbuyprice,:i_sptname
  1452. FROM u_spt_price_MX,u_spt
  1453. WHERE u_spt_price_MX.sptid = u_spt.sptid AND
  1454. u_spt_price_MX.mtrlid = :arg_mtrlid AND
  1455. u_spt_price_MX.sptid = :arg_sptid AND
  1456. u_spt_price_MX.woodcode = :arg_woodcode AND
  1457. u_spt_price_MX.status = :arg_status AND
  1458. u_spt_price_MX.pcode = :arg_pcode AND
  1459. u_spt_price_mx.billtype = 2
  1460. Order By u_spt_price_MX.opdate Desc;
  1461. ELSEIF sys_option_buylimit_ifbj = 2 THEN //设定购价
  1462. SELECT top 1 lmbuyprice INTO :i_lmbuyprice
  1463. FROM u_mtrldef
  1464. WHERE mtrlid = :arg_mtrlid;
  1465. i_sptname = ''
  1466. ELSEIF sys_option_buylimit_ifbj = 3 THEN //计划价 禁止
  1467. SELECT top 1 planprice INTO :i_lmbuyprice
  1468. FROM u_mtrldef
  1469. WHERE mtrlid = :arg_mtrlid;
  1470. i_sptname = ''
  1471. ELSEIF sys_option_buylimit_ifbj = 4 THEN //计划价 询问
  1472. GOTO ext //在收货单里面已经询问 所以这里直接跳过
  1473. END IF
  1474. IF sqlca.SQLCode <> 0 THEN
  1475. rslt = 0
  1476. arg_msg = '查询'+arg_mtrlcode+'收货限价失败,可能该供应商的收货限价还没有设定,请检查'
  1477. GOTO ext
  1478. END IF
  1479. IF arg_thflag = 0 THEN
  1480. IF arg_price > i_lmbuyprice THEN
  1481. rslt = 0
  1482. arg_msg = '供应商:'+i_sptname+','+arg_mtrlcode+'收货时,收货单价{'+String(arg_price,'#,##0.00##')+'} 高于收货限价{'+String(i_lmbuyprice,'#,##0.00##')+'}'
  1483. GOTO ext
  1484. END IF
  1485. ELSE
  1486. IF arg_price < i_lmbuyprice THEN
  1487. rslt = 0
  1488. arg_msg = '供应商:'+i_sptname+','+arg_mtrlcode+'退货时,退货单价{'+String(arg_price,'#,##0.00##')+'} 低于收货限价{'+String(i_lmbuyprice,'#,##0.00##')+'}'
  1489. GOTO ext
  1490. END IF
  1491. END IF
  1492. ext:
  1493. RETURN rslt
  1494. end function
  1495. on uo_spt_price.create
  1496. call super::create
  1497. TriggerEvent( this, "constructor" )
  1498. end on
  1499. on uo_spt_price.destroy
  1500. TriggerEvent( this, "destructor" )
  1501. call super::destroy
  1502. end on