uo_crm.sru 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685
  1. $PBExportHeader$uo_crm.sru
  2. forward
  3. global type uo_crm from nonvisualobject
  4. end type
  5. end forward
  6. global type uo_crm from nonvisualobject
  7. end type
  8. global uo_crm uo_crm
  9. type variables
  10. Long uo_cusid
  11. end variables
  12. forward prototypes
  13. public function integer uof_add_plan (s_cust_plan arg_s_cust_plan, string arg_opemp, ref string arg_msg, boolean arg_ifcommit)
  14. public function integer uof_add_interview (s_cust_interview arg_s_cust_interview, string arg_opemp, ref string arg_msg, boolean arg_ifcommit)
  15. public function integer uof_add_cust (s_custom arg_s_cust, string arg_opemp, ref string arg_msg, boolean arg_ifcommit)
  16. public function integer uof_del_interview (long arg_interviewid, string arg_opemp, ref string arg_msg, boolean arg_ifcommit)
  17. public function integer uof_del_plan (long arg_planid, string arg_opemp, ref string arg_msg, boolean arg_ifcommit)
  18. public function integer uof_del_rep (long arg_repid, string arg_opemp, ref string arg_msg, boolean arg_ifcommit)
  19. public function integer uof_add_rep (s_cust_rep arg_s_cust_rep, string arg_opemp, ref string arg_msg, boolean arg_ifcommit)
  20. public function integer uof_del_cust (long arg_cusid, ref string arg_msg, boolean arg_ifcommit)
  21. public function integer uof_change_state (long arg_cusid, integer arg_state, ref string arg_msg, boolean arg_ifcommit)
  22. public function integer uof_del_station (long arg_cusid, long arg_stationid, ref string arg_msg, boolean arg_ifcommit)
  23. public function integer uof_add_station (s_cust_station arg_s_cust_station, ref string arg_msg, boolean arg_ifcommit)
  24. public function integer uof_set_dft_station (s_cust_station arg_s_cust_station, ref string arg_msg, boolean arg_ifcommit)
  25. public function integer uof_add_item (s_item_cust_spt arg_s_item, ref string arg_msg, boolean arg_ifcommit)
  26. public function integer uof_add_sample (s_cust_sample arg_s_cust_sample, string arg_opemp, ref string arg_msg, boolean arg_ifcommit)
  27. public function integer uof_del_sample (long arg_sampleid, string arg_opemp, ref string arg_msg, boolean arg_ifcommit)
  28. public function integer uof_code_find (long arg_id, string arg_code, ref string arg_msg)
  29. public function integer uof_audit_cust_rq (long arg_rqid, boolean arg_approval, string arg_dscrp, ref string arg_msg, boolean arg_ifcommit)
  30. end prototypes
  31. public function integer uof_add_plan (s_cust_plan arg_s_cust_plan, string arg_opemp, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  32. Long cnt,ll_planid
  33. IF IsNull(arg_s_cust_plan.saler) THEN arg_s_cust_plan.saler = ''
  34. IF IsNull(arg_s_cust_plan.planrep) THEN arg_s_cust_plan.planrep = ''
  35. IF IsNull(arg_s_cust_plan.plancontent) THEN arg_s_cust_plan.plancontent = ''
  36. IF IsNull(arg_s_cust_plan.dscrp) THEN arg_s_cust_plan.dscrp = ''
  37. IF IsNull(arg_s_cust_plan.cusid) THEN arg_s_cust_plan.cusid = 0
  38. IF IsNull(arg_s_cust_plan.planid) THEN arg_s_cust_plan.planid = 0
  39. IF IsNull(arg_s_cust_plan.accomplishrslt) THEN arg_s_cust_plan.accomplishrslt = ''
  40. IF arg_s_cust_plan.saler = '' THEN
  41. arg_msg = '请输入业务员'
  42. rslt = 0
  43. GOTO ext
  44. END IF
  45. IF arg_s_cust_plan.plancontent = '' THEN
  46. arg_msg = '请输入计划内容'
  47. rslt = 0
  48. GOTO ext
  49. END IF
  50. SELECT count(*) INTO :cnt
  51. FROM u_cust
  52. Where cusid = :arg_s_cust_plan.cusid;
  53. IF sqlca.SQLCode <> 0 THEN
  54. arg_msg = '查询客户资料失败 '
  55. rslt = 0
  56. GOTO ext
  57. END IF
  58. IF cnt = 0 THEN
  59. arg_msg = '客户资料不存在或重复'
  60. rslt = 0
  61. GOTO ext
  62. END IF
  63. IF arg_s_cust_plan.planid = 0 THEN
  64. ll_planid = f_sys_scidentity(0,"u_cust_plan","planid",arg_msg,TRUE,sqlca)
  65. IF ll_planid <= 0 THEN
  66. rslt = 0
  67. GOTO ext
  68. END IF
  69. INSERT INTO u_cust_plan
  70. (planid,
  71. cusid,
  72. saler,
  73. plandate,
  74. planrep,
  75. plancontent,
  76. dscrp,
  77. opdate,
  78. opemp,
  79. planaccomplishdate,
  80. accomplishdate,
  81. accomplishrslt)
  82. VALUES(:ll_planid,
  83. :arg_s_cust_plan.cusid,
  84. :arg_s_cust_plan.saler,
  85. :arg_s_cust_plan.plandate,
  86. :arg_s_cust_plan.planrep,
  87. :arg_s_cust_plan.plancontent,
  88. :arg_s_cust_plan.dscrp,
  89. getdate(),
  90. :arg_opemp,
  91. :arg_s_cust_plan.planaccomplishdate,
  92. :arg_s_cust_plan.accomplishdate,
  93. :arg_s_cust_plan.accomplishrslt);
  94. IF sqlca.SQLCode <> 0 THEN
  95. if pos(lower(sqlca.SQLErrText),'pk_u_cust_plan') > 0 then
  96. arg_msg = '建立客户计划失败,关键字客户计划ID重复'
  97. else
  98. arg_msg = '建立客户计划失败,'+sqlca.SQLErrText
  99. end if
  100. rslt = 0
  101. GOTO ext
  102. END IF
  103. ELSE
  104. UPDATE u_cust_plan
  105. SET saler = :arg_s_cust_plan.saler,
  106. plandate = :arg_s_cust_plan.plandate,
  107. planrep = :arg_s_cust_plan.planrep,
  108. plancontent = :arg_s_cust_plan.plancontent,
  109. dscrp = :arg_s_cust_plan.dscrp,
  110. moddate = getdate(),
  111. modemp = :arg_opemp,
  112. planaccomplishdate = :arg_s_cust_plan.planaccomplishdate,
  113. accomplishdate = :arg_s_cust_plan.accomplishdate,
  114. accomplishrslt = :arg_s_cust_plan.accomplishrslt
  115. Where planid = :arg_s_cust_plan.planid;
  116. IF sqlca.SQLCode <> 0 THEN
  117. if pos(lower(sqlca.SQLErrText),'pk_u_cust_plan') > 0 then
  118. arg_msg = '更新客户计划失败,关键字客户计划ID重复'
  119. else
  120. arg_msg = '更新客户计划失败,'+sqlca.SQLErrText
  121. end if
  122. rslt = 0
  123. GOTO ext
  124. END IF
  125. END IF
  126. ext:
  127. IF rslt = 0 THEN
  128. ROLLBACK;
  129. ELSEIF rslt = 1 AND arg_ifcommit THEN
  130. COMMIT;
  131. END IF
  132. arg_msg = '客户管理,'+ arg_msg
  133. RETURN rslt
  134. end function
  135. public function integer uof_add_interview (s_cust_interview arg_s_cust_interview, string arg_opemp, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  136. Long cnt,ll_interviewid
  137. IF IsNull(arg_s_cust_interview.saler) THEN arg_s_cust_interview.saler = ''
  138. IF IsNull(arg_s_cust_interview.interviewrep) THEN arg_s_cust_interview.interviewrep = ''
  139. IF IsNull(arg_s_cust_interview.interviewcontent) THEN arg_s_cust_interview.interviewcontent = ''
  140. IF IsNull(arg_s_cust_interview.dscrp) THEN arg_s_cust_interview.dscrp = ''
  141. IF IsNull(arg_s_cust_interview.cusid) THEN arg_s_cust_interview.cusid = 0
  142. IF IsNull(arg_s_cust_interview.interviewid) THEN arg_s_cust_interview.interviewid = 0
  143. IF IsNull(arg_s_cust_interview.amt) THEN arg_s_cust_interview.amt = 0
  144. IF IsNull(arg_s_cust_interview.interviewway) THEN arg_s_cust_interview.interviewway = ''
  145. IF IsNull(arg_s_cust_interview.interviewrslt) THEN arg_s_cust_interview.interviewrslt = ''
  146. IF IsNull(arg_s_cust_interview.interviewform) THEN arg_s_cust_interview.interviewform = ''
  147. IF IsNull(arg_s_cust_interview.custassess) THEN arg_s_cust_interview.custassess = ''
  148. IF IsNull(arg_s_cust_interview.custview) THEN arg_s_cust_interview.custview = ''
  149. IF arg_s_cust_interview.saler = '' THEN
  150. arg_msg = '请输入业务员'
  151. rslt = 0
  152. GOTO ext
  153. END IF
  154. IF arg_s_cust_interview.interviewcontent = '' THEN
  155. arg_msg = '请输入走访内容'
  156. rslt = 0
  157. GOTO ext
  158. END IF
  159. SELECT count(*) INTO :cnt
  160. FROM u_cust
  161. Where cusid = :arg_s_cust_interview.cusid;
  162. IF sqlca.SQLCode <> 0 THEN
  163. arg_msg = '查询客户资料失败'
  164. rslt = 0
  165. GOTO ext
  166. END IF
  167. IF cnt = 0 THEN
  168. arg_msg = '客户资料不存在或重复'
  169. rslt = 0
  170. GOTO ext
  171. END IF
  172. IF arg_s_cust_interview.interviewid = 0 THEN
  173. ll_interviewid = f_sys_scidentity(0,"u_cust_interview","interviewid",arg_msg,TRUE,sqlca)
  174. IF ll_interviewid <= 0 THEN
  175. rslt = 0
  176. GOTO ext
  177. END IF
  178. INSERT INTO u_cust_interview
  179. (interviewid,
  180. cusid,
  181. saler,
  182. interviewdate,
  183. interviewrep,
  184. interviewtime,
  185. interviewcontent,
  186. dscrp,
  187. amt,
  188. opdate,
  189. opemp,
  190. interviewway,
  191. interviewrslt,
  192. interviewform,
  193. custassess,
  194. custview)
  195. VALUES(:ll_interviewid,
  196. :arg_s_cust_interview.cusid,
  197. :arg_s_cust_interview.saler,
  198. :arg_s_cust_interview.interviewdate,
  199. :arg_s_cust_interview.interviewrep,
  200. :arg_s_cust_interview.interviewtime,
  201. :arg_s_cust_interview.interviewcontent,
  202. :arg_s_cust_interview.dscrp,
  203. :arg_s_cust_interview.amt,
  204. getdate(),
  205. :arg_opemp,
  206. :arg_s_cust_interview.interviewway,
  207. :arg_s_cust_interview.interviewrslt,
  208. :arg_s_cust_interview.interviewform,
  209. :arg_s_cust_interview.custassess,
  210. :arg_s_cust_interview.custview);
  211. IF sqlca.SQLCode <> 0 THEN
  212. if pos(lower(sqlca.SQLErrText),'pk_u_cust_interview') > 0 then
  213. arg_msg = '建立客户走访失败,关键字走访记录ID重复'
  214. else
  215. arg_msg = '建立客户走访失败,'+sqlca.SQLErrText
  216. end if
  217. rslt = 0
  218. GOTO ext
  219. END IF
  220. ELSE
  221. UPDATE u_cust_interview
  222. SET saler = :arg_s_cust_interview.saler,
  223. interviewdate = :arg_s_cust_interview.interviewdate,
  224. interviewrep = :arg_s_cust_interview.interviewrep,
  225. interviewtime = :arg_s_cust_interview.interviewtime,
  226. interviewcontent = :arg_s_cust_interview.interviewcontent,
  227. dscrp = :arg_s_cust_interview.dscrp,
  228. amt = :arg_s_cust_interview.amt,
  229. moddate = getdate(),
  230. modemp = :arg_opemp,
  231. interviewway = :arg_s_cust_interview.interviewway,
  232. interviewrslt = :arg_s_cust_interview.interviewrslt,
  233. interviewform = :arg_s_cust_interview.interviewform,
  234. custassess = :arg_s_cust_interview.custassess,
  235. custview = :arg_s_cust_interview.custview
  236. Where interviewid = :arg_s_cust_interview.interviewid;
  237. IF sqlca.SQLCode <> 0 THEN
  238. if pos(lower(sqlca.SQLErrText),'pk_u_cust_interview') > 0 then
  239. arg_msg = '更新客户走访失败,关键字走访记录ID重复'
  240. else
  241. arg_msg = '更新客户走访失败,'+sqlca.SQLErrText
  242. end if
  243. rslt = 0
  244. GOTO ext
  245. END IF
  246. END IF
  247. ext:
  248. IF rslt = 0 THEN
  249. ROLLBACK;
  250. ELSEIF rslt = 1 AND arg_ifcommit THEN
  251. COMMIT;
  252. END IF
  253. arg_msg = '客户管理,'+ arg_msg
  254. RETURN rslt
  255. end function
  256. public function integer uof_add_cust (s_custom arg_s_cust, string arg_opemp, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  257. Long cnt,ll_cusid,ll_i,ll_repid
  258. String ls_cusareaname,ls_areaname
  259. IF IsNull(arg_s_cust.cusid) THEN arg_s_cust.cusid = 0
  260. IF IsNull(arg_s_cust.cuscode) THEN arg_s_cust.cuscode = ''
  261. IF IsNull(arg_s_cust.Name) THEN arg_s_cust.Name = ''
  262. IF IsNull(arg_s_cust.bsntype) THEN arg_s_cust.bsntype = ''
  263. IF IsNull(arg_s_cust.rep) THEN arg_s_cust.rep = ''
  264. IF IsNull(arg_s_cust.tele) THEN arg_s_cust.tele = ''
  265. IF IsNull(arg_s_cust.tele1) THEN arg_s_cust.tele1 = ''
  266. IF IsNull(arg_s_cust.bank) THEN arg_s_cust.bank = ''
  267. IF IsNull(arg_s_cust.cunt) THEN arg_s_cust.cunt = ''
  268. IF IsNull(arg_s_cust.Address) THEN arg_s_cust.Address = ''
  269. IF IsNull(arg_s_cust.code) THEN arg_s_cust.code = ''
  270. IF IsNull(arg_s_cust.dscrp) THEN arg_s_cust.dscrp = ''
  271. IF IsNull(arg_s_cust.givebackrate) THEN arg_s_cust.givebackrate = 0
  272. IF IsNull(arg_s_cust.freight) THEN arg_s_cust.freight = ''
  273. IF IsNull(arg_s_cust.freight_tele) THEN arg_s_cust.freight_tele = ''
  274. IF IsNull(arg_s_cust.fax) THEN arg_s_cust.fax = ''
  275. IF IsNull(arg_s_cust.upname) THEN arg_s_cust.upname = ''
  276. IF IsNull(arg_s_cust.inuse) THEN arg_s_cust.inuse = 0
  277. IF IsNull(arg_s_cust.cusareaid) THEN arg_s_cust.cusareaid = 0
  278. IF IsNull(arg_s_cust.areaname) THEN arg_s_cust.areaname = ''
  279. IF IsNull(arg_s_cust.cusareaname) THEN arg_s_cust.cusareaname = ''
  280. IF IsNull(arg_s_cust.email) THEN arg_s_cust.email = ''
  281. IF IsNull(arg_s_cust.State) THEN arg_s_cust.State = 0
  282. IF IsNull(arg_s_cust.peoplenum) THEN arg_s_cust.peoplenum = 0
  283. IF IsNull(arg_s_cust.mainmarket) THEN arg_s_cust.mainmarket = ''
  284. IF IsNull(arg_s_cust.saleamt) THEN arg_s_cust.saleamt = 0
  285. IF IsNull(arg_s_cust.nethttp) THEN arg_s_cust.nethttp = ''
  286. IF IsNull(arg_s_cust.trade) THEN arg_s_cust.trade = ''
  287. IF IsNull(arg_s_cust.corporation) THEN arg_s_cust.corporation = ''
  288. IF IsNull(arg_s_cust.grade) THEN arg_s_cust.grade = ''
  289. IF IsNull(arg_s_cust.ifself) THEN arg_s_cust.ifself = 0
  290. IF IsNull(arg_s_cust.cuskind) THEN arg_s_cust.cuskind = ''
  291. IF IsNull(arg_s_cust.simplename) THEN arg_s_cust.simplename = ''
  292. IF IsNull(arg_s_cust.viewdaynum) THEN arg_s_cust.viewdaynum = 0
  293. IF arg_s_cust.cuscode = '' THEN
  294. arg_msg = '请输入客户编号!'
  295. rslt = 0
  296. GOTO ext
  297. END IF
  298. IF arg_s_cust.Name = '' THEN
  299. arg_msg = '请输入客户名称!'
  300. rslt = 0
  301. GOTO ext
  302. END IF
  303. cnt = 0
  304. SELECT count(*) INTO :cnt
  305. FROM u_cust
  306. WHERE name = :arg_s_cust.Name
  307. AND cusid <> :arg_s_cust.cusid;
  308. IF sqlca.SQLCode <> 0 THEN
  309. arg_msg = '查询客户名称是否重复失败'
  310. rslt = 0
  311. GOTO ext
  312. END IF
  313. IF cnt > 0 THEN
  314. arg_msg = '客户名称重复,请检查客户资料'
  315. rslt = 0
  316. GOTO ext
  317. END IF
  318. cnt = 0
  319. SELECT count(*) INTO :cnt
  320. FROM u_Cusarea
  321. Where cusareaid = :arg_s_cust.cusareaid;
  322. IF sqlca.SQLCode <> 0 THEN
  323. arg_msg = '查询客户区域资料是否重复失败'
  324. rslt = 0
  325. GOTO ext
  326. END IF
  327. IF cnt <> 1 THEN
  328. arg_msg = '客户区域资料重复或不存在,请检查客户区域资料'
  329. rslt = 0
  330. GOTO ext
  331. END IF
  332. IF arg_s_cust.bsntype = '' THEN
  333. arg_msg = '请选择业务员'
  334. rslt = 0
  335. GOTO ext
  336. END IF
  337. IF arg_s_cust.viewdaynum < 0 THEN
  338. arg_msg = '不合理的预收款天数'
  339. rslt = 0
  340. GOTO ext
  341. END IF
  342. SELECT cusareaname,areaname
  343. INTO :ls_cusareaname,:ls_areaname
  344. FROM u_cusarea
  345. Where cusareaid = :arg_s_cust.cusareaid;
  346. IF sqlca.SQLCode <> 0 THEN
  347. arg_msg = '查询客户区域资料是否重复失败'
  348. rslt = 0
  349. GOTO ext
  350. END IF
  351. IF arg_s_cust.inuse = 0 AND arg_s_cust.cusid > 0 THEN
  352. IF f_check_cust_balcamt(arg_s_cust.cusid,arg_msg) = 0 THEN
  353. rslt = 0
  354. GOTO ext
  355. END IF
  356. END IF
  357. IF arg_s_cust.cusid = 0 THEN
  358. ll_cusid = f_sys_scidentity(0,"u_cust","cusid",arg_msg,FALSE,sqlca)
  359. IF ll_cusid <= 0 THEN
  360. rslt = 0
  361. GOTO ext
  362. END IF
  363. INSERT INTO u_cust
  364. (cusid,
  365. cuscode,
  366. name,
  367. custype,
  368. rep,
  369. tele,
  370. tele1,
  371. bank,
  372. cunt,
  373. address,
  374. code,
  375. dscrp,
  376. faxno,
  377. inuse,
  378. cusareaid,
  379. cusareaname,
  380. areaname,
  381. email,
  382. givebackrate,
  383. freight,
  384. freight_tele,
  385. upname,
  386. state,
  387. peoplenum,
  388. mainmarket,
  389. saleamt,
  390. nethttp,
  391. trade,
  392. corporation,
  393. grade,
  394. ifself,
  395. opdate,
  396. opemp,
  397. cuskind,
  398. simplename,
  399. viewdaynum)
  400. VALUES(:ll_cusid,
  401. :arg_s_cust.cuscode,
  402. :arg_s_cust.name,
  403. :arg_s_cust.bsntype,
  404. :arg_s_cust.rep,
  405. :arg_s_cust.tele,
  406. :arg_s_cust.tele1,
  407. :arg_s_cust.bank,
  408. :arg_s_cust.cunt,
  409. :arg_s_cust.address,
  410. :arg_s_cust.code,
  411. :arg_s_cust.dscrp,
  412. :arg_s_cust.fax,
  413. :arg_s_cust.inuse,
  414. :arg_s_cust.cusareaid,
  415. :ls_cusareaname,
  416. :ls_areaname,
  417. :arg_s_cust.email,
  418. :arg_s_cust.givebackrate,
  419. :arg_s_cust.freight,
  420. :arg_s_cust.freight_tele,
  421. :arg_s_cust.upname,
  422. :arg_s_cust.state,
  423. :arg_s_cust.peoplenum,
  424. :arg_s_cust.mainmarket,
  425. :arg_s_cust.saleamt,
  426. :arg_s_cust.nethttp,
  427. :arg_s_cust.trade,
  428. :arg_s_cust.corporation,
  429. :arg_s_cust.grade,
  430. :arg_s_cust.ifself,
  431. getdate(),
  432. :arg_opemp,
  433. :arg_s_cust.cuskind,
  434. :arg_s_cust.simplename,
  435. :arg_s_cust.viewdaynum);
  436. IF sqlca.SQLCode <> 0 THEN
  437. IF Pos(Lower(sqlca.SQLErrText),'i_cus_code') > 0 THEN
  438. arg_msg = '建立客户资料失败,客户编号重复'
  439. ELSEIF Pos(Lower(sqlca.SQLErrText),'ix_u_cust') > 0 THEN
  440. arg_msg = '建立客户资料失败,客户名称重复'
  441. ELSEIF Pos(Lower(sqlca.SQLErrText),'pk_u_cust') > 0 THEN
  442. arg_msg = '建立客户资料失败,关键字客户ID重复'
  443. ELSE
  444. arg_msg = '建立客户资料失败,'+sqlca.SQLErrText
  445. END IF
  446. rslt = 0
  447. GOTO ext
  448. END IF
  449. uo_cusid = ll_cusid
  450. ELSE
  451. UPDATE u_cust
  452. SET cuscode = :arg_s_cust.cuscode,
  453. name = :arg_s_cust.name,
  454. custype = :arg_s_cust.bsntype,
  455. rep = :arg_s_cust.rep,
  456. tele = :arg_s_cust.tele,
  457. tele1 = :arg_s_cust.tele1,
  458. bank = :arg_s_cust.bank,
  459. cunt = :arg_s_cust.cunt,
  460. address = :arg_s_cust.address,
  461. code = :arg_s_cust.code,
  462. dscrp = :arg_s_cust.dscrp,
  463. faxno = :arg_s_cust.fax,
  464. inuse = :arg_s_cust.inuse,
  465. cusareaid = :arg_s_cust.cusareaid,
  466. cusareaname = :ls_cusareaname,
  467. areaname = :ls_areaname,
  468. email = :arg_s_cust.email,
  469. givebackrate = :arg_s_cust.givebackrate,
  470. freight = :arg_s_cust.freight,
  471. freight_tele = :arg_s_cust.freight_tele,
  472. upname = :arg_s_cust.upname,
  473. state = :arg_s_cust.state,
  474. peoplenum = :arg_s_cust.peoplenum,
  475. mainmarket = :arg_s_cust.mainmarket,
  476. saleamt = :arg_s_cust.saleamt,
  477. nethttp = :arg_s_cust.nethttp,
  478. trade = :arg_s_cust.trade,
  479. corporation = :arg_s_cust.corporation,
  480. grade = :arg_s_cust.grade,
  481. ifself = :arg_s_cust.ifself,
  482. moddate = getdate(),
  483. modemp = :arg_opemp,
  484. cuskind = :arg_s_cust.cuskind,
  485. simplename = :arg_s_cust.simplename,
  486. viewdaynum = :arg_s_cust.viewdaynum
  487. Where cusid = :arg_s_cust.cusid;
  488. IF sqlca.SQLCode <> 0 THEN
  489. /////zww 090916
  490. IF Pos(Lower(sqlca.SQLErrText),'i_cus_code') > 0 THEN
  491. arg_msg = '更新客户资料失败,客户编号重复'
  492. ELSEIF Pos(Lower(sqlca.SQLErrText),'ix_u_cust') > 0 THEN
  493. arg_msg = '更新客户资料失败,客户名称重复'
  494. ELSEIF Pos(Lower(sqlca.SQLErrText),'pk_u_cust') > 0 THEN
  495. arg_msg = '更新客户资料失败,关键字客户ID重复'
  496. ELSE
  497. arg_msg = '更新客户资料失败,'+sqlca.SQLErrText
  498. END IF
  499. // arg_msg = '更新客户资料失败,'+sqlca.SQLErrText
  500. rslt = 0
  501. GOTO ext
  502. END IF
  503. uo_cusid = arg_s_cust.cusid
  504. END IF
  505. ext:
  506. IF rslt = 0 THEN
  507. ROLLBACK;
  508. ELSEIF rslt = 1 AND arg_ifcommit THEN
  509. COMMIT;
  510. END IF
  511. /////////zww 090916
  512. arg_msg = '客户管理,'+ arg_msg
  513. RETURN rslt
  514. end function
  515. public function integer uof_del_interview (long arg_interviewid, string arg_opemp, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  516. String ls_opemp
  517. SELECT opemp INTO :ls_opemp
  518. FROM u_cust_interview
  519. Where interviewid = :arg_interviewid;
  520. IF sqlca.SQLCode <> 0 THEN
  521. if pos(lower(sqlca.SQLErrText),'more than') > 0 then
  522. arg_msg = '查询客户走访资料失败,查询数据返回值多于一个'
  523. else
  524. arg_msg = '查询客户走访资料失败'
  525. end if
  526. rslt = 0
  527. GOTO ext
  528. END IF
  529. IF NOT sys_power_issuper AND arg_opemp <> ls_opemp THEN
  530. arg_msg = '不是资料建立人或系统管理员,不能删除'
  531. rslt = 0
  532. GOTO ext
  533. END IF
  534. DELETE FROM u_cust_interview Where interviewid = :arg_interviewid;
  535. IF sqlca.SQLCode <> 0 THEN
  536. arg_msg = '删除客户走访资料失败 '
  537. rslt = 0
  538. GOTO ext
  539. END IF
  540. ext:
  541. IF rslt = 0 THEN
  542. ROLLBACK;
  543. ELSEIF rslt = 1 AND arg_ifcommit THEN
  544. COMMIT;
  545. END IF
  546. arg_msg = '客户管理,'+ arg_msg
  547. RETURN rslt
  548. end function
  549. public function integer uof_del_plan (long arg_planid, string arg_opemp, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  550. String ls_opemp
  551. SELECT opemp INTO :ls_opemp
  552. FROM u_cust_plan
  553. Where planid = :arg_planid;
  554. IF sqlca.SQLCode <> 0 THEN
  555. if pos(lower(sqlca.SQLErrText),'more than') > 0 then
  556. arg_msg = '查询客户工作计划失败,查询数据返回值多于一个'
  557. else
  558. arg_msg = '查询客户工作计划失败'
  559. end if
  560. rslt = 0
  561. GOTO ext
  562. END IF
  563. IF NOT sys_power_issuper AND arg_opemp <> ls_opemp THEN
  564. arg_msg = '不是资料建立人或系统管理员,不能删除'
  565. rslt = 0
  566. GOTO ext
  567. END IF
  568. DELETE FROM u_cust_plan Where planid = :arg_planid;
  569. IF sqlca.SQLCode <> 0 THEN
  570. arg_msg = '删除客户工作计划失败 '
  571. rslt = 0
  572. GOTO ext
  573. END IF
  574. ext:
  575. IF rslt = 0 THEN
  576. ROLLBACK;
  577. ELSEIF rslt = 1 AND arg_ifcommit THEN
  578. COMMIT;
  579. END IF
  580. arg_msg = '客户管理,'+ arg_msg
  581. RETURN rslt
  582. end function
  583. public function integer uof_del_rep (long arg_repid, string arg_opemp, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  584. String ls_opemp
  585. SELECT opemp INTO :ls_opemp
  586. FROM u_cust_rep
  587. Where repid = :arg_repid;
  588. IF sqlca.SQLCode <> 0 THEN
  589. if pos(lower(sqlca.SQLErrText),'more than') > 0 then
  590. arg_msg = '查询客户联系人资料失败,查询数据返回值多于一个'
  591. else
  592. arg_msg = '查询客户联系人资料失败'
  593. end if
  594. rslt = 0
  595. GOTO ext
  596. END IF
  597. IF NOT sys_power_issuper AND arg_opemp <> ls_opemp THEN
  598. arg_msg = '不是资料建立人或系统管理员,不能删除'
  599. rslt = 0
  600. GOTO ext
  601. END IF
  602. DELETE FROM u_cust_rep Where repid = :arg_repid;
  603. IF sqlca.SQLCode <> 0 THEN
  604. arg_msg = '删除客户联系人失败'
  605. rslt = 0
  606. GOTO ext
  607. END IF
  608. ext:
  609. IF rslt = 0 THEN
  610. ROLLBACK;
  611. ELSEIF rslt = 1 AND arg_ifcommit THEN
  612. COMMIT;
  613. END IF
  614. arg_msg = '客户管理,'+ arg_msg
  615. RETURN rslt
  616. end function
  617. public function integer uof_add_rep (s_cust_rep arg_s_cust_rep, string arg_opemp, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  618. Long cnt,ll_repid
  619. IF IsNull(arg_s_cust_rep.repname) THEN arg_s_cust_rep.repname = ''
  620. IF IsNull(arg_s_cust_rep.duty) THEN arg_s_cust_rep.duty = ''
  621. IF IsNull(arg_s_cust_rep.sex) THEN arg_s_cust_rep.sex = ''
  622. IF IsNull(arg_s_cust_rep.officetel) THEN arg_s_cust_rep.officetel = ''
  623. IF IsNull(arg_s_cust_rep.handtel) THEN arg_s_cust_rep.handtel = ''
  624. IF IsNull(arg_s_cust_rep.faxno) THEN arg_s_cust_rep.faxno = ''
  625. IF IsNull(arg_s_cust_rep.email) THEN arg_s_cust_rep.email = ''
  626. IF IsNull(arg_s_cust_rep.dscrp) THEN arg_s_cust_rep.dscrp = ''
  627. IF IsNull(arg_s_cust_rep.deptname) THEN arg_s_cust_rep.deptname = ''
  628. IF IsNull(arg_s_cust_rep.interest) THEN arg_s_cust_rep.interest = ''
  629. IF IsNull(arg_s_cust_rep.mainproduct) THEN arg_s_cust_rep.mainproduct = ''
  630. IF arg_s_cust_rep.repname = '' THEN
  631. arg_msg = '请输入联系人名称'
  632. rslt = 0
  633. GOTO ext
  634. END IF
  635. SELECT count(*) INTO :cnt
  636. FROM u_cust
  637. Where cusid = :arg_s_cust_rep.cusid;
  638. IF sqlca.SQLCode <> 0 THEN
  639. arg_msg = '查询客户资料失败'
  640. rslt = 0
  641. GOTO ext
  642. END IF
  643. IF cnt = 0 THEN
  644. arg_msg = '客户资料不存在或重复'
  645. rslt = 0
  646. GOTO ext
  647. END IF
  648. IF arg_s_cust_rep.repid = 0 THEN
  649. ll_repid = f_sys_scidentity(0,"u_cust_rep","repid",arg_msg,TRUE,sqlca)
  650. IF ll_repid <= 0 THEN
  651. rslt = 0
  652. GOTO ext
  653. END IF
  654. INSERT INTO u_cust_rep
  655. (repid,
  656. cusid,
  657. repname,
  658. duty,
  659. sex,
  660. officetel,
  661. handtel,
  662. faxno,
  663. email,
  664. dscrp,
  665. deptname,
  666. interest,
  667. mainproduct,
  668. opdate,
  669. opemp)
  670. VALUES(:ll_repid,
  671. :arg_s_cust_rep.cusid,
  672. :arg_s_cust_rep.repname,
  673. :arg_s_cust_rep.duty,
  674. :arg_s_cust_rep.sex,
  675. :arg_s_cust_rep.officetel,
  676. :arg_s_cust_rep.handtel,
  677. :arg_s_cust_rep.faxno,
  678. :arg_s_cust_rep.email,
  679. :arg_s_cust_rep.dscrp,
  680. :arg_s_cust_rep.deptname,
  681. :arg_s_cust_rep.interest,
  682. :arg_s_cust_rep.mainproduct,
  683. getdate(),
  684. :arg_opemp);
  685. IF sqlca.SQLCode <> 0 THEN
  686. if pos(lower(sqlca.SQLErrText),'ix_u_cust_rep') > 0 then
  687. arg_msg = '建立客户联系人失败,联系人名称重复'
  688. elseif pos(lower(sqlca.SQLErrText),'pk_u_cust_rep') > 0 then
  689. arg_msg = '建立客户联系人失败,违反关键字约束:客户ID、联系人ID重复'
  690. else
  691. arg_msg = '建立客户联系人失败,'+sqlca.SQLErrText
  692. end if
  693. rslt = 0
  694. GOTO ext
  695. END IF
  696. ELSE
  697. UPDATE u_cust_rep
  698. SET repname = :arg_s_cust_rep.repname,
  699. duty = :arg_s_cust_rep.duty,
  700. sex = :arg_s_cust_rep.sex,
  701. officetel = :arg_s_cust_rep.officetel,
  702. handtel = :arg_s_cust_rep.handtel,
  703. faxno = :arg_s_cust_rep.faxno,
  704. email = :arg_s_cust_rep.email,
  705. dscrp = :arg_s_cust_rep.dscrp,
  706. deptname = :arg_s_cust_rep.deptname,
  707. interest = :arg_s_cust_rep.interest,
  708. mainproduct = :arg_s_cust_rep.mainproduct,
  709. moddate = getdate(),
  710. modemp = :arg_opemp
  711. Where repid = :arg_s_cust_rep.repid;
  712. IF sqlca.SQLCode <> 0 THEN
  713. if pos(lower(sqlca.SQLErrText),'ix_u_cust_rep') > 0 then
  714. arg_msg = '更新客户联系人失败,联系人名称重复'
  715. elseif pos(lower(sqlca.SQLErrText),'pk_u_cust_rep') > 0 then
  716. arg_msg = '更新客户联系人失败,违反关键字约束:客户ID、联系人ID重复'
  717. else
  718. arg_msg = '更新客户联系人失败,'+sqlca.SQLErrText
  719. end if
  720. rslt = 0
  721. GOTO ext
  722. END IF
  723. END IF
  724. ext:
  725. IF rslt = 0 THEN
  726. ROLLBACK;
  727. ELSEIF rslt = 1 AND arg_ifcommit THEN
  728. COMMIT;
  729. END IF
  730. arg_msg = '客户管理,'+ arg_msg
  731. RETURN rslt
  732. end function
  733. public function integer uof_del_cust (long arg_cusid, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  734. Long cnt
  735. SELECT count(*) INTO :cnt
  736. FROM u_cust
  737. Where cusid = :arg_cusid;
  738. IF sqlca.SQLCode <> 0 THEN
  739. arg_msg = '查询客户资料失败 '
  740. rslt = 0
  741. GOTO ext
  742. END IF
  743. cnt = 0
  744. SELECT count(*) INTO :cnt
  745. FROM u_cust_interview Where cusid = :arg_cusid ;
  746. IF sqlca.SQLCode <> 0 THEN
  747. arg_msg = "查询客户走访计划操作失败! "
  748. rslt = 0
  749. GOTO ext
  750. END IF
  751. IF cnt > 0 THEN
  752. arg_msg = "该资料已经使用于客户走访计划,不可以删除!"
  753. rslt = 0
  754. GOTO ext
  755. END IF
  756. cnt = 0
  757. SELECT count(*) INTO :cnt
  758. FROM u_cust_plan Where cusid = :arg_cusid ;
  759. IF sqlca.SQLCode <> 0 THEN
  760. arg_msg = "查询客户工作计划操作失败!"
  761. rslt = 0
  762. GOTO ext
  763. END IF
  764. IF cnt > 0 THEN
  765. arg_msg = "该资料已经使用于客户工作计划,不可以删除!"
  766. rslt = 0
  767. GOTO ext
  768. END IF
  769. cnt = 0
  770. SELECT count(*) INTO :cnt
  771. FROM u_saletask Where cusid = :arg_cusid ;
  772. IF sqlca.SQLCode <> 0 THEN
  773. arg_msg = "查询客户订货单记录操作失败! "
  774. rslt = 0
  775. GOTO ext
  776. END IF
  777. IF cnt > 0 THEN
  778. arg_msg = "该资料已经使用于订货单记录,不可以删除!"
  779. rslt = 0
  780. GOTO ext
  781. END IF
  782. cnt = 0
  783. SELECT COUNT(*) INTO :cnt
  784. FROM u_outware WHERE u_outware.cusid = :arg_cusid
  785. AND billtype = 1;
  786. IF sqlca.SQLCode <> 0 THEN
  787. arg_msg = "查询客户出仓记录操作失败!"
  788. rslt = 0
  789. GOTO ext
  790. END IF
  791. IF cnt > 0 THEN
  792. arg_msg = "该资料已经使用于出仓记录,不可以删除!"
  793. rslt = 0
  794. GOTO ext
  795. END IF
  796. cnt = 0
  797. SELECT COUNT(*) INTO :cnt
  798. FROM u_bmsttake Where cusid = :arg_cusid ;
  799. IF sqlca.SQLCode <> 0 THEN
  800. arg_msg = "查询客户应收帐记录操作失败!"
  801. rslt = 0
  802. GOTO ext
  803. END IF
  804. IF cnt > 0 THEN
  805. arg_msg = "该资料已经使用于应收帐,不可以删除!"
  806. rslt = 0
  807. GOTO ext
  808. END IF
  809. IF f_check_cust_balcamt(arg_cusid,arg_msg) = 0 THEN
  810. rslt = 0
  811. GOTO ext
  812. END IF
  813. DELETE FROM u_cust_rep Where cusid = :arg_cusid;
  814. IF sqlca.SQLCode <> 0 THEN
  815. arg_msg = '删除客户联系人失败 '
  816. rslt = 0
  817. GOTO ext
  818. END IF
  819. DELETE FROM u_cust_station Where cusid = :arg_cusid;
  820. IF sqlca.SQLCode <> 0 THEN
  821. arg_msg = '删除客户货运部失败 '
  822. rslt = 0
  823. GOTO ext
  824. END IF
  825. DELETE FROM u_item_cust_spt
  826. WHERE relid = :arg_cusid
  827. AND reltype = 0;
  828. IF sqlca.SQLCode <> 0 THEN
  829. arg_msg = '删除客户辅助项目失败 '
  830. rslt = 0
  831. GOTO ext
  832. END IF
  833. DELETE FROM u_cust Where cusid = :arg_cusid;
  834. IF sqlca.SQLCode <> 0 THEN
  835. arg_msg = '删除客户资料失败 '
  836. rslt = 0
  837. GOTO ext
  838. END IF
  839. ext:
  840. IF rslt = 0 THEN
  841. ROLLBACK;
  842. ELSEIF rslt = 1 AND arg_ifcommit THEN
  843. COMMIT;
  844. END IF
  845. arg_msg = '客户管理,'+ arg_msg
  846. RETURN rslt
  847. end function
  848. public function integer uof_change_state (long arg_cusid, integer arg_state, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1,li_state
  849. SELECT state INTO :li_state
  850. FROM u_cust
  851. Where cusid = :arg_cusid;
  852. IF sqlca.SQLCode <> 0 THEN
  853. arg_msg = '查询客户资料失败 '
  854. rslt = 0
  855. GOTO ext
  856. END IF
  857. IF arg_state = 1 THEN
  858. IF li_state = 1 THEN
  859. arg_msg = '客户资料已成为正式客户资料,不能再操作'
  860. rslt = 0
  861. GOTO ext
  862. END IF
  863. UPDATE u_cust SET state = 1
  864. WHERE cusid = :arg_cusid
  865. AND State <> 1;
  866. IF sqlca.SQLCode <> 0 THEN
  867. arg_msg = '更新客户资料类型失败 '
  868. rslt = 0
  869. GOTO ext
  870. END IF
  871. ELSEif arg_state = 0 THEN
  872. IF li_state = 0 THEN
  873. arg_msg = '客户资料已成为公共客户资料,不能再操作'
  874. rslt = 0
  875. GOTO ext
  876. END IF
  877. UPDATE u_cust SET state = 0
  878. WHERE cusid = :arg_cusid
  879. AND State <> 0;
  880. IF sqlca.SQLCode <> 0 THEN
  881. arg_msg = '更新客户资料类型失败 '
  882. rslt = 0
  883. GOTO ext
  884. END IF
  885. ELSEif arg_state = 2 THEN
  886. IF li_state = 2 THEN
  887. arg_msg = '客户资料成为黑名单客户资料,不能再操作'
  888. rslt = 0
  889. GOTO ext
  890. END IF
  891. UPDATE u_cust SET state = 2
  892. WHERE cusid = :arg_cusid
  893. AND State <> 2;
  894. IF sqlca.SQLCode <> 0 THEN
  895. arg_msg = '更新客户资料类型失败 '
  896. rslt = 0
  897. GOTO ext
  898. END IF
  899. ELSEif arg_state = 3 THEN
  900. IF li_state = 3 THEN
  901. arg_msg = '客户资料成为准客户资料,不能再操作'
  902. rslt = 0
  903. GOTO ext
  904. END IF
  905. UPDATE u_cust SET state = 3
  906. WHERE cusid = :arg_cusid
  907. AND State <> 3;
  908. IF sqlca.SQLCode <> 0 THEN
  909. arg_msg = '更新客户资料类型失败 '
  910. rslt = 0
  911. GOTO ext
  912. END IF
  913. END IF
  914. ext:
  915. IF rslt = 0 THEN
  916. ROLLBACK;
  917. ELSEIF rslt = 1 AND arg_ifcommit THEN
  918. COMMIT;
  919. END IF
  920. arg_msg = '客户管理,'+ arg_msg
  921. RETURN rslt
  922. end function
  923. public function integer uof_del_station (long arg_cusid, long arg_stationid, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  924. long cnt
  925. SELECT count(*) INTO :cnt
  926. FROM u_station
  927. Where stationid = :arg_stationid;
  928. IF sqlca.SQLCode <> 0 THEN
  929. arg_msg = '查询货运部资料失败 '
  930. rslt = 0
  931. GOTO ext
  932. END IF
  933. DELETE FROM u_cust_station
  934. Where cusid = :arg_cusid
  935. and stationid = :arg_stationid;
  936. IF sqlca.SQLCode <> 0 THEN
  937. arg_msg = '删除客户货运部资料失败'
  938. rslt = 0
  939. GOTO ext
  940. END IF
  941. ext:
  942. IF rslt = 0 THEN
  943. ROLLBACK;
  944. ELSEIF rslt = 1 AND arg_ifcommit THEN
  945. COMMIT;
  946. END IF
  947. arg_msg = '客户管理,'+ arg_msg
  948. RETURN rslt
  949. end function
  950. public function integer uof_add_station (s_cust_station arg_s_cust_station, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  951. Long cnt
  952. IF IsNull(arg_s_cust_station.cusid) THEN arg_s_cust_station.cusid = 0
  953. IF IsNull(arg_s_cust_station.stationid) THEN arg_s_cust_station.stationid = 0
  954. IF IsNull(arg_s_cust_station.dftflag) THEN arg_s_cust_station.dftflag = 0
  955. cnt = 0
  956. SELECT count(*) INTO :cnt
  957. FROM u_cust
  958. Where cusid = :arg_s_cust_station.cusid;
  959. IF sqlca.SQLCode <> 0 THEN
  960. arg_msg = '查询客户资料失败 '
  961. rslt = 0
  962. GOTO ext
  963. END IF
  964. IF cnt = 0 THEN
  965. arg_msg = '客户资料不存在或重复'
  966. rslt = 0
  967. GOTO ext
  968. END IF
  969. cnt = 0
  970. SELECT count(*) INTO :cnt
  971. FROM u_station
  972. Where stationid = :arg_s_cust_station.stationid;
  973. IF sqlca.SQLCode <> 0 THEN
  974. arg_msg = '查询货运部资料失败 '
  975. rslt = 0
  976. GOTO ext
  977. END IF
  978. IF cnt = 0 THEN
  979. arg_msg = '货运部资料不存在或重复'
  980. rslt = 0
  981. GOTO ext
  982. END IF
  983. SELECT count(*)
  984. INTO :cnt
  985. FROM u_cust_station
  986. WHERE stationid = :arg_s_cust_station.stationid AND
  987. cusid = :arg_s_cust_station.cusid ;
  988. IF sqlca.SQLCode <> 0 THEN
  989. arg_msg = '查询货运部资料失败 '
  990. rslt = 0
  991. GOTO ext
  992. END IF
  993. IF cnt = 0 THEN
  994. INSERT INTO u_cust_station
  995. (stationid,
  996. cusid,
  997. dftflag)
  998. VALUES(:arg_s_cust_station.stationid,
  999. :arg_s_cust_station.cusid,
  1000. :arg_s_cust_station.dftflag);
  1001. IF sqlca.SQLCode <> 0 THEN
  1002. IF Pos(Lower(sqlca.SQLErrText),'pk_u_cust_station') > 0 THEN
  1003. arg_msg = '建立客户货运部失败,违反关键字约束:客户ID、货运部ID重复'
  1004. ELSE
  1005. arg_msg = '建立客户货运部失败,'+sqlca.SQLErrText
  1006. END IF
  1007. rslt = 0
  1008. GOTO ext
  1009. END IF
  1010. END IF
  1011. ext:
  1012. IF rslt = 0 THEN
  1013. ROLLBACK;
  1014. ELSEIF rslt = 1 AND arg_ifcommit THEN
  1015. COMMIT;
  1016. END IF
  1017. arg_msg = '客户管理,'+ arg_msg
  1018. RETURN rslt
  1019. end function
  1020. public function integer uof_set_dft_station (s_cust_station arg_s_cust_station, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  1021. Long cnt
  1022. String ls_dft_name,ls_dft_tel
  1023. IF IsNull(arg_s_cust_station.cusid) THEN arg_s_cust_station.cusid = 0
  1024. IF IsNull(arg_s_cust_station.stationid) THEN arg_s_cust_station.stationid = 0
  1025. IF IsNull(arg_s_cust_station.dftflag) THEN arg_s_cust_station.dftflag = 0
  1026. cnt = 0
  1027. SELECT count(*) INTO :cnt
  1028. FROM u_cust
  1029. Where cusid = :arg_s_cust_station.cusid;
  1030. IF sqlca.SQLCode <> 0 THEN
  1031. arg_msg = '查询客户资料失败 '
  1032. rslt = 0
  1033. GOTO ext
  1034. END IF
  1035. SELECT stationname,tele
  1036. INTO :ls_dft_name,:ls_dft_tel
  1037. FROM u_station
  1038. Where stationid = :arg_s_cust_station.stationid;
  1039. IF sqlca.SQLCode <> 0 THEN
  1040. if pos(lower(sqlca.SQLErrText),'more than') > 0 then
  1041. arg_msg = '查询货运部资料失败,查询数据返回值多于一个'
  1042. else
  1043. arg_msg = '查询货运部资料失败'
  1044. end if
  1045. rslt = 0
  1046. GOTO ext
  1047. END IF
  1048. UPDATE u_cust_station
  1049. SET dftflag = 1
  1050. WHERE stationid = :arg_s_cust_station.stationid
  1051. AND cusid = :arg_s_cust_station.cusid;
  1052. IF sqlca.SQLCode <> 0 THEN
  1053. arg_msg = '设置客户默认货运部失败 '
  1054. rslt = 0
  1055. GOTO ext
  1056. END IF
  1057. UPDATE u_cust_station
  1058. SET dftflag = 0
  1059. WHERE stationid <> :arg_s_cust_station.stationid
  1060. AND cusid = :arg_s_cust_station.cusid;
  1061. IF sqlca.SQLCode <> 0 THEN
  1062. arg_msg = '取消设置客户其它默认货运部失败 '
  1063. rslt = 0
  1064. GOTO ext
  1065. END IF
  1066. UPDATE u_cust
  1067. SET freight = :ls_dft_name,
  1068. freight_tele = :ls_dft_tel
  1069. Where cusid = :arg_s_cust_station.cusid;
  1070. IF sqlca.SQLCode <> 0 THEN
  1071. arg_msg = '更新客户默认货运部失败 '
  1072. rslt = 0
  1073. GOTO ext
  1074. END IF
  1075. ext:
  1076. IF rslt = 0 THEN
  1077. ROLLBACK;
  1078. ELSEIF rslt = 1 AND arg_ifcommit THEN
  1079. COMMIT;
  1080. END IF
  1081. arg_msg = '客户管理,'+ arg_msg
  1082. RETURN rslt
  1083. end function
  1084. public function integer uof_add_item (s_item_cust_spt arg_s_item, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  1085. Long cnt,ll_repid
  1086. IF IsNull(arg_s_item.itemid) THEN arg_s_item.itemid = 0
  1087. IF IsNull(arg_s_item.relid) THEN arg_s_item.relid = 0
  1088. IF IsNull(arg_s_item.reltype) THEN arg_s_item.reltype = 0
  1089. IF IsNull(arg_s_item.dscrp) THEN arg_s_item.dscrp = ''
  1090. cnt = 0
  1091. SELECT count(*) INTO :cnt
  1092. FROM u_item_cust_spt_def
  1093. Where itemid = :arg_s_item.itemid;
  1094. IF sqlca.SQLCode <> 0 THEN
  1095. arg_msg = '查询辅助项目资料失败'
  1096. rslt = 0
  1097. GOTO ext
  1098. END IF
  1099. cnt = 0
  1100. IF arg_s_item.reltype = 0 THEN
  1101. SELECT count(*) INTO :cnt
  1102. FROM u_cust
  1103. Where cusid = :arg_s_item.relid;
  1104. IF sqlca.SQLCode <> 0 THEN
  1105. arg_msg = '查询客户资料失败'
  1106. rslt = 0
  1107. GOTO ext
  1108. END IF
  1109. ELSE
  1110. arg_msg = '错误的项目类型'
  1111. rslt = 0
  1112. GOTO ext
  1113. END IF
  1114. UPDATE u_item_cust_spt
  1115. SET dscrp = :arg_s_item.dscrp
  1116. WHERE itemid = :arg_s_item.itemid
  1117. AND relid = :arg_s_item.relid
  1118. AND reltype = :arg_s_item.reltype;
  1119. IF sqlca.SQLCode = 0 THEN
  1120. IF sqlca.SQLNRows = 0 THEN
  1121. INSERT INTO u_item_cust_spt
  1122. (itemid,
  1123. relid,
  1124. reltype,
  1125. dscrp)
  1126. VALUES(:arg_s_item.itemid,
  1127. :arg_s_item.relid,
  1128. :arg_s_item.reltype,
  1129. :arg_s_item.dscrp);
  1130. IF sqlca.SQLCode <> 0 THEN
  1131. IF Pos(Lower(sqlca.SQLErrText),'pk_u_item_cust_spt') > 0 THEN
  1132. arg_msg = '建立辅助项目资料失败,违反关键字约束:客户、辅助项目重复'
  1133. ELSE
  1134. arg_msg = '建立辅助项目资料失败,'+sqlca.SQLErrText
  1135. END IF
  1136. rslt = 0
  1137. GOTO ext
  1138. END IF
  1139. END IF
  1140. ELSE
  1141. IF Pos(Lower(sqlca.SQLErrText),'pk_u_item_cust_spt') > 0 THEN
  1142. arg_msg = '更新辅助项目资料失败,违反关键字约束:客户、辅助项目重复'
  1143. ELSE
  1144. arg_msg = '更新辅助项目资料失败,'+sqlca.SQLErrText
  1145. END IF
  1146. rslt = 0
  1147. GOTO ext
  1148. END IF
  1149. ext:
  1150. IF rslt = 0 THEN
  1151. ROLLBACK;
  1152. ELSEIF rslt = 1 AND arg_ifcommit THEN
  1153. COMMIT;
  1154. END IF
  1155. arg_msg = '客户管理,'+ arg_msg
  1156. RETURN rslt
  1157. end function
  1158. public function integer uof_add_sample (s_cust_sample arg_s_cust_sample, string arg_opemp, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  1159. Long cnt,ll_sampleid
  1160. IF IsNull(arg_s_cust_sample.saler) THEN arg_s_cust_sample.saler = ''
  1161. IF IsNull(arg_s_cust_sample.mtrlid) THEN arg_s_cust_sample.mtrlid = 0
  1162. IF IsNull(arg_s_cust_sample.samplecontent) THEN arg_s_cust_sample.samplecontent = ''
  1163. IF IsNull(arg_s_cust_sample.cusid) THEN arg_s_cust_sample.cusid = 0
  1164. IF IsNull(arg_s_cust_sample.sampleid) THEN arg_s_cust_sample.sampleid = 0
  1165. IF IsNull(arg_s_cust_sample.qty) THEN arg_s_cust_sample.qty = 0
  1166. IF arg_s_cust_sample.saler = '' THEN
  1167. arg_msg = '请输入业务员'
  1168. rslt = 0
  1169. GOTO ext
  1170. END IF
  1171. cnt = 0
  1172. SELECT count(*) INTO :cnt
  1173. FROM u_cust
  1174. Where cusid = :arg_s_cust_sample.cusid;
  1175. IF sqlca.SQLCode <> 0 THEN
  1176. arg_msg = '查询客户资料失败 '
  1177. rslt = 0
  1178. GOTO ext
  1179. END IF
  1180. IF cnt = 0 THEN
  1181. arg_msg = '客户资料不存在或重复'
  1182. rslt = 0
  1183. GOTO ext
  1184. END IF
  1185. cnt = 0
  1186. SELECT count(*) INTO :cnt
  1187. FROM u_mtrldef
  1188. Where mtrlid = :arg_s_cust_sample.mtrlid;
  1189. IF sqlca.SQLCode <> 0 THEN
  1190. arg_msg = '查询物料资料失败 '
  1191. rslt = 0
  1192. GOTO ext
  1193. END IF
  1194. IF cnt = 0 THEN
  1195. arg_msg = '物料资料不存在或重复'
  1196. rslt = 0
  1197. GOTO ext
  1198. END IF
  1199. IF arg_s_cust_sample.sampleid = 0 THEN
  1200. ll_sampleid = f_sys_scidentity(0,"u_cust_sample","sampleid",arg_msg,TRUE,sqlca)
  1201. IF ll_sampleid <= 0 THEN
  1202. rslt = 0
  1203. GOTO ext
  1204. END IF
  1205. INSERT INTO u_cust_sample
  1206. (sampleid,
  1207. cusid,
  1208. saler,
  1209. sampledate,
  1210. mtrlid,
  1211. samplecontent,
  1212. qty,
  1213. opdate,
  1214. opemp)
  1215. VALUES(:ll_sampleid,
  1216. :arg_s_cust_sample.cusid,
  1217. :arg_s_cust_sample.saler,
  1218. :arg_s_cust_sample.sampledate,
  1219. :arg_s_cust_sample.mtrlid,
  1220. :arg_s_cust_sample.samplecontent,
  1221. :arg_s_cust_sample.qty,
  1222. getdate(),
  1223. :arg_opemp);
  1224. IF sqlca.SQLCode <> 0 THEN
  1225. if pos(lower(sqlca.SQLErrText),'pk_u_cust_sample') > 0 then
  1226. arg_msg = '建立客户样版失败,关键字客户样版ID重复'
  1227. else
  1228. arg_msg = '建立客户样版失败,'+sqlca.SQLErrText
  1229. end if
  1230. rslt = 0
  1231. GOTO ext
  1232. END IF
  1233. ELSE
  1234. UPDATE u_cust_sample
  1235. SET saler = :arg_s_cust_sample.saler,
  1236. sampledate = :arg_s_cust_sample.sampledate,
  1237. mtrlid = :arg_s_cust_sample.mtrlid,
  1238. samplecontent = :arg_s_cust_sample.samplecontent,
  1239. qty = :arg_s_cust_sample.qty,
  1240. moddate = getdate(),
  1241. modemp = :arg_opemp
  1242. Where sampleid = :arg_s_cust_sample.sampleid;
  1243. IF sqlca.SQLCode <> 0 THEN
  1244. if pos(lower(sqlca.SQLErrText),'pk_u_cust_sample') > 0 then
  1245. arg_msg = '更新客户样版失败,关键字客户样版ID重复'
  1246. else
  1247. arg_msg = '更新客户样版失败,'+sqlca.SQLErrText
  1248. end if
  1249. rslt = 0
  1250. GOTO ext
  1251. END IF
  1252. END IF
  1253. ext:
  1254. IF rslt = 0 THEN
  1255. ROLLBACK;
  1256. ELSEIF rslt = 1 AND arg_ifcommit THEN
  1257. COMMIT;
  1258. END IF
  1259. arg_msg = '客户管理,'+ arg_msg
  1260. RETURN rslt
  1261. end function
  1262. public function integer uof_del_sample (long arg_sampleid, string arg_opemp, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  1263. String ls_opemp
  1264. SELECT opemp INTO :ls_opemp
  1265. FROM u_cust_sample
  1266. Where sampleid = :arg_sampleid;
  1267. IF sqlca.SQLCode <> 0 THEN
  1268. if pos(lower(sqlca.SQLErrText),'more than') > 0 then
  1269. arg_msg = '查询客户样版失败,查询数据返回值多于一个'
  1270. else
  1271. arg_msg = '查询客户样版失败'
  1272. end if
  1273. rslt = 0
  1274. GOTO ext
  1275. END IF
  1276. IF NOT sys_power_issuper AND arg_opemp <> ls_opemp THEN
  1277. arg_msg = '不是资料建立人或系统管理员,不能删除'
  1278. rslt = 0
  1279. GOTO ext
  1280. END IF
  1281. DELETE FROM u_cust_sample Where sampleid = :arg_sampleid;
  1282. IF sqlca.SQLCode <> 0 THEN
  1283. arg_msg = '删除客户样版失败'
  1284. rslt = 0
  1285. GOTO ext
  1286. END IF
  1287. ext:
  1288. IF rslt = 0 THEN
  1289. ROLLBACK;
  1290. ELSEIF rslt = 1 AND arg_ifcommit THEN
  1291. COMMIT;
  1292. END IF
  1293. arg_msg = '客户管理,'+ arg_msg
  1294. RETURN rslt
  1295. end function
  1296. public function integer uof_code_find (long arg_id, string arg_code, ref string arg_msg);Int rslt = 1
  1297. long cnt
  1298. SELECT count(*) INTO :cnt
  1299. FROM u_cust
  1300. WHERE cusid <> :arg_id
  1301. AND cuscode = :arg_code;
  1302. IF sqlca.SQLCode <> 0 THEN
  1303. arg_msg = '查询客户编号:'+arg_code+',是否已用失败 '
  1304. rslt = 0
  1305. GOTO ext
  1306. END IF
  1307. IF cnt > 0 THEN
  1308. arg_msg = '查询客户编号:'+arg_code+',已用,请重新输入'
  1309. rslt = 0
  1310. GOTO ext
  1311. END IF
  1312. ext:
  1313. arg_msg = '客户管理,'+ arg_msg
  1314. RETURN rslt
  1315. end function
  1316. public function integer uof_audit_cust_rq (long arg_rqid, boolean arg_approval, string arg_dscrp, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  1317. Long cnt
  1318. Long ll_cusid
  1319. String ls_custype, ls_dscrp
  1320. Int li_flag
  1321. SELECT cusid, custype, flag
  1322. INTO :ll_cusid, :ls_custype, :li_flag
  1323. FROM u_cust_rq
  1324. Where rqid = :arg_rqid;
  1325. IF sqlca.SQLCode <> 0 THEN
  1326. rslt = 0
  1327. arg_msg = "查询客户申请状况操作失败"
  1328. GOTO ext
  1329. END IF
  1330. IF li_flag = 1 THEN
  1331. rslt = 0
  1332. arg_msg = "客户申请已审核"
  1333. GOTO ext
  1334. END IF
  1335. IF arg_approval THEN
  1336. ls_dscrp = "批准"
  1337. ELSE
  1338. ls_dscrp = "驳回"
  1339. END IF
  1340. IF arg_dscrp <> "" THEN
  1341. ls_dscrp += ",原因:"+arg_dscrp
  1342. END IF
  1343. UPDATE u_cust_rq
  1344. SET flag = 1,
  1345. auditdate = getdate(),
  1346. auditemp = :publ_operator,
  1347. dscrp = :ls_dscrp
  1348. WHERE rqid = :arg_rqid
  1349. And flag = 0;
  1350. IF sqlca.SQLCode <> 0 THEN
  1351. rslt = 0
  1352. arg_msg = "审核客户申请状况操作失败"
  1353. GOTO ext
  1354. ELSEIF sqlca.SQLNRows = 0 THEN
  1355. rslt = 0
  1356. arg_msg = "审核客户申请状况操作失败,正在审核中......"
  1357. GOTO ext
  1358. END IF
  1359. IF arg_approval THEN //更新客户状态
  1360. UPDATE u_cust
  1361. SET state = 1
  1362. Where cusid = :ll_cusid;
  1363. ELSE
  1364. UPDATE u_cust
  1365. SET state = 0
  1366. Where cusid = :ll_cusid;
  1367. END IF
  1368. IF sqlca.SQLCode <> 0 THEN
  1369. rslt = 0
  1370. arg_msg = "更新客户类型操作失败"
  1371. GOTO ext
  1372. END IF
  1373. ext:
  1374. IF rslt = 0 THEN
  1375. ROLLBACK;
  1376. ELSEIF rslt = 1 And arg_ifcommit THEN
  1377. COMMIT;
  1378. END IF
  1379. arg_msg = '客户资料,'+ arg_msg
  1380. RETURN rslt
  1381. end function
  1382. on uo_crm.create
  1383. call super::create
  1384. TriggerEvent( this, "constructor" )
  1385. end on
  1386. on uo_crm.destroy
  1387. TriggerEvent( this, "destructor" )
  1388. call super::destroy
  1389. end on