f_cmp_di_qty.srf 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. $PBExportHeader$f_cmp_di_qty.srf
  2. global type f_cmp_di_qty from function_object
  3. end type
  4. forward prototypes
  5. global function integer f_cmp_di_qty (long arg_mtrlid, long arg_storageid, string arg_status, ref decimal arg_ref_qty, ref string arg_lsg, ref string arg_msg)
  6. end prototypes
  7. global function integer f_cmp_di_qty (long arg_mtrlid, long arg_storageid, string arg_status, ref decimal arg_ref_qty, ref string arg_lsg, ref string arg_msg);Int rslt = 1
  8. Long ll_SonMtrlid[]
  9. String ls_pf_status[],ls_status_find
  10. Decimal ld_Sonscale[]
  11. Long it_mxt = 1
  12. Decimal ld_qty
  13. Long ll_i,ll_row
  14. DECLARE cur_pf CURSOR FOR
  15. SELECT u_PrdPF.SonMtrlid,
  16. u_PrdPF.Sonscale,
  17. u_PrdPF.status
  18. FROM u_PrdPF
  19. Where u_PrdPF.mtrlid = :arg_mtrlid;
  20. OPEN cur_pf;
  21. FETCH cur_pf Into :ll_SonMtrlid[it_mxt],:ld_Sonscale[it_mxt],:ls_pf_status[it_mxt];
  22. DO WHILE sqlca.SQLCode = 0
  23. it_mxt++
  24. FETCH cur_pf Into :ll_SonMtrlid[it_mxt],:ld_Sonscale[it_mxt],:ls_pf_status[it_mxt];
  25. LOOP
  26. it_mxt = it_mxt - 1
  27. CLOSE cur_pf;
  28. IF it_mxt = 0 THEN
  29. rslt = 0
  30. arg_msg = '该产品没有建立组装结构,不能计算'
  31. GOTO ext
  32. END IF
  33. String ls_mtrlcode,ls_mtrlname
  34. Decimal ld_noallocqty,ld_allqty,ld_maxqty
  35. ld_maxqty = 1000000
  36. FOR ll_i = 1 To it_mxt
  37. SELECT mtrlcode,
  38. mtrlname
  39. INTO :ls_mtrlcode,
  40. :ls_mtrlname
  41. FROM u_mtrldef
  42. Where mtrlid = :ll_SonMtrlid[ll_i];
  43. IF sqlca.SQLCode <> 0 THEN
  44. rslt = 0
  45. arg_msg = '查询产品资料失败'
  46. GOTO ext
  47. END IF
  48. IF sys_option_if_color = 1 THEN
  49. ls_status_find = arg_status
  50. ELSE
  51. ls_status_find = ls_pf_status[ll_i]
  52. END IF
  53. ld_noallocqty = 0
  54. ld_allqty = 0
  55. SELECT sum(noallocqty) INTO :ld_noallocqty
  56. FROM u_mtrlware
  57. WHERE (storageid = :arg_storageid OR :arg_storageid = -1)
  58. AND mtrlid = :ll_SonMtrlid[ll_i]
  59. And status = :ls_status_find;
  60. IF sqlca.SQLCode <> 0 THEN
  61. rslt = 0
  62. arg_msg = '查询该产品组装材料'+ls_mtrlname+'的库存资料失败'
  63. GOTO ext
  64. END IF
  65. ld_allqty = ld_noallocqty/ld_Sonscale[ll_i]
  66. ld_maxqty = Min(ld_maxqty,ld_allqty)
  67. IF IsNull(ld_maxqty) THEN ld_maxqty = 0
  68. NEXT
  69. ld_qty = Truncate ( ld_maxqty, 0 )
  70. arg_lsg = '可装货数量:'+String(ld_qty,'#,##0.####')
  71. arg_ref_qty = ld_qty
  72. ext:
  73. RETURN rslt
  74. end function