uo_warebalc_cmpl.sru 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091
  1. $PBExportHeader$uo_warebalc_cmpl.sru
  2. forward
  3. global type uo_warebalc_cmpl from nonvisualobject
  4. end type
  5. end forward
  6. global type uo_warebalc_cmpl from nonvisualobject
  7. end type
  8. global uo_warebalc_cmpl uo_warebalc_cmpl
  9. type variables
  10. Int uo_option_warebalc_checksale
  11. int uo_option_wkpmtrlware
  12. int uo_option_outware_scll_new_cj_mtrlware
  13. end variables
  14. forward prototypes
  15. public function integer uof_warebalc_cmplamt (long arg_storageid, long arg_balcdateint, long arg_mtrlwareid, ref string arg_msg, boolean arg_ifcommit, transaction commit_transaction)
  16. public function integer uof_get_planprice (long arg_mtrlid, string arg_status, string arg_woodcode, string arg_pcode, ref decimal arg_planprice, ref string arg_msg)
  17. public function integer uof_cmpl_warebalc_amt (long cur_storageid, long ll_balcdateint_cmpl, ref string arg_msg)
  18. public function integer uof_warebalc_cmplamt_all (long arg_storageid, long arg_balcdateint, ref string arg_msg, boolean arg_ifcommit, transaction commit_transaction)
  19. end prototypes
  20. public function integer uof_warebalc_cmplamt (long arg_storageid, long arg_balcdateint, long arg_mtrlwareid, ref string arg_msg, boolean arg_ifcommit, transaction commit_transaction);//0.采购收货单、成本价调整单的成本价不调整;采购退货单考虑【311】选项判断
  21. //1.查找最后成本调整时间,无则用上月结存时间;查上月结存时间(无则询问确定?怕是截数了的);查下月结存时间
  22. //2.依次更新外协收货单成本价、更新其他进仓单成本价(进仓正数)、更新其他进仓单成本价(进仓负数)
  23. //3.更新出仓单成本价
  24. //4.更新结存金额,下月期初金额;如果是最后结存,则更新库存金额
  25. Long rslt = 1
  26. Int li_storagetype
  27. Long ll_scid_storage
  28. Long ll_balcdateint_cmpl_arr[], ll_cmpl_cnt
  29. Long ll_balcdateint
  30. Long ll_balcdateint_cmpl = 0 //要计算的月份结存日期
  31. Long ll_balcdateint_last //= ? 前一个月份的结存日期
  32. Long i, j, cnt
  33. Decimal ld_newcost // 最新成本价
  34. Decimal ld_bgqty,ld_bgamt,ld_incqty,ld_incamt,ld_desqty,ld_desamt
  35. Decimal ld_ubgqty,ld_uincqty,ld_udesqty
  36. Long ll_mtrlid
  37. Int li_ifunit, li_BalcCmplNotUpdate
  38. String ls_status,ls_pcode,ls_woodcode
  39. String ls_mtrlcode,ls_msg
  40. Decimal ld_balcqty_update,ld_balcamt_update
  41. Decimal ld_desamt_update,ld_outcost_update
  42. Decimal lde_add_desamt, lde_costamt_add, lde_addamt
  43. Long ll_scid_add, ll_outwareid_add, ll_printid_add
  44. Decimal ld_vincqty,ld_vincamt,ld_vdesqty,ld_vdesamt,ld_uvincqty,ld_uvdesqty
  45. Decimal ld_vinqty,ld_vuinqty,ld_vinamt
  46. Decimal ld_voutqty,ld_vuoutqty,ld_voutamt, ld_vdesamt_update
  47. DateTime ldt_Aduitingdate, ldt_chkdate
  48. String ls_pfcode
  49. Decimal lde_planprice, lde_cost_in, lde_cost, lde_mtrlprice, lde_planprice_son
  50. Long ll_sonmtrlid[]
  51. Decimal ld_qty[]
  52. IF arg_storageid = -1 THEN
  53. rslt = 0
  54. arg_msg = '请先选择仓库'
  55. GOTO ext
  56. END IF
  57. //如果是算历史,但后期有成本调整的,同样不算
  58. SELECT MAX(u_inware.auditingdate)
  59. INTO :ldt_Aduitingdate
  60. FROM u_inware INNER JOIN
  61. u_inwaremx ON u_inware.scid = u_inwaremx.scid AND
  62. u_inware.inwareid = u_inwaremx.inwareid
  63. WHERE (u_inware.storageid = :arg_storageid)
  64. AND (u_inwaremx.mtrlwareid = :arg_mtrlwareid)
  65. AND (u_inware.sptname = '调整成本价(负单)' OR
  66. u_inware.sptname = '更新成本价(正单)')
  67. Using commit_transaction;
  68. IF commit_transaction.SQLCode <> 0 THEN
  69. rslt = 0
  70. arg_msg = '查询成本价调整单失败,操作取消'
  71. GOTO ext
  72. END IF
  73. //
  74. SELECT scid,storagetype
  75. INTO :ll_scid_storage,:li_storagetype
  76. FROM u_storage
  77. WHERE storageid = :arg_storageid
  78. Using commit_transaction;
  79. IF commit_transaction.SQLCode <> 0 THEN
  80. rslt = 0
  81. arg_msg = '查询仓库资料失败,操作取消'
  82. GOTO ext
  83. END IF
  84. SELECT u_mtrldef.mtrlid, u_mtrldef.mtrlcode, u_warebalc.status, u_warebalc.woodcode,
  85. u_warebalc.pcode, u_mtrldef.ifunit, u_mtrldef.BalcCmplNotUpdate
  86. INTO :ll_mtrlid, :ls_mtrlcode, :ls_status, :ls_woodcode, :ls_pcode, :li_ifunit, :li_BalcCmplNotUpdate
  87. FROM u_warebalc INNER JOIN
  88. u_mtrldef ON u_warebalc.mtrlid = u_mtrldef.mtrlid
  89. WHERE u_warebalc.storageid = :arg_storageid
  90. AND u_warebalc.balcdateint = :arg_balcdateint
  91. AND u_warebalc.mtrlwareid = :arg_mtrlwareid
  92. Using commit_transaction;
  93. IF commit_transaction.SQLCode <> 0 THEN
  94. rslt = 0
  95. arg_msg = '查询结存信息失败,'+commit_transaction.SQLErrText
  96. GOTO ext
  97. END IF
  98. IF uof_get_planprice(ll_mtrlid, ls_status,ls_woodcode, ls_pcode, lde_planprice, arg_msg) = 0 THEN
  99. rslt = 0
  100. GOTO ext
  101. END IF
  102. //确定要计算的范围
  103. IF arg_balcdateint = 0 THEN
  104. ll_cmpl_cnt++
  105. ll_balcdateint_cmpl_arr[ll_cmpl_cnt] = arg_balcdateint
  106. ELSE
  107. DECLARE waredate_cur CURSOR FOR
  108. SELECT distinct u_warebalc.balcdateint
  109. FROM u_warebalc
  110. WHERE ( storageid = :arg_storageid )
  111. AND balcdateint >= :arg_balcdateint
  112. AND mtrlwareid = :arg_mtrlwareid
  113. ORDER BY balcdateint
  114. Using commit_transaction;
  115. OPEN waredate_cur;
  116. FETCH waredate_cur Into :ll_balcdateint;
  117. DO WHILE commit_transaction.SQLCode = 0 //循环读取明细数据
  118. ll_cmpl_cnt++
  119. ll_balcdateint_cmpl_arr[ll_cmpl_cnt] = ll_balcdateint
  120. FETCH waredate_cur Into :ll_balcdateint;
  121. LOOP
  122. CLOSE waredate_cur;
  123. ll_cmpl_cnt++
  124. ll_balcdateint_cmpl_arr[ll_cmpl_cnt] = 0
  125. END IF
  126. ll_balcdateint_cmpl = ll_balcdateint_cmpl_arr[1] //按选择, 可以重算历史
  127. SELECT max(balcdateint) INTO :ll_balcdateint_last
  128. FROM u_warebalc
  129. WHERE storageid = :arg_storageid
  130. AND mtrlwareid = :arg_mtrlwareid
  131. AND ((:ll_balcdateint_cmpl = 0 AND balcdateint > 0)
  132. OR (:ll_balcdateint_cmpl > 0 AND balcdateint > 0 AND balcdateint < :ll_balcdateint_cmpl))
  133. Using commit_transaction;
  134. IF commit_transaction.SQLCode <> 0 THEN
  135. rslt = 0
  136. arg_msg = '查询上次结存失败,操作取消'
  137. GOTO ext
  138. END IF
  139. IF IsNull(ll_balcdateint_last) THEN ll_balcdateint_last = -1
  140. FOR i = 1 To ll_cmpl_cnt
  141. ll_balcdateint_cmpl = ll_balcdateint_cmpl_arr[i]
  142. IF IsNull(ldt_Aduitingdate) THEN
  143. IF ll_balcdateint_last = -1 THEN
  144. ldt_chkdate = DateTime(2000-01-01,23:59:59)
  145. ELSE
  146. ldt_chkdate = DateTime(Date(Left(String(ll_balcdateint_last),4)+'-'+Mid(String(ll_balcdateint_last), 5, 2)+'-'+Right(String(ll_balcdateint_last),2)),23:59:59)
  147. END IF
  148. ELSE
  149. ldt_chkdate = ldt_Aduitingdate
  150. END IF
  151. IF ll_balcdateint_cmpl = 0 THEN
  152. ls_msg = '期间:本期'
  153. ELSE
  154. ls_msg = '期间:'+String(ll_balcdateint_cmpl)
  155. END IF
  156. ls_msg += ',物料:'+ls_mtrlcode+ ',库存id:'+String(arg_mtrlwareid)
  157. IF ls_status <> "" THEN
  158. ls_msg += ','+sys_option_change_status+':'+ls_status
  159. END IF
  160. IF ls_woodcode <> "" THEN
  161. ls_msg += ','+sys_option_change_woodcode+':'+ls_woodcode
  162. END IF
  163. IF ls_pcode <> "" THEN
  164. ls_msg += ','+sys_option_change_pcode+':'+ls_pcode
  165. END IF
  166. //查期初
  167. SELECT balcqty,balcamt,ubalcqty
  168. INTO :ld_bgqty,:ld_bgamt,:ld_ubgqty
  169. FROM u_warebalc
  170. WHERE storageid = :arg_storageid
  171. AND mtrlwareid = :arg_mtrlwareid
  172. AND balcdateint = :ll_balcdateint_last
  173. Using commit_transaction;
  174. IF commit_transaction.SQLCode = -1 THEN
  175. rslt = 0
  176. arg_msg = ls_msg+'~r~n'+'查询上月结存失败,'+commit_transaction.SQLErrText
  177. GOTO ext
  178. ELSEIF commit_transaction.SQLCode = 100 THEN
  179. ld_bgqty = 0
  180. ld_bgamt = 0
  181. ld_ubgqty = 0
  182. END IF
  183. IF IsNull(ld_bgqty) THEN ld_bgqty = 0
  184. IF IsNull(ld_bgamt) THEN ld_bgamt = 0
  185. IF IsNull(ld_ubgqty) THEN ld_ubgqty = 0
  186. IF ld_bgqty = 0 THEN ld_bgamt = 0
  187. //0.更新进仓costamt
  188. UPDATE u_inwaremx
  189. SET u_inwaremx.costamt = round(u_inwaremx.price * u_inwaremx.qty, 2)
  190. FROM u_inware INNER JOIN
  191. u_inwaremx ON u_inware.scid = u_inwaremx.scid AND
  192. u_inware.inwareid = u_inwaremx.inwareid
  193. WHERE (u_inwaremx.mtrlwareid = :arg_mtrlwareid)
  194. AND (u_inware.balcdateint = :ll_balcdateint_cmpl)
  195. Using commit_transaction;
  196. IF commit_transaction.SQLCode <> 0 THEN
  197. rslt = 0
  198. arg_msg = ls_msg+'~r~n'+'更新进仓单成本金额失败,'+commit_transaction.SQLErrText
  199. GOTO ext
  200. END IF
  201. //1.更新外协收货单单价(billtype = 4)
  202. //有外协单的才查,提搞速度
  203. SELECT count(*) INTO :cnt
  204. FROM ow_wfjgmx_in_aft
  205. WHERE EXISTS
  206. (SELECT 1
  207. FROM (SELECT u_inware.scid, u_inware.relid, u_inwaremx.printid
  208. FROM u_inware INNER JOIN
  209. u_inwaremx ON u_inware.scid = u_inwaremx.scid AND
  210. u_inware.inwareid = u_inwaremx.inwareid
  211. WHERE (u_inware.billtype = 4)
  212. AND (u_inwaremx.mtrlwareid = :arg_mtrlwareid)
  213. AND (u_inware.auditingdate > :ldt_chkdate)
  214. AND (u_inware.balcdateint = :ll_balcdateint_cmpl)) a
  215. WHERE a.scid = ow_wfjgmx_in_aft.scid AND
  216. a.relid = ow_wfjgmx_in_aft.inwareid AND
  217. a.printid = ow_wfjgmx_in_aft.printid)
  218. Using commit_transaction;
  219. IF commit_transaction.SQLCode <> 0 THEN
  220. rslt = 0
  221. arg_msg = ls_msg+'~r~n'+'更新外协收货单材料成本价失败,'+commit_transaction.SQLErrText
  222. GOTO ext
  223. END IF
  224. IF cnt > 0 THEN
  225. ls_pfcode = f_get_dft_pf(ll_mtrlid)
  226. //
  227. j = 1
  228. DECLARE cur_inmx CURSOR FOR
  229. SELECT u_PrdPF.SonMtrlid,
  230. u_prdpf.Sonscale / (1 - u_PrdPF.sonloss) + u_PrdPF.SonDECLoss
  231. FROM u_PrdPF
  232. WHERE ( u_PrdPF.mtrlid = :ll_mtrlid )
  233. And ( u_PrdPF.pfcode = :ls_pfcode );
  234. OPEN cur_inmx;
  235. FETCH cur_inmx Into :ll_sonmtrlid[j],:ld_qty[j];
  236. DO WHILE sqlca.SQLCode = 0
  237. j++
  238. FETCH cur_inmx Into :ll_sonmtrlid[j],:ld_qty[j];
  239. LOOP
  240. CLOSE cur_inmx;
  241. cnt = j - 1
  242. lde_mtrlprice = 0
  243. FOR j = 1 To cnt
  244. IF uof_get_planprice(ll_sonmtrlid[j], '','', '', lde_planprice_son, arg_msg) = 0 THEN
  245. rslt = 0
  246. GOTO ext
  247. END IF
  248. lde_mtrlprice += lde_planprice_son * ld_qty[j]
  249. NEXT
  250. //更新外协收货单材料成本价
  251. UPDATE ow_wfjgmx_in_aft
  252. SET fprice = :lde_mtrlprice,
  253. price = :lde_mtrlprice + case when qty = 0 then 0 else round(jgprice * uqty / qty, 5) * rebate END
  254. WHERE EXISTS
  255. (SELECT 1
  256. FROM (SELECT u_inware.scid, u_inware.relid, u_inwaremx.printid
  257. FROM u_inware INNER JOIN
  258. u_inwaremx ON u_inware.scid = u_inwaremx.scid AND
  259. u_inware.inwareid = u_inwaremx.inwareid
  260. WHERE (u_inware.billtype = 4)
  261. AND (u_inwaremx.mtrlwareid = :arg_mtrlwareid)
  262. AND (u_inware.auditingdate > :ldt_chkdate)
  263. AND (u_inware.balcdateint = :ll_balcdateint_cmpl)) a
  264. WHERE a.scid = ow_wfjgmx_in_aft.scid AND
  265. a.relid = ow_wfjgmx_in_aft.inwareid AND
  266. a.printid = ow_wfjgmx_in_aft.printid)
  267. Using commit_transaction;
  268. IF commit_transaction.SQLCode <> 0 THEN
  269. rslt = 0
  270. arg_msg = ls_msg+'~r~n'+'更新外协收货单材料成本价失败,'+commit_transaction.SQLErrText
  271. GOTO ext
  272. END IF
  273. //更新外协收货单对应进仓单成本价
  274. UPDATE u_inwaremx
  275. SET u_inwaremx.fprice = ow_wfjgmx_in_aft.fprice * ow_wfjgmx_in_aft.rate + ow_wfjgmx_in_aft.jgprice * ow_wfjgmx_in_aft.rebate,
  276. u_inwaremx.planprice = ow_wfjgmx_in_aft.fprice * ow_wfjgmx_in_aft.rate + ow_wfjgmx_in_aft.jgprice * ow_wfjgmx_in_aft.rebate,
  277. u_inwaremx.price = ow_wfjgmx_in_aft.fprice * ow_wfjgmx_in_aft.rate + ow_wfjgmx_in_aft.jgprice * ow_wfjgmx_in_aft.rebate,
  278. u_inwaremx.cost = ow_wfjgmx_in_aft.fprice * ow_wfjgmx_in_aft.rate + ow_wfjgmx_in_aft.jgprice * ow_wfjgmx_in_aft.rebate,
  279. u_inwaremx.uprice = ( ow_wfjgmx_in_aft.fprice * ow_wfjgmx_in_aft.rate + ow_wfjgmx_in_aft.jgprice * ow_wfjgmx_in_aft.rebate) /u_inwaremx.rate,
  280. u_inwaremx.costamt = round(( ow_wfjgmx_in_aft.fprice * ow_wfjgmx_in_aft.rate + ow_wfjgmx_in_aft.jgprice * ow_wfjgmx_in_aft.rebate) * u_inwaremx.qty, 2)
  281. FROM u_inware INNER JOIN
  282. u_inwaremx ON u_inware.scid = u_inwaremx.scid AND
  283. u_inware.inwareid = u_inwaremx.inwareid INNER JOIN
  284. ow_wfjgmx_in_aft ON u_inware.scid = ow_wfjgmx_in_aft.scid AND
  285. u_inware.relid = ow_wfjgmx_in_aft.inwareid AND
  286. u_inwaremx.printid = ow_wfjgmx_in_aft.printid
  287. WHERE (u_inware.billtype = 4)
  288. AND (u_inwaremx.mtrlwareid = :arg_mtrlwareid)
  289. AND (u_inware.auditingdate > :ldt_chkdate)
  290. AND (u_inware.balcdateint = :ll_balcdateint_cmpl)
  291. Using commit_transaction;
  292. IF commit_transaction.SQLCode <> 0 THEN
  293. rslt = 0
  294. arg_msg = ls_msg+'~r~n'+'更新外协收货单对应进仓单成本价失败,'+commit_transaction.SQLErrText
  295. GOTO ext
  296. END IF
  297. END IF
  298. //,23,25,
  299. //2.更新其他正数进仓单价(qty > 0 billtype <> 1 billtype <> 4)
  300. IF li_BalcCmplNotUpdate = 0 THEN
  301. UPDATE u_inwaremx
  302. SET u_inwaremx.fprice = :lde_planprice,
  303. u_inwaremx.planprice = :lde_planprice,
  304. u_inwaremx.price = :lde_planprice,
  305. u_inwaremx.cost = :lde_planprice,
  306. u_inwaremx.uprice = :lde_planprice /u_inwaremx.rate,
  307. u_inwaremx.costamt = round(:lde_planprice * u_inwaremx.qty, 2)
  308. FROM u_inware INNER JOIN
  309. u_inwaremx ON u_inware.scid = u_inwaremx.scid AND
  310. u_inware.inwareid = u_inwaremx.inwareid
  311. WHERE (u_inwaremx.qty > 0) AND (u_inware.billtype <> 1 AND u_inware.billtype <> 4)
  312. AND (u_inwaremx.mtrlwareid = :arg_mtrlwareid)
  313. AND (u_inware.auditingdate > :ldt_chkdate)
  314. AND (u_inware.balcdateint = :ll_balcdateint_cmpl)
  315. Using commit_transaction;
  316. IF commit_transaction.SQLCode <> 0 THEN
  317. rslt = 0
  318. arg_msg = ls_msg+'~r~n'+'更新非采购外协的正数进仓单成本价失败,'+commit_transaction.SQLErrText
  319. GOTO ext
  320. END IF
  321. END IF
  322. //处理一次带V的数据
  323. //查正数进仓
  324. SELECT isnull(sum(u_inwaremx.qty),0),
  325. isnull(sum(u_inwaremx.uqty),0),
  326. isnull(sum(u_inwaremx.costamt),0)
  327. INTO :ld_vincqty,
  328. :ld_uvincqty,
  329. :ld_vincamt
  330. FROM u_inware,u_inwaremx
  331. WHERE u_inware.scid = u_inwaremx.scid
  332. AND u_inware.inwareid = u_inwaremx.inwareid
  333. AND u_inwaremx.mtrlwareid = :arg_mtrlwareid
  334. AND u_inware.storageid = :arg_storageid
  335. AND u_inware.balcdateint = :ll_balcdateint_cmpl
  336. AND u_inware.flag = 1
  337. AND u_inwaremx.qty > 0
  338. AND u_inwaremx.ifvqty = 0
  339. Using commit_transaction;
  340. IF commit_transaction.SQLCode <> 0 THEN
  341. rslt = 0
  342. arg_msg = ls_msg+'~r~n'+'查询正数进仓信息失败,'+ls_msg+','+commit_transaction.SQLErrText
  343. GOTO ext
  344. END IF
  345. IF IsNull(ld_vincqty) THEN ld_vincqty = 0
  346. IF IsNull(ld_vincamt) THEN ld_vincamt = 0
  347. IF IsNull(ld_uvincqty) THEN ld_uvincqty = 0
  348. IF ld_bgqty + ld_vincqty <> 0 And ld_bgamt + ld_vincamt <> 0 THEN
  349. lde_cost_in = Round((ld_bgamt + ld_vincamt) / (ld_bgqty + ld_vincqty),sys_option_cost_dec)
  350. ELSE
  351. lde_cost_in = lde_planprice
  352. END IF
  353. UPDATE u_inwaremx
  354. SET u_inwaremx.fprice = :lde_cost_in,
  355. u_inwaremx.planprice = :lde_cost_in,
  356. u_inwaremx.price = :lde_cost_in,
  357. u_inwaremx.cost = :lde_cost_in,
  358. u_inwaremx.uprice = :lde_cost_in /u_inwaremx.rate,
  359. u_inwaremx.costamt = round(:lde_cost_in * u_inwaremx.qty, 2)
  360. FROM u_inware INNER JOIN
  361. u_inwaremx ON u_inware.scid = u_inwaremx.scid AND
  362. u_inware.inwareid = u_inwaremx.inwareid
  363. WHERE (u_inwaremx.qty > 0) AND (u_inware.billtype <> 1 AND u_inware.billtype <> 4)
  364. AND (u_inwaremx.mtrlwareid = :arg_mtrlwareid)
  365. AND (u_inware.auditingdate > :ldt_chkdate)
  366. AND (u_inware.balcdateint = :ll_balcdateint_cmpl)
  367. AND (u_inwaremx.ifvqty = 1)
  368. Using commit_transaction;
  369. IF commit_transaction.SQLCode <> 0 THEN
  370. rslt = 0
  371. arg_msg = ls_msg+'~r~n'+'更新非采购外协的正数进仓单成本价失败,'+commit_transaction.SQLErrText
  372. GOTO ext
  373. END IF
  374. //END IF
  375. //3.更新其他负数进仓单价(qty < 0 billtype <> 1 billtype <> 4)
  376. //查正数进仓
  377. SELECT isnull(sum(u_inwaremx.qty),0),
  378. isnull(sum(u_inwaremx.uqty),0),
  379. isnull(sum(u_inwaremx.costamt),0),
  380. isnull(sum(case u_inwaremx.ifvqty when 0 then 0 else u_inwaremx.qty END ),0),
  381. isnull(sum(case u_inwaremx.ifvqty when 0 then 0 else u_inwaremx.uqty END ),0),
  382. isnull(sum(round(case u_inwaremx.ifvqty when 0 then 0 else u_inwaremx.costamt END,2)),0)
  383. INTO :ld_incqty,
  384. :ld_uincqty,
  385. :ld_incamt,
  386. :ld_vincqty,
  387. :ld_uvincqty,
  388. :ld_vincamt
  389. FROM u_inware,u_inwaremx
  390. WHERE u_inware.scid = u_inwaremx.scid
  391. AND u_inware.inwareid = u_inwaremx.inwareid
  392. AND u_inwaremx.mtrlwareid = :arg_mtrlwareid
  393. AND u_inware.storageid = :arg_storageid
  394. AND u_inware.balcdateint = :ll_balcdateint_cmpl
  395. AND u_inware.flag = 1
  396. AND u_inwaremx.qty > 0
  397. Using commit_transaction;
  398. IF commit_transaction.SQLCode <> 0 THEN
  399. rslt = 0
  400. arg_msg = ls_msg+'~r~n'+'查询正数进仓信息失败,'+ls_msg+','+commit_transaction.SQLErrText
  401. GOTO ext
  402. END IF
  403. IF IsNull(ld_incqty) THEN ld_incqty = 0
  404. IF IsNull(ld_incamt) THEN ld_incamt = 0
  405. IF IsNull(ld_uincqty) THEN ld_uincqty = 0
  406. IF IsNull(ld_vincqty) THEN ld_vincqty = 0
  407. IF IsNull(ld_vincamt) THEN ld_vincamt = 0
  408. IF IsNull(ld_uvincqty) THEN ld_uvincqty = 0
  409. IF ld_bgqty + ld_incqty <> 0 And ld_bgamt + ld_incamt <> 0 THEN
  410. lde_cost_in = Round((ld_bgamt + ld_incamt) / (ld_bgqty + ld_incqty),sys_option_cost_dec)
  411. ELSE
  412. lde_cost_in = lde_planprice
  413. END IF
  414. IF lde_cost_in < 0 THEN lde_cost_in = lde_planprice
  415. UPDATE u_inwaremx
  416. SET u_inwaremx.fprice = :lde_cost_in,
  417. u_inwaremx.planprice = :lde_cost_in,
  418. u_inwaremx.price = :lde_cost_in,
  419. u_inwaremx.cost = :lde_cost_in,
  420. u_inwaremx.uprice = :lde_cost_in /u_inwaremx.rate,
  421. u_inwaremx.costamt = round(:lde_cost_in * u_inwaremx.qty, 2)
  422. FROM u_inware INNER JOIN
  423. u_inwaremx ON u_inware.scid = u_inwaremx.scid AND
  424. u_inware.inwareid = u_inwaremx.inwareid
  425. WHERE (u_inwaremx.qty < 0) AND (u_inware.billtype <> 1) AND (u_inware.billtype <> 4)
  426. AND (u_inwaremx.mtrlwareid = :arg_mtrlwareid)
  427. AND (u_inware.auditingdate > :ldt_chkdate)
  428. AND (u_inware.balcdateint = :ll_balcdateint_cmpl)
  429. Using commit_transaction;
  430. IF commit_transaction.SQLCode <> 0 THEN
  431. rslt = 0
  432. arg_msg = ls_msg+'~r~n'+'更新非采购外协的负数进仓单成本价失败,'+commit_transaction.SQLErrText
  433. GOTO ext
  434. END IF
  435. IF sys_option_buyth_use_price_update_wareamt = 0 THEN
  436. UPDATE u_inwaremx
  437. SET u_inwaremx.planprice = :lde_cost_in,
  438. u_inwaremx.cost = :lde_cost_in,
  439. u_inwaremx.costamt = round(:lde_cost_in * u_inwaremx.qty, 2)
  440. FROM u_inware INNER JOIN
  441. u_inwaremx ON u_inware.scid = u_inwaremx.scid AND
  442. u_inware.inwareid = u_inwaremx.inwareid
  443. WHERE (u_inwaremx.qty < 0) AND (u_inware.billtype = 1)
  444. AND (u_inwaremx.mtrlwareid = :arg_mtrlwareid)
  445. AND (u_inware.auditingdate > :ldt_chkdate)
  446. AND (u_inware.balcdateint = :ll_balcdateint_cmpl)
  447. Using commit_transaction;
  448. IF commit_transaction.SQLCode <> 0 THEN
  449. rslt = 0
  450. arg_msg = ls_msg+'~r~n'+'更新采购退货单成本价失败,'+commit_transaction.SQLErrText
  451. GOTO ext
  452. END IF
  453. END IF
  454. //4.更新出仓单价
  455. //查进仓
  456. SELECT isnull(sum(u_inwaremx.qty),0),
  457. isnull(sum(u_inwaremx.uqty),0),
  458. isnull(sum(u_inwaremx.costamt),0),
  459. isnull(sum(case u_inwaremx.ifvqty when 0 then 0 else u_inwaremx.qty END ),0),
  460. isnull(sum(case u_inwaremx.ifvqty when 0 then 0 else u_inwaremx.uqty END ),0),
  461. isnull(sum(case u_inwaremx.ifvqty when 0 then 0 else u_inwaremx.costamt END),0)
  462. INTO :ld_incqty,
  463. :ld_uincqty,
  464. :ld_incamt,
  465. :ld_vincqty,
  466. :ld_uvincqty,
  467. :ld_vincamt
  468. FROM u_inware,u_inwaremx
  469. WHERE u_inware.scid = u_inwaremx.scid
  470. AND u_inware.inwareid = u_inwaremx.inwareid
  471. AND u_inwaremx.mtrlwareid = :arg_mtrlwareid
  472. AND u_inware.storageid = :arg_storageid
  473. AND u_inware.balcdateint = :ll_balcdateint_cmpl
  474. AND u_inware.flag = 1
  475. Using commit_transaction;
  476. IF commit_transaction.SQLCode <> 0 THEN
  477. rslt = 0
  478. arg_msg = ls_msg+'~r~n'+'查询进仓信息失败,'+commit_transaction.SQLErrText
  479. GOTO ext
  480. END IF
  481. IF IsNull(ld_incqty) THEN ld_incqty = 0
  482. IF IsNull(ld_incamt) THEN ld_incamt = 0
  483. IF IsNull(ld_uincqty) THEN ld_uincqty = 0
  484. IF IsNull(ld_vincqty) THEN ld_vincqty = 0
  485. IF IsNull(ld_vincamt) THEN ld_vincamt = 0
  486. IF IsNull(ld_uvincqty) THEN ld_uvincqty = 0
  487. //查出仓
  488. SELECT isnull(sum(u_outwaremx.qty),0),
  489. isnull(sum(u_outwaremx.uqty),0),
  490. isnull(sum(round(u_outwaremx.costamt,2)),0),
  491. isnull(sum(case u_outwaremx.ifvqty when 0 then 0 else u_outwaremx.qty END),0),
  492. isnull(sum(case u_outwaremx.ifvqty when 0 then 0 else u_outwaremx.uqty END),0),
  493. isnull(sum(case u_outwaremx.ifvqty when 0 then 0 else u_outwaremx.costamt END),0)
  494. INTO :ld_desqty,
  495. :ld_udesqty,
  496. :ld_desamt,
  497. :ld_vdesqty,
  498. :ld_uvdesqty,
  499. :ld_vdesamt
  500. FROM u_outware,u_outwaremx
  501. WHERE u_outware.scid = u_outwaremx.scid
  502. AND u_outware.outwareid = u_outwaremx.outwareid
  503. AND u_outwaremx.mtrlwareid = :arg_mtrlwareid
  504. AND u_outware.storageid = :arg_storageid
  505. AND u_outware.balcdateint = :ll_balcdateint_cmpl
  506. AND u_outware.flag = 1
  507. Using commit_transaction;
  508. IF commit_transaction.SQLCode <> 0 THEN
  509. rslt = 0
  510. arg_msg = ls_msg+'~r~n'+'查询出仓信息失败,'+commit_transaction.SQLErrText
  511. GOTO ext
  512. END IF
  513. IF IsNull(ld_desqty) THEN ld_desqty = 0
  514. IF IsNull(ld_desamt) THEN ld_desamt = 0
  515. IF IsNull(ld_udesqty) THEN ld_udesqty = 0
  516. IF IsNull(ld_vdesqty) THEN ld_vdesqty = 0
  517. IF IsNull(ld_vdesamt) THEN ld_vdesamt = 0
  518. IF IsNull(ld_uvdesqty) THEN ld_uvdesqty = 0
  519. // SELECT count(*)
  520. // INTO :cnt
  521. // FROM u_outwaremx INNER JOIN
  522. // u_outware ON u_outwaremx.scid = u_outware.scid AND
  523. // u_outwaremx.outwareid = u_outware.outwareid
  524. // WHERE u_outwaremx.mtrlwareid = :arg_mtrlwareid
  525. // AND u_outware.storageid = :arg_storageid
  526. // AND u_outware.scid = :ll_scid_storage
  527. // AND u_outware.balcdateint = :ll_balcdateint_cmpl
  528. // AND (u_outware.auditingdate > :ldt_chkdate)
  529. // Using commit_transaction;
  530. // IF commit_transaction.SQLCode <> 0 THEN
  531. // rslt = 0
  532. // arg_msg = ls_msg+'~r~n'+'更新出仓单成本价失败,'+commit_transaction.SQLErrText
  533. // GOTO ext
  534. // END IF
  535. //
  536. // IF cnt > 0 THEN
  537. IF ld_bgqty + ld_incqty <> 0 And ld_bgamt + ld_incamt <> 0 THEN
  538. lde_cost = Round((ld_bgamt + ld_incamt) / (ld_bgqty + ld_incqty),sys_option_cost_dec)
  539. ELSE
  540. lde_cost = lde_planprice
  541. END IF
  542. IF lde_cost < 0 THEN lde_cost = lde_planprice
  543. UPDATE u_outwaremx
  544. SET u_outwaremx.cost = :lde_cost,
  545. u_outwaremx.costamt = round(u_outwaremx.qty * :lde_cost,2)
  546. FROM u_outwaremx INNER JOIN
  547. u_outware ON u_outwaremx.scid = u_outware.scid AND
  548. u_outwaremx.outwareid = u_outware.outwareid
  549. WHERE u_outwaremx.mtrlwareid = :arg_mtrlwareid
  550. AND u_outware.storageid = :arg_storageid
  551. AND u_outware.scid = :ll_scid_storage
  552. AND u_outware.balcdateint = :ll_balcdateint_cmpl
  553. AND (u_outware.auditingdate > :ldt_chkdate)
  554. Using commit_transaction;
  555. IF commit_transaction.SQLCode <> 0 THEN
  556. rslt = 0
  557. arg_msg = ls_msg+'~r~n'+'更新出仓单成本价失败,'+commit_transaction.SQLErrText
  558. GOTO ext
  559. END IF
  560. // END IF
  561. //5.更新结存(库存)金额
  562. //再读一次数,防止小数点的误差
  563. SELECT isnull(sum(round(u_outwaremx.costamt,2)),0),
  564. isnull(sum(case u_outwaremx.ifvqty when 0 then 0 else u_outwaremx.costamt END),0)
  565. INTO :ld_desamt_update, :ld_vdesamt_update
  566. FROM u_outware,u_outwaremx
  567. WHERE u_outware.scid = u_outwaremx.scid
  568. AND u_outware.outwareid = u_outwaremx.outwareid
  569. AND u_outwaremx.mtrlwareid = :arg_mtrlwareid
  570. AND u_outware.storageid = :arg_storageid
  571. AND u_outware.balcdateint = :ll_balcdateint_cmpl
  572. AND u_outware.flag = 1
  573. Using commit_transaction;
  574. IF commit_transaction.SQLCode <> 0 THEN
  575. rslt = 0
  576. arg_msg = ls_msg+'~r~n'+'重新查询本月出仓成本金额失败,'+commit_transaction.SQLErrText
  577. GOTO ext
  578. END IF
  579. //修正结余为负数; 结余数=0,结余金额<>0;的情况
  580. If (ld_bgqty + ld_incqty - ld_desqty = 0 And ld_bgamt + ld_incamt - ld_desamt_update <> 0) Or ld_bgamt + ld_incamt - ld_desamt_update < 0 THEN
  581. lde_add_desamt = ld_bgamt + ld_incamt - ld_desamt_update
  582. DECLARE outware CURSOR FOR
  583. SELECT u_outwaremx.scid, u_outwaremx.outwareid, u_outwaremx.printid, u_outwaremx.costamt
  584. FROM u_outware,u_outwaremx
  585. WHERE u_outware.scid = u_outwaremx.scid
  586. AND u_outware.outwareid = u_outwaremx.outwareid
  587. AND u_outwaremx.mtrlwareid = :arg_mtrlwareid
  588. AND u_outware.storageid = :arg_storageid
  589. AND u_outware.balcdateint = :ll_balcdateint_cmpl
  590. AND u_outware.flag = 1
  591. Using commit_transaction;
  592. OPEN outware;
  593. FETCH outware Into :ll_scid_add, :ll_outwareid_add, :ll_printid_add, :lde_costamt_add;
  594. DO WHILE commit_transaction.SQLCode = 0
  595. IF lde_add_desamt > 0 THEN
  596. lde_addamt = lde_add_desamt
  597. lde_add_desamt = 0
  598. ELSE
  599. IF lde_costamt_add > Abs(lde_add_desamt) THEN
  600. lde_addamt = lde_add_desamt
  601. lde_add_desamt = 0
  602. ELSE
  603. lde_addamt = 0 - lde_costamt_add
  604. lde_add_desamt = lde_add_desamt + lde_costamt_add
  605. END IF
  606. END IF
  607. UPDATE u_outwaremx
  608. SET costamt = costamt + :lde_addamt
  609. WHERE scid = :ll_scid_add
  610. AND outwareid = :ll_outwareid_add
  611. AND printid = :ll_printid_add
  612. Using commit_transaction;
  613. IF commit_transaction.SQLCode <> 0 THEN
  614. rslt = 0
  615. arg_msg = ls_msg+'~r~n'+"修正出仓明细金额失败,"+commit_transaction.SQLErrText
  616. GOTO ext
  617. END IF
  618. IF lde_add_desamt = 0 THEN EXIT //完成修正
  619. FETCH outware Into :ll_scid_add, :ll_outwareid_add, :ll_printid_add, :lde_costamt_add;
  620. LOOP
  621. CLOSE outware;
  622. ld_desamt_update = ld_bgamt + ld_incamt
  623. END IF
  624. ld_balcqty_update = ld_bgqty + ld_incqty - ld_desqty
  625. ld_balcamt_update = ld_bgamt + ld_incamt - ld_desamt_update
  626. IF ld_balcqty_update = 0 THEN ld_balcamt_update = 0
  627. IF ld_balcqty_update <> 0 THEN
  628. ld_newcost = Round(ld_balcamt_update/ld_balcqty_update,sys_option_cost_dec)
  629. ELSE
  630. ld_newcost = lde_planprice
  631. END IF
  632. //yyx2012-10-27_end
  633. IF li_ifunit = 0 THEN
  634. ld_ubgqty = 0
  635. ld_uincqty = 0
  636. ld_udesqty = 0
  637. END IF
  638. //更新期间出金额,结存金额
  639. UPDATE u_warebalc
  640. SET bgamt = :ld_bgamt,
  641. incamt = :ld_incamt,
  642. desamt = :ld_desamt_update,
  643. balcamt = :ld_balcamt_update,
  644. vincamt = :ld_vincamt,
  645. vdesamt = :ld_vdesamt_update
  646. WHERE mtrlwareid = :arg_mtrlwareid
  647. AND balcdateint = :ll_balcdateint_cmpl
  648. AND scid = :ll_scid_storage
  649. Using commit_transaction;
  650. IF commit_transaction.SQLCode <> 0 THEN
  651. rslt = 0
  652. arg_msg = ls_msg+'~r~n'+'更新结存失败,'+commit_transaction.SQLErrText
  653. GOTO ext
  654. END IF
  655. IF ll_balcdateint_cmpl = 0 THEN
  656. UPDATE u_mtrlware
  657. SET cost = :ld_newcost,
  658. wareamt = :ld_balcamt_update
  659. WHERE mtrlwareid = :arg_mtrlwareid
  660. AND Storageid = :arg_storageid
  661. AND scid = :ll_scid_storage
  662. Using commit_transaction;
  663. IF commit_transaction.SQLCode <> 0 THEN
  664. rslt = 0
  665. arg_msg = ls_msg+'~r~n'+'更新库存金额失败,'+commit_transaction.SQLErrText
  666. GOTO ext
  667. END IF
  668. END IF
  669. // //更新期间出金额,结存金额
  670. // UPDATE u_warebalc
  671. // SET bgqty = :ld_bgqty,
  672. // bgamt = :ld_bgamt,
  673. // incqty = :ld_incqty,
  674. // incamt = :ld_incamt,
  675. // desqty = :ld_desqty,
  676. // desamt = :ld_desamt_update,
  677. // balcqty = :ld_balcqty_update,
  678. // balcamt = :ld_balcamt_update,
  679. // ubgqty = :ld_ubgqty,
  680. // uincqty = :ld_uincqty,
  681. // udesqty = :ld_udesqty,
  682. // ubalcqty = :ld_ubgqty + :ld_uincqty - :ld_udesqty,
  683. // vincqty = :ld_vincqty,
  684. // vdesqty = :ld_vdesqty,
  685. // vincamt = :ld_vincamt,
  686. // vdesamt = :ld_vdesamt,
  687. // uvincqty = :ld_uvincqty,
  688. // uvdesqty = :ld_uvdesqty
  689. // WHERE mtrlwareid = :arg_mtrlwareid
  690. // AND balcdateint = :ll_balcdateint_cmpl
  691. // AND scid = :ll_scid_storage
  692. // Using commit_transaction;
  693. // IF commit_transaction.SQLCode <> 0 THEN
  694. // rslt = 0
  695. // arg_msg = ls_msg+'~r~n'+'更新结存失败,'+commit_transaction.SQLErrText
  696. // GOTO ext
  697. // END IF
  698. //
  699. // IF ll_balcdateint_cmpl = 0 THEN
  700. // UPDATE u_mtrlware
  701. // SET cost = :ld_newcost,
  702. // noallocqty = :ld_balcqty_update,
  703. // unoallocqty = :ld_ubgqty + :ld_uincqty - :ld_udesqty,
  704. // wareamt = :ld_balcamt_update
  705. // WHERE mtrlwareid = :arg_mtrlwareid
  706. // AND Storageid = :arg_storageid
  707. // AND scid = :ll_scid_storage
  708. // Using commit_transaction;
  709. // IF commit_transaction.SQLCode <> 0 THEN
  710. // rslt = 0
  711. // arg_msg = ls_msg+'~r~n'+'更新库存金额失败,'+commit_transaction.SQLErrText
  712. // GOTO ext
  713. // END IF
  714. // END IF
  715. ll_balcdateint_last = ll_balcdateint_cmpl //为下个循环准备
  716. NEXT
  717. ext:
  718. IF rslt = 0 THEN
  719. ROLLBACK Using commit_transaction;
  720. ELSEIF arg_ifcommit THEN
  721. COMMIT Using commit_transaction;
  722. END IF
  723. RETURN rslt
  724. end function
  725. public function integer uof_get_planprice (long arg_mtrlid, string arg_status, string arg_woodcode, string arg_pcode, ref decimal arg_planprice, ref string arg_msg);Int rslt = 1
  726. Decimal lde_planprice,ld_price_sh,ld_price_bj
  727. Int li_mtrlorigin
  728. SELECT mtrlorigin INTO :li_mtrlorigin
  729. FROM u_mtrldef
  730. WHERE u_mtrldef.mtrlid = :arg_mtrlid
  731. Using sqlca;
  732. IF sqlca.SQLCode <> 0 THEN
  733. rslt = 0
  734. arg_msg = '查询物料计划价失败,'+sqlca.SQLErrText
  735. GOTO ext
  736. END IF
  737. //采购类,如果最新价为0,取最新报价,
  738. IF li_mtrlorigin = 2 THEN
  739. SELECT top 1 v_maxprice_sptprice.price,v_maxprice_sptprice.price_bj
  740. INTO :ld_price_sh,:ld_price_bj
  741. FROM v_maxprice_sptprice
  742. WHERE v_maxprice_sptprice.mtrlid = :arg_mtrlid
  743. Using sqlca;
  744. IF sqlca.SQLCode = -1 THEN
  745. rslt = 0
  746. arg_msg = '查询采购物料最新价失败,'+sqlca.SQLErrText
  747. GOTO ext
  748. ELSEIF sqlca.SQLCode = 100 THEN
  749. lde_planprice = 0
  750. ELSEIF sqlca.SQLCode = 0 THEN
  751. IF ld_price_sh > 0 THEN
  752. lde_planprice = ld_price_sh
  753. ELSE
  754. IF ld_price_bj > 0 THEN
  755. lde_planprice = ld_price_bj
  756. ELSE
  757. lde_planprice = 0
  758. END IF
  759. END IF
  760. END IF
  761. END IF
  762. IF lde_planprice = 0 THEN
  763. SELECT top 1 dbo.f_get_planprice_mtrl(:arg_mtrlid,:arg_status,:arg_woodcode, :arg_pcode)
  764. INTO :lde_planprice
  765. FROM u_user
  766. WHERE empid = 0
  767. Using sqlca;
  768. IF sqlca.SQLCode <> 0 THEN
  769. rslt = 0
  770. arg_msg = '查询物料计划价失败,'+sqlca.SQLErrText
  771. GOTO ext
  772. END IF
  773. END IF
  774. arg_planprice = lde_planprice
  775. ext:
  776. RETURN rslt
  777. end function
  778. public function integer uof_cmpl_warebalc_amt (long cur_storageid, long ll_balcdateint_cmpl, ref string arg_msg);Long rslt = 1
  779. IF cur_storageid <= 0 THEN
  780. rslt = 0
  781. arg_msg = '请先选择仓库'
  782. RETURN rslt
  783. END IF
  784. Long cnt
  785. Long ll_i = 0
  786. Long ll_mtrlwareid, arr_mtrlwareid[]
  787. SELECT count(0)
  788. INTO :cnt
  789. FROM u_inwaremx INNER JOIN
  790. u_inware ON u_inwaremx.scid = u_inware.scid AND
  791. u_inwaremx.inwareid = u_inware.inwareid
  792. WHERE (u_inware.flag = 1)
  793. AND u_inware.balcdateint = :ll_balcdateint_cmpl
  794. AND u_inwaremx.mtrlwareid = 0
  795. And u_inware.storageid = :cur_storageid;
  796. IF sqlca.SQLCode <> 0 THEN
  797. arg_msg = '查询进仓明细库存ID失败,'+sqlca.SQLErrText
  798. rslt = 0
  799. GOTO ext
  800. END IF
  801. IF cnt > 0 THEN
  802. arg_msg = '进仓明细存在非法库存ID,请先更新进仓明细库存ID'
  803. rslt = 0
  804. GOTO ext
  805. END IF
  806. DECLARE cur1 CURSOR FOR
  807. SELECT u_warebalc.mtrlwareid
  808. FROM u_mtrldef INNER JOIN
  809. u_warebalc ON u_mtrldef.mtrlid = u_warebalc.mtrlid
  810. WHERE (u_warebalc.Storageid = :cur_storageid)
  811. And (u_warebalc.balcdateint = :ll_balcdateint_cmpl);
  812. OPEN cur1;
  813. FETCH cur1 Into :ll_mtrlwareid;
  814. DO WHILE sqlca.SQLCode = 0
  815. ll_i++
  816. arr_mtrlwareid[ll_i] = ll_mtrlwareid
  817. FETCH cur1 Into :ll_mtrlwareid;
  818. LOOP
  819. CLOSE cur1;
  820. FOR ll_i = 1 To UpperBound(arr_mtrlwareid)
  821. ll_mtrlwareid = arr_mtrlwareid[ll_i]
  822. IF uof_warebalc_cmplamt(cur_storageid, ll_balcdateint_cmpl, ll_mtrlwareid, arg_msg, True, sqlca) = 0 THEN
  823. rslt = 0
  824. GOTO ext
  825. END IF
  826. NEXT
  827. ext:
  828. RETURN rslt
  829. end function
  830. public function integer uof_warebalc_cmplamt_all (long arg_storageid, long arg_balcdateint, ref string arg_msg, boolean arg_ifcommit, transaction commit_transaction);
  831. Long rslt = 1
  832. datastore ds_cmpl
  833. IF arg_storageid = -1 THEN
  834. rslt = 0
  835. arg_msg = "请选择仓库!"
  836. GOTO ext
  837. END IF
  838. String ls_storagename
  839. ls_storagename = f_find_storageid(String(arg_storageid))
  840. Long cnt
  841. Long ll_balcdateint_cmpl = 0 //要计算的月份结存日期
  842. Long ll_balcdateint_last //= ? 前一个月份的结存日期
  843. ll_balcdateint_cmpl = arg_balcdateint //按选择, 可以重算历史
  844. Long ll_i
  845. Long ll_mtrlid,ll_mtrlwareid
  846. String ls_mtrlcode,ls_msg
  847. //ll_i = dw_pageretr.GetRow()
  848. ds_cmpl = Create datastore
  849. ds_cmpl.DataObject = 'ds_warebalc_cmpl_warebalc_amt'
  850. ds_cmpl.SetTransObject(sqlca)
  851. SELECT count(*)
  852. INTO :cnt
  853. FROM u_inwaremx INNER JOIN
  854. u_inware ON u_inwaremx.scid = u_inware.scid AND
  855. u_inwaremx.inwareid = u_inware.inwareid
  856. WHERE (u_inware.flag = 1)
  857. AND u_inware.balcdateint = :ll_balcdateint_cmpl
  858. AND u_inwaremx.mtrlwareid = 0
  859. And u_inware.storageid = :arg_storageid;
  860. IF sqlca.SQLCode <> 0 THEN
  861. arg_msg = '查询进仓明细库存ID失败,'+sqlca.SQLErrText
  862. rslt = 0
  863. GOTO ext
  864. END IF
  865. IF cnt > 0 THEN
  866. arg_msg = '进仓明细存在非法库存ID,请先更新进仓明细库存ID'
  867. rslt = 0
  868. GOTO ext
  869. END IF
  870. //清空筛选内容
  871. cnt = ds_cmpl.Retrieve(arg_storageid,ll_balcdateint_cmpl,sys_option_cost_dec)
  872. //
  873. String ls_status, ls_woodcode, ls_pcode
  874. FOR ll_i = 1 To ds_cmpl.RowCount()
  875. ll_mtrlid = ds_cmpl.Object.u_mtrldef_mtrlid[ll_i]
  876. ll_mtrlwareid = ds_cmpl.Object.u_warebalc_mtrlwareid[ll_i]
  877. ls_mtrlcode = ds_cmpl.Object.u_mtrldef_mtrlcode[ll_i]
  878. ls_status = ds_cmpl.Object.u_warebalc_status[ll_i]
  879. ls_woodcode = ds_cmpl.Object.u_warebalc_woodcode[ll_i]
  880. ls_pcode = ds_cmpl.Object.u_warebalc_pcode[ll_i]
  881. ls_msg = '物料:'+ls_mtrlcode+',库存id:'+String(ll_mtrlwareid)
  882. IF ls_status <> "" THEN
  883. ls_msg += ','+sys_option_change_status+':'+ls_status
  884. END IF
  885. IF ls_woodcode <> "" THEN
  886. ls_msg += ','+sys_option_change_woodcode+':'+ls_woodcode
  887. END IF
  888. IF ls_pcode <> "" THEN
  889. ls_msg += ','+sys_option_change_pcode+':'+ls_pcode
  890. END IF
  891. IF uof_warebalc_cmplamt(arg_storageid, ll_balcdateint_cmpl, ll_mtrlwareid, arg_msg, false, commit_transaction) = 0 THEN
  892. rslt = 0
  893. GOTO ext
  894. END IF
  895. NEXT
  896. ext:
  897. Destroy ds_cmpl
  898. IF rslt = 0 THEN
  899. ROLLBACK Using commit_transaction;
  900. ELSEIF arg_ifcommit THEN
  901. COMMIT Using commit_transaction;
  902. END IF
  903. RETURN rslt
  904. end function
  905. on uo_warebalc_cmpl.create
  906. call super::create
  907. TriggerEvent( this, "constructor" )
  908. end on
  909. on uo_warebalc_cmpl.destroy
  910. TriggerEvent( this, "destructor" )
  911. call super::destroy
  912. end on
  913. event constructor;String arg_msg
  914. String str_optionvalue
  915. str_optionvalue = ''
  916. f_get_sys_option_value('152',str_optionvalue,arg_msg)
  917. uo_option_warebalc_checksale = Long(str_optionvalue)
  918. str_optionvalue = ''
  919. f_get_sys_option_value('057',str_optionvalue,arg_msg)
  920. uo_option_wkpmtrlware = Long(str_optionvalue)
  921. end event