uo_update_cost.sru 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957
  1. $PBExportHeader$uo_update_cost.sru
  2. forward
  3. global type uo_update_cost from nonvisualobject
  4. end type
  5. end forward
  6. global type uo_update_cost from nonvisualobject
  7. end type
  8. global uo_update_cost uo_update_cost
  9. type variables
  10. PUBLIC PROTECTEDWRITE Long wareid
  11. PUBLIC PROTECTEDWRITE String warecode
  12. PUBLIC PROTECTEDWRITE DateTime opdate
  13. PUBLIC PROTECTEDWRITE String opemp
  14. PUBLIC PROTECTEDWRITE DateTime modidate
  15. PUBLIC PROTECTEDWRITE String modiemp
  16. PUBLIC PROTECTEDWRITE Int flag = 0
  17. PUBLIC PROTECTEDWRITE DateTime auditingdate
  18. PUBLIC PROTECTEDWRITE String auditingrep
  19. Long storageid
  20. DateTime moddate
  21. String modrep
  22. String part
  23. String dscrp
  24. Boolean if_getid_ture = TRUE
  25. Transaction commit_transaction //数据commit事务
  26. s_inwaremx s_mx[] //明细结构数组
  27. Long it_mxbt = 0 //明细结构数组末指针
  28. Boolean it_newbegin = FALSE //新建标志
  29. Boolean it_updatebegin = FALSE //修改标志
  30. end variables
  31. forward prototypes
  32. public function integer save (boolean arg_ifcommit, ref string arg_msg)
  33. public function integer auditing (boolean arg_ifcommit, ref string arg_msg)
  34. public function integer p_clearmx ()
  35. public function integer p_reset ()
  36. public function integer add_dscrp (long arg_wareid, string arg_newdescppart, ref string arg_msg)
  37. public function integer p_getinfo (long arg_wareid, ref string arg_msg)
  38. public function integer getinfo (long arg_wareid, ref string arg_msg)
  39. public function integer del (long arg_wareid, ref string arg_msg, boolean arg_ifcommit)
  40. public function integer updatebegin (long arg_wareid, ref string arg_msg)
  41. public function integer newbegin ()
  42. public function integer acceptmx (long arg_printid, long arg_mtrlwarescid, long arg_mtrlwareid, string arg_mtrlcode, string arg_mxdscrp, ref string arg_msg, decimal arg_newcost, string arg_unit, decimal arg_rate)
  43. end prototypes
  44. public function integer save (boolean arg_ifcommit, ref string arg_msg);Integer rslt = 1,cnt = 0,i
  45. DateTime server_dt
  46. Long ls_newid
  47. String ls_sccode
  48. IF IsNull(storageid) THEN storageid = 0
  49. IF IsNull(modrep) THEN modrep = ''
  50. IF IsNull(dscrp) THEN dscrp = ''
  51. IF IsNull(part) THEN part = ''
  52. IF it_newbegin = FALSE AND it_updatebegin = FALSE THEN
  53. rslt = 0
  54. arg_msg = "非编辑状态不可以提交"
  55. GOTO ext
  56. END IF
  57. SELECT Top 1 getdate() INTO :server_dt FROM u_user USING commit_transaction ;
  58. //取得系统时间,借用操作员表
  59. IF commit_transaction.SQLCode <> 0 THEN
  60. rslt = 0
  61. arg_msg = "查询操作失败,日期 "
  62. GOTO ext
  63. END IF
  64. IF it_mxbt = 0 THEN //如果输入物料资料错则已经清空
  65. rslt = 0
  66. arg_msg = "没有正确进仓内容"
  67. GOTO ext
  68. END IF
  69. cnt = 0
  70. //检查仓库
  71. SELECT count(*)
  72. INTO :cnt
  73. FROM u_storage
  74. Where u_storage.storageid = :storageid USING commit_transaction ;
  75. IF commit_transaction.SQLCode <> 0 THEN
  76. rslt = 0
  77. arg_msg = "查询操作失败,仓库"
  78. GOTO ext
  79. END IF
  80. IF cnt = 0 THEN
  81. rslt = 0
  82. arg_msg = "错误的仓库编号: "+String(storageid)
  83. GOTO ext
  84. END IF
  85. IF Year(Date(moddate)) < 2000 OR IsNull(moddate) THEN
  86. rslt = 0
  87. arg_msg = "缺少更新发生时间或不合理"
  88. GOTO ext
  89. END IF
  90. IF f_check_inoutdate(storageid,moddate,TRUE,arg_msg) = 0 THEN
  91. rslt = 0
  92. GOTO ext
  93. END IF
  94. ////////////////////////////////////////////////开始区分:新建/更新 处理
  95. IF wareid = 0 THEN //新建
  96. ls_newid = f_sys_scidentity(0,"u_updatecost","wareid",arg_msg,TRUE,id_sqlca)
  97. IF ls_newid <= 0 THEN
  98. rslt = 0
  99. GOTO ext
  100. END IF
  101. //取分部代号
  102. IF f_get_sccode(0,commit_transaction,ls_sccode,arg_msg) = 0 THEN
  103. rslt = 0
  104. GOTO ext
  105. END IF
  106. warecode = getid(0,ls_sccode + 'UC',Date(server_dt),if_getid_ture,commit_transaction)
  107. IF warecode = "err" THEN
  108. warecode = ''
  109. rslt = 0
  110. arg_msg = "无法获取单据编号"+"~n"+commit_transaction.SQLErrText
  111. GOTO ext
  112. END IF
  113. INSERT INTO u_updatecost (
  114. wareid,
  115. warecode,
  116. storageid,
  117. part,
  118. moddate,
  119. modrep,
  120. dscrp,
  121. opdate,
  122. opemp)
  123. VALUES (
  124. :ls_newid,
  125. :warecode,
  126. :storageid,
  127. :part,
  128. :moddate,
  129. :modrep,
  130. :dscrp,
  131. :server_dt,
  132. :publ_operator) USING commit_transaction ;
  133. IF commit_transaction.SQLCode <> 0 THEN
  134. rslt = 0
  135. arg_msg = "因网络或其它原因导致插入操作失败"+"~n"+commit_transaction.SQLErrText
  136. GOTO ext
  137. END IF
  138. //读取新inwareid
  139. wareid = ls_newid
  140. FOR i = 1 TO it_mxbt
  141. INSERT INTO u_updatecostmx
  142. (wareid,
  143. mtrlwarescid,
  144. mtrlwareid,
  145. mtrlid,
  146. plancode,
  147. status,
  148. mxdscrp,
  149. noallocqty,
  150. woodcode,
  151. pcode,
  152. cost,
  153. newcost,
  154. printid,
  155. sptid,
  156. unewcost,
  157. unit,
  158. rate,
  159. mtrlcuscode,
  160. location)
  161. VALUES (
  162. :ls_newid,
  163. :s_mx[i].scid,
  164. :s_mx[i].mtrlwareid,
  165. :s_mx[i].mtrlid,
  166. :s_mx[i].plancode,
  167. :s_mx[i].status,
  168. :s_mx[i].mxdscrp,
  169. :s_mx[i].qty,
  170. :s_mx[i].woodcode,
  171. :s_mx[i].pcode,
  172. :s_mx[i].cost,
  173. :s_mx[i].newcost,
  174. :s_mx[i].printid,
  175. :s_mx[i].sptid,
  176. :s_mx[i].unewcost,
  177. :s_mx[i].uunit,
  178. :s_mx[i].rate,
  179. :s_mx[i].mtrlcuscode,
  180. :s_mx[i].location) USING commit_transaction;
  181. IF commit_transaction.SQLCode <> 0 THEN
  182. wareid = 0 //还原inwareid
  183. rslt = 0
  184. arg_msg = "因网络或其它原因导致插入明细操作失败"+"~n"+commit_transaction.SQLErrText
  185. GOTO ext
  186. END IF
  187. NEXT
  188. ELSE //////////////////////////////////////////////////更新
  189. UPDATE u_updatecost
  190. SET
  191. storageid = :storageid,
  192. moddate = :moddate,
  193. modrep = :modrep,
  194. part = :part,
  195. dscrp = :dscrp,
  196. modidate = :server_dt,
  197. modiemp = :publ_operator
  198. WHERE u_updatecost.wareid = :wareid
  199. AND flag = 0 USING commit_transaction;
  200. IF commit_transaction.SQLCode <> 0 OR commit_transaction.SQLNRows <= 0 THEN
  201. rslt = 0
  202. arg_msg = "因网络或其它原因导致更新单据操作失败"+"~n"+commit_transaction.SQLErrText
  203. GOTO ext
  204. END IF
  205. //删除原有明细
  206. DELETE FROM u_updatecostmx
  207. WHERE u_updatecostmx.wareid = :wareid
  208. USING commit_transaction;
  209. IF commit_transaction.SQLCode <> 0 THEN
  210. rslt = 0
  211. arg_msg = "删除旧有明细操作失败"+"~n"+commit_transaction.SQLErrText
  212. GOTO ext
  213. END IF
  214. FOR i = 1 TO it_mxbt
  215. INSERT INTO u_updatecostmx
  216. (wareid,
  217. mtrlwarescid,
  218. mtrlwareid,
  219. mtrlid,
  220. plancode,
  221. status,
  222. mxdscrp,
  223. noallocqty,
  224. woodcode,
  225. pcode,
  226. cost,
  227. newcost,
  228. printid,
  229. sptid,
  230. unewcost,
  231. unit,
  232. rate,
  233. mtrlcuscode,
  234. location)
  235. VALUES (
  236. :wareid,
  237. :s_mx[i].scid,
  238. :s_mx[i].mtrlwareid,
  239. :s_mx[i].mtrlid,
  240. :s_mx[i].plancode,
  241. :s_mx[i].status,
  242. :s_mx[i].mxdscrp,
  243. :s_mx[i].qty,
  244. :s_mx[i].woodcode,
  245. :s_mx[i].pcode,
  246. :s_mx[i].cost,
  247. :s_mx[i].newcost,
  248. :s_mx[i].printid,
  249. :s_mx[i].sptid,
  250. :s_mx[i].unewcost,
  251. :s_mx[i].uunit,
  252. :s_mx[i].rate,
  253. :s_mx[i].mtrlcuscode,
  254. :s_mx[i].location) USING commit_transaction;
  255. IF commit_transaction.SQLCode <> 0 THEN
  256. rslt = 0
  257. arg_msg = "因网络或其它原因导致插入明细操作失败"+"~n"+commit_transaction.SQLErrText
  258. GOTO ext
  259. END IF
  260. NEXT
  261. END IF
  262. it_newbegin = FALSE
  263. it_updatebegin = FALSE
  264. ext:
  265. IF rslt = 0 THEN
  266. ROLLBACK USING commit_transaction;
  267. p_clearmx()
  268. ELSEIF rslt = 1 AND arg_ifcommit THEN
  269. COMMIT USING commit_transaction;
  270. END IF
  271. RETURN rslt
  272. end function
  273. public function integer auditing (boolean arg_ifcommit, ref string arg_msg);Long rslt = 1,cnt = 0,i
  274. Decimal ld_qty,ld_price
  275. IF wareid = 0 THEN
  276. rslt = 0
  277. arg_msg = "没有审核对象"
  278. GOTO ext
  279. END IF
  280. IF flag = 1 THEN
  281. rslt = 0
  282. arg_msg = "单据已经审核"
  283. GOTO ext
  284. END IF
  285. UPDATE u_updatecost
  286. SET auditingrep = :publ_operator,
  287. auditingdate = getdate(),
  288. flag = 1
  289. WHERE u_updatecost.wareid = :wareid
  290. AND flag = 0
  291. Using commit_transaction;
  292. IF commit_transaction.SQLCode <> 0 THEN
  293. rslt = 0
  294. arg_msg = "因网络或其它原因导致审核单据操作失败"+"~n"+commit_transaction.SQLErrText
  295. GOTO ext
  296. ELSEIF commit_transaction.SQLNRows = 0 THEN
  297. rslt = 0
  298. arg_msg = "单据正在审核,请稍后查询。"+"~n"+commit_transaction.SQLErrText
  299. GOTO ext
  300. END IF
  301. Long ll_scid
  302. uo_inware uo_1
  303. SELECT scid INTO :ll_scid
  304. FROM u_storage
  305. WHERE storageid = :storageid
  306. Using commit_transaction;
  307. IF commit_transaction.SQLCode <> 0 THEN
  308. rslt = 0
  309. arg_msg = "查询仓库分部资料失败"+"~n"+commit_transaction.SQLErrText
  310. GOTO ext
  311. END IF
  312. uo_1 = Create uo_inware
  313. //生成进仓单 负
  314. IF uo_1.newbegin(ll_scid,8,arg_msg) = 0 THEN //
  315. rslt = 0
  316. GOTO ext
  317. END IF
  318. uo_1.indate = moddate
  319. uo_1.inrep = modrep // 经手人
  320. uo_1.part = warecode
  321. uo_1.dscrp = dscrp //备注
  322. uo_1.storageid = storageid
  323. uo_1.sptname = '调整成本价(负单)'
  324. uo_1.relid = wareid
  325. uo_1.if_getid_ture = False
  326. uo_1.commit_transaction = commit_transaction
  327. FOR i = 1 To it_mxbt
  328. IF s_mx[i].mtrlwareid > 0 THEN
  329. IF s_mx[i].qty <> 0 THEN
  330. ld_qty = s_mx[i].qty
  331. ld_price = s_mx[i].cost
  332. ELSE
  333. ld_qty = -1
  334. ld_price = s_mx[i].newcost
  335. END IF
  336. IF uo_1.acceptmx(s_mx[i].printid,&
  337. s_mx[i].mtrlid,&
  338. s_mx[i].mtrlcode,&
  339. s_mx[i].plancode,&
  340. s_mx[i].status,&
  341. 0 - ld_qty,&
  342. ld_price,&
  343. 1,&
  344. s_mx[i].mxdscrp,&
  345. arg_msg,&
  346. 0,0,0,&
  347. s_mx[i].woodcode,&
  348. s_mx[i].pcode,&
  349. s_mx[i].sptid,&
  350. s_mx[i].unit,1,0 - ld_qty,0,0,'','',0,0,&
  351. s_mx[i].mtrlcuscode,s_mx[i].Location,&
  352. 0 - ld_qty,&
  353. 0) = 0 THEN
  354. rslt = 0
  355. GOTO ext
  356. END IF
  357. END IF
  358. NEXT
  359. IF uo_1.it_mxbt > 0 THEN
  360. IF uo_1.Save(False,arg_msg) = 0 THEN
  361. rslt = 0
  362. GOTO ext
  363. END IF
  364. IF uo_1.getinfo(uo_1.scid,uo_1.inwareid,arg_msg) = 0 THEN
  365. rslt = 0
  366. GOTO ext
  367. END IF
  368. IF uo_1.auditing(False,arg_msg) = 0 THEN
  369. rslt = 0
  370. GOTO ext
  371. END IF
  372. IF uo_1.uof_secaudit(uo_1.scid,uo_1.inwareid,arg_msg,False) = 0 THEN
  373. rslt = 0
  374. GOTO ext
  375. END IF
  376. END IF
  377. Destroy uo_1
  378. uo_1 = Create uo_inware
  379. //生成进仓单  正
  380. IF uo_1.newbegin(ll_scid,8,arg_msg) = 0 THEN
  381. rslt = 0
  382. GOTO ext
  383. END IF
  384. uo_1.indate = moddate
  385. uo_1.inrep = modrep // 经手人
  386. uo_1.part = warecode //相关部门
  387. uo_1.dscrp = dscrp //备注
  388. uo_1.storageid = storageid
  389. uo_1.sptname = '更新成本价(正单)'
  390. uo_1.relid = wareid
  391. uo_1.if_getid_ture = False
  392. uo_1.commit_transaction = commit_transaction
  393. FOR i = 1 To it_mxbt
  394. IF s_mx[i].mtrlwareid > 0 THEN
  395. IF s_mx[i].qty <> 0 THEN
  396. ld_qty = s_mx[i].qty
  397. ld_price = s_mx[i].newcost
  398. ELSE
  399. ld_qty = -1
  400. ld_price = 0
  401. END IF
  402. IF uo_1.acceptmx(s_mx[i].printid,&
  403. s_mx[i].mtrlid,&
  404. s_mx[i].mtrlcode,&
  405. s_mx[i].plancode,&
  406. s_mx[i].status,&
  407. ld_qty,&
  408. ld_price,&
  409. 1,&
  410. s_mx[i].mxdscrp,&
  411. arg_msg,0,0,0,&
  412. s_mx[i].woodcode,&
  413. s_mx[i].pcode,&
  414. s_mx[i].sptid,&
  415. s_mx[i].unit,&
  416. 1,ld_qty,0,0,'','',0,0,&
  417. s_mx[i].mtrlcuscode,&
  418. s_mx[i].Location,&
  419. ld_qty,&
  420. 0) = 0 THEN
  421. MessageBox('Error!',arg_msg)
  422. rslt = 0
  423. GOTO ext
  424. END IF
  425. END IF
  426. NEXT
  427. IF uo_1.it_mxbt > 0 THEN
  428. IF uo_1.Save(False,arg_msg) = 0 THEN
  429. rslt = 0
  430. GOTO ext
  431. END IF
  432. IF uo_1.getinfo(uo_1.scid,uo_1.inwareid,arg_msg) = 0 THEN
  433. rslt = 0
  434. GOTO ext
  435. END IF
  436. IF uo_1.auditing(False,arg_msg) = 0 THEN
  437. rslt = 0
  438. GOTO ext
  439. END IF
  440. IF uo_1.uof_secaudit(uo_1.scid,uo_1.inwareid,arg_msg,False) = 0 THEN
  441. rslt = 0
  442. GOTO ext
  443. END IF
  444. END IF
  445. flag = 1
  446. ext:
  447. IF rslt = 0 THEN
  448. ROLLBACK Using commit_transaction;
  449. ELSEIF rslt = 1 And arg_ifcommit THEN
  450. COMMIT Using commit_transaction;
  451. END IF
  452. Destroy uo_1
  453. RETURN rslt
  454. end function
  455. public function integer p_clearmx ();//int p_clearmx()
  456. //清除明细
  457. it_mxbt=0
  458. return 1
  459. end function
  460. public function integer p_reset ();//int p_reset()
  461. //清除对象及其明细
  462. wareid = 0
  463. warecode = ''
  464. opemp = ''
  465. modiemp = ''
  466. auditingrep = ''
  467. flag = 0
  468. storageid = 0
  469. modrep = ''
  470. part = ''
  471. dscrp = ''
  472. it_newbegin = FALSE
  473. it_updatebegin = FALSE
  474. //清除明细
  475. p_clearmx()
  476. RETURN 1
  477. end function
  478. public function integer add_dscrp (long arg_wareid, string arg_newdescppart, ref string arg_msg);
  479. Int rslt = 1
  480. arg_newdescppart = Trim(arg_newdescppart)
  481. IF it_updatebegin OR it_newbegin THEN
  482. rslt = 0
  483. arg_msg = "编辑状态下不可用"
  484. GOTO ext
  485. END IF
  486. IF arg_newdescppart = '' THEN
  487. rslt = 0
  488. arg_msg = "要添加内容为空,操作取消"
  489. GOTO ext
  490. END IF
  491. rslt = p_getinfo(arg_wareid,arg_msg)
  492. IF rslt = 0 THEN GOTO ext
  493. IF flag = 0 THEN
  494. rslt = 0
  495. arg_msg = "非审核状态下不可用"
  496. GOTO ext
  497. END IF
  498. UPDATE u_updatecost
  499. SET dscrp = dscrp+' '+:arg_newdescppart
  500. WHERE u_updatecost.wareid = :wareid
  501. USING commit_transaction;
  502. IF commit_transaction.SQLCode <> 0 THEN
  503. ROLLBACK USING commit_transaction;
  504. rslt = 0
  505. arg_msg = "因网络或其它原因导致添加单据备注操作失败"+"~n"+commit_transaction.SQLErrText
  506. GOTO ext
  507. END IF
  508. COMMIT USING commit_transaction;
  509. dscrp = dscrp+' '+arg_newdescppart
  510. ext:
  511. Return (rslt)
  512. end function
  513. public function integer p_getinfo (long arg_wareid, ref string arg_msg);//p_getinfo(arg_scid,arg_inwareid,arg_msg)
  514. //0 失败 1成功
  515. INT rslt=1
  516. IF arg_wareid<=0 THEN
  517. rslt=0
  518. arG_MSG="非法单据唯一码"
  519. goto ext
  520. end if
  521. SELECT u_updatecost.warecode,
  522. u_updatecost.storageid,
  523. u_updatecost.moddate,
  524. u_updatecost.modrep,
  525. u_updatecost.part,
  526. u_updatecost.dscrp,
  527. u_updatecost.modidate,
  528. u_updatecost.modiemp,
  529. u_updatecost.auditingdate,
  530. u_updatecost.auditingrep,
  531. u_updatecost.flag
  532. INTO :warecode,
  533. :storageid,
  534. :moddate,
  535. :modrep,
  536. :part,
  537. :dscrp,
  538. :modidate,
  539. :modiemp,
  540. :auditingdate,
  541. :auditingrep,
  542. :flag
  543. FROM u_updatecost
  544. WHERE u_updatecost.wareid = :arg_wareid
  545. using commit_transaction;
  546. if commit_transaction.sqlcode<>0 then
  547. rslt=0
  548. arG_MSG="查询操作失败(错误单据唯一码)"+commit_transaction.sqlerrtext
  549. goto ext
  550. end if
  551. wareid = arg_wareid
  552. ext:
  553. IF rslt=0 THEN p_reset()
  554. return rslt
  555. end function
  556. public function integer getinfo (long arg_wareid, ref string arg_msg);Int rslt = 1,i = 1,no_mxcheck = 0
  557. IF arg_wareid <= 0 THEN
  558. rslt = 0
  559. arg_msg = "非法单据唯一码"
  560. GOTO ext
  561. END IF
  562. rslt = p_getinfo(arg_wareid,arg_msg)
  563. IF rslt = 0 THEN GOTO ext
  564. //用游标读取明细
  565. DECLARE cur_waremx CURSOR FOR
  566. SELECT u_updatecostmx.printid,
  567. u_updatecostmx.mtrlwarescid,
  568. u_updatecostmx.mtrlwareid,
  569. u_updatecostmx.mtrlid,
  570. u_updatecostmx.plancode,
  571. u_updatecostmx.status,
  572. u_updatecostmx.noallocqty,
  573. u_updatecostmx.mxdscrp,
  574. u_mtrldef.mtrlcode,
  575. u_updatecostmx.woodcode,
  576. u_updatecostmx.pcode,
  577. u_updatecostmx.cost,
  578. u_updatecostmx.newcost,
  579. u_mtrldef.mtrlcode,
  580. u_mtrldef.unit,
  581. u_updatecostmx.unewcost,
  582. u_updatecostmx.unit,
  583. u_updatecostmx.rate,
  584. u_updatecostmx.mtrlcuscode,
  585. u_updatecostmx.location,
  586. u_updatecostmx.sptid
  587. FROM u_updatecostmx,u_mtrldef
  588. WHERE u_updatecostmx.wareid = :arg_wareid AND
  589. u_updatecostmx.mtrlid = u_mtrldef.mtrlid
  590. USING commit_transaction;
  591. OPEN cur_waremx;
  592. FETCH cur_waremx INTO :s_mx[i].printid,:s_mx[i].scid,
  593. :s_mx[i].mtrlwareid,:s_mx[i].mtrlid,
  594. :s_mx[i].plancode,:s_mx[i].status,:s_mx[i].qty,
  595. :s_mx[i].mxdscrp,:s_mx[i].mtrlcode,
  596. :s_mx[i].woodcode,:s_mx[i].pcode,:s_mx[i].cost,:s_mx[i].newcost,
  597. :s_mx[i].mtrlcode,:s_mx[i].unit,:s_mx[i].unewcost,:s_mx[i].uunit,
  598. :s_mx[i].rate,:s_mx[i].mtrlcuscode,:s_mx[i].location,:s_mx[i].sptid;
  599. DO WHILE commit_transaction.SQLCode = 0
  600. i++
  601. FETCH cur_waremx INTO :s_mx[i].printid,:s_mx[i].scid,
  602. :s_mx[i].mtrlwareid,:s_mx[i].mtrlid,
  603. :s_mx[i].plancode,:s_mx[i].status,:s_mx[i].qty,
  604. :s_mx[i].mxdscrp,:s_mx[i].mtrlcode,
  605. :s_mx[i].woodcode,:s_mx[i].pcode,:s_mx[i].cost,:s_mx[i].newcost,
  606. :s_mx[i].mtrlcode,:s_mx[i].unit,:s_mx[i].unewcost,:s_mx[i].uunit,
  607. :s_mx[i].rate,:s_mx[i].mtrlcuscode,:s_mx[i].location,:s_mx[i].sptid;
  608. LOOP
  609. CLOSE cur_waremx;
  610. //检验明细是否读入完整
  611. SELECT count(*) INTO :no_mxcheck
  612. FROM u_updatecostmx
  613. WHERE u_updatecostmx.wareid = :arg_wareid
  614. USING commit_transaction;
  615. IF commit_transaction.SQLCode <> 0 THEN
  616. rslt = 0
  617. arg_msg = "查询操作失败,单据明细数量"
  618. GOTO ext
  619. END IF
  620. IF i <> (no_mxcheck+1) THEN
  621. rslt = 0
  622. arg_msg = "查询操作失败,单据明细"
  623. GOTO ext
  624. END IF
  625. wareid = arg_wareid
  626. it_mxbt = i - 1
  627. it_newbegin = FALSE
  628. it_updatebegin = FALSE
  629. ext:
  630. IF rslt = 0 THEN p_reset()
  631. RETURN rslt
  632. end function
  633. public function integer del (long arg_wareid, ref string arg_msg, boolean arg_ifcommit);//del(arg_scid,arg_inwareid,arg_msg)
  634. //如果单据还没有审核删除单据极其明细
  635. //0 fail, 1 success
  636. Int rslt = 1
  637. IF arg_wareid = 0 THEN
  638. rslt = 0
  639. arg_msg = "没有删除对象,操作取消"
  640. GOTO ext
  641. END IF
  642. rslt = p_getinfo(arg_wareid,arg_msg)
  643. IF rslt = 0 THEN GOTO ext
  644. IF flag = 1 THEN
  645. rslt = 0
  646. arg_msg = "单据已经审核,不可以删除"
  647. GOTO ext
  648. END IF
  649. DELETE FROM u_updatecostmx
  650. WHERE u_updatecostmx.wareid = :arg_wareid
  651. USING commit_transaction;
  652. IF commit_transaction.SQLCode <> 0 THEN
  653. rslt = 0
  654. arg_msg = "删除库存成本价调整单明细操作失败"+"~n"+commit_transaction.SQLErrText
  655. GOTO ext
  656. END IF
  657. DELETE FROM u_updatecost
  658. WHERE u_updatecost.wareid = :arg_wareid
  659. USING commit_transaction;
  660. IF commit_transaction.SQLCode <> 0 THEN
  661. rslt = 0
  662. arg_msg = "删除库存成本价调整单操作失败"+"~n"+commit_transaction.SQLErrText
  663. GOTO ext
  664. END IF
  665. it_newbegin = FALSE
  666. it_updatebegin = FALSE
  667. ext:
  668. IF rslt = 0 THEN
  669. ROLLBACK USING commit_transaction;
  670. ELSEIF rslt = 1 AND arg_ifcommit THEN
  671. COMMIT USING commit_transaction;
  672. END IF
  673. p_reset()
  674. RETURN rslt
  675. end function
  676. public function integer updatebegin (long arg_wareid, ref string arg_msg);Long rslt = 1
  677. IF arg_wareid <= 0 THEN
  678. rslt = 0
  679. GOTO ext
  680. END IF
  681. rslt = p_getinfo(arg_wareid,arg_msg)
  682. IF rslt = 0 THEN GOTO ext
  683. IF flag = 1 THEN
  684. rslt = 0
  685. arg_msg = '单据已经审核,不可以修改'
  686. GOTO ext
  687. END IF
  688. wareid = arg_wareid
  689. it_newbegin = FALSE
  690. it_updatebegin = TRUE
  691. p_clearmx() //清除明细
  692. ext:
  693. IF rslt = 0 THEN p_reset()
  694. RETURN rslt
  695. end function
  696. public function integer newbegin ();int rslt=1
  697. p_reset()
  698. it_newbegin=true
  699. it_updatebegin=false
  700. return rslt
  701. end function
  702. public function integer acceptmx (long arg_printid, long arg_mtrlwarescid, long arg_mtrlwareid, string arg_mtrlcode, string arg_mxdscrp, ref string arg_msg, decimal arg_newcost, string arg_unit, decimal arg_rate);Long rslt = 1,cnt = 0
  703. Long i_mtrlid,i_storageid,i_sptid,i_dxflag
  704. String i_plancode,i_status,i_woodcode,i_pcode,i_mtrlcuscode,i_location
  705. Dec i_cost,i_noallocqty
  706. string i_unit
  707. IF it_newbegin = FALSE AND it_updatebegin = FALSE THEN
  708. rslt = 0
  709. arg_msg = "非编辑状态不可以使用,操作取消"
  710. GOTO ext
  711. END IF
  712. IF arg_mtrlwareid <= 0 THEN
  713. rslt = 0
  714. GOTO ext
  715. END IF
  716. //清除空值
  717. IF IsNull(arg_printid) THEN arg_printid = 0
  718. IF IsNull(arg_mtrlcode) THEN arg_mtrlcode = ''
  719. IF IsNull(arg_mxdscrp) THEN arg_mxdscrp = ''
  720. IF IsNull(arg_newcost) THEN arg_newcost = 0
  721. if isnull(arg_rate) then arg_rate = 1
  722. if isnull(arg_unit) then arg_unit = ''
  723. IF arg_rate = 0 THEN arg_rate = 1
  724. //检查物料库存ID
  725. SELECT u_mtrlware.mtrlid,
  726. u_mtrlware.storageid,
  727. u_mtrlware.plancode,
  728. u_mtrlware.status,
  729. u_mtrlware.cost,
  730. u_mtrlware.woodcode,
  731. u_mtrlware.pcode,
  732. u_mtrlware.noallocqty,
  733. u_mtrlware.dxflag,
  734. u_mtrlware.sptid,
  735. u_mtrlware.mtrlcuscode,
  736. u_mtrlware.location,
  737. u_mtrldef.unit
  738. INTO :i_mtrlid,
  739. :i_storageid,
  740. :i_plancode,
  741. :i_status,
  742. :i_cost,
  743. :i_woodcode,
  744. :i_pcode,
  745. :i_noallocqty,
  746. :i_dxflag,
  747. :i_sptid,
  748. :i_mtrlcuscode,
  749. :i_location,
  750. :i_unit
  751. FROM u_mtrlware,u_mtrldef
  752. WHERE ( u_mtrlware.mtrlwareid = :arg_mtrlwareid )
  753. AND ( u_mtrlware.scid = :arg_mtrlwarescid )
  754. AND ( u_mtrlware.mtrlid = u_mtrldef.mtrlid )
  755. USING commit_transaction;
  756. IF commit_transaction.SQLCode <> 0 THEN
  757. rslt = 0
  758. arg_msg = "查询物料:"+arg_mtrlcode+"库存资料失败,"+commit_transaction.sqlerrtext
  759. GOTO ext
  760. END IF
  761. IF i_storageid <> storageid THEN
  762. arg_msg = '仓库资料与明细资料不相符'
  763. rslt = 0
  764. GOTO ext
  765. END IF
  766. it_mxbt++
  767. s_mx[it_mxbt].scid = arg_mtrlwarescid
  768. s_mx[it_mxbt].mtrlwareid = arg_mtrlwareid
  769. s_mx[it_mxbt].printid = arg_printid
  770. s_mx[it_mxbt].mtrlid = i_mtrlid
  771. s_mx[it_mxbt].mtrlcode = arg_mtrlcode
  772. s_mx[it_mxbt].plancode = i_plancode
  773. s_mx[it_mxbt].status = i_status
  774. s_mx[it_mxbt].qty = i_noallocqty
  775. s_mx[it_mxbt].mxdscrp = arg_mxdscrp
  776. s_mx[it_mxbt].woodcode = i_woodcode
  777. s_mx[it_mxbt].pcode = i_pcode
  778. s_mx[it_mxbt].cost = i_cost
  779. s_mx[it_mxbt].dxflag = i_dxflag
  780. s_mx[it_mxbt].sptid = i_sptid
  781. s_mx[it_mxbt].unit = i_unit
  782. s_mx[it_mxbt].newcost = arg_newcost / arg_rate
  783. s_mx[it_mxbt].unewcost = arg_newcost
  784. s_mx[it_mxbt].uunit = arg_unit
  785. s_mx[it_mxbt].rate = arg_rate
  786. s_mx[it_mxbt].mtrlcuscode = i_mtrlcuscode
  787. s_mx[it_mxbt].location = i_location
  788. ext:
  789. IF rslt = 0 THEN p_clearmx()
  790. Return(rslt)
  791. end function
  792. on uo_update_cost.create
  793. call super::create
  794. TriggerEvent( this, "constructor" )
  795. end on
  796. on uo_update_cost.destroy
  797. TriggerEvent( this, "destructor" )
  798. call super::destroy
  799. end on
  800. event constructor;//uo_unit_change = create uo_unit
  801. end event
  802. event destructor;//destroy uo_unit_change
  803. end event