7 Replies Latest reply on Sep 12, 2012 2:02 PM by LimeyBrant

    Qty Discount Calculation?

    LimeyBrant

      Hi everyone,

       

      I've created lots of Forms before, but this one is the most complicated.  It's an order form for bottles of vitamins and so far I have it working like this:

       

      User specifies a quantity (not hidden), then that gets multiplied by the hidden price fields -"A1000 Price" and that gets placed in another hidden "A1000 Subtotal" field.  Then all the Subtotal fields are summed to provide a grand total.

       

      This all works well.  Here's what it looks like:

       

      https://dl.dropbox.com/u/7102005/calcshot.png

       

      https://dl.dropbox.com/u/7102005/calcshot.png

       

      My difficulty come in that I need to make the subtotalling much more complicated, as if a user orders a certain amount of each kind of bottle, it should apply a discount to that line item.

       

      Our discounts are:

       

      0-12 Bottles  - No Discount

      12+  Bottles - 10%

      24+  Bottles - 15%

      36+  Bottles - 20%

       

      I think I have to use the javascript calc area?  I have no clue what I'm doing in there!

       

      Thanks for any insight,

      Brant

        • 1. Re: Qty Discount Calculation?
          try67 MVP & Adobe Community Professional

          Yes, you need to use JS for this. If the discount rates are consistent, I would place a function at the document level and then call it from the custom calculation code of each field. The function can be something like this:

           

          function calcPriceWithDiscount(priceFieldName, qtyFieldName) {

               var price = +this.getField(priceFieldName).value;

               var qty = +this.getField(qtyFieldName).value;

               var discount = 0;

               if (qty>36) discount = 20;

               else if (qty>24) discount = 15;

               else if (qty>12) discount = 10;

               event.value = (price*qty) * ((100-discount)/100);

          }

           

          You then call this function like so (using the field names in the screenshot, for example):

          calcPriceWithDiscount("A1005 Price", "A1005 Qty");

          • 2. Re: Qty Discount Calculation?
            LimeyBrant Level 1

            Wow!  Thanks a ton! I'm going to try this out right now!  I don't know where to put the document level function but I'll hunt around a bit. 

             

            Boy I wish there were a way to update all the subtotal fields incrementing the "A1005 Price", to 1006, 1007 etc.  Not hard work but takes a while to edit 80+ items.

             

            I'll be back to let you know how it goes...

             

            Thanks again!

            • 3. Re: Qty Discount Calculation?
              try67 MVP & Adobe Community Professional

              The location is based on your version of Acrobat... In Acrobat X it's under

              Tools - JavaScript - Document JavaScripts.

               

              Regarding automating applying the script to multiple fields, I think it

              will be possible (again, using a script), since your naming scheme seems

              quite consistent.

              • 4. Re: Qty Discount Calculation?
                LimeyBrant Level 1

                Thanks!

                 

                Yes, the naming is consistent mostly - with some outliers in there.  I'll just do it manually this time at least.  I'm trying to work but the iPhone announcment keeps distracting me! 

                • 5. Re: Qty Discount Calculation?
                  LimeyBrant Level 1

                  Hey,

                   

                  So I have it working, although it seems very weird about when it wants to update the totals.  It'll only update after you change a value in one of the other fields.  Do I need to add a "calculate now" button somewhere somehow?  As they fill in the qty for the last item they are ordering, even if they tab to the next field (which isnt likely), the total doesn't update.

                  • 6. Re: Qty Discount Calculation?
                    try67 MVP & Adobe Community Professional

                    You just need to make sure that the field calculation order is correct. The

                    totals need to appear last in the list.

                    • 7. Re: Qty Discount Calculation?
                      LimeyBrant Level 1

                      Works like a charm. Thanks again for all your help! Love it!