f_cmp_fifo_warebalc.srf 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. $PBExportHeader$f_cmp_fifo_warebalc.srf
  2. global type f_cmp_fifo_warebalc from function_object
  3. end type
  4. forward prototypes
  5. global function integer f_cmp_fifo_warebalc (long arg_scid, long arg_mtrlwareid, boolean arg_ifcommit, ref transaction commit_transaction, ref string arg_msg)
  6. end prototypes
  7. global function integer f_cmp_fifo_warebalc (long arg_scid, long arg_mtrlwareid, boolean arg_ifcommit, ref transaction commit_transaction, ref string arg_msg);Long rslt = 1
  8. Long ll_i
  9. Decimal ld_newcost // 最新成本价
  10. Decimal ld_bgqty,ld_bgamt,ld_incqty,ld_incamt,ld_desqty,ld_desamt
  11. Decimal ld_balcqty,ld_balcamt
  12. Long ll_mtrlid
  13. String ls_status,ls_pcode,ls_woodcode
  14. String ls_mtrlcode
  15. Decimal ld_noallocqty,ld_wareamt
  16. Decimal ld_noallocqty_sum,ld_wareamt_sum
  17. Long ll_sptid
  18. decimal ld_incamt_notax,ld_desamt_notax,ld_wareamt_notax
  19. Long cur_storageid
  20. //
  21. ////结存查库存
  22. //库存计结存
  23. Long cnt,ll_scid
  24. datastore ds_mtrlware
  25. SELECT storageid INTO :cur_storageid
  26. From u_mtrlware Where scid = :arg_scid And mtrlwareid = :arg_mtrlwareid Using commit_transaction;
  27. ds_mtrlware = Create datastore
  28. ds_mtrlware.DataObject = 'ds_warebalc_view_cmpl_mtrlware_to_balc3' //ds_warebalc_view_cmpl_mtrlware_to_balc2
  29. ds_mtrlware.SetTransObject( commit_transaction)
  30. ds_mtrlware.Retrieve(cur_storageid,arg_scid,arg_mtrlwareid) //
  31. ds_mtrlware.AcceptText()
  32. //IF ld_noallocqty_sum <> ds_mtrlware.Object.sumqty[1] OR &
  33. // ld_wareamt_sum <> ds_mtrlware.Object.sumamt[1] THEN
  34. SELECT scid INTO :ll_scid
  35. FROM u_storage
  36. Where storageid = :cur_storageid Using commit_transaction;
  37. IF commit_transaction.SQLCode <> 0 THEN
  38. rslt = 0
  39. arg_msg = '查询仓库所属分部失败'
  40. GOTO ext
  41. END IF
  42. FOR ll_i = 1 To ds_mtrlware.RowCount()
  43. ll_mtrlid = 0
  44. ls_mtrlcode = ''
  45. ls_status = ''
  46. ls_woodcode = ''
  47. ls_pcode = ''
  48. ld_noallocqty = 0
  49. ld_wareamt = 0
  50. ll_sptid = 0
  51. cnt = 0
  52. ls_mtrlcode = ds_mtrlware.Object.u_mtrldef_mtrlcode[ll_i]
  53. ll_mtrlid = ds_mtrlware.Object.mtrlid[ll_i]
  54. ls_status = ds_mtrlware.Object.status[ll_i]
  55. ls_woodcode = ds_mtrlware.Object.woodcode[ll_i]
  56. ls_pcode = ds_mtrlware.Object.pcode[ll_i]
  57. ld_noallocqty = ds_mtrlware.Object.qty[ll_i]
  58. ld_wareamt = ds_mtrlware.Object.amt[ll_i]
  59. ll_sptid = ds_mtrlware.Object.u_mtrlware_sptid[ll_i]
  60. ld_wareamt_notax = ds_mtrlware.Object.amt_notax[ll_i]
  61. SELECT sum(Round(u_inwaremx.qty * u_inwaremx.cost,2)) ,
  62. sum(u_inwaremx.qty),
  63. sum(Round(u_inwaremx.qty * u_inwaremx.cost_notax,2))
  64. INTO :ld_incamt,:ld_incqty,:ld_incamt_notax
  65. FROM u_inwaremx,u_inware
  66. WHERE u_inwaremx.scid = u_inware.scid
  67. AND u_inwaremx.inwareid = u_inware.inwareid
  68. AND u_inware.storageid = :cur_storageid
  69. AND u_inware.balcdateint = 0
  70. AND u_inwaremx.mtrlid = :ll_mtrlid
  71. AND u_inwaremx.status = :ls_status
  72. AND u_inwaremx.woodcode = :ls_woodcode
  73. AND u_inwaremx.pcode = :ls_pcode
  74. AND u_inwaremx.sptid_cusid = :ll_sptid
  75. And u_inware.flag = 1 Using commit_transaction;
  76. IF commit_transaction.SQLCode <> 0 THEN
  77. rslt = 0
  78. arg_msg = '查询进仓失败,物料:'+ls_mtrlcode+','+sys_option_change_status+':'+ls_status+','+sys_option_change_woodcode+':'+ls_woodcode+','+sys_option_change_pcode+':'+ls_pcode
  79. GOTO ext
  80. END IF
  81. SELECT sum(u_outwaremx.costamt) ,
  82. sum(u_outwaremx.qty),
  83. sum(Round(u_outwaremx.qty * u_outwaremx.cost_notax,2))
  84. INTO :ld_desamt,:ld_desqty,:ld_desamt_notax
  85. FROM u_outwaremx,u_outware
  86. WHERE u_outwaremx.scid = u_outware.scid
  87. AND u_outwaremx.outwareid = u_outware.outwareid
  88. AND u_outware.storageid = :cur_storageid
  89. AND u_outware.balcdateint = 0
  90. AND u_outwaremx.mtrlid = :ll_mtrlid
  91. AND u_outwaremx.status = :ls_status
  92. AND u_outwaremx.woodcode = :ls_woodcode
  93. AND u_outwaremx.pcode = :ls_pcode
  94. AND u_outwaremx.sptid = :ll_sptid
  95. And u_outware.flag = 1 Using commit_transaction;
  96. IF commit_transaction.SQLCode <> 0 THEN
  97. rslt = 0
  98. arg_msg = '查询出仓失败,物料:'+ls_mtrlcode+','+sys_option_change_status+':'+ls_status+','+sys_option_change_woodcode+':'+ls_woodcode+','+sys_option_change_pcode+':'+ls_pcode
  99. GOTO ext
  100. END IF
  101. IF IsNull(ld_desqty) THEN ld_desqty = 0
  102. IF IsNull(ld_incqty) THEN ld_incqty = 0
  103. IF IsNull(ld_desamt) THEN ld_desamt = 0
  104. IF IsNull(ld_incamt) THEN ld_incamt = 0
  105. IF IsNull(ld_desamt_notax) THEN ld_desamt_notax = 0
  106. IF IsNull(ld_incamt_notax) THEN ld_incamt_notax = 0
  107. UPDATE u_warebalc
  108. SET balcqty = :ld_noallocqty,
  109. balcamt = :ld_wareamt,
  110. balcamt_notax = :ld_wareamt_notax,
  111. bgqty = :ld_noallocqty + :ld_desqty - :ld_incqty,
  112. bgamt = :ld_wareamt + :ld_desamt - :ld_incamt,
  113. bgamt_notax = :ld_wareamt_notax + :ld_desamt_notax - :ld_incamt_notax,
  114. incqty = :ld_incqty,
  115. incamt = :ld_incamt,
  116. incamt_notax = :ld_incamt_notax,
  117. desqty = :ld_desqty,
  118. desamt = :ld_desamt,
  119. desamt_notax = :ld_desamt_notax
  120. WHERE mtrlid = :ll_mtrlid
  121. AND balcdateint = 0
  122. AND Storageid = :cur_storageid
  123. AND status = :ls_status
  124. AND woodcode = :ls_woodcode
  125. AND pcode = :ls_pcode
  126. And sptid_cusid = :ll_sptid Using commit_transaction;
  127. IF commit_transaction.SQLCode <> 0 THEN
  128. rslt = 0
  129. arg_msg = '更新结存失败,物料:'+ls_mtrlcode+','+sys_option_change_status+':'+ls_status+','+sys_option_change_woodcode+':'+ls_woodcode+','+sys_option_change_pcode+':'+ls_pcode+" "+sqlca.sqlerrtext
  130. GOTO ext
  131. ELSEIF commit_transaction.SQLNRows = 0 THEN
  132. INSERT INTO u_warebalc
  133. (scid,
  134. balcdateint,
  135. storageid,
  136. mtrlid,
  137. status,
  138. woodcode,
  139. pcode,
  140. bgqty,
  141. bgamt,
  142. incqty,
  143. incamt,
  144. desqty,
  145. desamt,
  146. balcqty,
  147. balcamt,
  148. sptid_cusid,
  149. balcamt_notax,
  150. bgamt_notax,
  151. incamt_notax,
  152. desamt_notax)
  153. VALUES
  154. (:sys_scid,0,
  155. :cur_storageid,
  156. :ll_mtrlid,
  157. :ls_status,
  158. :ls_woodcode,
  159. :ls_pcode,
  160. :ld_noallocqty + :ld_desqty - :ld_incqty,
  161. :ld_wareamt + :ld_desamt - :ld_incamt,
  162. :ld_incqty,
  163. :ld_incamt,
  164. :ld_desqty,
  165. :ld_desamt,
  166. :ld_noallocqty,
  167. :ld_wareamt,
  168. :ll_sptid,
  169. :ld_wareamt_notax,
  170. :ld_wareamt_notax + :ld_desamt_notax - :ld_incamt_notax,
  171. :ld_incamt_notax,
  172. :ld_desamt_notax) Using commit_transaction;
  173. IF commit_transaction.SQLCode <> 0 THEN
  174. rslt = 0
  175. arg_msg = '新加结存失败,物料:'+ls_mtrlcode+','+sys_option_change_status+':'+ls_status+','+sys_option_change_woodcode+':'+ls_woodcode+','+sys_option_change_pcode+':'+ls_pcode
  176. GOTO ext
  177. END IF
  178. END IF
  179. NEXT
  180. //END IF
  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 ds_mtrlware
  188. RETURN rslt
  189. end function