uo_mtrlware_pzcode_trans.sru 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156
  1. $PBExportHeader$uo_mtrlware_pzcode_trans.sru
  2. forward
  3. global type uo_mtrlware_pzcode_trans from nonvisualobject
  4. end type
  5. end forward
  6. global type uo_mtrlware_pzcode_trans from nonvisualobject
  7. end type
  8. global uo_mtrlware_pzcode_trans uo_mtrlware_pzcode_trans
  9. type variables
  10. Long uo_billid
  11. end variables
  12. forward prototypes
  13. public function integer updatebegin (long arg_billid, ref string arg_msg)
  14. public function integer caudit (long arg_billid, ref string arg_msg, boolean arg_ifcommit)
  15. public function integer audit (long arg_billid, string arg_opemp, ref string arg_msg, boolean arg_ifcommit)
  16. public function integer add_dscrp (long arg_billid, string arg_newdescppart, ref string arg_msg)
  17. public function integer del (long arg_billid, integer arg_chk_auto, ref string arg_msg, boolean arg_ifcommit)
  18. public function integer p_getinfo (long arg_billid, ref s_mtrlware_pzcode_trans arg_s_trans, ref string arg_msg)
  19. public function integer save (s_mtrlware_pzcode_trans arg_s_trans, string arg_opemp, ref string arg_msg, boolean arg_ifcommit)
  20. public function integer getinfo (long arg_billid, ref s_mtrlware_pzcode_trans arg_ref_s_trans, ref long arg_arr_cnt, ref string arg_msg)
  21. public function integer uof_update_waredate (long arg_billid, boolean arg_ifcommit, ref string arg_msg)
  22. end prototypes
  23. public function integer updatebegin (long arg_billid, ref string arg_msg);Int rslt = 1
  24. s_mtrlware_pzcode_trans arg_s_trans
  25. IF arg_billid <= 0 THEN
  26. rslt = 0
  27. ARG_MSG = '错误单据唯一码'
  28. GOTO ext
  29. END IF
  30. IF p_getinfo(arg_billid,arg_s_trans,ARG_MSG) = 0 THEN
  31. rslt = 0
  32. GOTO ext
  33. END IF
  34. IF arg_s_trans.flag = 1 THEN
  35. rslt = 0
  36. ARG_MSG = '单据已经审核,不可以修改,要修改请先撤销审核'
  37. GOTO ext
  38. END IF
  39. ext:
  40. RETURN rslt
  41. end function
  42. public function integer caudit (long arg_billid, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  43. DateTime null_dt
  44. long ll_arr_cnt
  45. SetNull(null_dt)
  46. Long ll_inware_out,ll_inware_in
  47. IF arg_billid <= 0 THEN
  48. rslt = 0
  49. arg_msg = '错误单据唯一码'
  50. GOTO ext
  51. END IF
  52. s_mtrlware_pzcode_trans arg_s_trans
  53. IF getinfo(arg_billid,arg_s_trans,ll_arr_cnt,arg_msg) = 0 THEN
  54. rslt = 0
  55. GOTO ext
  56. END IF
  57. IF arg_s_trans.flag = 0 THEN
  58. rslt = 0
  59. arg_msg = '单据未审核,不可以撤审'
  60. GOTO ext
  61. END IF
  62. UPDATE u_mtrlware_pzcode_trans
  63. SET flag = 0,
  64. auditemp = '',
  65. auditdate = :null_dt
  66. WHERE billid = :arg_billid
  67. AND flag = 1;
  68. IF sqlca.SQLCode <> 0 THEN
  69. rslt = 0
  70. arg_msg = "单据撤消审核操作失败"+"~n"+sqlca.SQLErrText
  71. GOTO ext
  72. END IF
  73. uo_inware uo_in
  74. uo_in = CREATE uo_inware
  75. uo_in.commit_transaction = sqlca
  76. uo_in.if_getid_ture = FALSE
  77. //撤审删除相关进仓单(正)
  78. SELECT inwareid INTO :ll_inware_in
  79. FROM u_inware
  80. WHERE scid = :arg_s_trans.scid
  81. AND relid = :arg_billid
  82. AND billtype = 22
  83. AND relint_2 = 1;
  84. IF sqlca.SQLCode <> 0 THEN
  85. arg_msg = '查询相关进仓单(正)失败'+sqlca.SQLErrText
  86. rslt = 0
  87. GOTO ext
  88. END IF
  89. IF uo_in.getinfo(arg_s_trans.scid,ll_inware_in,arg_msg) = 0 THEN
  90. rslt = 0
  91. GOTO ext
  92. END IF
  93. IF uo_in.c_auditing(FALSE,arg_msg) = 0 THEN
  94. rslt = 0
  95. GOTO ext
  96. END IF
  97. IF uo_in.del(arg_s_trans.scid,ll_inware_in,arg_msg,FALSE) = 0 THEN
  98. rslt = 0
  99. GOTO ext
  100. END IF
  101. //撤审删除相关进仓单(负)
  102. SELECT inwareid INTO :ll_inware_out
  103. FROM u_inware
  104. WHERE scid = :arg_s_trans.scid
  105. AND relid = :arg_billid
  106. AND billtype = 22
  107. AND relint_2 = 0;
  108. IF sqlca.SQLCode <> 0 THEN
  109. arg_msg = '查询相关进仓单(负)失败'+sqlca.SQLErrText
  110. rslt = 0
  111. GOTO ext
  112. END IF
  113. IF uo_in.getinfo(arg_s_trans.scid,ll_inware_out,arg_msg) = 0 THEN
  114. rslt = 0
  115. GOTO ext
  116. END IF
  117. IF uo_in.c_auditing(FALSE,arg_msg) = 0 THEN
  118. rslt = 0
  119. GOTO ext
  120. END IF
  121. IF uo_in.del(arg_s_trans.scid,ll_inware_out,arg_msg,FALSE) = 0 THEN
  122. rslt = 0
  123. GOTO ext
  124. END IF
  125. ext:
  126. IF rslt = 0 THEN
  127. ROLLBACK;
  128. ELSEIF rslt = 1 AND arg_ifcommit THEN
  129. COMMIT;
  130. END IF
  131. DESTROY uo_in
  132. RETURN rslt
  133. end function
  134. public function integer audit (long arg_billid, string arg_opemp, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  135. Long ll_arr_cnt
  136. String ls_uunit
  137. Decimal ld_rate,ld_uqty,ld_uprice
  138. Long ll_i
  139. Long ll_inwareid_out,ll_inwareid_in
  140. IF arg_billid <= 0 THEN
  141. rslt = 0
  142. arg_msg = '错误单据唯一码'
  143. GOTO ext
  144. END IF
  145. s_mtrlware_pzcode_trans arg_s_trans
  146. IF getinfo(arg_billid,arg_s_trans,ll_arr_cnt,arg_msg) = 0 THEN
  147. rslt = 0
  148. GOTO ext
  149. END IF
  150. IF arg_s_trans.flag = 1 THEN
  151. rslt = 0
  152. arg_msg = '单据已经审核,不可以再审'
  153. GOTO ext
  154. END IF
  155. //更新审核标记
  156. UPDATE u_mtrlware_pzcode_trans
  157. SET auditemp = :arg_opemp,
  158. auditdate = getdate(),
  159. flag = 1
  160. WHERE billid = :arg_billid
  161. AND flag = 0;
  162. IF sqlca.SQLCode <> 0 THEN
  163. rslt = 0
  164. arg_msg = "单据审核操作失败"+"~n"+sqlca.SQLErrText
  165. GOTO ext
  166. END IF
  167. uo_inware uo_in
  168. uo_in = CREATE uo_inware
  169. uo_in.commit_transaction = sqlca
  170. uo_in.if_getid_ture = FALSE
  171. s_inwaremx s_mx
  172. //这里现在有个bug, 当仓库部使用批号时,进到accepttext是会清空的, 找不到相应的库存id
  173. //负单
  174. IF uo_in.newbegin(arg_s_trans.scid,22,arg_msg) = 0 THEN
  175. rslt = 0
  176. GOTO ext
  177. END IF
  178. uo_in.relid = arg_s_trans.billid
  179. uo_in.indate = arg_s_trans.billdate
  180. uo_in.inrep = arg_s_trans.rep
  181. uo_in.part = arg_s_trans.billcode
  182. uo_in.dscrp = arg_s_trans.dscrp
  183. uo_in.relint_2 = 0 // 0 - 负 1 - 正
  184. uo_in.storageid = arg_s_trans.storageid
  185. uo_in.sptname = '库存配置调整单(负)'
  186. FOR ll_i = 1 TO ll_arr_cnt
  187. //转换
  188. ls_uunit = ''
  189. ld_rate = 0
  190. ld_uqty = 0
  191. ld_uprice = 0
  192. IF arg_s_trans.arg_s_mx[ll_i].ifunit = 0 THEN
  193. ls_uunit = arg_s_trans.arg_s_mx[ll_i].unit
  194. ld_rate = 1
  195. ld_uqty = arg_s_trans.arg_s_mx[ll_i].qty
  196. ld_uprice = arg_s_trans.arg_s_mx[ll_i].cost
  197. ELSE
  198. IF arg_s_trans.arg_s_mx[ll_i].rate = 0 THEN
  199. arg_msg = '调货产品资料设为双数量核算,但没有设置默认转换率,请检查'
  200. rslt = 0
  201. GOTO ext
  202. END IF
  203. ls_uunit = arg_s_trans.arg_s_mx[ll_i].uunit
  204. ld_rate = arg_s_trans.arg_s_mx[ll_i].rate
  205. ld_uqty = arg_s_trans.arg_s_mx[ll_i].qty / arg_s_trans.arg_s_mx[ll_i].rate
  206. ld_uprice = arg_s_trans.arg_s_mx[ll_i].cost * arg_s_trans.arg_s_mx[ll_i].rate
  207. END IF
  208. s_mx.printid = ll_i
  209. s_mx.mtrlid = arg_s_trans.arg_s_mx[ll_i].mtrlid
  210. s_mx.mtrlcode = arg_s_trans.arg_s_mx[ll_i].mtrlcode
  211. s_mx.plancode = arg_s_trans.arg_s_mx[ll_i].plancode
  212. s_mx.status = arg_s_trans.arg_s_mx[ll_i].status
  213. s_mx.uqty = 0 - ld_uqty
  214. s_mx.addqty =0 - arg_s_trans.arg_s_mx[ll_i].addqty
  215. s_mx.uprice = ld_uprice
  216. s_mx.rebate = 1
  217. s_mx.mxdscrp = arg_s_trans.arg_s_mx[ll_i].mxdscrp
  218. s_mx.jgprice = 0
  219. s_mx.relid = 0
  220. s_mx.relprintid = 0
  221. s_mx.ifrel = 0
  222. s_mx.woodcode = arg_s_trans.arg_s_mx[ll_i].woodcode
  223. s_mx.pcode = arg_s_trans.arg_s_mx[ll_i].pcode
  224. s_mx.mtrlcuscode = ''
  225. s_mx.sptid = arg_s_trans.arg_s_mx[ll_i].sptid
  226. s_mx.unit = ls_uunit
  227. s_mx.rate = ld_rate
  228. s_mx.formula = ''
  229. s_mx.waredscrp = ''
  230. s_mx.inworkdate = arg_s_trans.billdate
  231. IF uo_in.acceptmx(s_mx,arg_msg) = 0 THEN
  232. rslt = 0
  233. GOTO ext
  234. END IF
  235. NEXT
  236. IF uo_in.Save(FALSE,arg_msg) = 0 THEN
  237. rslt = 0
  238. GOTO ext
  239. END IF
  240. ll_inwareid_out = uo_in.inwareid
  241. IF uo_in.getinfo(arg_s_trans.scid,ll_inwareid_out,arg_msg) = 0 THEN
  242. rslt = 0
  243. GOTO ext
  244. END IF
  245. IF uo_in.auditing(FALSE,arg_msg) = 0 THEN
  246. rslt = 0
  247. GOTO ext
  248. END IF
  249. //正
  250. IF uo_in.newbegin(arg_s_trans.scid,22,arg_msg) = 0 THEN
  251. rslt = 0
  252. GOTO ext
  253. END IF
  254. uo_in.relid = arg_s_trans.billid
  255. uo_in.indate = arg_s_trans.billdate
  256. uo_in.inrep = arg_s_trans.rep
  257. uo_in.part = arg_s_trans.billcode
  258. uo_in.dscrp = arg_s_trans.dscrp
  259. uo_in.relint_2 = 1 // 0 - 负 1 - 正
  260. uo_in.storageid = arg_s_trans.storageid
  261. uo_in.sptname = '库存配置调整单(正)'
  262. FOR ll_i = 1 TO ll_arr_cnt
  263. //转换
  264. ls_uunit = ''
  265. ld_rate = 0
  266. ld_uqty = 0
  267. ld_uprice = 0
  268. IF arg_s_trans.arg_s_mx[ll_i].ifunit = 0 THEN
  269. ls_uunit = arg_s_trans.arg_s_mx[ll_i].unit
  270. ld_rate = 1
  271. ld_uqty = arg_s_trans.arg_s_mx[ll_i].qty
  272. ld_uprice = arg_s_trans.arg_s_mx[ll_i].cost
  273. ELSE
  274. IF arg_s_trans.arg_s_mx[ll_i].rate = 0 THEN
  275. arg_msg = '调货产品资料设为双数量核算,但没有设置默认转换率,请检查'
  276. rslt = 0
  277. GOTO ext
  278. END IF
  279. ls_uunit = arg_s_trans.arg_s_mx[ll_i].uunit
  280. ld_rate = arg_s_trans.arg_s_mx[ll_i].rate
  281. ld_uqty = arg_s_trans.arg_s_mx[ll_i].qty / arg_s_trans.arg_s_mx[ll_i].rate
  282. ld_uprice = arg_s_trans.arg_s_mx[ll_i].cost * arg_s_trans.arg_s_mx[ll_i].rate
  283. END IF
  284. s_mx.printid = ll_i
  285. s_mx.mtrlid = arg_s_trans.arg_s_mx[ll_i].mtrlid
  286. s_mx.mtrlcode = arg_s_trans.arg_s_mx[ll_i].mtrlcode
  287. s_mx.plancode = arg_s_trans.arg_s_mx[ll_i].plancode_new
  288. s_mx.status = arg_s_trans.arg_s_mx[ll_i].status_new
  289. s_mx.uqty = ld_uqty
  290. s_mx.addqty = arg_s_trans.arg_s_mx[ll_i].addqty
  291. s_mx.uprice = ld_uprice
  292. s_mx.rebate = 1
  293. s_mx.mxdscrp = arg_s_trans.arg_s_mx[ll_i].mxdscrp
  294. s_mx.jgprice = 0
  295. s_mx.relid = 0
  296. s_mx.relprintid = 0
  297. s_mx.ifrel = 0
  298. s_mx.woodcode = arg_s_trans.arg_s_mx[ll_i].woodcode_new
  299. s_mx.pcode = arg_s_trans.arg_s_mx[ll_i].pcode_new
  300. s_mx.mtrlcuscode = ''
  301. s_mx.sptid = arg_s_trans.arg_s_mx[ll_i].sptid_new
  302. s_mx.unit = ls_uunit
  303. s_mx.rate = ld_rate
  304. s_mx.formula = ''
  305. s_mx.waredscrp = ''
  306. s_mx.inworkdate = arg_s_trans.billdate
  307. IF uo_in.acceptmx(s_mx,arg_msg) = 0 THEN
  308. rslt = 0
  309. GOTO ext
  310. END IF
  311. NEXT
  312. IF uo_in.Save(FALSE,arg_msg) = 0 THEN
  313. rslt = 0
  314. GOTO ext
  315. END IF
  316. ll_inwareid_in = uo_in.inwareid
  317. IF uo_in.getinfo(arg_s_trans.scid,ll_inwareid_in,arg_msg) = 0 THEN
  318. rslt = 0
  319. GOTO ext
  320. END IF
  321. IF uo_in.auditing(FALSE,arg_msg) = 0 THEN
  322. rslt = 0
  323. GOTO ext
  324. END IF
  325. //====================================================================
  326. // 修改: 负进仓已经修改了最近进仓时间,所以正进仓的最近进仓时间肯定是当时
  327. //--------------------------------------------------------------------
  328. // 作者: lwl 日期: 2015年05月30日
  329. //====================================================================
  330. //IF uof_update_waredate(arg_billid,FALSE,arg_msg) = 0 THEN
  331. // rslt = 0
  332. // GOTO ext
  333. //END IF
  334. ext:
  335. IF rslt = 0 THEN
  336. ROLLBACK;
  337. ELSEIF rslt = 1 AND arg_ifcommit THEN
  338. COMMIT;
  339. END IF
  340. DESTROY uo_in
  341. RETURN rslt
  342. end function
  343. public function integer add_dscrp (long arg_billid, string arg_newdescppart, ref string arg_msg);Int rslt = 1
  344. s_mtrlware_pzcode_trans arg_s_trans
  345. IF arg_billid <= 0 THEN
  346. rslt = 0
  347. arg_msg = '错误单据唯一码'
  348. GOTO ext
  349. END IF
  350. IF arg_newdescppart = '' THEN
  351. rslt = 0
  352. arg_msg = "要添加内容为空,操作取消"
  353. GOTO ext
  354. END IF
  355. IF p_getinfo(arg_billid,arg_s_trans,arg_msg) = 0 THEN
  356. rslt = 0
  357. GOTO ext
  358. END IF
  359. IF arg_s_trans.flag = 0 THEN
  360. rslt = 0
  361. arg_msg = '单据未审核,不可以增加备注'
  362. GOTO ext
  363. END IF
  364. UPDATE u_mtrlware_pzcode_trans
  365. SET DSCRP = DSCRP+' '+:arg_newdescppart
  366. WHERE billid = :arg_billid
  367. AND flag = 1;
  368. IF SQLCA.SQLCode <> 0 THEN
  369. rslt = 0
  370. arg_msg = "添加备注操作失败"+"~n"+SQLCA.SQLErrText
  371. GOTO ext
  372. END IF
  373. ext:
  374. IF rslt = 1 THEN
  375. COMMIT;
  376. ELSE
  377. ROLLBACK;
  378. END IF
  379. Return (rslt)
  380. end function
  381. public function integer del (long arg_billid, integer arg_chk_auto, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
  382. s_mtrlware_pzcode_trans arg_s_trans
  383. IF arg_billid <= 0 THEN
  384. rslt = 0
  385. ARG_MSG = '错误单据唯一码'
  386. GOTO ext
  387. END IF
  388. IF p_getinfo(arg_billid,arg_s_trans,ARG_MSG) = 0 THEN
  389. rslt = 0
  390. GOTO ext
  391. END IF
  392. IF arg_s_trans.flag = 1 THEN
  393. rslt = 0
  394. ARG_MSG = '单据已经审核,不可以删除'
  395. GOTO ext
  396. END IF
  397. DELETE FROM u_mtrlware_pzcode_trans Where billid = :arg_billid;
  398. IF sqlca.SQLCode <> 0 THEN
  399. rslt = 0
  400. ARG_MSG = "删除单据操作失败"+"~n"+sqlca.SQLErrText
  401. GOTO ext
  402. END IF
  403. DELETE FROM u_mtrlware_pzcode_transmx Where billid = :arg_billid ;
  404. IF sqlca.SQLCode <> 0 THEN
  405. rslt = 0
  406. ARG_MSG = "删除单据明细操作失败"+"~n"+sqlca.SQLErrText
  407. GOTO ext
  408. END IF
  409. ext:
  410. IF rslt = 0 THEN
  411. ROLLBACK;
  412. ELSEIF rslt = 1 AND arg_ifcommit THEN
  413. COMMIT;
  414. END IF
  415. RETURN rslt
  416. end function
  417. public function integer p_getinfo (long arg_billid, ref s_mtrlware_pzcode_trans arg_s_trans, ref string arg_msg);Int rslt = 1
  418. IF arg_billid <= 0 THEN
  419. rslt = 0
  420. ARG_MSG = '错误单据唯一码'
  421. GOTO ext
  422. END IF
  423. SELECT
  424. billid,
  425. billcode,
  426. scid,
  427. billdate,
  428. rep,
  429. storageid,
  430. dscrp,
  431. relcode,
  432. flag
  433. INTO
  434. :arg_s_trans.billid,
  435. :arg_s_trans.billcode,
  436. :arg_s_trans.scid,
  437. :arg_s_trans.billdate,
  438. :arg_s_trans.rep,
  439. :arg_s_trans.storageid,
  440. :arg_s_trans.dscrp,
  441. :arg_s_trans.relcode,
  442. :arg_s_trans.flag
  443. FROM u_mtrlware_pzcode_trans
  444. Where billid = :arg_billid;
  445. IF sqlca.SQLCode <> 0 THEN
  446. rslt = 0
  447. ARG_MSG = '查询库存配置调整单内容失败(错误单据唯一码)'
  448. GOTO ext
  449. END IF
  450. ext:
  451. RETURN rslt
  452. end function
  453. public function integer save (s_mtrlware_pzcode_trans arg_s_trans, string arg_opemp, ref string arg_msg, boolean arg_ifcommit);Integer rslt = 1
  454. Long cnt = 0
  455. DateTime server_dt
  456. Long ll_billid,it_mxbt,ll_i,i
  457. String ls_unit
  458. String ls_sccode,ls_billcode,ls_reltaskcode
  459. IF IsNull(arg_s_trans.scid) THEN arg_s_trans.scid = 0
  460. IF IsNull(arg_s_trans.billid) THEN arg_s_trans.billid = 0
  461. IF IsNull(arg_s_trans.rep) THEN arg_s_trans.rep = ''
  462. IF IsNull(arg_s_trans.relcode) THEN arg_s_trans.relcode = ''
  463. IF IsNull(arg_s_trans.dscrp) THEN arg_s_trans.dscrp = ''
  464. IF IsNull(arg_s_trans.storageid) THEN arg_s_trans.storageid = 0
  465. IF IsNull(arg_s_trans.relcode) THEN arg_s_trans.relcode = ''
  466. IF arg_s_trans.rep = '' THEN
  467. rslt = 0
  468. arg_msg = "请输入经手人"
  469. GOTO ext
  470. END IF
  471. cnt = 0
  472. SELECT count(*) INTO :cnt
  473. FROM u_storage
  474. Where storageid = :arg_s_trans.storageid ;
  475. IF sqlca.SQLCode <> 0 THEN
  476. rslt = 0
  477. arg_msg = "查询操作失败,仓库资料"
  478. GOTO ext
  479. END IF
  480. IF cnt = 0 THEN
  481. rslt = 0
  482. arg_msg = "仓库未定义或错误"
  483. GOTO ext
  484. END IF
  485. SELECT Top 1 getdate() Into :server_dt From u_user;
  486. IF sqlca.SQLCode <> 0 THEN
  487. rslt = 0
  488. arg_msg = "查询操作失败,日期 "
  489. GOTO ext
  490. END IF
  491. it_mxbt = UpperBound(arg_s_trans.arg_s_mx)
  492. IF it_mxbt <= 0 THEN
  493. rslt = 0
  494. arg_msg = "没有正确明细内容"
  495. GOTO ext
  496. END IF
  497. Int li_if_cus_mtrlware, li_if_plancode, li_inwaretype
  498. SELECT balctype , if_plancode, inwaretype
  499. INTO :li_if_cus_mtrlware, :li_if_plancode, :li_inwaretype
  500. FROM u_storage
  501. Where storageid = :arg_s_trans.storageid;
  502. IF sqlca.SQLCode <> 0 THEN
  503. arg_msg = "查询仓库是否使用客户库存失败"
  504. rslt = 0
  505. GOTO ext
  506. END IF
  507. FOR i = 1 To it_mxbt
  508. IF li_if_plancode = 0 THEN
  509. arg_s_trans.arg_s_mx[i].plancode_new = ''
  510. END IF
  511. IF li_if_cus_mtrlware <> 1 THEN
  512. arg_s_trans.arg_s_mx[i].sptid_new = 0
  513. END IF
  514. NEXT
  515. IF arg_s_trans.billid = 0 THEN
  516. ll_billid = f_sys_scidentity(0,"u_mtrlware_pzcode_trans","billid",arg_msg,True,id_sqlca)
  517. IF ll_billid <= 0 THEN
  518. rslt = 0
  519. GOTO ext
  520. END IF
  521. IF f_get_sccode(arg_s_trans.scid,sqlca,ls_sccode,arg_msg) = 0 THEN
  522. rslt = 0
  523. GOTO ext
  524. END IF
  525. ls_billcode = getid(arg_s_trans.scid,ls_sccode + 'MP',Date(server_dt),False,sqlca)
  526. IF ls_billcode = "err" THEN
  527. rslt = 0
  528. arg_msg = "无法获取单据编号"+"~n"+sqlca.SQLErrText
  529. GOTO ext
  530. END IF
  531. INSERT INTO u_mtrlware_pzcode_trans
  532. (scid,
  533. billid,
  534. billcode,
  535. billdate,
  536. rep,
  537. storageid,
  538. relcode,
  539. dscrp,
  540. opemp,
  541. opdate)
  542. VALUES (
  543. :arg_s_trans.scid,
  544. :ll_billid,
  545. :ls_billcode,
  546. :arg_s_trans.billdate,
  547. :arg_s_trans.rep,
  548. :arg_s_trans.storageid,
  549. :arg_s_trans.relcode,
  550. :arg_s_trans.dscrp,
  551. :arg_opemp,
  552. getdate()) ;
  553. IF sqlca.SQLCode <> 0 THEN
  554. rslt = 0
  555. arg_msg = "建立单据操作失败"+"~n"+sqlca.SQLErrText
  556. GOTO ext
  557. END IF
  558. FOR i = 1 To it_mxbt
  559. INSERT INTO u_mtrlware_pzcode_transmx
  560. (billid,
  561. printid,
  562. scid,
  563. mtrlwareid,
  564. mtrlid,
  565. status,
  566. woodcode,
  567. pcode,
  568. plancode,
  569. mtrlcuscode,
  570. location,
  571. sptid,
  572. qty,
  573. cost,
  574. status_new,
  575. woodcode_new,
  576. pcode_new,
  577. plancode_new,
  578. mtrlcuscode_new,
  579. location_new,
  580. sptid_new,
  581. mxdscrp,
  582. addqty
  583. )
  584. VALUES (:ll_billid,
  585. :arg_s_trans.arg_s_mx[i].printid,
  586. :arg_s_trans.arg_s_mx[i].scid,
  587. :arg_s_trans.arg_s_mx[i].mtrlwareid,
  588. :arg_s_trans.arg_s_mx[i].mtrlid,
  589. :arg_s_trans.arg_s_mx[i].status,
  590. :arg_s_trans.arg_s_mx[i].woodcode,
  591. :arg_s_trans.arg_s_mx[i].pcode,
  592. :arg_s_trans.arg_s_mx[i].plancode,
  593. :arg_s_trans.arg_s_mx[i].mtrlcuscode,
  594. :arg_s_trans.arg_s_mx[i].location,
  595. :arg_s_trans.arg_s_mx[i].sptid,
  596. :arg_s_trans.arg_s_mx[i].qty,
  597. :arg_s_trans.arg_s_mx[i].cost,
  598. :arg_s_trans.arg_s_mx[i].status_new,
  599. :arg_s_trans.arg_s_mx[i].woodcode_new,
  600. :arg_s_trans.arg_s_mx[i].pcode_new,
  601. :arg_s_trans.arg_s_mx[i].plancode_new,
  602. :arg_s_trans.arg_s_mx[i].mtrlcuscode_new,
  603. :arg_s_trans.arg_s_mx[i].location_new,
  604. :arg_s_trans.arg_s_mx[i].sptid_new,
  605. :arg_s_trans.arg_s_mx[i].mxdscrp,
  606. :arg_s_trans.arg_s_mx[i].addqty
  607. );
  608. IF sqlca.SQLCode <> 0 THEN
  609. rslt = 0
  610. arg_msg = "插入明细操作失败"+"~n"+sqlca.SQLErrText
  611. GOTO ext
  612. END IF
  613. NEXT
  614. uo_billid = ll_billid
  615. ELSE
  616. UPDATE u_mtrlware_pzcode_trans
  617. SET rep = :arg_s_trans.rep,
  618. billdate = :arg_s_trans.billdate,
  619. storageid = :arg_s_trans.storageid,
  620. moddate = getdate(),
  621. modemp = :arg_opemp,
  622. relcode = :arg_s_trans.relcode,
  623. dscrp = :arg_s_trans.dscrp
  624. WHERE billid = :arg_s_trans.billid
  625. And flag = 0;
  626. IF sqlca.SQLCode <> 0 Or sqlca.SQLNRows <= 0 THEN
  627. rslt = 0
  628. arg_msg = "更新单据操作失败"+"~n"+sqlca.SQLErrText
  629. GOTO ext
  630. END IF
  631. DELETE FROM u_mtrlware_pzcode_transmx
  632. Where billid = :arg_s_trans.billid;
  633. IF sqlca.SQLCode <> 0 THEN
  634. rslt = 0
  635. arg_msg = "删除旧有明细操作失败"+"~n"+sqlca.SQLErrText
  636. GOTO ext
  637. END IF
  638. FOR i = 1 To it_mxbt
  639. INSERT INTO u_mtrlware_pzcode_transmx
  640. (billid,
  641. printid,
  642. scid,
  643. mtrlwareid,
  644. mtrlid,
  645. status,
  646. woodcode,
  647. pcode,
  648. plancode,
  649. mtrlcuscode,
  650. location,
  651. sptid,
  652. qty,
  653. cost,
  654. status_new,
  655. woodcode_new,
  656. pcode_new,
  657. plancode_new,
  658. mtrlcuscode_new,
  659. location_new,
  660. sptid_new,
  661. mxdscrp,
  662. addqty)
  663. VALUES (:arg_s_trans.billid,
  664. :arg_s_trans.arg_s_mx[i].printid,
  665. :arg_s_trans.arg_s_mx[i].scid,
  666. :arg_s_trans.arg_s_mx[i].mtrlwareid,
  667. :arg_s_trans.arg_s_mx[i].mtrlid,
  668. :arg_s_trans.arg_s_mx[i].status,
  669. :arg_s_trans.arg_s_mx[i].woodcode,
  670. :arg_s_trans.arg_s_mx[i].pcode,
  671. :arg_s_trans.arg_s_mx[i].plancode,
  672. :arg_s_trans.arg_s_mx[i].mtrlcuscode,
  673. :arg_s_trans.arg_s_mx[i].location,
  674. :arg_s_trans.arg_s_mx[i].sptid,
  675. :arg_s_trans.arg_s_mx[i].qty,
  676. :arg_s_trans.arg_s_mx[i].cost,
  677. :arg_s_trans.arg_s_mx[i].status_new,
  678. :arg_s_trans.arg_s_mx[i].woodcode_new,
  679. :arg_s_trans.arg_s_mx[i].pcode_new,
  680. :arg_s_trans.arg_s_mx[i].plancode_new,
  681. :arg_s_trans.arg_s_mx[i].mtrlcuscode_new,
  682. :arg_s_trans.arg_s_mx[i].location_new,
  683. :arg_s_trans.arg_s_mx[i].sptid_new,
  684. :arg_s_trans.arg_s_mx[i].mxdscrp,
  685. :arg_s_trans.arg_s_mx[i].addqty
  686. );
  687. IF sqlca.SQLCode <> 0 THEN
  688. rslt = 0
  689. arg_msg = "插入明细操作失败"+"~n"+sqlca.SQLErrText
  690. GOTO ext
  691. END IF
  692. NEXT
  693. uo_billid = arg_s_trans.billid
  694. END IF
  695. ext:
  696. IF rslt = 0 THEN
  697. ROLLBACK;
  698. ELSEIF arg_ifcommit And rslt = 1 THEN
  699. COMMIT;
  700. END IF
  701. RETURN rslt
  702. end function
  703. public function integer getinfo (long arg_billid, ref s_mtrlware_pzcode_trans arg_ref_s_trans, ref long arg_arr_cnt, ref string arg_msg);Int rslt = 1
  704. Long i = 1,no_mxcheck = 0
  705. IF arg_billid <= 0 THEN
  706. rslt = 0
  707. arg_msg = '错误单据唯一码'
  708. GOTO ext
  709. END IF
  710. IF p_getinfo(arg_billid,arg_ref_s_trans,arg_msg) = 0 THEN
  711. rslt = 0
  712. GOTO ext
  713. END IF
  714. //用游标读取明细
  715. DECLARE cur_mx CURSOR FOR
  716. SELECT u_mtrlware_pzcode_transmx.billid,
  717. u_mtrlware_pzcode_transmx.printid,
  718. u_mtrlware_pzcode_transmx.scid,
  719. u_mtrlware_pzcode_transmx.mtrlwareid,
  720. u_mtrlware_pzcode_transmx.mtrlid,
  721. u_mtrlware_pzcode_transmx.status,
  722. u_mtrlware_pzcode_transmx.woodcode,
  723. u_mtrlware_pzcode_transmx.pcode,
  724. u_mtrlware_pzcode_transmx.plancode,
  725. u_mtrlware_pzcode_transmx.mtrlcuscode,
  726. u_mtrlware_pzcode_transmx.location,
  727. u_mtrlware_pzcode_transmx.sptid,
  728. u_mtrlware_pzcode_transmx.qty,
  729. u_mtrlware_pzcode_transmx.addqty,
  730. u_mtrlware_pzcode_transmx.cost,
  731. u_mtrlware_pzcode_transmx.status_new,
  732. u_mtrlware_pzcode_transmx.woodcode_new,
  733. u_mtrlware_pzcode_transmx.pcode_new,
  734. u_mtrlware_pzcode_transmx.plancode_new,
  735. u_mtrlware_pzcode_transmx.mtrlcuscode_new,
  736. u_mtrlware_pzcode_transmx.location_new,
  737. u_mtrlware_pzcode_transmx.sptid_new,
  738. u_mtrlware_pzcode_transmx.mxdscrp,
  739. u_mtrldef.unit,
  740. u_mtrldef.ifunit,
  741. u_mtrldef.unit_buy,
  742. u_mtrldef.rate_buy
  743. FROM u_mtrlware_pzcode_transmx INNER JOIN
  744. u_mtrldef ON u_mtrlware_pzcode_transmx.mtrlid = u_mtrldef.mtrlid
  745. WHERE billid = :arg_billid
  746. Order By printid;
  747. OPEN cur_mx;
  748. FETCH cur_mx
  749. INTO
  750. :arg_ref_s_trans.arg_s_mx[i].billid,
  751. :arg_ref_s_trans.arg_s_mx[i].printid,
  752. :arg_ref_s_trans.arg_s_mx[i].scid,
  753. :arg_ref_s_trans.arg_s_mx[i].mtrlwareid,
  754. :arg_ref_s_trans.arg_s_mx[i].mtrlid,
  755. :arg_ref_s_trans.arg_s_mx[i].status,
  756. :arg_ref_s_trans.arg_s_mx[i].woodcode,
  757. :arg_ref_s_trans.arg_s_mx[i].pcode,
  758. :arg_ref_s_trans.arg_s_mx[i].plancode,
  759. :arg_ref_s_trans.arg_s_mx[i].mtrlcuscode,
  760. :arg_ref_s_trans.arg_s_mx[i].location,
  761. :arg_ref_s_trans.arg_s_mx[i].sptid,
  762. :arg_ref_s_trans.arg_s_mx[i].qty,
  763. :arg_ref_s_trans.arg_s_mx[i].addqty,
  764. :arg_ref_s_trans.arg_s_mx[i].cost,
  765. :arg_ref_s_trans.arg_s_mx[i].status_new,
  766. :arg_ref_s_trans.arg_s_mx[i].woodcode_new,
  767. :arg_ref_s_trans.arg_s_mx[i].pcode_new,
  768. :arg_ref_s_trans.arg_s_mx[i].plancode_new,
  769. :arg_ref_s_trans.arg_s_mx[i].mtrlcuscode_new,
  770. :arg_ref_s_trans.arg_s_mx[i].location_new,
  771. :arg_ref_s_trans.arg_s_mx[i].sptid_new,
  772. :arg_ref_s_trans.arg_s_mx[i].mxdscrp,
  773. :arg_ref_s_trans.arg_s_mx[i].unit,
  774. :arg_ref_s_trans.arg_s_mx[i].ifunit,
  775. :arg_ref_s_trans.arg_s_mx[i].uunit,
  776. :arg_ref_s_trans.arg_s_mx[i].rate;
  777. DO WHILE sqlca.SQLCode = 0
  778. i++
  779. FETCH cur_mx
  780. INTO
  781. :arg_ref_s_trans.arg_s_mx[i].billid,
  782. :arg_ref_s_trans.arg_s_mx[i].printid,
  783. :arg_ref_s_trans.arg_s_mx[i].scid,
  784. :arg_ref_s_trans.arg_s_mx[i].mtrlwareid,
  785. :arg_ref_s_trans.arg_s_mx[i].mtrlid,
  786. :arg_ref_s_trans.arg_s_mx[i].status,
  787. :arg_ref_s_trans.arg_s_mx[i].woodcode,
  788. :arg_ref_s_trans.arg_s_mx[i].pcode,
  789. :arg_ref_s_trans.arg_s_mx[i].plancode,
  790. :arg_ref_s_trans.arg_s_mx[i].mtrlcuscode,
  791. :arg_ref_s_trans.arg_s_mx[i].location,
  792. :arg_ref_s_trans.arg_s_mx[i].sptid,
  793. :arg_ref_s_trans.arg_s_mx[i].qty,
  794. :arg_ref_s_trans.arg_s_mx[i].addqty,
  795. :arg_ref_s_trans.arg_s_mx[i].cost,
  796. :arg_ref_s_trans.arg_s_mx[i].status_new,
  797. :arg_ref_s_trans.arg_s_mx[i].woodcode_new,
  798. :arg_ref_s_trans.arg_s_mx[i].pcode_new,
  799. :arg_ref_s_trans.arg_s_mx[i].plancode_new,
  800. :arg_ref_s_trans.arg_s_mx[i].mtrlcuscode_new,
  801. :arg_ref_s_trans.arg_s_mx[i].location_new,
  802. :arg_ref_s_trans.arg_s_mx[i].sptid_new,
  803. :arg_ref_s_trans.arg_s_mx[i].mxdscrp,
  804. :arg_ref_s_trans.arg_s_mx[i].unit,
  805. :arg_ref_s_trans.arg_s_mx[i].ifunit,
  806. :arg_ref_s_trans.arg_s_mx[i].uunit,
  807. :arg_ref_s_trans.arg_s_mx[i].rate;
  808. LOOP
  809. CLOSE cur_mx;
  810. //检验明细是否读入完整
  811. SELECT count(*) INTO :no_mxcheck
  812. FROM u_mtrlware_pzcode_transmx
  813. Where billid = :arg_billid;
  814. IF sqlca.SQLCode <> 0 THEN
  815. rslt = 0
  816. arg_msg = "查询库存配置调整单操作失败,单据明细数量"
  817. GOTO ext
  818. END IF
  819. IF i <> (no_mxcheck+1) THEN
  820. rslt = 0
  821. arg_msg = "查询库存配置调整单操作失败,单据明细"
  822. GOTO ext
  823. END IF
  824. arg_arr_cnt = i - 1
  825. ext:
  826. RETURN rslt
  827. end function
  828. public function integer uof_update_waredate (long arg_billid, boolean arg_ifcommit, ref string arg_msg);Int rslt = 1
  829. Long ll_arr_cnt
  830. DateTime ld_waredate,ld_auditingdate,ld_waradate_mx
  831. String ls_auditdate,ls_waredate
  832. Long ll_mtrlid,ll_sptid,ll_mtrlwareid,ll_sptid_new
  833. String ls_status,ls_woodcode,ls_pcode,ls_plancode
  834. String ls_mtrlcuscode,ls_location
  835. String ls_status_new,ls_woodcode_new,ls_pcode_new,ls_plancode_new
  836. String ls_mtrlcuscode_new,ls_location_new
  837. Long i
  838. Int li_if_cus_mtrlware, li_if_plancode, li_inwaretype
  839. IF arg_billid <= 0 THEN
  840. rslt = 0
  841. arg_msg = '错误单据唯一码'
  842. GOTO ext
  843. END IF
  844. s_mtrlware_pzcode_trans arg_s_trans
  845. IF getinfo(arg_billid,arg_s_trans,ll_arr_cnt,arg_msg) = 0 THEN
  846. rslt = 0
  847. GOTO ext
  848. END IF
  849. SELECT auditdate INTO :ld_auditingdate
  850. FROM u_mtrlware_pzcode_trans
  851. Where billid = :arg_billid;
  852. IF sqlca.SQLCode <> 0 THEN
  853. rslt = 0
  854. arg_msg = "单据审核操作失败"+"~n"+sqlca.SQLErrText
  855. GOTO ext
  856. END IF
  857. ls_auditdate = String(ld_auditingdate,'yyyy-mm-dd hh:mm')
  858. FOR i = 1 To ll_arr_cnt
  859. ll_mtrlid = arg_s_trans.arg_s_mx[i].mtrlid
  860. ll_sptid = arg_s_trans.arg_s_mx[i].sptid
  861. ls_status = arg_s_trans.arg_s_mx[i].status
  862. ls_woodcode = arg_s_trans.arg_s_mx[i].woodcode
  863. ls_pcode = arg_s_trans.arg_s_mx[i].pcode
  864. ls_plancode = arg_s_trans.arg_s_mx[i].plancode
  865. ls_mtrlcuscode = arg_s_trans.arg_s_mx[i].mtrlcuscode
  866. ls_location = arg_s_trans.arg_s_mx[i].Location
  867. ls_status_new = arg_s_trans.arg_s_mx[i].status_new
  868. ls_woodcode_new = arg_s_trans.arg_s_mx[i].woodcode_new
  869. ls_pcode_new = arg_s_trans.arg_s_mx[i].pcode_new
  870. ls_plancode_new = arg_s_trans.arg_s_mx[i].plancode_new
  871. ls_mtrlcuscode_new = arg_s_trans.arg_s_mx[i].mtrlcuscode_new
  872. ls_location_new = arg_s_trans.arg_s_mx[i].Location_new
  873. ll_sptid_new = arg_s_trans.arg_s_mx[i].sptid_new
  874. SELECT balctype , if_plancode
  875. INTO :li_if_cus_mtrlware, :li_if_plancode
  876. FROM u_storage
  877. Where storageid = :arg_s_trans.storageid;
  878. IF sqlca.SQLCode <> 0 THEN
  879. arg_msg = '查询仓库资料失败'
  880. rslt = 0
  881. GOTO ext
  882. END IF
  883. IF li_if_cus_mtrlware = 1 THEN //使用客户库存
  884. ELSE
  885. IF ll_sptid <> 0 THEN
  886. ll_sptid = 0
  887. END IF
  888. IF ll_sptid_new <> 0 THEN
  889. ll_sptid_new = 0
  890. END IF
  891. END IF
  892. IF li_if_plancode = 1 THEN //使用批号
  893. ELSE
  894. IF ls_plancode <> '' THEN
  895. ls_plancode = ''
  896. END IF
  897. IF ls_plancode_new <> '' THEN
  898. ls_plancode_new = ''
  899. END IF
  900. END IF
  901. SELECT waredate INTO :ld_waredate
  902. FROM u_mtrlware
  903. WHERE scid = :arg_s_trans.scid
  904. AND storageid = :arg_s_trans.storageid
  905. AND mtrlid = :ll_mtrlid
  906. AND sptid = :ll_sptid
  907. AND status = :ls_status
  908. AND woodcode = :ls_woodcode
  909. AND pcode = :ls_pcode
  910. And plancode = :ls_plancode;
  911. IF sqlca.SQLCode <> 0 THEN
  912. rslt = 0
  913. arg_msg = '明细行:'+String(i)+',查询明细原库存最近进仓日期失败,'+sqlca.SQLErrText
  914. GOTO ext
  915. END IF
  916. SELECT waredate INTO :ld_waradate_mx
  917. FROM u_mtrlware
  918. WHERE scid = :arg_s_trans.scid
  919. AND storageid = :arg_s_trans.storageid
  920. AND mtrlid = :ll_mtrlid
  921. AND sptid = :ll_sptid_new
  922. AND status = :ls_status_new
  923. AND woodcode = :ls_woodcode_new
  924. AND pcode = :ls_pcode_new
  925. And plancode = :ls_plancode_new;
  926. IF sqlca.SQLCode <> 0 THEN
  927. rslt = 0
  928. arg_msg = '明细行:'+String(i)+',查询明细新库存最近进仓日期失败,错误:'+String(sqlca.SQLCode)+','+sqlca.SQLErrText
  929. GOTO ext
  930. END IF
  931. ls_waredate = String(ld_waradate_mx,'yyyy-mm-dd hh:mm')
  932. IF ls_auditdate = ls_waredate THEN
  933. UPDATE u_mtrlware
  934. SET waredate = :ld_waredate
  935. WHERE scid = :arg_s_trans.scid
  936. AND storageid = :arg_s_trans.storageid
  937. AND mtrlid = :ll_mtrlid
  938. AND sptid = :ll_sptid_new
  939. AND status = :ls_status_new
  940. AND woodcode = :ls_woodcode_new
  941. AND pcode = :ls_pcode_new
  942. And plancode = :ls_plancode_new;
  943. IF sqlca.SQLCode <> 0 THEN
  944. rslt = 0
  945. arg_msg = '明细行:'+String(i)+',更新明细新库存最近进仓日期失败,'+sqlca.SQLErrText
  946. GOTO ext
  947. END IF
  948. END IF
  949. NEXT
  950. ext:
  951. IF rslt = 0 THEN
  952. ROLLBACK;
  953. ELSEIF rslt = 1 And arg_ifcommit THEN
  954. COMMIT;
  955. END IF
  956. RETURN rslt
  957. end function
  958. on uo_mtrlware_pzcode_trans.create
  959. call super::create
  960. TriggerEvent( this, "constructor" )
  961. end on
  962. on uo_mtrlware_pzcode_trans.destroy
  963. TriggerEvent( this, "destructor" )
  964. call super::destroy
  965. end on
  966. global type uo_incase from nonvisualobject
  967. end type