Search code examples
jqueryjquery-calculation

Adding Sales Tax to Jquery Calculation Plugin


Hi I need some help implementing a simple sales tax calculation to a delivery price estimation form that uses the Jquery Calculation Plugin that I'm sure many have come acros: http://www.pengoworks.com/workshop/jquery/calculation/calculation.plugin.htm

Here's my current test page: http://jsfiddle.net/treigh/afk3C/4/

  $("#FirstHourRate, #HalfHourRate, [rel='eta']").keyup(recalc);

  function recalc() {

  $("#subtotal").calc(
  // the equation to use for the calculation
  "FirstHourRate + (eta-1)*2*HalfHourRate", {
      bind: "keyup",
    eta: $("[rel='eta']").sum(),
      FirstHourRate: $("#FirstHourRate"),
      HalfHourRate: $("#HalfHourRate")
  }, function(s) {
      // return the number as a dollar amount
      return "$" + s.toFixed(2);
  });
}

Currently I can generate a subtotal. but I'd like to also calculate a grandtotal that will essentially be a sum of the subtoal + a 13% tax on the subtotal.

Someone had a similar question here, but my issue is slightly different.

I'd appreciate any Help.

EDIT

With the great help of @Mohammad Adil, I managed to have almost everything to work. So far I can display the subtotal and the grand total, which includes a 13% sales tax. I also need to display the actual tax value after the subtotal as well as fuel charge to help the user distinguish the service charge from the any other surcharges and sales tax. In other words, the form should display a breakdown of the charges before displaying the Grand total. The output should look like this:

Subtotal = $amount(based on "FirstHourRate + (eta-1)*2*HalfHourRate" as seen in the equation)

Fuel = $amount

Sales tax = 0.13(subtotal + fuel) Total = subtotal + fuel + sales tax

I hope it makes some sense.


Solution

  • if you want to calculate the grandtotal (sum of the subtoal + a 13% tax on the subtotal) you can do that with simple math.

    Demo Fiddle

    Integrated with calculation plugin

    grandtotal = subtotal * 1.13 ;