f_getcusrepamt_info.srf 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. $PBExportHeader$f_getcusrepamt_info.srf
  2. global type f_getcusrepamt_info from function_object
  3. end type
  4. forward prototypes
  5. global function integer f_getcusrepamt_info (long arg_scid, long arg_cusid, long arg_moneyid, ref decimal arg_cusbalcamt, ref decimal arg_cusmaxamt, ref decimal arg_outrep_balcamt, ref decimal arg_outrep_maxamt)
  6. end prototypes
  7. global function integer f_getcusrepamt_info (long arg_scid, long arg_cusid, long arg_moneyid, ref decimal arg_cusbalcamt, ref decimal arg_cusmaxamt, ref decimal arg_outrep_balcamt, ref decimal arg_outrep_maxamt);//f_getcusrepamt_info(arg_cusid,arg_cusbalcamt,arg_cusmaxamt,arg_outrep_balcamt,arg_outrep_maxamt)
  8. Long rslt = 1
  9. Decimal cusamt,cusmaxamt,outrep_amt,outrep_maxamt,rep_cus_count
  10. String custype
  11. IF sys_option_scid_msttake_mstpay = 1 THEN
  12. SELECT u_cust.custype,
  13. u_cust.maxmtnum,
  14. isnull(v_cus_balcamt.cus_balcamt ,0)
  15. INTO :custype,:cusmaxamt,:cusamt
  16. FROM u_cust left OUTER join
  17. v_cus_balcamt on u_cust.cusid = v_cus_balcamt.cusid
  18. WHERE ( u_cust.cusid = :arg_cusid )
  19. AND isnull(v_cus_balcamt.scid,0) = :arg_scid
  20. And IsNull(v_cus_balcamt.moneyid,0) = :arg_moneyid;
  21. IF sqlca.SQLCode <> 0 THEN
  22. rslt = 0
  23. GOTO ext
  24. END IF
  25. SELECT u_outrepdef.maxamt,
  26. count(v_cus_balcamt.cus_balcamt) as rep_cus_count,
  27. sum(v_cus_balcamt.cus_balcamt) as outrep_balcamt
  28. INTO :outrep_maxamt,
  29. :rep_cus_count,
  30. :outrep_amt
  31. FROM u_cust,
  32. v_cus_balcamt,
  33. u_outrepdef
  34. WHERE ( u_cust.cusid = v_cus_balcamt.cusid )
  35. AND ( u_cust.custype = u_outrepdef.outrepname)
  36. AND ( u_cust.custype = :custype )
  37. AND isnull(v_cus_balcamt.scid ,0) = :arg_scid
  38. AND isnull(v_cus_balcamt.moneyid ,0) = :arg_moneyid
  39. Group By u_cust.custype ,u_outrepdef.maxamt;
  40. IF sqlca.SQLCode <> 0 THEN
  41. // rslt = 0
  42. // GOTO ext
  43. outrep_maxamt = 0
  44. rep_cus_count = 0
  45. outrep_amt = 0
  46. END IF
  47. ELSE
  48. SELECT u_cust.custype,
  49. u_cust.maxmtnum,
  50. sum(v_cus_balcamt.cus_balcamt)
  51. INTO :custype,:cusmaxamt,:cusamt
  52. FROM u_cust,
  53. v_cus_balcamt
  54. WHERE ( u_cust.cusid = v_cus_balcamt.cusid ) AND
  55. ( u_cust.cusid = :arg_cusid ) AND
  56. ( v_cus_balcamt.moneyid = :arg_moneyid)
  57. Group By u_cust.custype,u_cust.maxmtnum;
  58. IF sqlca.SQLCode <> 0 THEN
  59. rslt = 0
  60. GOTO ext
  61. END IF
  62. SELECT u_outrepdef.maxamt,
  63. count(v_cus_balcamt.cus_balcamt) as rep_cus_count,
  64. sum(v_cus_balcamt.cus_balcamt) as outrep_balcamt
  65. INTO :outrep_maxamt,
  66. :rep_cus_count,
  67. :outrep_amt
  68. FROM u_cust,
  69. v_cus_balcamt,
  70. u_outrepdef
  71. WHERE ( u_cust.cusid = v_cus_balcamt.cusid )
  72. AND ( u_cust.custype = u_outrepdef.outrepname)
  73. AND ( u_cust.custype = :custype )
  74. AND isnull(v_cus_balcamt.moneyid ,0) = :arg_moneyid
  75. Group By u_cust.custype ,u_outrepdef.maxamt;
  76. IF sqlca.SQLCode <> 0 THEN
  77. // rslt = 0
  78. // GOTO ext
  79. outrep_maxamt = 0
  80. rep_cus_count = 0
  81. outrep_amt = 0
  82. END IF
  83. END IF
  84. IF IsNull(cusamt) THEN cusamt = 0
  85. IF IsNull(cusmaxamt) THEN cusmaxamt = 0
  86. IF IsNull(outrep_amt) THEN outrep_amt = 0
  87. IF IsNull(outrep_maxamt) THEN outrep_maxamt = 0
  88. arg_cusbalcamt = cusamt
  89. arg_cusmaxamt = cusmaxamt
  90. arg_outrep_balcamt = outrep_amt
  91. arg_outrep_maxamt = outrep_maxamt
  92. rslt = rep_cus_count
  93. ext:
  94. RETURN rslt
  95. end function