uo_cmplcost.sru 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. $PBExportHeader$uo_cmplcost.sru
  2. forward
  3. global type uo_cmplcost from nonvisualobject
  4. end type
  5. end forward
  6. global type uo_cmplcost from nonvisualobject
  7. end type
  8. global uo_cmplcost uo_cmplcost
  9. type variables
  10. long deep = 0
  11. boolean ifcmpl_1 = false
  12. end variables
  13. forward prototypes
  14. public function integer uof_get_wageprice (long arg_mtrlid, string arg_mtrlcode, decimal arg_qty, ref decimal arg_wageprice, ref string arg_msg)
  15. public function integer uof_get_cost (long arg_scid, long arg_mtrlid, string arg_mtrlcode, string arg_pfcode, decimal arg_qty, long arg_lp, ref decimal arg_price, ref decimal arg_mprice, ref decimal arg_outcost, ref decimal arg_wageprice, ref string arg_msg)
  16. public function integer uof_get_f_price (long arg_mtrlid, string arg_mtrlcode, decimal arg_qty, ref decimal arg_f_price, ref string arg_msg)
  17. end prototypes
  18. public function integer uof_get_wageprice (long arg_mtrlid, string arg_mtrlcode, decimal arg_qty, ref decimal arg_wageprice, ref string arg_msg);int rslt = 1
  19. decimal ld_wageprice
  20. SELECT sum(workprice * u_sc_workprice.workqty) INTO :ld_wageprice
  21. FROM u_sc_workprice
  22. WHERE ifownpro = 0
  23. AND mtrlid = :arg_mtrlid;
  24. IF sqlca.SQLCode = -1 THEN
  25. arg_msg = '查询物料:'+arg_mtrlcode+'本厂工价失败'
  26. rslt = 0
  27. GOTO ext
  28. END IF
  29. IF IsNull(ld_wageprice) THEN ld_wageprice = 0
  30. arg_wageprice = ld_wageprice * arg_qty
  31. ext:
  32. return rslt
  33. end function
  34. public function integer uof_get_cost (long arg_scid, long arg_mtrlid, string arg_mtrlcode, string arg_pfcode, decimal arg_qty, long arg_lp, ref decimal arg_price, ref decimal arg_mprice, ref decimal arg_outcost, ref decimal arg_wageprice, ref string arg_msg);Int rslt = 1
  35. Decimal Sonscale,SonLoss,SonDECLosS
  36. Long SonMtrlid,count = 0,ls_i
  37. String mtrlcode, mtrlname
  38. s_pfmx ls_s_pfmx[]
  39. Decimal ld_price,ld_qty,ld_outcost,ld_wageprice
  40. Decimal ld_planprice
  41. Int li_mtrlorigin
  42. Long ll_scid
  43. deep++
  44. IF deep > 10000 THEN //防止死递归
  45. arg_msg = '物料:'+arg_mtrlcode+'死循环'
  46. rslt = 0
  47. GOTO ext
  48. END IF
  49. DECLARE pf_cur CURSOR FOR
  50. SELECT u_PrdPF.Sonscale,
  51. u_PrdPF.SonLoss,
  52. u_PrdPF.SonDECLosS,
  53. u_PrdPF.SonMtrlid,
  54. u_mtrldef.mtrlcode,
  55. :arg_pfcode
  56. FROM u_PrdPF,
  57. u_mtrldef
  58. WHERE ( u_PrdPF.SonMtrlid = u_mtrldef.mtrlid ) AND
  59. ( u_PrdPF.mtrlid = :arg_mtrlid ) AND
  60. ( u_PrdPF.pfcode = :arg_pfcode );
  61. OPEN pf_cur;
  62. count = 1
  63. FETCH pf_cur INTO :ls_s_pfmx[count].Sonscale,:ls_s_pfmx[count].SonLoss,&
  64. :ls_s_pfmx[count].SonDECLosS,:ls_s_pfmx[count].SonMtrlid,&
  65. :ls_s_pfmx[count].mtrlcode,:ls_s_pfmx[count].sonpfcode;
  66. DO WHILE sqlca.SQLCode = 0
  67. count++
  68. FETCH pf_cur INTO :ls_s_pfmx[count].Sonscale,:ls_s_pfmx[count].SonLoss,&
  69. :ls_s_pfmx[count].SonDECLosS,:ls_s_pfmx[count].SonMtrlid,&
  70. :ls_s_pfmx[count].mtrlcode,:ls_s_pfmx[count].sonpfcode;
  71. LOOP
  72. count = count - 1
  73. CLOSE pf_cur;
  74. //***查询最新采购价
  75. IF arg_lp > 1 OR ifcmpl_1 THEN
  76. SELECT mtrlorigin, planprice
  77. INTO :li_mtrlorigin, :ld_planprice
  78. FROM u_mtrldef
  79. Where mtrlid = :arg_mtrlid;
  80. IF sqlca.SQLCode <> 0 THEN
  81. MessageBox(publ_operator,'查询:'+arg_mtrlcode+'来源失败')
  82. rslt = 0
  83. GOTO ext
  84. END IF
  85. CHOOSE CASE li_mtrlorigin
  86. CASE 2,3
  87. SELECT price INTO :ld_price
  88. FROM v_maxprice_sptprice
  89. Where mtrlid = :arg_mtrlid;
  90. IF sqlca.SQLCode = -1 THEN
  91. arg_msg = '查询物料:'+arg_mtrlcode+'最新采购价或最新外加工单价失败'
  92. rslt = 0
  93. GOTO ext
  94. END IF
  95. IF IsNull(ld_price) THEN ld_price = 0
  96. IF li_mtrlorigin = 3 THEN
  97. arg_mprice = arg_mprice + ld_price * arg_qty
  98. END IF
  99. IF li_mtrlorigin = 2 AND count = 0 THEN
  100. arg_price = arg_price + ld_price * arg_qty
  101. rslt = 1
  102. GOTO ext
  103. END IF
  104. CASE 0
  105. IF arg_scid <> ll_scid THEN
  106. arg_price = arg_price + ld_planprice * arg_qty
  107. rslt = 1
  108. GOTO ext
  109. ELSE
  110. //计算分摊费用
  111. IF uof_get_f_price(arg_mtrlid,arg_mtrlcode,arg_qty,ld_outcost,arg_msg) = 0 THEN
  112. rslt = 0
  113. GOTO ext
  114. END IF
  115. arg_outcost = arg_outcost + ld_outcost
  116. //计算人工
  117. IF uof_get_wageprice(arg_mtrlid,arg_mtrlcode,arg_qty,ld_wageprice,arg_msg) = 0 THEN
  118. rslt = 0
  119. GOTO ext
  120. END IF
  121. arg_wageprice = arg_wageprice + ld_wageprice
  122. END IF
  123. END CHOOSE
  124. END IF
  125. FOR ls_i = 1 TO count
  126. ld_qty = round(arg_qty * (ls_s_pfmx[ls_i].Sonscale / (1 - ls_s_pfmx[ls_i].SonLoss) + ls_s_pfmx[ls_i].SonDECLosS),sys_option_produce_dec)
  127. IF uof_get_cost(arg_scid,ls_s_pfmx[ls_i].SonMtrlid,ls_s_pfmx[ls_i].mtrlcode,ls_s_pfmx[ls_i].sonpfcode,ld_qty,arg_lp+1,arg_price,arg_mprice,arg_outcost,arg_wageprice,arg_msg) = 0 THEN
  128. rslt = 0
  129. GOTO ext
  130. END IF
  131. NEXT
  132. ext:
  133. RETURN rslt
  134. end function
  135. public function integer uof_get_f_price (long arg_mtrlid, string arg_mtrlcode, decimal arg_qty, ref decimal arg_f_price, ref string arg_msg);Int rslt = 1
  136. Decimal ld_f_rice
  137. SELECT isnull(sum(u_mtrl_cost.cost),0) INTO :ld_f_rice
  138. FROM u_mtrl_cost
  139. Where u_mtrl_cost.mtrlid = :arg_mtrlid;
  140. IF sqlca.SQLCode = -1 THEN
  141. // arg_msg = '查询:'+arg_mtrlcode+'分摊费用成本失败,'+sqlca.sqlerrtext
  142. // rslt = 0
  143. // GOTO ext
  144. ld_f_rice = 0
  145. END IF
  146. IF IsNull(arg_f_price) THEN arg_f_price = 0
  147. arg_f_price = ld_f_rice * arg_qty
  148. //ext:
  149. RETURN rslt
  150. end function
  151. on uo_cmplcost.create
  152. call super::create
  153. TriggerEvent( this, "constructor" )
  154. end on
  155. on uo_cmplcost.destroy
  156. TriggerEvent( this, "destructor" )
  157. call super::destroy
  158. end on