f_findspt_paydate.srf 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. $PBExportHeader$f_findspt_paydate.srf
  2. global type f_findspt_paydate from function_object
  3. end type
  4. forward prototypes
  5. global function datetime f_findspt_paydate (long arg_sptid, datetime arg_indate)
  6. end prototypes
  7. global function datetime f_findspt_paydate (long arg_sptid, datetime arg_indate);Int rslt = 1
  8. String ls_paydate_style
  9. Date ld_paydate
  10. String ls_now_nextmonth
  11. Long ll_days
  12. Int thismonth,nextmonth,nextyear
  13. SELECT u_plandate_style.dscrp
  14. INTO :ls_paydate_style
  15. FROM u_plandate_style INNER JOIN
  16. u_spt ON u_plandate_style.styleid = u_spt.styleid
  17. Where u_spt.sptid = :arg_sptid;
  18. IF sqlca.SQLCode <> 0 THEN
  19. rslt = 0
  20. GOTO ext
  21. END IF
  22. ls_paydate_style = Trim(ls_paydate_style)
  23. ld_paydate = Date(String(arg_indate,'yyyy-mm-dd'))
  24. ls_now_nextmonth = Mid(ls_paydate_style,1,Pos(ls_paydate_style,'+') - 1)
  25. ll_days = Long(Mid(ls_paydate_style,Pos(ls_paydate_style,'+') + 1))
  26. IF ls_now_nextmonth = 'now' THEN
  27. else
  28. thismonth = Month(ld_paydate)
  29. nextyear = Year(ld_paydate)
  30. IF thismonth = 12 THEN
  31. nextyear++
  32. nextmonth = 1
  33. ELSE
  34. nextmonth = thismonth + 1
  35. END IF
  36. ld_paydate = Date(nextyear,nextmonth,1)
  37. END IF
  38. ld_paydate = RelativeDate ( ld_paydate, ll_days - 1)
  39. ext:
  40. IF rslt = 0 THEN
  41. SetNull(ld_paydate)
  42. END IF
  43. RETURN DateTime(ld_paydate)
  44. end function