uo_outware_sale_owe.sru 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. $PBExportHeader$uo_outware_sale_owe.sru
  2. forward
  3. global type uo_outware_sale_owe from uo_outware_sale
  4. end type
  5. end forward
  6. global type uo_outware_sale_owe from uo_outware_sale
  7. end type
  8. global uo_outware_sale_owe uo_outware_sale_owe
  9. forward prototypes
  10. public function integer auditing (boolean arg_ifcommit, ref string arg_msg)
  11. public function integer c_auditing (boolean arg_ifcommit, ref string arg_msg)
  12. end prototypes
  13. public function integer auditing (boolean arg_ifcommit, ref string arg_msg);
  14. Long rslt = 1,cnt = 0,i
  15. Long chc
  16. Long rst_outwareid //
  17. Long rst_inwareid //
  18. Long ll_i,ll_j,ll_k
  19. Int li_ifpack,li_ifunit,li_ifpackpro
  20. Int li_ifpackcnt,li_ifpackprocnt
  21. Decimal ld_rate,ld_uqty,ld_rate_buy
  22. Decimal ld_fprice,ld_uprice
  23. String ls_uunit,ls_unit_buy,ls_unit
  24. Long ll_storageid_arr[]
  25. Long ll_outwareid_out
  26. IF uo_option_confirmaudit_sale = -1000 THEN
  27. rslt = 0
  28. arg_msg = '选项:[025]销售单先确认后审核,读取初始默认值失败,操作取消!'
  29. GOTO ext
  30. END IF
  31. uo_sqlpro uo_pro
  32. uo_pro = Create uo_sqlpro
  33. uo_pro.commit_transaction = commit_transaction
  34. uo_owegood uo_owe
  35. uo_owe = Create uo_owegood
  36. IF storageid = 0 THEN
  37. rslt = 0
  38. arg_msg = '没有正确的仓库'
  39. GOTO ext
  40. END IF
  41. IF billtype <> 9 THEN
  42. IF uof_check_warepdb_audit(storageid,arg_msg) = 0 THEN
  43. rslt = 0
  44. GOTO ext
  45. END IF
  46. END IF
  47. String ls_storagename
  48. SELECT storagename
  49. INTO :ls_storagename
  50. FROM u_storage
  51. Where storageid = :storageid Using commit_transaction ;
  52. IF commit_transaction.SQLCode <> 0 THEN
  53. rslt = 0
  54. arg_msg = "查询操作失败,仓库"
  55. GOTO ext
  56. END IF
  57. //检查是否有该仓库的建立权限
  58. IF sys_user_storagestr_audit <> '0' THEN
  59. IF Pos(sys_user_storagestr_audit,','+String(storageid)+',') <= 0 THEN
  60. rslt = 0
  61. arg_msg = '没有仓库: '+ls_storagename+' 的审核权限,不允许审核该仓库的单据'
  62. GOTO ext
  63. END IF
  64. END IF
  65. //
  66. IF outwareid = 0 THEN
  67. rslt = 0
  68. arg_msg = "没有审核对象"
  69. GOTO ext
  70. END IF
  71. IF flag = 1 THEN
  72. rslt = 0
  73. arg_msg = "单据已经审核"
  74. GOTO ext
  75. END IF
  76. IF uo_option_confirmaudit_sale = 1 THEN
  77. IF priceflag = 0 THEN
  78. rslt = 0
  79. arg_msg = "销售单要确认后才能审核"
  80. GOTO ext
  81. END IF
  82. END IF
  83. UPDATE u_outware
  84. SET Auditingrep = :publ_operator,
  85. Auditingdate = getdate(),
  86. flag = 1
  87. WHERE u_outware.outwareid = :outwareid
  88. AND flag = 0
  89. And scid = :scid Using commit_transaction;
  90. IF commit_transaction.SQLCode <> 0 THEN
  91. rslt = 0
  92. arg_msg = "因网络或其它原因导致审核单据操作失败"+"~n"+commit_transaction.SQLErrText
  93. GOTO ext
  94. ELSEIF commit_transaction.SQLNRows = 0 THEN
  95. rslt = 0
  96. arg_msg = "单据正在审核,请稍后查询。"+"~n"+commit_transaction.SQLErrText
  97. GOTO ext
  98. END IF
  99. uo_outware uo_out
  100. uo_out = Create uo_outware
  101. uo_out.commit_transaction = sqlca
  102. uo_out.if_getid_ture = False
  103. IF relid = 1 THEN
  104. IF uo_out.newbegin(scid,22,arg_msg) = 0 THEN
  105. rslt = 0
  106. GOTO ext
  107. END IF
  108. uo_out.relid = outwareid
  109. uo_out.outdate = outdate
  110. uo_out.outrep = publ_operator
  111. uo_out.part = outwarecode
  112. uo_out.dscrp = ''
  113. uo_out.cusname = '欠货终止出仓单'
  114. uo_out.storageid = storageid
  115. FOR i = 1 To it_mxbt
  116. IF uo_out.acceptmx(outwaremx[i].mtrlwareid,&
  117. 0 - outwaremx[i].qty,&
  118. outwaremx[i].cost,&
  119. 1,'',i,arg_msg,0,0,0,0,'',0,0,outwaremx[i].unit,0 - outwaremx[i].uqty,outwaremx[i].rate,'','',0,0,'',0,0,0,0,'','') = 0 THEN
  120. rslt = 0
  121. GOTO ext
  122. END IF
  123. NEXT
  124. IF uo_out.Save(False,arg_msg) = 0 THEN
  125. rslt = 0
  126. GOTO ext
  127. END IF
  128. ll_outwareid_out = uo_out.outwareid
  129. //2.原事务审核出仓单
  130. IF uo_out.getinfo(scid,ll_outwareid_out,arg_msg) = 0 THEN
  131. rslt = 0
  132. GOTO ext
  133. END IF
  134. IF uo_out.auditing(False,arg_msg) = 0 THEN
  135. rslt = 0
  136. GOTO ext
  137. END IF
  138. END IF
  139. FOR i = 1 To it_mxbt
  140. Decimal ld_ref_costamt
  141. If (billtype = 1 Or billtype = 5) And outwaremx[i].relid > 0 THEN
  142. IF uo_owe.addstopqty(outwaremx[i].relid,outwaremx[i].relprintid,0 - outwaremx[i].qty,arg_msg,False) <> 1 THEN
  143. rslt = 0
  144. GOTO ext
  145. END IF
  146. END IF
  147. If (billtype = 1 Or billtype = 5) And outwaremx[i].relid > 0 THEN
  148. IF uo_owe.tryfinish(outwaremx[i].relid,arg_msg,False) = 0 THEN
  149. rslt = 0
  150. GOTO ext
  151. END IF
  152. END IF
  153. IF p_update_cost(outwaremx[i].mtrlwareid,outwaremx[i].mtrlcode,&
  154. outwaremx[i].qty,outwaremx[i].printid,ld_ref_costamt,arg_msg,False) = 0 THEN
  155. rslt = 0
  156. GOTO ext
  157. END IF
  158. IF sys_option_inout_procedure = 0 THEN
  159. IF p_update_mtrlware ( outwaremx[i].mtrlwareid, outwaremx[i].mtrlid, &
  160. outwaremx[i].mtrlcode, storageid, outwaremx[i].plancode,&
  161. outwaremx[i].status, outwaremx[i].qty,outwaremx[i].uqty, ld_ref_costamt,&
  162. outwaremx[i].planprice, outwaremx[i].sptid,outwaremx[i].dxflag,&
  163. outwaremx[i].woodcode,outwaremx[i].pcode,outwaremx[i].mtrlcuscode,&
  164. outwaremx[i].Location,outwaremx[i].ifvqty,arg_msg) = 0 THEN
  165. rslt = 0
  166. GOTO ext
  167. END IF
  168. ELSE
  169. IF uo_pro.p_outware_update_mtrlware(scid,outwareid,outwaremx[i].printid,outwaremx[i].mtrlwareid,&
  170. outwaremx[i].mtrlid,outwaremx[i].mtrlcode,storageid,outwaremx[i].plancode,outwaremx[i].status,&
  171. outwaremx[i].qty,outwaremx[i].uqty,ld_ref_costamt,&
  172. outwaremx[i].planprice, outwaremx[i].sptid,outwaremx[i].dxflag,&
  173. outwaremx[i].woodcode, outwaremx[i].pcode,outwaremx[i].mtrlcuscode,outwaremx[i].Location,arg_msg) = 0 THEN
  174. arg_msg = '行:'+String(i)+','+arg_msg
  175. rslt = 0
  176. GOTO ext
  177. END IF
  178. END IF
  179. NEXT
  180. flag = 1
  181. ext:
  182. IF rslt = 0 THEN
  183. ROLLBACK Using commit_transaction;
  184. ELSEIF rslt = 1 And arg_ifcommit THEN
  185. COMMIT Using commit_transaction;
  186. END IF
  187. Destroy uo_pro
  188. Destroy uo_out
  189. Destroy uo_owe
  190. RETURN rslt
  191. end function
  192. public function integer c_auditing (boolean arg_ifcommit, ref string arg_msg);Long rslt = 1,cnt = 0,i
  193. Long ls_newid
  194. DateTime null_dt
  195. Long ll_inwareid_rel,ll_outwareid_rel
  196. String ls_inwarecode_rel,ls_outwarecode_rel
  197. String ls_outwarecode_arr[]
  198. Long ll_outwareid[]
  199. Long ll_itmx = 1,ll_i
  200. Long ll_outwareid_out
  201. SetNull(null_dt)
  202. uo_inware uo_in
  203. uo_outware uo_out
  204. uo_owegood uo_owe
  205. uo_owe = Create uo_owegood
  206. uo_sqlpro uo_pro
  207. uo_pro = Create uo_sqlpro
  208. uo_pro.commit_transaction = commit_transaction
  209. uo_out = Create uo_outware
  210. uo_out.commit_transaction = sqlca
  211. uo_out.if_getid_ture = False
  212. IF storageid = 0 THEN
  213. rslt = 0
  214. arg_msg = '没有正确的仓库'
  215. GOTO ext
  216. END IF
  217. IF billtype <> 9 THEN
  218. IF uof_check_warepdb_audit(storageid,arg_msg) = 0 THEN
  219. rslt = 0
  220. GOTO ext
  221. END IF
  222. END IF
  223. String ls_storagename
  224. SELECT storagename
  225. INTO :ls_storagename
  226. FROM u_storage
  227. Where storageid = :storageid Using commit_transaction ;
  228. IF commit_transaction.SQLCode <> 0 THEN
  229. rslt = 0
  230. arg_msg = "查询操作失败,仓库"
  231. GOTO ext
  232. END IF
  233. //检查是否有该仓库的建立权限
  234. IF sys_user_storagestr_audit <> '0' THEN
  235. IF Pos(sys_user_storagestr_audit,','+String(storageid)+',') <= 0 THEN
  236. rslt = 0
  237. arg_msg = '没有仓库: '+ls_storagename+' 的审核权限,不允许撤审该仓库的单据'
  238. GOTO ext
  239. END IF
  240. END IF
  241. //
  242. IF outwareid = 0 THEN
  243. rslt = 0
  244. arg_msg = "没有审核对象"
  245. GOTO ext
  246. END IF
  247. IF ctmint > 0 THEN
  248. arg_msg = '单据已截数,不能操作'
  249. rslt = 0
  250. GOTO ext
  251. END IF
  252. IF flag = 0 THEN
  253. rslt = 0
  254. arg_msg = "单据还未审核"
  255. GOTO ext
  256. END IF
  257. IF secflag = 1 THEN
  258. rslt = 0
  259. arg_msg = "单据已经过财务审核"
  260. GOTO ext
  261. END IF
  262. IF balcflag = 1 THEN
  263. rslt = 0
  264. arg_msg = "单据已经日结,不能撤审"
  265. GOTO ext
  266. END IF
  267. String ls_owecode
  268. Int li_oweflag
  269. Long ll_owebillid
  270. cnt = 0
  271. UPDATE u_outware
  272. SET Auditingrep = '',
  273. Auditingdate = :null_dt,
  274. flag = 0
  275. WHERE u_outware.outwareid = :outwareid
  276. AND flag = 1
  277. And scid = :scid Using commit_transaction;
  278. IF commit_transaction.SQLCode <> 0 THEN
  279. rslt = 0
  280. arg_msg = "因网络或其它原因导致审核单据操作失败"+"~n"+commit_transaction.SQLErrText
  281. GOTO ext
  282. ELSEIF commit_transaction.SQLNRows = 0 THEN
  283. rslt = 0
  284. arg_msg = "单据正在审核,请稍后查询。"+"~n"+commit_transaction.SQLErrText
  285. GOTO ext
  286. END IF
  287. FOR i = 1 To it_mxbt
  288. IF sys_option_inout_procedure = 0 THEN
  289. IF p_update_mtrlware ( outwaremx[i].mtrlwareid, outwaremx[i].mtrlid, &
  290. outwaremx[i].mtrlcode, storageid, outwaremx[i].plancode,&
  291. outwaremx[i].status, 0 - outwaremx[i].qty,0 - outwaremx[i].uqty,0 - outwaremx[i].costamt,&
  292. outwaremx[i].planprice, outwaremx[i].sptid, outwaremx[i].dxflag,&
  293. outwaremx[i].woodcode, outwaremx[i].pcode, outwaremx[i].mtrlcuscode,&
  294. outwaremx[i].Location,outwaremx[i].ifvqty,arg_msg) = 0 THEN
  295. rslt = 0
  296. GOTO ext
  297. END IF
  298. ELSE
  299. IF uo_pro.p_outware_update_mtrlware(scid,outwareid,outwaremx[i].printid,outwaremx[i].mtrlwareid,&
  300. outwaremx[i].mtrlid,outwaremx[i].mtrlcode,storageid,outwaremx[i].plancode,outwaremx[i].status,&
  301. 0 - outwaremx[i].qty,0 - outwaremx[i].uqty,outwaremx[i].costamt,&
  302. outwaremx[i].planprice, outwaremx[i].sptid,outwaremx[i].dxflag,&
  303. outwaremx[i].woodcode, outwaremx[i].pcode,outwaremx[i].mtrlcuscode,outwaremx[i].Location,arg_msg) = 0 THEN
  304. arg_msg = '行:'+String(i)+','+arg_msg
  305. rslt = 0
  306. GOTO ext
  307. END IF
  308. END IF
  309. If (billtype = 1 Or billtype = 5) And outwaremx[i].relid > 0 THEN
  310. IF uo_owe.addstopqty(outwaremx[i].relid,outwaremx[i].relprintid,outwaremx[i].qty,arg_msg,False) <> 1 THEN
  311. rslt = 0
  312. GOTO ext
  313. END IF
  314. END IF
  315. If (billtype = 1 Or billtype = 5) And outwaremx[i].relid > 0 THEN
  316. IF uo_owe.tryfinish(outwaremx[i].relid,arg_msg,False) = 0 THEN
  317. rslt = 0
  318. GOTO ext
  319. END IF
  320. END IF
  321. NEXT
  322. IF relid = 1 THEN
  323. SELECT count(*) INTO :cnt
  324. FROM u_outware
  325. WHERE scid = :scid
  326. AND relid = :outwareid
  327. And billtype = 22;
  328. IF sqlca.SQLCode <> 0 THEN
  329. arg_msg = '查询是否有相关出仓单失败'+sqlca.SQLErrText
  330. rslt = 0
  331. GOTO ext
  332. END IF
  333. IF cnt = 1 THEN
  334. SELECT outwareid INTO :ll_outwareid_out
  335. FROM u_outware
  336. WHERE scid = :scid
  337. AND relid = :outwareid
  338. And billtype = 22;
  339. IF sqlca.SQLCode <> 0 THEN
  340. arg_msg = '查询是否有相关出仓单失败'+sqlca.SQLErrText
  341. rslt = 0
  342. GOTO ext
  343. END IF
  344. IF uo_out.getinfo(scid,ll_outwareid_out,arg_msg) = 0 THEN
  345. rslt = 0
  346. GOTO ext
  347. END IF
  348. IF uo_out.c_auditing(False,arg_msg) = 0 THEN
  349. rslt = 0
  350. GOTO ext
  351. END IF
  352. IF uo_out.del(scid,ll_outwareid_out,0,arg_msg,False) = 0 THEN
  353. rslt = 0
  354. GOTO ext
  355. END IF
  356. END IF
  357. END IF
  358. flag = 0
  359. ext:
  360. IF rslt = 0 THEN
  361. ROLLBACK Using commit_transaction;
  362. ELSEIF rslt = 1 And arg_ifcommit THEN
  363. COMMIT Using commit_transaction;
  364. END IF
  365. Destroy uo_pro
  366. Destroy uo_out
  367. Destroy uo_owe
  368. RETURN rslt
  369. end function
  370. on uo_outware_sale_owe.create
  371. call super::create
  372. end on
  373. on uo_outware_sale_owe.destroy
  374. call super::destroy
  375. end on