uo_cusprice.sru 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490
  1. $PBExportHeader$uo_cusprice.sru
  2. forward
  3. global type uo_cusprice from nonvisualobject
  4. end type
  5. end forward
  6. global type uo_cusprice from nonvisualobject
  7. end type
  8. global uo_cusprice uo_cusprice
  9. forward prototypes
  10. public function integer uf_autodel_cuspricemx (datetime arg_begindate, boolean arg_ifcommit, ref string arg_msg)
  11. public function integer uf_update_custprice (integer arg_ifth, long arg_scid, long arg_cusid, long arg_mtrlid, string arg_mtrlcode, string arg_woodcode, string arg_status, string arg_pcode, long arg_outwareid, string arg_outwarecode, datetime arg_outdate, decimal arg_price, decimal arg_zqrate, decimal arg_cost, long arg_flag, string arg_dscrp, long arg_printid, long arg_moneyid, boolean arg_ifcommit, ref string arg_msg, decimal arg_rate, decimal arg_wareprice, string arg_unit)
  12. public function integer uf_check_price (long arg_cusid, long arg_mtrlid, string arg_mtrlcode, string arg_unit, string arg_status, string arg_pcode, string arg_woodcode, long arg_moneyid, decimal arg_price, ref string arg_msg)
  13. public function integer uf_getmtrlcusprice (long arg_moneyid, long arg_mtrlid, string arg_unit, string arg_woodcode, string arg_status, string arg_pcode, long arg_cusid, long arg_flag, ref decimal arg_price, ref decimal arg_zqrate, ref decimal arg_rate, ref string arg_msg)
  14. public function integer uf_del_sdcusprice (long arg_cusid, long arg_mtrlid, string arg_unit, string arg_woodcode, string arg_status, string arg_pcode, datetime arg_opdate, decimal arg_price, decimal arg_zqrate, long arg_moneyid, boolean arg_ifcommit, ref string arg_msg)
  15. public function integer uf_del_cusprice (integer arg_ifth, long arg_cusid, long arg_mtrlid, string arg_unit, string arg_status, string arg_woodcode, string arg_pcode, long arg_outwareid, long arg_printid, long arg_moneyid, boolean arg_ifcommit, ref string arg_msg)
  16. public function integer uof_get_dft_pricelistid (ref s_sale_price_mx arg_s_mx, ref string arg_msg)
  17. public function integer uof_chk_pricelistid (long arg_pricelistid, long arg_moneyid, ref string arg_msg)
  18. public function integer uof_get_pricelist_price (ref s_sale_price_mx arg_s_mx, ref string arg_msg)
  19. public function integer uof_get_mtrl_saleprice (long arg_moneyid, long arg_cusid, long arg_mtrlid, string arg_unit, string arg_woodcode, string arg_status, string arg_pcode, ref decimal arg_price, ref decimal arg_zqrate, ref decimal arg_rate, ref string arg_msg)
  20. public function integer uof_get_lmsaleprice (long arg_mtrlid, ref decimal arg_saleprice, ref decimal arg_rebate)
  21. public function integer uof_get_quoteprice (long arg_mtrlid, string arg_status, string arg_woodcode, string arg_pcode, string arg_unit, ref decimal arg_saleprice, ref decimal arg_rebate)
  22. public function integer uof_get_saleprice_his (long arg_cusid, long arg_moneyid, long arg_mtrlid, string arg_status, string arg_woodcode, string arg_pcode, string arg_unit, ref decimal arg_saleprice, ref decimal arg_rebate)
  23. public function integer uof_get_mtrl_saleprice_qty (long arg_moneyid, long arg_cusid, long arg_mtrlid, string arg_unit, string arg_woodcode, string arg_status, string arg_pcode, ref decimal arg_price, ref decimal arg_zqrate, ref decimal arg_rate, decimal arg_qty, ref string arg_msg)
  24. end prototypes
  25. public function integer uf_autodel_cuspricemx (datetime arg_begindate, boolean arg_ifcommit, ref string arg_msg);//uf_autodel_cuspricemx(arg_begindate,arg_ifcommit,arg_msg)
  26. //自动删除客户销售价格明细?指定时间以前的
  27. Long rslt = 1
  28. Long cnt = 0
  29. ////参数检查
  30. //IF arg_begindate < DateTime(Date('1900-01-01'),Time(0)) THEN MessageBox('提示','日期太早了')
  31. //IF Trim(arg_msg) = '' THEN arg_msg = ''
  32. ////删除时间范围内的记录
  33. //IF MessageBox(' 重要提示','删除指定时间以前所有采购历史价格记录(不能恢复),确认吗?',Exclamation!,OKCancel!) = 1 THEN
  34. // DELETE
  35. // FROM u_spt_price_mx
  36. // Where u_spt_price_mx.opdate <= :arg_begindate;
  37. // IF sqlca.SQLCode <> 0 THEN
  38. // rslt = 0
  39. // arg_msg = '因网络或其他原因删除失败'+sqlca.SQLErrText
  40. // GOTO ext
  41. // END IF
  42. //END IF
  43. //ext:
  44. //IF rslt = 0 THEN
  45. // ROLLBACK;
  46. //ELSEIF rslt = 1 AND arg_ifcommit THEN
  47. // COMMIT;
  48. //END IF
  49. RETURN rslt
  50. end function
  51. public function integer uf_update_custprice (integer arg_ifth, long arg_scid, long arg_cusid, long arg_mtrlid, string arg_mtrlcode, string arg_woodcode, string arg_status, string arg_pcode, long arg_outwareid, string arg_outwarecode, datetime arg_outdate, decimal arg_price, decimal arg_zqrate, decimal arg_cost, long arg_flag, string arg_dscrp, long arg_printid, long arg_moneyid, boolean arg_ifcommit, ref string arg_msg, decimal arg_rate, decimal arg_wareprice, string arg_unit);Long rslt = 1
  52. Long cnt = 0
  53. DateTime server_time
  54. //检查退货,退货不加报价
  55. IF arg_ifth = 1 THEN
  56. rslt = 1
  57. GOTO ext
  58. END IF
  59. //检查参数
  60. IF IsNull(arg_cusid) THEN arg_cusid = 0
  61. IF IsNull(arg_mtrlid) THEN arg_mtrlid = 0
  62. IF IsNull(arg_status) THEN arg_status = ''
  63. IF IsNull(arg_price) THEN arg_price = 0
  64. IF arg_outdate <= DateTime(Date('1900-01-01'),Time(0)) THEN
  65. rslt = 0
  66. arg_msg = '错误的发生时间'
  67. GOTO ext
  68. END IF
  69. arg_outwarecode = Trim(arg_outwarecode)
  70. //获得服务器时间
  71. SELECT Top 1 getdate() Into :server_time From u_user;
  72. //检查客户存在否
  73. SELECT count(*)
  74. INTO :cnt
  75. FROM u_cust
  76. Where u_cust.cusid = :arg_cusid;
  77. IF sqlca.SQLCode <> 0 THEN
  78. rslt = 0
  79. arg_msg = '查询客户失败'+sqlca.SQLErrText
  80. GOTO ext
  81. END IF
  82. IF cnt = 0 THEN
  83. rslt = 0
  84. arg_msg = '客户不存在'
  85. GOTO ext
  86. END IF
  87. //检查商品存在否
  88. SELECT count(*)
  89. INTO :cnt
  90. FROM u_mtrldef
  91. Where u_mtrldef.mtrlid = :arg_mtrlid;
  92. IF sqlca.SQLCode <> 0 THEN
  93. rslt = 0
  94. arg_msg = '查询'+arg_mtrlcode+'失败'+sqlca.SQLErrText
  95. GOTO ext
  96. END IF
  97. IF cnt = 0 THEN
  98. rslt = 0
  99. arg_msg = '编码不存在'+arg_mtrlcode
  100. GOTO ext
  101. END IF
  102. int ifpz = 7
  103. string ll_status = '',ll_woodcode = '',ll_pcode = ''
  104. //暂时改为三个配置
  105. //select price_ifpz into :ifpz from u_mtrldef where mtrlid = :arg_mtrlid;
  106. //IF sqlca.SQLCode <> 0 THEN
  107. // rslt = 0
  108. // arg_msg = "查询操作失败,操作员"
  109. // GOTO ext
  110. //END IF
  111. choose case ifpz
  112. case 0
  113. case 1
  114. ll_status = arg_status
  115. case 2
  116. ll_woodcode = arg_woodcode
  117. case 3
  118. ll_pcode = arg_pcode
  119. case 4
  120. ll_status = arg_status
  121. ll_woodcode = arg_woodcode
  122. case 5
  123. ll_status = arg_status
  124. ll_pcode =arg_pcode
  125. case 6
  126. ll_woodcode = arg_woodcode
  127. ll_pcode = arg_pcode
  128. case else
  129. ll_status = arg_status
  130. ll_woodcode = arg_woodcode
  131. ll_pcode = arg_pcode
  132. end choose
  133. //1.更新客户销售价表
  134. UPDATE u_cus_price
  135. SET u_cus_price.price = :arg_price * :arg_zqrate,
  136. u_cus_price.fprice = :arg_price,
  137. u_cus_price.zqrate = :arg_zqrate,
  138. u_cus_price.wareprice = :arg_wareprice,
  139. u_cus_price.rate = :arg_rate,
  140. u_cus_price.dscrp = :arg_dscrp
  141. WHERE u_cus_price.cusid = :arg_cusid
  142. AND u_cus_price.mtrlid = :arg_mtrlid
  143. AND u_cus_price.woodcode = :ll_woodcode
  144. AND u_cus_price.status = :ll_status
  145. AND u_cus_price.pcode = :ll_pcode
  146. AND u_cus_price.moneyid = :arg_moneyid
  147. And u_cus_price.unit = :arg_unit;
  148. IF sqlca.SQLCode = 0 THEN
  149. IF sqlca.SQLNRows = 0 THEN
  150. INSERT INTO u_cus_price
  151. (cusid,
  152. mtrlid,
  153. woodcode,
  154. status,
  155. pcode,
  156. price,
  157. fprice,
  158. zqrate,
  159. dscrp,
  160. moneyid,
  161. unit,
  162. wareprice,
  163. rate)
  164. VALUES
  165. (
  166. :arg_cusid,
  167. :arg_mtrlid,
  168. :ll_woodcode,
  169. :ll_status,
  170. :ll_pcode,
  171. :arg_price * :arg_zqrate,
  172. :arg_price,
  173. :arg_zqrate,
  174. :arg_dscrp,
  175. :arg_moneyid,
  176. :arg_unit,
  177. :arg_wareprice,
  178. :arg_rate);
  179. IF sqlca.SQLCode <> 0 THEN
  180. rslt = 0
  181. arg_msg = '新增客户销售'+arg_mtrlcode+'价格失败,'+sqlca.SQLErrText
  182. GOTO ext
  183. END IF
  184. END IF
  185. ELSE
  186. rslt = 0
  187. arg_msg = '客户销售价表更新'+arg_mtrlcode+'失败'+sqlca.SQLErrText
  188. GOTO ext
  189. END IF
  190. //2.插入客户销售变动明细价表
  191. INSERT INTO u_cus_price_mx
  192. (
  193. u_cus_price_mx.cusid,
  194. u_cus_price_mx.mtrlid,
  195. u_cus_price_mx.opdate,
  196. u_cus_price_mx.opemp,
  197. u_cus_price_mx.outwareid,
  198. u_cus_price_mx.outwarecode,
  199. u_cus_price_mx.outdate,
  200. u_cus_price_mx.price,
  201. u_cus_price_mx.fprice,
  202. u_cus_price_mx.zqrate,
  203. u_cus_price_mx.cost,
  204. u_cus_price_mx.woodcode,
  205. u_cus_price_mx.status,
  206. u_cus_price_mx.pcode,
  207. u_cus_price_mx.dscrp,
  208. u_cus_price_mx.buildtype,
  209. u_cus_price_mx.printid,
  210. u_cus_price_mx.moneyid,
  211. u_cus_price_mx.unit,
  212. u_cus_price_mx.wareprice,
  213. u_cus_price_mx.rate)
  214. VALUES
  215. (
  216. :arg_cusid,
  217. :arg_mtrlid,
  218. getdate(),
  219. :publ_operator,
  220. :arg_outwareid,
  221. :arg_outwarecode,
  222. :arg_outdate,
  223. :arg_price* :arg_zqrate,
  224. :arg_price,
  225. :arg_zqrate,
  226. :arg_cost,
  227. :arg_woodcode,
  228. :arg_status,
  229. :arg_pcode,
  230. :arg_dscrp,
  231. :arg_flag,
  232. :arg_printid,
  233. :arg_moneyid,
  234. :arg_unit,
  235. :arg_wareprice,
  236. :arg_rate);
  237. IF sqlca.SQLCode <> 0 THEN
  238. rslt = 0
  239. arg_msg = '登记在客户'+arg_mtrlcode+'售价变动明细表失败,'+sqlca.SQLErrText
  240. GOTO ext
  241. END IF
  242. ext:
  243. IF rslt = 0 THEN
  244. ROLLBACK;
  245. ELSEIF arg_ifcommit And rslt = 1 THEN
  246. COMMIT;
  247. END IF
  248. RETURN rslt
  249. end function
  250. public function integer uf_check_price (long arg_cusid, long arg_mtrlid, string arg_mtrlcode, string arg_unit, string arg_status, string arg_pcode, string arg_woodcode, long arg_moneyid, decimal arg_price, ref string arg_msg);Decimal ld_lmsaleprice
  251. String ls_cusname,ls_listname
  252. Long ll_pricelistid
  253. Int rslt = 1,li_flag
  254. Long cnt = 0
  255. IF NOT f_power_ind(492) OR sys_power_issuper THEN
  256. rslt = 1
  257. GOTO ext
  258. END IF
  259. IF sys_option_price_if_status = 0 THEN
  260. arg_status = ''
  261. arg_pcode = ''
  262. arg_woodcode = ''
  263. END IF
  264. SELECT name,pricelistid INTO :ls_cusname,:ll_pricelistid
  265. FROM u_cust
  266. Where cusid = :arg_cusid;
  267. IF sqlca.SQLCode <> 0 THEN
  268. rslt = 0
  269. arg_msg = "查询操作失败,客户资料"
  270. GOTO ext
  271. END IF
  272. IF ll_pricelistid = 0 THEN
  273. SELECT u_sale_price_list.pricelistid INTO :ll_pricelistid
  274. FROM u_sale_price_list,u_sale_price_mx
  275. WHERE u_sale_price_mx.pricelistid = u_sale_price_list.pricelistid
  276. AND u_sale_price_mx.mtrlid = :arg_mtrlid
  277. AND u_sale_price_mx.status = :arg_status
  278. AND u_sale_price_mx.pcode = :arg_pcode
  279. AND u_sale_price_mx.woodcode = :arg_woodcode
  280. AND u_sale_price_mx.unit = :arg_unit
  281. AND u_sale_price_list.moneyid = :arg_moneyid
  282. AND u_sale_price_list.dftflag = 1
  283. AND u_sale_price_list.flag = 1;
  284. IF sqlca.SQLCode = 0 THEN
  285. IF sqlca.SQLNRows = 0 THEN
  286. rslt = 0
  287. arg_msg = "编码:"+arg_mtrlcode+",标准格价表未设定"
  288. GOTO ext
  289. ELSEIF sqlca.SQLNRows > 1 THEN
  290. rslt = 0
  291. arg_msg = "编码:"+arg_mtrlcode+",有多于两个标准格价表"
  292. GOTO ext
  293. END IF
  294. ELSE
  295. rslt = 0
  296. arg_msg = "查询编码:"+arg_mtrlcode+",标准格价表操作失败"
  297. GOTO ext
  298. END IF
  299. END IF
  300. SELECT price,
  301. flag,
  302. listname
  303. INTO :ld_lmsaleprice,:li_flag,:ls_listname
  304. FROM u_sale_price_list,u_sale_price_mx
  305. WHERE u_sale_price_mx.pricelistid = u_sale_price_list.pricelistid
  306. AND u_sale_price_mx.mtrlid = :arg_mtrlid
  307. AND u_sale_price_mx.status = :arg_status
  308. AND u_sale_price_mx.pcode = :arg_pcode
  309. AND u_sale_price_mx.woodcode = :arg_woodcode
  310. AND u_sale_price_mx.pricelistid = :ll_pricelistid
  311. AND u_sale_price_mx.unit = :arg_unit ;
  312. IF sqlca.SQLCode <> 0 THEN
  313. rslt = 0
  314. arg_msg = '查询编码:'+arg_mtrlcode+'销售限价失败,可能该客户的销售限价还没有设定,请检查'
  315. GOTO ext
  316. END IF
  317. IF li_flag = 0 THEN
  318. rslt = 0
  319. arg_msg = '价格表:'+ls_listname+'未审核'
  320. GOTO ext
  321. END IF
  322. IF arg_price < ld_lmsaleprice THEN
  323. rslt = 0
  324. arg_msg = '客户:'+ls_cusname+',编码:'+arg_mtrlcode+'销售单价{'+String(arg_price,'#,##0.00##')+'} 低于销售限价{'+String(ld_lmsaleprice,'#,##0.00##')+'}'
  325. GOTO ext
  326. END IF
  327. ext:
  328. RETURN rslt
  329. end function
  330. public function integer uf_getmtrlcusprice (long arg_moneyid, long arg_mtrlid, string arg_unit, string arg_woodcode, string arg_status, string arg_pcode, long arg_cusid, long arg_flag, ref decimal arg_price, ref decimal arg_zqrate, ref decimal arg_rate, ref string arg_msg);//淘汰, 不用了
  331. //uf_getmtrlcusprice(arg_mtrlid,arg_cusid,arg_flag,arg_price,arg_zqrate,arg_msg)
  332. //功能:获得指定商品,指定客户的最新销售价格
  333. //参数:flag[0,最新销售价格,1次新销售价格]
  334. //参数:arg_price[返回最新价格]
  335. //返回:1成功,0失败,2查询失败
  336. Long rslt = 1
  337. //Long cnt = 0
  338. //Long count = 1 //记录取出个数
  339. //Decimal rtn_price,rtn_zqrate,rtn_rate
  340. //String rtn_unit
  341. //String rtn_wareunit
  342. //
  343. ////参数合法性检查
  344. //IF IsNull(arg_flag) THEN arg_flag = 0 //默认最新价格
  345. //IF IsNull(arg_msg) THEN arg_msg = ''
  346. //
  347. //IF arg_flag = 0 THEN
  348. // IF sys_option_price_if_list = 0 THEN
  349. //
  350. // SELECT fprice,zqrate,rate,unit
  351. // INTO :rtn_price,:rtn_zqrate,:rtn_rate ,:rtn_unit
  352. // FROM u_cus_price
  353. // WHERE u_cus_price.mtrlid = :arg_mtrlid
  354. // AND u_cus_price.cusid = :arg_cusid
  355. // AND u_cus_price.woodcode = :arg_woodcode
  356. // AND u_cus_price.status = :arg_status
  357. // AND u_cus_price.pcode = :Arg_pcode
  358. // AND u_cus_price.moneyid = :arg_moneyid
  359. // And u_cus_price.unit = :arg_unit;
  360. // IF sqlca.SQLCode = -1 THEN
  361. // rslt = 0
  362. // arg_msg = '查询操作失败'+sqlca.SQLErrText
  363. // GOTO ext
  364. // ELSEIF sqlca.SQLCode = 100 Or IsNull(rtn_price) THEN
  365. // rslt = 2
  366. // rtn_price = 0.00
  367. // rtn_zqrate = 1
  368. // rtn_rate = 1
  369. // GOTO ext
  370. // END IF
  371. // ELSE //查价格表 rtn_rate 按默认值
  372. // String ls_cusname,ls_listname
  373. // Long ll_pricelistid
  374. // Decimal ld_lmsaleprice, lde_rebate, lde_rate
  375. // Int li_flag
  376. //
  377. // //
  378. // SELECT CASE :arg_unit when unit THEN 1 when unit_buy THEN rate_buy when unit_scll THEN rate_scll when unit_sale THEN rate_sale END
  379. // Into :lde_rate
  380. // From u_mtrldef
  381. // Where mtrlid = :arg_mtrlid;
  382. // IF sqlca.SQLCode <> 0 THEN
  383. // rtn_rate = arg_rate
  384. // ELSE
  385. // rtn_rate = lde_rate
  386. // END IF
  387. //
  388. // SELECT name,pricelistid INTO :ls_cusname,:ll_pricelistid
  389. // FROM u_cust
  390. // Where cusid = :arg_cusid;
  391. // IF sqlca.SQLCode <> 0 THEN
  392. // rslt = 2
  393. // rtn_price = 0.00
  394. // rtn_zqrate = 1
  395. // GOTO ext
  396. // END IF
  397. //
  398. // IF sys_option_price_if_status = 0 THEN
  399. // arg_status = ''
  400. // Arg_pcode = ''
  401. // arg_woodcode = ''
  402. // END IF
  403. //
  404. //
  405. //
  406. //
  407. // IF ll_pricelistid = 0 THEN
  408. // SELECT u_sale_price_list.pricelistid INTO :ll_pricelistid
  409. // FROM u_sale_price_list,u_sale_price_mx
  410. // WHERE u_sale_price_mx.pricelistid = u_sale_price_list.pricelistid
  411. // AND u_sale_price_mx.mtrlid = :arg_mtrlid
  412. // AND u_sale_price_mx.status = :arg_status
  413. // AND u_sale_price_mx.pcode = :arg_pcode
  414. // AND u_sale_price_mx.woodcode = :arg_woodcode
  415. // AND u_sale_price_list.dftflag = 1
  416. // AND u_sale_price_list.moneyid = :arg_moneyid
  417. // And u_sale_price_list.flag = 1;
  418. //
  419. // IF sqlca.SQLCode = 0 THEN
  420. // IF sqlca.SQLNRows = 0 THEN
  421. // rslt = 2
  422. // rtn_price = 0.00
  423. // rtn_zqrate = 1
  424. // GOTO ext
  425. // ELSEIF sqlca.SQLNRows > 1 THEN
  426. // rslt = 2
  427. // rtn_price = 0.00
  428. // rtn_zqrate = 1
  429. // GOTO ext
  430. // END IF
  431. // ELSE
  432. // rslt = 2
  433. // rtn_price = 0.00
  434. // rtn_zqrate = 1
  435. // GOTO ext
  436. // END IF
  437. // END IF
  438. //
  439. //
  440. //
  441. //
  442. // SELECT price,
  443. // rebate,
  444. // flag,
  445. // listname
  446. // INTO :ld_lmsaleprice, :lde_rebate,:li_flag,:ls_listname
  447. // FROM u_sale_price_list,u_sale_price_mx
  448. // WHERE u_sale_price_mx.pricelistid = u_sale_price_list.pricelistid
  449. // AND u_sale_price_mx.mtrlid = :arg_mtrlid
  450. // AND u_sale_price_mx.status = :arg_status
  451. // AND u_sale_price_mx.pcode = :arg_pcode
  452. // AND u_sale_price_mx.woodcode = :arg_woodcode
  453. // AND u_sale_price_mx.pricelistid = :ll_pricelistid
  454. // AND u_sale_price_list.flag = 1
  455. // And u_sale_price_mx.unit = :arg_unit;
  456. // IF sqlca.SQLCode <> 0 THEN
  457. // rslt = 2
  458. // rtn_price = 0.00
  459. // rtn_zqrate = 1
  460. // GOTO ext
  461. // END IF
  462. //
  463. // IF li_flag = 0 THEN
  464. // rslt = 2
  465. // rtn_price = 0.00
  466. // rtn_zqrate = 1
  467. // GOTO ext
  468. // END IF
  469. //
  470. // rtn_price = ld_lmsaleprice
  471. // rtn_zqrate = lde_rebate
  472. // END IF
  473. //ELSEIF arg_flag = 1 THEN //取较新的价格
  474. // DECLARE get_price CURSOR FOR
  475. // SELECT fprice,zqrate,rate,unit
  476. // FROM u_cus_price_MX
  477. // WHERE u_cus_price_MX.cusid = :arg_cusid
  478. // AND u_cus_price_MX.mtrlid = :arg_mtrlid
  479. // AND u_cus_price_MX.woodcode = :arg_woodcode
  480. // AND u_cus_price_MX.status = :arg_status
  481. // AND u_cus_price_MX.pcode = :Arg_pcode
  482. // AND u_cus_price_MX.moneyid = :arg_moneyid
  483. // AND u_cus_price_MX.unit = :arg_unit
  484. // Order By u_cus_price_MX.opdate Desc;
  485. // //打开游标
  486. // OPEN get_price;
  487. // FETCH get_price Into :rtn_price,:rtn_zqrate,:rtn_rate,:rtn_unit;
  488. // rtn_price = 0.0
  489. // DO While (sqlca.SQLCode = 0 And count < 2 )
  490. // count++
  491. // FETCH get_price Into :rtn_price,:rtn_zqrate,:rtn_rate,:rtn_unit;
  492. // LOOP
  493. // CLOSE get_price;
  494. // //关闭游标
  495. // IF count = 1 THEN
  496. // rslt = 0
  497. // arg_msg = '没有较新的价格存在'
  498. // GOTO ext
  499. // END IF
  500. //END IF
  501. //
  502. //
  503. //ext:
  504. //arg_price = rtn_price
  505. //arg_zqrate = rtn_zqrate
  506. //arg_rate = rtn_rate
  507. //arg_unit = rtn_unit
  508. //
  509. RETURN rslt
  510. end function
  511. public function integer uf_del_sdcusprice (long arg_cusid, long arg_mtrlid, string arg_unit, string arg_woodcode, string arg_status, string arg_pcode, datetime arg_opdate, decimal arg_price, decimal arg_zqrate, long arg_moneyid, boolean arg_ifcommit, ref string arg_msg);//手动删除记录
  512. //uf_del_cusprice(arg_cusid,arg_mtrlid,arg_opdate,arg_price,arg_ifcommit,arg_msg)
  513. Long rslt = 1
  514. Long cnt = 0
  515. //检查客户存在否
  516. SELECT count(*)
  517. INTO :cnt
  518. FROM u_cust
  519. Where u_cust.cusid = :arg_cusid;
  520. IF sqlca.SQLCode <> 0 THEN
  521. rslt = 0
  522. arg_msg = '因网络和其他原因查询失败'+sqlca.SQLErrText
  523. GOTO ext
  524. END IF
  525. IF cnt = 0 THEN
  526. rslt = 0
  527. arg_msg = '客户不存在'
  528. GOTO ext
  529. END IF
  530. //检查商品存在否
  531. SELECT count(*)
  532. INTO :cnt
  533. FROM u_mtrldef
  534. Where u_mtrldef.mtrlid = :arg_mtrlid;
  535. IF sqlca.SQLCode <> 0 THEN
  536. rslt = 0
  537. arg_msg = '因网络和其他原因查询失败'+sqlca.SQLErrText
  538. GOTO ext
  539. END IF
  540. IF cnt = 0 THEN
  541. rslt = 0
  542. arg_msg = '商品不存在'
  543. GOTO ext
  544. END IF
  545. //删除手动添加价格
  546. DELETE FROM u_cus_price_mx
  547. WHERE u_cus_price_mx.cusid = :arg_cusid
  548. AND u_cus_price_mx.mtrlid = :arg_mtrlid
  549. AND u_cus_price_mx.opdate = :arg_opdate
  550. AND u_cus_price_mx.woodcode = :arg_woodcode
  551. AND u_cus_price_mx.status = :arg_status
  552. AND u_cus_price_mx.pcode = :arg_pcode
  553. AND u_cus_price_mx.moneyid = :arg_moneyid
  554. AND u_cus_price_mx.unit = :arg_unit;
  555. IF sqlca.SQLCode <> 0 THEN
  556. rslt = 0
  557. arg_msg = '查询失败'+sqlca.SQLErrText
  558. GOTO ext
  559. END IF
  560. //更新最新价格表
  561. UPDATE u_cus_price
  562. SET u_cus_price.price = :arg_price * :arg_zqrate,
  563. u_cus_price.fprice = :arg_price,
  564. u_cus_price.zqrate = :arg_zqrate
  565. WHERE u_cus_price.cusid = :arg_cusid
  566. AND u_cus_price.mtrlid = :arg_mtrlid
  567. AND u_cus_price.woodcode = :arg_woodcode
  568. AND u_cus_price.status = :arg_status
  569. AND u_cus_price.pcode = :arg_pcode
  570. AND u_cus_price.moneyid = :arg_moneyid
  571. AND u_cus_price.unit = :arg_unit;
  572. IF sqlca.SQLCode <> 0 THEN
  573. rslt = 0
  574. arg_msg = '查询失败'+sqlca.SQLErrText
  575. GOTO ext
  576. END IF
  577. ext:
  578. IF rslt = 0 THEN
  579. ROLLBACK;
  580. ELSEIF rslt = 1 AND arg_ifcommit THEN
  581. COMMIT;
  582. END IF
  583. RETURN rslt
  584. end function
  585. public function integer uf_del_cusprice (integer arg_ifth, long arg_cusid, long arg_mtrlid, string arg_unit, string arg_status, string arg_woodcode, string arg_pcode, long arg_outwareid, long arg_printid, long arg_moneyid, boolean arg_ifcommit, ref string arg_msg);Int rslt = 1
  586. Long cnt = 0,ll_cnt = 0
  587. DateTime ld_opdate
  588. //检查客户存在否
  589. SELECT count(*)
  590. INTO :cnt
  591. FROM u_cust
  592. Where u_cust.cusid = :arg_cusid;
  593. IF sqlca.SQLCode <> 0 THEN
  594. rslt = 0
  595. arg_msg = '因网络和其他原因查询失败'+sqlca.SQLErrText
  596. GOTO ext
  597. END IF
  598. IF cnt = 0 THEN
  599. rslt = 0
  600. arg_msg = '客户不存在'
  601. GOTO ext
  602. END IF
  603. //检查商品存在否
  604. SELECT count(*)
  605. INTO :cnt
  606. FROM u_mtrldef
  607. Where u_mtrldef.mtrlid = :arg_mtrlid;
  608. IF sqlca.SQLCode <> 0 THEN
  609. rslt = 0
  610. arg_msg = '因网络和其他原因查询失败'+sqlca.SQLErrText
  611. GOTO ext
  612. END IF
  613. IF cnt = 0 THEN
  614. rslt = 0
  615. arg_msg = '物料不存在'
  616. GOTO ext
  617. END IF
  618. int ifpz = 7
  619. int ll_status = 0,ll_woodcode = 0,ll_pcode = 0
  620. select price_ifpz into :ifpz from u_mtrldef where mtrlid = :arg_mtrlid;
  621. IF sqlca.SQLCode <> 0 THEN
  622. rslt = 0
  623. arg_msg = '因网络和其他原因查询失败'+sqlca.SQLErrText
  624. GOTO ext
  625. END IF
  626. choose case ifpz
  627. case 0
  628. case 1
  629. ll_status = 1
  630. case 2
  631. ll_woodcode = 1
  632. case 3
  633. ll_pcode = 1
  634. case 4
  635. ll_status = 1
  636. ll_woodcode = 1
  637. case 5
  638. ll_status = 1
  639. ll_pcode =1
  640. case 6
  641. ll_woodcode = 1
  642. ll_pcode = 1
  643. case else
  644. ll_status = 1
  645. ll_woodcode = 1
  646. ll_pcode = 1
  647. end choose
  648. SELECT count(*) INTO :cnt
  649. FROM u_cus_price_mx
  650. WHERE cusid = :arg_cusid
  651. AND mtrlid = :arg_mtrlid
  652. AND unit = :arg_unit
  653. AND outwareid = :arg_outwareid
  654. AND printid = :arg_printid
  655. AND (status = :arg_status or :ll_status = 0)
  656. AND (woodcode = :arg_woodcode or :ll_woodcode = 0 )
  657. AND (pcode = :arg_pcode or :ll_pcode = 0)
  658. AND moneyid = :arg_moneyid;
  659. IF sqlca.SQLCode <> 0 THEN
  660. rslt = 0
  661. arg_msg = '查询失败'+sqlca.SQLErrText
  662. GOTO ext
  663. END IF
  664. IF cnt = 0 THEN
  665. rslt = 1
  666. GOTO ext
  667. END IF
  668. SELECT top 1 Opdate INTO :ld_opdate
  669. FROM u_cus_price_mx
  670. WHERE cusid = :arg_cusid
  671. AND mtrlid = :arg_mtrlid
  672. AND unit = :arg_unit
  673. AND outwareid = :arg_outwareid
  674. AND printid = :arg_printid
  675. AND (status = :arg_status or :ll_status = 0)
  676. AND (woodcode = :arg_woodcode or :ll_woodcode = 0 )
  677. AND (pcode = :arg_pcode or :ll_pcode = 0)
  678. AND moneyid = :arg_moneyid
  679. Order By Opdate Desc;
  680. IF sqlca.SQLCode <> 0 THEN
  681. rslt = 0
  682. arg_msg = '查询失败'+sqlca.SQLErrText
  683. GOTO ext
  684. END IF
  685. SELECT count(*) INTO :cnt
  686. FROM u_cus_price_mx
  687. WHERE cusid = :arg_cusid
  688. AND mtrlid = :arg_mtrlid
  689. AND unit = :arg_unit
  690. AND (status = :arg_status or :ll_status = 0)
  691. AND (woodcode = :arg_woodcode or :ll_woodcode = 0 )
  692. AND (pcode = :arg_pcode or :ll_pcode = 0)
  693. AND Opdate > :ld_opdate
  694. AND moneyid = :arg_moneyid;
  695. IF sqlca.SQLCode <> 0 THEN
  696. rslt = 0
  697. arg_msg = '查询失败'+sqlca.SQLErrText
  698. GOTO ext
  699. END IF
  700. Decimal ld_fprice,ld_zqrate,ld_price
  701. DateTime ld_sys_changetime,ld_nulldt
  702. SetNull(ld_nulldt)
  703. IF cnt = 0 THEN //如果被删明细是最新,用次新明细更新最新价
  704. SELECT count(*) INTO :ll_cnt
  705. FROM u_cus_price_mx
  706. WHERE cusid = :arg_cusid
  707. AND mtrlid = :arg_mtrlid
  708. AND unit = :arg_unit
  709. AND (status = :arg_status or :ll_status = 0)
  710. AND (woodcode = :arg_woodcode or :ll_woodcode = 0 )
  711. AND (pcode = :arg_pcode or :ll_pcode = 0)
  712. AND Opdate < :ld_opdate
  713. AND moneyid = :arg_moneyid;
  714. IF sqlca.SQLCode <> 0 THEN
  715. rslt = 0
  716. arg_msg = '查询失败'+sqlca.SQLErrText
  717. GOTO ext
  718. END IF
  719. IF ll_cnt = 0 THEN
  720. DELETE FROM u_cus_price
  721. WHERE cusid = :arg_cusid
  722. AND mtrlid = :arg_mtrlid
  723. AND unit = :arg_unit
  724. AND (status = :arg_status or :ll_status = 0)
  725. AND (woodcode = :arg_woodcode or :ll_woodcode = 0 )
  726. AND (pcode = :arg_pcode or :ll_pcode = 0)
  727. AND moneyid = :arg_moneyid;
  728. IF sqlca.SQLCode <> 0 THEN
  729. rslt = 0
  730. arg_msg = '更新最新价失败'+sqlca.SQLErrText
  731. GOTO ext
  732. END IF
  733. ELSE
  734. SELECT top 1 fprice,zqrate,price,sys_changetime
  735. INTO :ld_fprice,:ld_zqrate,:ld_price,:ld_sys_changetime
  736. FROM u_cus_price_mx
  737. WHERE cusid = :arg_cusid
  738. AND mtrlid = :arg_mtrlid
  739. AND unit = :arg_unit
  740. AND (status = :arg_status or :ll_status = 0)
  741. AND (woodcode = :arg_woodcode or :ll_woodcode = 0 )
  742. AND (pcode = :arg_pcode or :ll_pcode = 0)
  743. AND Opdate < :ld_opdate
  744. AND moneyid = :arg_moneyid
  745. Order By Opdate Desc;
  746. IF sqlca.SQLCode <> 0 THEN
  747. rslt = 0
  748. arg_msg = '查询失败'+sqlca.SQLErrText
  749. GOTO ext
  750. END IF
  751. UPDATE u_cus_price
  752. SET fprice = :ld_fprice ,
  753. zqrate = :ld_zqrate,
  754. price = :ld_price,
  755. sys_changetime = :ld_sys_changetime
  756. WHERE cusid = :arg_cusid
  757. AND mtrlid = :arg_mtrlid
  758. AND unit = :arg_unit
  759. AND (status = :arg_status or :ll_status = 0)
  760. AND (woodcode = :arg_woodcode or :ll_woodcode = 0 )
  761. AND (pcode = :arg_pcode or :ll_pcode = 0)
  762. AND moneyid = :arg_moneyid;
  763. IF sqlca.SQLCode <> 0 THEN
  764. rslt = 0
  765. arg_msg = '更新最新价失败'+sqlca.SQLErrText
  766. GOTO ext
  767. END IF
  768. END IF
  769. END IF
  770. //删除手动添加价格
  771. DELETE FROM u_cus_price_mx
  772. Where cusid = :arg_cusid
  773. AND mtrlid = :arg_mtrlid
  774. AND unit = :arg_unit
  775. AND outwareid = :arg_outwareid
  776. AND printid = :arg_printid
  777. AND status = :arg_status
  778. AND woodcode = :arg_woodcode
  779. AND pcode = :arg_pcode
  780. AND moneyid = :arg_moneyid;
  781. IF sqlca.SQLCode <> 0 THEN
  782. rslt = 0
  783. arg_msg = '查询失败'+sqlca.SQLErrText
  784. GOTO ext
  785. END IF
  786. ext:
  787. IF rslt = 0 THEN
  788. ROLLBACK;
  789. ELSEIF rslt = 1 AND arg_ifcommit THEN
  790. COMMIT;
  791. END IF
  792. RETURN rslt
  793. end function
  794. public function integer uof_get_dft_pricelistid (ref s_sale_price_mx arg_s_mx, ref string arg_msg);Int rslt = 1
  795. Long ll_pricelistid
  796. SELECT top 1 u_sale_price_list.pricelistid INTO :ll_pricelistid
  797. FROM u_sale_price_list,u_sale_price_mx
  798. WHERE u_sale_price_mx.pricelistid = u_sale_price_list.pricelistid
  799. AND u_sale_price_mx.mtrlid = :arg_s_mx.mtrlid
  800. // AND u_sale_price_mx.status = :arg_s_mx.status
  801. // AND u_sale_price_mx.pcode = :arg_s_mx.pcode
  802. // AND u_sale_price_mx.woodcode = :arg_s_mx.woodcode
  803. AND (u_sale_price_mx.saleqty <= :arg_s_mx.qty and u_sale_price_mx.saleqty1 >= :arg_s_mx.qty)
  804. AND u_sale_price_list.dftflag = 1
  805. AND u_sale_price_list.moneyid = :arg_s_mx.moneyid
  806. And u_sale_price_list.flag = 1;
  807. IF sqlca.SQLCode <> 0 THEN
  808. ll_pricelistid = 0
  809. END IF
  810. IF IsNull(ll_pricelistid) THEN ll_pricelistid = 0
  811. IF ll_pricelistid = 0 THEN
  812. rslt = 0
  813. END IF
  814. arg_s_mx.pricelistid = ll_pricelistid
  815. RETURN rslt
  816. end function
  817. public function integer uof_chk_pricelistid (long arg_pricelistid, long arg_moneyid, ref string arg_msg);
  818. //检查价格表和币种是否对应
  819. Int rslt = 1
  820. Long ll_moneyid_pricelist
  821. Int li_flag
  822. IF arg_pricelistid = 0 THEN
  823. arg_msg = '客户价格表ID错误(=0)'
  824. rslt = 0
  825. GOTO ext
  826. END IF
  827. SELECT moneyid , flag
  828. INTO :ll_moneyid_pricelist, :li_flag
  829. FROM u_sale_price_list
  830. Where u_sale_price_list.pricelistid = :arg_pricelistid;
  831. IF sqlca.SQLCode <> 0 THEN
  832. arg_msg = '查询客户价格表对应币种失败,'+sqlca.SQLErrText
  833. rslt = 0
  834. GOTO ext
  835. END IF
  836. IF ll_moneyid_pricelist <> arg_moneyid THEN
  837. arg_msg = '客户价格表对应币种与检查币种不相符'
  838. rslt = 0
  839. GOTO ext
  840. END IF
  841. IF li_flag = 0 THEN
  842. arg_msg = '客户价格表未审核'
  843. rslt = 0
  844. GOTO ext
  845. END IF
  846. ext:
  847. RETURN rslt
  848. end function
  849. public function integer uof_get_pricelist_price (ref s_sale_price_mx arg_s_mx, ref string arg_msg);Int rslt = 1
  850. Long ll_i
  851. Int li_statusflag
  852. String ls_status
  853. Decimal obj_price, lde_saleprice, lde_rebate
  854. s_mtrlcfg_expr s_pz[]
  855. SELECT statusflag
  856. INTO :li_statusflag
  857. FROM u_mtrldef
  858. Where mtrlid = :arg_s_mx.mtrlid;
  859. IF sqlca.SQLCode <> 0 THEN
  860. li_statusflag = 0
  861. END IF
  862. IF li_statusflag = 2 And arg_s_mx.status <> '' THEN //组合配置,自动按子件计算单价
  863. //类似于 price_ifpz = 1
  864. f_checkpz(arg_s_mx.status,s_pz[])
  865. arg_s_mx.pcode = ''
  866. arg_s_mx.woodcode = ''
  867. ELSE
  868. s_pz[1].cfgname = arg_s_mx.status
  869. s_pz[1].qty = '1'
  870. END IF
  871. lde_saleprice = 0
  872. lde_rebate = 1
  873. FOR ll_i = 1 To UpperBound(s_pz)
  874. ls_status = s_pz[ll_i].cfgname
  875. SELECT top 1 price,
  876. rebate
  877. INTO :obj_price, :lde_rebate
  878. FROM u_sale_price_list,u_sale_price_mx
  879. WHERE u_sale_price_mx.pricelistid = u_sale_price_list.pricelistid
  880. AND u_sale_price_mx.mtrlid = :arg_s_mx.mtrlid
  881. AND u_sale_price_mx.status = :ls_status
  882. AND u_sale_price_mx.pcode = :arg_s_mx.pcode
  883. AND u_sale_price_mx.woodcode = :arg_s_mx.woodcode
  884. AND (u_sale_price_mx.saleqty <= :arg_s_mx.qty and u_sale_price_mx.saleqty1 >= :arg_s_mx.qty)
  885. AND u_sale_price_mx.pricelistid = :arg_s_mx.pricelistid
  886. And u_sale_price_mx.unit = :arg_s_mx.unit;
  887. IF sqlca.SQLCode <> 0 THEN
  888. rslt = 0
  889. arg_msg = "查询价格表价格失败,"+sqlca.sqlerrtext
  890. lde_saleprice = 0
  891. obj_price = 0
  892. lde_rebate = 1
  893. goto ext
  894. END IF
  895. lde_saleprice += obj_price * Dec(s_pz[ll_i].qty)
  896. NEXT
  897. ext:
  898. arg_s_mx.price = lde_saleprice
  899. arg_s_mx.rebate = lde_rebate
  900. RETURN rslt
  901. end function
  902. public function integer uof_get_mtrl_saleprice (long arg_moneyid, long arg_cusid, long arg_mtrlid, string arg_unit, string arg_woodcode, string arg_status, string arg_pcode, ref decimal arg_price, ref decimal arg_zqrate, ref decimal arg_rate, ref string arg_msg);//uof_get_mtrl_saleprice(arg_mtrlid,arg_cusid,arg_flag,arg_price,arg_zqrate,arg_msg)
  903. //功能:获得指定商品,指定客户的最新销售价格
  904. //参数:flag[0,最新销售价格,1次新销售价格]
  905. //参数:arg_price[返回最新价格]
  906. //返回:1成功,0失败,2查询失败
  907. Long rslt = 1
  908. Long cnt = 0
  909. Long count = 1 //记录取出个数
  910. Decimal rtn_price,rtn_zqrate,rtn_rate
  911. Decimal lde_saleprice, lde_rebate, lde_rate, obj_price
  912. String rtn_unit
  913. String rtn_wareunit
  914. int ls_price_ifpz
  915. //参数合法性检查
  916. IF arg_moneyid = 0 THEN
  917. rslt = 0
  918. GOTO ext
  919. END IF
  920. IF arg_cusid = 0 THEN
  921. rslt = 0
  922. GOTO ext
  923. END IF
  924. IF arg_mtrlid = 0 THEN
  925. rslt = 0
  926. GOTO ext
  927. END IF
  928. if sys_option_price_if_list <> 0 then
  929. select price_ifpz into :ls_price_ifpz from u_mtrldef where mtrlid = :arg_mtrlid;
  930. IF sqlca.SQLCode <> 0 THEN
  931. rslt = 2
  932. GOTO ext
  933. END IF
  934. choose case ls_price_ifpz
  935. case 0 //不使用
  936. arg_status = ''
  937. arg_woodcode = ''
  938. arg_pcode = ''
  939. case 1//配置
  940. arg_woodcode = ''
  941. arg_pcode = ''
  942. case 2//配置1
  943. arg_status = ''
  944. arg_pcode = ''
  945. case 3//配置2
  946. arg_status = ''
  947. arg_woodcode = ''
  948. case 4//配置+配置1
  949. arg_pcode = ''
  950. case 5//配置1+配置2
  951. arg_status = ''
  952. case 6//配置+配置2
  953. arg_woodcode = ''
  954. //else 配置+配置1+配置2
  955. end choose
  956. end if
  957. IF sys_option_price_if_list = 0 THEN //取销售历史
  958. IF uof_get_saleprice_his(arg_cusid, arg_moneyid, arg_mtrlid, arg_status, arg_woodcode, arg_pcode, arg_unit , lde_saleprice, lde_rebate) = 0 THEN
  959. lde_saleprice = 0
  960. lde_rebate = 1
  961. END IF
  962. rtn_price = lde_saleprice
  963. rtn_zqrate = lde_rebate
  964. ELSEIF sys_option_price_if_list = 1 THEN //查价格表 rtn_rate 按默认值
  965. Long ll_i
  966. String ls_cusname,ls_listname
  967. Long ll_pricelistid
  968. Int li_flag, li_statusflag, li_price_ifpz
  969. String ls_unit, ls_status
  970. s_mtrlcfg_expr s_pz[]
  971. //
  972. SELECT unit,
  973. CASE :arg_unit when unit THEN 1 when unit_buy THEN rate_buy when unit_scll THEN rate_scll when unit_sale THEN rate_sale END,
  974. statusflag
  975. INTO :ls_unit, :lde_rate, :li_statusflag
  976. FROM u_mtrldef
  977. Where mtrlid = :arg_mtrlid;
  978. IF sqlca.SQLCode <> 0 THEN
  979. rtn_rate = arg_rate
  980. arg_unit = ls_unit
  981. ELSE
  982. rtn_rate = lde_rate
  983. END IF
  984. IF sys_option_price_if_status = 0 THEN
  985. IF li_statusflag <> 2 THEN
  986. arg_status = ''
  987. END IF
  988. arg_pcode = ''
  989. arg_woodcode = ''
  990. END IF
  991. SELECT name,pricelistid
  992. INTO :ls_cusname,:ll_pricelistid
  993. FROM u_cust
  994. Where cusid = :arg_cusid;
  995. IF sqlca.SQLCode <> 0 THEN
  996. rslt = 2 //没有价格表
  997. GOTO ext
  998. END IF
  999. s_sale_price_mx s_mx
  1000. s_mx.mtrlid = arg_mtrlid
  1001. s_mx.status = arg_status
  1002. s_mx.woodcode = arg_woodcode
  1003. s_mx.pcode = arg_pcode
  1004. s_mx.unit = arg_unit
  1005. s_mx.moneyid = arg_moneyid
  1006. IF ll_pricelistid = 0 THEN
  1007. IF uof_get_dft_pricelistid(s_mx, arg_msg) = 0 THEN
  1008. rslt = 2 //无标准价格表 或未审核
  1009. GOTO ext
  1010. END IF
  1011. ll_pricelistid = s_mx.pricelistid
  1012. ELSE
  1013. s_mx.pricelistid = ll_pricelistid
  1014. END IF
  1015. IF uof_chk_pricelistid(ll_pricelistid, arg_moneyid, arg_msg) = 0 THEN
  1016. rslt = 2 //币种不对, 未审核
  1017. GOTO ext
  1018. END IF
  1019. //新增,优化代码 20130925
  1020. IF uof_get_pricelist_price(s_mx, arg_msg) = 0 THEN
  1021. rslt = 2 //查询失败
  1022. GOTO ext
  1023. END IF
  1024. rtn_price = s_mx.price
  1025. rtn_zqrate = s_mx.rebate
  1026. ELSEIF sys_option_price_if_list = 2 THEN //取报价单
  1027. IF uof_get_quoteprice(arg_mtrlid, arg_status, arg_woodcode, arg_pcode, arg_unit , lde_saleprice, lde_rebate) = 0 THEN
  1028. lde_saleprice = 0
  1029. lde_rebate = 1
  1030. END IF
  1031. rtn_price = lde_saleprice
  1032. rtn_zqrate = lde_rebate
  1033. ELSEIF sys_option_price_if_list = 3 THEN //取设定售价
  1034. IF uof_get_lmsaleprice(arg_mtrlid, lde_saleprice, lde_rebate) = 0 THEN
  1035. lde_saleprice = 0
  1036. lde_rebate = 1
  1037. END IF
  1038. rtn_price = lde_saleprice
  1039. rtn_zqrate = lde_rebate
  1040. END IF
  1041. ext:
  1042. IF rslt <> 1 THEN
  1043. rtn_price = 0.00
  1044. rtn_zqrate = 1
  1045. rtn_rate = 1
  1046. END IF
  1047. arg_price = rtn_price
  1048. arg_zqrate = rtn_zqrate
  1049. arg_rate = rtn_rate //这2个字段没用的
  1050. arg_unit = rtn_unit //这2个字段没用的
  1051. RETURN rslt
  1052. end function
  1053. public function integer uof_get_lmsaleprice (long arg_mtrlid, ref decimal arg_saleprice, ref decimal arg_rebate);Int rslt = 1
  1054. SELECT lmsaleprice
  1055. INTO :arg_saleprice
  1056. FROM u_mtrldef
  1057. Where mtrlid = :arg_mtrlid;
  1058. IF sqlca.SQLCode <> 0 THEN
  1059. arg_saleprice = 0
  1060. END IF
  1061. arg_rebate = 1
  1062. RETURN rslt
  1063. end function
  1064. public function integer uof_get_quoteprice (long arg_mtrlid, string arg_status, string arg_woodcode, string arg_pcode, string arg_unit, ref decimal arg_saleprice, ref decimal arg_rebate);Int rslt = 1
  1065. SELECT top 1 u_quotemx.sumprice, u_quotemx.rebate
  1066. INTO :arg_saleprice, :arg_rebate
  1067. FROM u_quotemx INNER JOIN
  1068. u_quote ON u_quotemx.scid = u_quote.scid AND
  1069. u_quotemx.quoteid = u_quote.quoteid
  1070. WHERE (u_quote.flag = 1)
  1071. AND u_quotemx.mtrlid = :arg_mtrlid
  1072. AND u_quotemx.status = :arg_status
  1073. AND u_quotemx.woodcode = :arg_woodcode
  1074. AND u_quotemx.pcode = :arg_pcode
  1075. AND u_quotemx.unit = :arg_unit
  1076. Order By u_quote.quotedate Desc;
  1077. IF sqlca.SQLCode <> 0 THEN
  1078. arg_saleprice = 0
  1079. arg_rebate = 1
  1080. END IF
  1081. RETURN rslt
  1082. end function
  1083. public function integer uof_get_saleprice_his (long arg_cusid, long arg_moneyid, long arg_mtrlid, string arg_status, string arg_woodcode, string arg_pcode, string arg_unit, ref decimal arg_saleprice, ref decimal arg_rebate);Int rslt = 1
  1084. SELECT fprice,zqrate
  1085. INTO :arg_saleprice,:arg_rebate
  1086. FROM u_cus_price
  1087. WHERE u_cus_price.cusid = :arg_cusid
  1088. AND u_cus_price.moneyid = :arg_moneyid
  1089. AND u_cus_price.mtrlid = :arg_mtrlid
  1090. AND u_cus_price.status = :arg_status
  1091. AND u_cus_price.woodcode = :arg_woodcode
  1092. AND u_cus_price.pcode = :arg_pcode
  1093. And u_cus_price.unit = :arg_unit;
  1094. IF sqlca.SQLCode <> 0 THEN
  1095. arg_saleprice = 0
  1096. arg_rebate = 1
  1097. END IF
  1098. RETURN rslt
  1099. end function
  1100. public function integer uof_get_mtrl_saleprice_qty (long arg_moneyid, long arg_cusid, long arg_mtrlid, string arg_unit, string arg_woodcode, string arg_status, string arg_pcode, ref decimal arg_price, ref decimal arg_zqrate, ref decimal arg_rate, decimal arg_qty, ref string arg_msg);//uof_get_mtrl_saleprice(arg_mtrlid,arg_cusid,arg_flag,arg_price,arg_zqrate,arg_msg)
  1101. //功能:获得指定商品,指定客户的最新销售价格
  1102. //参数:flag[0,最新销售价格,1次新销售价格]
  1103. //参数:arg_price[返回最新价格]
  1104. //返回:1成功,0失败,2查询失败
  1105. Long rslt = 1
  1106. Long cnt = 0
  1107. Long count = 1 //记录取出个数
  1108. Decimal rtn_price,rtn_zqrate,rtn_rate
  1109. Decimal lde_saleprice, lde_rebate, lde_rate, obj_price
  1110. String rtn_unit
  1111. String rtn_wareunit
  1112. int ls_price_ifpz
  1113. //参数合法性检查
  1114. IF arg_moneyid = 0 THEN
  1115. rslt = 0
  1116. GOTO ext
  1117. END IF
  1118. IF arg_cusid = 0 THEN
  1119. rslt = 0
  1120. GOTO ext
  1121. END IF
  1122. IF arg_mtrlid = 0 THEN
  1123. rslt = 0
  1124. GOTO ext
  1125. END IF
  1126. if sys_option_price_if_list <> 0 then
  1127. select price_ifpz into :ls_price_ifpz from u_mtrldef where mtrlid = :arg_mtrlid;
  1128. IF sqlca.SQLCode <> 0 THEN
  1129. rslt = 2
  1130. GOTO ext
  1131. END IF
  1132. choose case ls_price_ifpz
  1133. case 0 //不使用
  1134. arg_status = ''
  1135. arg_woodcode = ''
  1136. arg_pcode = ''
  1137. case 1//配置
  1138. arg_woodcode = ''
  1139. arg_pcode = ''
  1140. case 2//配置1
  1141. arg_status = ''
  1142. arg_pcode = ''
  1143. case 3//配置2
  1144. arg_status = ''
  1145. arg_woodcode = ''
  1146. case 4//配置+配置1
  1147. arg_pcode = ''
  1148. case 5//配置1+配置2
  1149. arg_status = ''
  1150. case 6//配置+配置2
  1151. arg_woodcode = ''
  1152. //else 配置+配置1+配置2
  1153. end choose
  1154. end if
  1155. IF sys_option_price_if_list = 0 THEN //取销售历史
  1156. IF uof_get_saleprice_his(arg_cusid, arg_moneyid, arg_mtrlid, arg_status, arg_woodcode, arg_pcode, arg_unit , lde_saleprice, lde_rebate) = 0 THEN
  1157. lde_saleprice = 0
  1158. lde_rebate = 1
  1159. END IF
  1160. rtn_price = lde_saleprice
  1161. rtn_zqrate = lde_rebate
  1162. ELSEIF sys_option_price_if_list = 1 THEN //查价格表 rtn_rate 按默认值
  1163. Long ll_i
  1164. String ls_cusname,ls_listname
  1165. Long ll_pricelistid
  1166. Int li_flag, li_statusflag, li_price_ifpz
  1167. String ls_unit, ls_status
  1168. s_mtrlcfg_expr s_pz[]
  1169. //
  1170. SELECT unit,
  1171. CASE :arg_unit when unit THEN 1 when unit_buy THEN rate_buy when unit_scll THEN rate_scll when unit_sale THEN rate_sale END,
  1172. statusflag
  1173. INTO :ls_unit, :lde_rate, :li_statusflag
  1174. FROM u_mtrldef
  1175. Where mtrlid = :arg_mtrlid;
  1176. IF sqlca.SQLCode <> 0 THEN
  1177. rtn_rate = arg_rate
  1178. arg_unit = ls_unit
  1179. ELSE
  1180. rtn_rate = lde_rate
  1181. END IF
  1182. IF sys_option_price_if_status = 0 THEN
  1183. IF li_statusflag <> 2 THEN
  1184. arg_status = ''
  1185. END IF
  1186. arg_pcode = ''
  1187. arg_woodcode = ''
  1188. END IF
  1189. SELECT name,pricelistid
  1190. INTO :ls_cusname,:ll_pricelistid
  1191. FROM u_cust
  1192. Where cusid = :arg_cusid;
  1193. IF sqlca.SQLCode <> 0 THEN
  1194. rslt = 2 //没有价格表
  1195. GOTO ext
  1196. END IF
  1197. s_sale_price_mx s_mx
  1198. s_mx.mtrlid = arg_mtrlid
  1199. s_mx.status = arg_status
  1200. s_mx.woodcode = arg_woodcode
  1201. s_mx.pcode = arg_pcode
  1202. s_mx.unit = arg_unit
  1203. s_mx.moneyid = arg_moneyid
  1204. s_mx.qty = arg_qty
  1205. IF ll_pricelistid = 0 THEN
  1206. IF uof_get_dft_pricelistid(s_mx, arg_msg) = 0 THEN
  1207. rslt = 2 //无标准价格表 或未审核
  1208. GOTO ext
  1209. END IF
  1210. ll_pricelistid = s_mx.pricelistid
  1211. ELSE
  1212. s_mx.pricelistid = ll_pricelistid
  1213. END IF
  1214. IF uof_chk_pricelistid(ll_pricelistid, arg_moneyid, arg_msg) = 0 THEN
  1215. rslt = 2 //币种不对, 未审核
  1216. GOTO ext
  1217. END IF
  1218. //新增,优化代码 20130925
  1219. IF uof_get_pricelist_price(s_mx, arg_msg) = 0 THEN
  1220. rslt = 2 //查询失败
  1221. GOTO ext
  1222. END IF
  1223. rtn_price = s_mx.price
  1224. rtn_zqrate = s_mx.rebate
  1225. ELSEIF sys_option_price_if_list = 2 THEN //取报价单
  1226. IF uof_get_quoteprice(arg_mtrlid, arg_status, arg_woodcode, arg_pcode, arg_unit , lde_saleprice, lde_rebate) = 0 THEN
  1227. lde_saleprice = 0
  1228. lde_rebate = 1
  1229. END IF
  1230. rtn_price = lde_saleprice
  1231. rtn_zqrate = lde_rebate
  1232. ELSEIF sys_option_price_if_list = 3 THEN //取设定售价
  1233. IF uof_get_lmsaleprice(arg_mtrlid, lde_saleprice, lde_rebate) = 0 THEN
  1234. lde_saleprice = 0
  1235. lde_rebate = 1
  1236. END IF
  1237. rtn_price = lde_saleprice
  1238. rtn_zqrate = lde_rebate
  1239. END IF
  1240. ext:
  1241. IF rslt <> 1 THEN
  1242. rtn_price = 0.00
  1243. rtn_zqrate = 1
  1244. rtn_rate = 1
  1245. END IF
  1246. arg_price = rtn_price
  1247. arg_zqrate = rtn_zqrate
  1248. arg_rate = rtn_rate //这2个字段没用的
  1249. arg_unit = rtn_unit //这2个字段没用的
  1250. RETURN rslt
  1251. end function
  1252. on uo_cusprice.create
  1253. call super::create
  1254. TriggerEvent( this, "constructor" )
  1255. end on
  1256. on uo_cusprice.destroy
  1257. TriggerEvent( this, "destructor" )
  1258. call super::destroy
  1259. end on