#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    9
    Rep Power
    0

    Need help with delphi script for Report


    Hello, I'm new to this forum, i have been slowly getting my head around Delphi. Although I have only started getting very simple things worked out. This one has really tested me, and I think i'm going in circles now without a clue.
    Any help would be Greatly Appreciated.

    Situation: I have been trying to get a report to show me a prompt payment discount amount from a invoice, which I can display on the report.

    Task 1: Is to only give the discount within 10 days of the Transdate.
    Thats my first problem, I don't know if there is a symbol or something i can use in the code for within a period of time.

    Task 2: Is then, if it falls within that 10 day period of time it gets its discount from a field in our system called master['PROMPTPAY_PC']. Which i would give me the amount to show on the report.


    What i started with is below.
    If there are any suggestions/ directions im all ears.

    begin
    IF Lines['Transdate'] + 10
    then Lines['Amount']- (master['PROMPTPAY_PC']*Lines['Amount'])
    end;
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    352
    Rep Power
    7
    For the first part of your problem, you can use the DaysBetween function that is part of the DateUtils unit.

    You can read about it here . Remember to add DateUtils to your uses clause.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    9
    Rep Power
    0
    Thanks for the link, this bit is completely new to me.
    So i have to get my head around how it works.
    Any hints on how to read it would be great.. meanwhile ill keep googling for answers.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    352
    Rep Power
    7
    I'm not sure I understand what Lines['Transdate'] is, so it's hard for me to give you actual code that will work. If the date you want to test is held in Lines['Transdate'], and assuming it is of type TDateTime (hold both the date and time) and assuming you want to test if that date and time is within 10 days of the current date and time, then you would use the function I linked like so:
    Code:
    if DaysBetween(Now, Lines['Transdate']) <= 10 then
    begin
      //do what you would if within the 10 days.
      //BTW, the function "Now" returns the current Date and Time
      //while the function "Date" returns the current Date
    end;
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    9
    Rep Power
    0
    Hi majlumbo
    Yes the Transdate is just the date, which is on the order.
    So i should then change Now to Date. Correct?

    if DaysBetween(Date, Lines['Transdate']) <= 10 then
    begin
    //do what you would if within the 10 days.
    //BTW, the function "Now" returns the current Date and Time
    //while the function "Date" returns the current Date
    end;

    Thanks for the heads up, will let you know how i go.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    9
    Rep Power
    0
    I feel like im close just getting errors still.

    If DaysBetween(Date, Lines['Transdate'])<=10 then
    Lines['Amount']-( Lines['Amount']* master['PROMPTPAY_PC'])
    := Value


    The error I get is Variable1oncalc, Line1: incompatible types.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    352
    Rep Power
    7
    Originally Posted by Tymar
    I feel like im close just getting errors still.

    If DaysBetween(Date, Lines['Transdate'])<=10 then
    Lines['Amount']-( Lines['Amount']* master['PROMPTPAY_PC'])
    := Value


    The error I get is Variable1oncalc, Line1: incompatible types.
    The function is expecting you to pass it TWO variables declared as TDATETIME, since, as I mentioned in my previous post, I don't understand what "Lines['Transdate']" is, my guess would be that it is NOT a variable declared as TDATETIME.

IMN logo majestic logo threadwatch logo seochat tools logo