2 Replies Latest reply on Feb 22, 2011 12:14 PM by gsolorio

    Need Help with a Complex Calculated Script

    gsolorio

      I have another one...this should probably be the last one but not sure if you can use a table (chart) with scripts.  I am no expert at writing scripts so I am hoping someone can help me with this one.

       

      I have a field called R_CAL and this seems more complicated to calculate because it relies on 3 important fields that the user must provide (TERM, FIRSTERM and DateWithdrawal).

       

      The formula to determine R_CAL (which is a dollar figure) is:

       

      R_CAL = 3831.67 - z (T_CAL + 397.67)

       

       

      This is calculated based on several criterias:

       

      If FIRSTTERM = "Y", TERM = "Fall Term", and DateWithdrawal (d/m/yyyy) is

       

      DateWithdrawal                Percent (z)

      ===========                ========

      9/23/2010                        0.0

      9/24/2010 - 9/29/2010       0.1

      9/30/2010 - 10/6/2010       0.2

      10/7/2010 - 10/13/2010     0.3

      10/14/2010 - 10/20/2010   0.4

      10/21/2010 - 10/27/2010   0.5

      10/28/2010 - 11/3/2010     0.6

      >= 11/4/2010                   1.0

       

      or

       

      If FIRSTTERM = "Y", TERM = "Winter Term", and DateWithdrawal (d/m/yyyy) is

       

      DateWithdrawal                Percent (z)

      ===========                ========

      1/4/2011                          0.0

      1/5/2011 - 1/10/2011        0.1

      1/11/2011 - 1/17/2011      0.2

      1/18/2011 - 1/24/2011      0.3

      1/25/2011 - 1/31/2011      0.4

      2/1/2011 - 2/7/2011          0.5

      2/8/2011 - 2/14/2011        0.6

      >= 2/15/2011                  1.0

       

      or

       

      If FIRSTTERM = "Y", TERM = "Spring Term", and DateWithdrawal (d/m/yyyy) is

       

      DateWithdrawal                Percent (z)

      ===========                ========

      3/28/2011                        0.0

      3/29/2011 - 4/3/2011        0.1

      4/4/2011 - 4/10/2011        0.2

      4/11/2011 - 4/17/2011      0.3

      4/18/2011 - 4/24/2011      0.4

      4/25/2011 - 5/1/2011        0.5

      5/2/2011 - 5/8/2011          0.6

      >= 5/9/2011                    1.0

       

      or

       

      If FIRSTTERM = "N", TERM = "Fall Term", and DateWithdrawal (d/m/yyyy) is

       

      DateWithdrawal                Percent (z)

      ===========                ========

      9/23/2010                        1.0

      9/24/2010 - 9/29/2010       0.9

      9/30/2010 - 10/10/2010     0.5

      10/11/2010 - 10/27/2010   0.25

      >=10/28/2010                  0.0

       

      or

       

      If FIRSTTERM = "N", TERM = "Winter Term", and DateWithdrawal (d/m/yyyy) is

       

      DateWithdrawal                Percent (z)

      ===========                ========

      1/4/2011                          1.0

      1/5/2011 - 1/10/2011        0.9

      1/11/2011 - 1/21/2011      0.5

      1/22/2011 - 2/7/2011        0.25

      >= 2/8/2011                    0.0

       

      or

       

      If FIRSTTERM = "N", TERM = "Spring Term", and DateWithdrawal (d/m/yyyy) is

       

      DateWithdrawal                Percent (z)

      ===========                ========

      3/28/2011                        1.0

      3/29/2011 - 4/3/2011        0.9

      4/4/2011 - 4/14/2011        0.5

      4/15/2011 - 5/1/2011        0.25

      >= 5/2/2011                    0.0

       

      But if FIRSTTERM = " " (or blank) or any of the other "TERM" and DateWithdrawal, then the value is zero

       

      Thanks!

      Gilbert

        • 1. Re: Need Help with a Complex Calculated Script
          maxwyss Level 4

          What you are kind of building up is a look-up-table for a set of withdrawal dates, which are themselves little look-up-tables.

           

          A look-up-table is represented in PDF/Acrobat as a (multidimensional) array. So, that's what we have to deal with. Not that difficult, but you may have to concentrate when developing it, and you may need to make notes. Chances to get confused do exist…

           

          The first thing to look at would be the withdrawal date tables. You have the beginning dates of various periods. You can convert them to "days since a reference date", which is provided by the Date object (milliseconds since a reference date, which you may divide by milliseconds per day to get smaller numbers). These numbers and the values for z form value pairs, and the whole set of these pairs can be looked at as an array.

           

          First Term and Term can also be represented as parts of an array, and on the form you might use checkboxes or combo boxes where the return values correspond to the index number of the selection in the array.

           

          The first dimension would be First Term, the second dimension would be Term. The value of the element [First Term][Term] would either be an index number of the z-look-up-tables or the tables themselves.

           

          And then you can look up what you need.

           

          HTH.

           

          Max Wyss.

          • 2. Re: Need Help with a Complex Calculated Script
            gsolorio Level 1

            Thanks Max for your response.

             

            Not sure how to begin because I do not know how to write scripts although some people have provided scripts for me, but nothing this complex.

            I will read it and see what it is.

             

            Thank you again!